From c19423a271b2d1590e9cc1c94265197ccd07277f Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 24 Oct 2021 13:39:17 +0200 Subject: [PATCH] Move commands to api crate Signed-off-by: trivernis --- mediarepo-ui/src-tauri/Cargo.lock | 860 +----------------- mediarepo-ui/src-tauri/Cargo.toml | 21 +- mediarepo-ui/src-tauri/src/commands/files.rs | 92 -- mediarepo-ui/src-tauri/src/commands/mod.rs | 41 - mediarepo-ui/src-tauri/src/commands/repo.rs | 104 --- mediarepo-ui/src-tauri/src/commands/tags.rs | 21 - mediarepo-ui/src-tauri/src/context.rs | 31 - mediarepo-ui/src-tauri/src/error.rs | 62 -- mediarepo-ui/src-tauri/src/ipc/files.rs | 0 mediarepo-ui/src-tauri/src/ipc/mod.rs | 51 -- mediarepo-ui/src-tauri/src/main.rs | 62 +- mediarepo-ui/src-tauri/src/settings.rs | 48 - mediarepo-ui/src/app/models/Thumbnail.ts | 2 +- .../src/app/pages/home/home.component.ts | 3 +- .../src/app/services/file/file.service.ts | 17 +- .../services/repository/repository.service.ts | 9 +- .../src/app/services/tag/tag.service.ts | 2 +- 17 files changed, 81 insertions(+), 1345 deletions(-) delete mode 100644 mediarepo-ui/src-tauri/src/commands/files.rs delete mode 100644 mediarepo-ui/src-tauri/src/commands/mod.rs delete mode 100644 mediarepo-ui/src-tauri/src/commands/repo.rs delete mode 100644 mediarepo-ui/src-tauri/src/commands/tags.rs delete mode 100644 mediarepo-ui/src-tauri/src/context.rs delete mode 100644 mediarepo-ui/src-tauri/src/error.rs delete mode 100644 mediarepo-ui/src-tauri/src/ipc/files.rs delete mode 100644 mediarepo-ui/src-tauri/src/ipc/mod.rs delete mode 100644 mediarepo-ui/src-tauri/src/settings.rs diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index 700e015..6097b35 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -14,17 +14,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" -[[package]] -name = "ahash" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" -dependencies = [ - "getrandom 0.2.3", - "once_cell", - "version_check", -] - [[package]] name = "aho-corasick" version = "0.7.18" @@ -53,16 +42,13 @@ checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" name = "app" version = "0.1.0" dependencies = [ - "directories", - "mediarepo", - "rmp-ipc", + "mediarepo-api", "serde", "serde_json", "tauri", "tauri-build", "thiserror", - "tokio", - "toml", + "tracing-subscriber 0.3.0", "typemap_rev", ] @@ -103,27 +89,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "async-stream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.51" @@ -159,15 +124,6 @@ dependencies = [ "system-deps 3.2.0", ] -[[package]] -name = "atoi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" -dependencies = [ - "num-traits", -] - [[package]] name = "attohttpc" version = "0.17.0" @@ -192,25 +148,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "bae" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec107f431ee3d8a8e45e6dd117adab769556ef463959e77bf6a4888d5fd500cf" -dependencies = [ - "heck", - "proc-macro-error 0.4.12", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "base-x" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" - [[package]] name = "base64" version = "0.13.0" @@ -243,17 +180,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "blake2s_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "constant_time_eq", -] - [[package]] name = "blake3" version = "1.0.0" @@ -275,22 +201,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "block-padding", - "generic-array", -] - -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bstr" version = "0.2.17" @@ -306,12 +216,6 @@ version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" -[[package]] -name = "bytemuck" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" - [[package]] name = "byteorder" version = "1.4.3" @@ -466,12 +370,6 @@ dependencies = [ "objc", ] -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - [[package]] name = "com" version = "0.2.0" @@ -612,30 +510,6 @@ dependencies = [ "objc", ] -[[package]] -name = "cpufeatures" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" -dependencies = [ - "libc", -] - -[[package]] -name = "crc" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10c2722795460108a7872e1cd933a85d6ec38abc4baecad51028f702da28889f" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" - [[package]] name = "crc32fast" version = "1.2.1" @@ -679,16 +553,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" -dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.5" @@ -761,32 +625,6 @@ dependencies = [ "syn", ] -[[package]] -name = "data-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" - -[[package]] -name = "data-encoding-macro" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" -dependencies = [ - "data-encoding", - "data-encoding-macro-internal", -] - -[[package]] -name = "data-encoding-macro-internal" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" -dependencies = [ - "data-encoding", - "syn", -] - [[package]] name = "deflate" version = "0.7.20" @@ -898,12 +736,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" -[[package]] -name = "dotenv" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" - [[package]] name = "dtoa" version = "0.4.8" @@ -1078,17 +910,6 @@ dependencies = [ "futures-util", ] -[[package]] -name = "futures-intrusive" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot", -] - [[package]] name = "futures-io" version = "0.3.17" @@ -1268,16 +1089,6 @@ dependencies = [ "wasi 0.10.0+wasi-snapshot-preview1", ] -[[package]] -name = "gif" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b" -dependencies = [ - "color_quant", - "weezl", -] - [[package]] name = "gio" version = "0.14.8" @@ -1349,7 +1160,7 @@ dependencies = [ "anyhow", "heck", "proc-macro-crate 1.1.0", - "proc-macro-error 1.0.4", + "proc-macro-error", "proc-macro2", "quote", "syn", @@ -1460,30 +1271,12 @@ dependencies = [ "anyhow", "heck", "proc-macro-crate 1.1.0", - "proc-macro-error 1.0.4", + "proc-macro-error", "proc-macro2", "quote", "syn", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashlink" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" -dependencies = [ - "hashbrown", -] - [[package]] name = "heck" version = "0.3.3" @@ -1502,12 +1295,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "html5ever" version = "0.25.1" @@ -1584,35 +1371,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "image" -version = "0.23.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "gif", - "jpeg-decoder", - "num-iter", - "num-rational", - "num-traits", - "png 0.16.8", - "scoped_threadpool", - "tiff", -] - -[[package]] -name = "indexmap" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "infer" version = "0.4.0" @@ -1689,15 +1447,6 @@ dependencies = [ "libc", ] -[[package]] -name = "jpeg-decoder" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" -dependencies = [ - "rayon", -] - [[package]] name = "js-sys" version = "0.3.55" @@ -1707,12 +1456,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "keccak" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" - [[package]] name = "kuchiki" version = "0.8.1" @@ -1737,17 +1480,6 @@ version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" -[[package]] -name = "libsqlite3-sys" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "lock_api" version = "0.4.5" @@ -1778,7 +1510,7 @@ dependencies = [ "serde", "serde_json", "tracing", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -1831,6 +1563,15 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.9" @@ -1838,73 +1579,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] -name = "mediarepo" -version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=ce93a5793348a05052b324562730d97f5c6e2128#ce93a5793348a05052b324562730d97f5c6e2128" -dependencies = [ - "log", - "mediarepo-core", - "mediarepo-socket", - "tokio", -] - -[[package]] -name = "mediarepo-core" +name = "mediarepo-api" version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=ce93a5793348a05052b324562730d97f5c6e2128#ce93a5793348a05052b324562730d97f5c6e2128" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=2b6a968e6d5343326e20c73f4fcbbb88848b0c35#2b6a968e6d5343326e20c73f4fcbbb88848b0c35" dependencies = [ - "base64", - "futures", - "image", - "multibase", - "multihash", + "async-trait", + "chrono", + "directories", + "parking_lot", "rmp-ipc", - "sea-orm", "serde", - "sqlx", + "serde_json", + "tauri", "thiserror", "tokio", "toml", - "typemap_rev", -] - -[[package]] -name = "mediarepo-database" -version = "0.2.0" -source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=ce93a5793348a05052b324562730d97f5c6e2128#ce93a5793348a05052b324562730d97f5c6e2128" -dependencies = [ - "chrono", - "mediarepo-core", - "sea-orm", - "sqlx", -] - -[[package]] -name = "mediarepo-model" -version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=ce93a5793348a05052b324562730d97f5c6e2128#ce93a5793348a05052b324562730d97f5c6e2128" -dependencies = [ - "chrono", - "mediarepo-core", - "mediarepo-database", - "mime", - "mime_guess", - "sea-orm", - "serde", - "tokio", - "typemap_rev", -] - -[[package]] -name = "mediarepo-socket" -version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-daemon?rev=ce93a5793348a05052b324562730d97f5c6e2128#ce93a5793348a05052b324562730d97f5c6e2128" -dependencies = [ - "chrono", - "mediarepo-core", - "mediarepo-model", - "serde", - "tokio", + "tracing", ] [[package]] @@ -1922,28 +1612,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "minimal-lexical" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c64630dcdd71f1a64c435f54885086a0de5d6a12d104d69b165fb7d5286d677" - [[package]] name = "minisign-verify" version = "0.1.8" @@ -1992,52 +1660,10 @@ dependencies = [ ] [[package]] -name = "multibase" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" -dependencies = [ - "base-x", - "data-encoding", - "data-encoding-macro", -] - -[[package]] -name = "multihash" -version = "0.15.0" +name = "native-tls" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e540106213dc639fe2b632a7d9e3525169ef081378a7c2da4457b84fec44c0" -dependencies = [ - "blake2b_simd", - "blake2s_simd", - "blake3", - "digest", - "generic-array", - "multihash-derive", - "sha2", - "sha3", - "unsigned-varint", -] - -[[package]] -name = "multihash-derive" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" -dependencies = [ - "proc-macro-crate 1.1.0", - "proc-macro-error 1.0.4", - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "native-tls" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" dependencies = [ "lazy_static", "libc", @@ -2132,17 +1758,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[package]] -name = "nom" -version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" -dependencies = [ - "memchr", - "minimal-lexical", - "version_check", -] - [[package]] name = "notify-rust" version = "4.5.4" @@ -2166,17 +1781,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-bigint" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-integer" version = "0.1.44" @@ -2198,17 +1802,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-rational" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.14" @@ -2285,12 +1878,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "open" version = "2.0.1" @@ -2616,45 +2203,19 @@ dependencies = [ "toml", ] -[[package]] -name = "proc-macro-error" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" -dependencies = [ - "proc-macro-error-attr 0.4.12", - "proc-macro2", - "quote", - "syn", - "version_check", -] - [[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "proc-macro-error-attr 1.0.4", + "proc-macro-error-attr", "proc-macro2", "quote", "syn", "version_check", ] -[[package]] -name = "proc-macro-error-attr" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "syn-mid", - "version_check", -] - [[package]] name = "proc-macro-error-attr" version = "1.0.4" @@ -2927,16 +2488,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -2963,17 +2524,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "rust_decimal" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f1028de22e436bb35fce070310ee57d57b5e59ae77b4e3f24ce4773312b813" -dependencies = [ - "arrayvec 0.5.2", - "num-traits", - "serde", -] - [[package]] name = "rustc_version" version = "0.3.3" @@ -3020,100 +2570,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" -[[package]] -name = "scoped_threadpool" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" - [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "sea-orm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c5c7f0848ed7ddb2b3956abc84d5167dd33bb34c43e3b69172f565ca657a11" -dependencies = [ - "async-stream", - "async-trait", - "chrono", - "futures", - "futures-util", - "rust_decimal", - "sea-orm-macros", - "sea-query", - "sea-strum", - "serde", - "serde_json", - "sqlx", - "uuid", -] - -[[package]] -name = "sea-orm-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9466819cb0878e7fb6f6a1d7e46471a93b7121fef39db82f5799127884e39534" -dependencies = [ - "bae", - "convert_case", - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sea-query" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db6d690760e4f48663f0ecd9d91b03c1e6a5b17991d1c53043c5f07ba7db29" -dependencies = [ - "chrono", - "rust_decimal", - "sea-query-derive", - "serde_json", - "uuid", -] - -[[package]] -name = "sea-query-derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cdc022b4f606353fe5dc85b09713a04e433323b70163e81513b141c6ae6eb5" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", - "thiserror", -] - -[[package]] -name = "sea-strum" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c77c6c6c8b3950fccb65edd5d04985b5377f4c8f669cb9a215553f0369ec001" -dependencies = [ - "sea-strum_macros", -] - -[[package]] -name = "sea-strum_macros" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51c247af6c2c4ffd372fe97e9afa579b4438e4c306c9aa3f11cbf72f1e845180" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "security-framework" version = "2.4.2" @@ -3207,7 +2669,6 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ - "indexmap", "itoa", "ryu", "serde", @@ -3246,31 +2707,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "sha2" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" -dependencies = [ - "block-buffer", - "cfg-if 1.0.0", - "cpufeatures", - "digest", - "opaque-debug", -] - -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer", - "digest", - "keccak", - "opaque-debug", -] - [[package]] name = "sharded-slab" version = "0.1.3" @@ -3333,107 +2769,6 @@ dependencies = [ "system-deps 1.3.2", ] -[[package]] -name = "sqlformat" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" -dependencies = [ - "itertools", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7911b0031a0247af40095838002999c7a52fba29d9739e93326e71a5a1bc9d43" -dependencies = [ - "sqlx-core", - "sqlx-macros", -] - -[[package]] -name = "sqlx-core" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aec89bfaca8f7737439bad16d52b07f1ccd0730520d3bf6ae9d069fe4b641fb1" -dependencies = [ - "ahash", - "atoi", - "bitflags", - "byteorder", - "bytes", - "chrono", - "crc", - "crossbeam-channel", - "crossbeam-queue", - "crossbeam-utils", - "either", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-util", - "hashlink", - "hex", - "indexmap", - "itoa", - "libc", - "libsqlite3-sys", - "log", - "memchr", - "num-bigint", - "once_cell", - "parking_lot", - "percent-encoding", - "rust_decimal", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlformat", - "sqlx-rt", - "stringprep", - "thiserror", - "tokio-stream", - "url", - "uuid", - "whoami", -] - -[[package]] -name = "sqlx-macros" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584866c833511b1a152e87a7ee20dee2739746f60c858b3c5209150bc4b466f5" -dependencies = [ - "dotenv", - "either", - "heck", - "once_cell", - "proc-macro2", - "quote", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-rt", - "syn", - "url", -] - -[[package]] -name = "sqlx-rt" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d1bd069de53442e7a320f525a6d4deb8bb0621ac7a55f7eccbc2b58b57f43d0" -dependencies = [ - "native-tls", - "once_cell", - "tokio", - "tokio-native-tls", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -3480,16 +2815,6 @@ dependencies = [ "quote", ] -[[package]] -name = "stringprep" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "strsim" version = "0.9.3" @@ -3546,29 +2871,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa8e7560a164edb1621a55d18a0c59abf49d360f47aa7b821061dd7eea7fac9" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - [[package]] name = "system-deps" version = "1.3.2" @@ -3859,17 +3161,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tiff" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" -dependencies = [ - "jpeg-decoder", - "miniz_oxide 0.4.4", - "weezl", -] - [[package]] name = "time" version = "0.1.44" @@ -3909,42 +3200,9 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "tokio-macros", "winapi", ] -[[package]] -name = "tokio-macros" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-stream" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.5.8" @@ -4016,7 +3274,7 @@ dependencies = [ "ansi_term", "chrono", "lazy_static", - "matchers", + "matchers 0.0.1", "regex", "serde", "serde_json", @@ -4029,6 +3287,24 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cf865b5ddc38e503a29c41c4843e616a73028ae18c637bc3eb2afaef4909c84" +dependencies = [ + "ansi_term", + "lazy_static", + "matchers 0.1.0", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "typemap_rev" version = "0.1.5" @@ -4047,15 +3323,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.7" @@ -4083,18 +3350,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - -[[package]] -name = "unsigned-varint" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f8d425fafb8cd76bc3f22aace4af471d3156301d7508f2107e98fbeae10bc7f" - [[package]] name = "url" version = "2.2.2" @@ -4121,7 +3376,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ "getrandom 0.2.3", - "serde", ] [[package]] @@ -4328,12 +3582,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "weezl" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e" - [[package]] name = "wepoll-ffi" version = "0.1.2" @@ -4343,16 +3591,6 @@ dependencies = [ "cc", ] -[[package]] -name = "whoami" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "483a59fee1a93fec90eb08bc2eb4315ef10f4ebc478b3a5fadc969819cb66117" -dependencies = [ - "wasm-bindgen", - "web-sys", -] - [[package]] name = "widestring" version = "0.4.3" diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index b3c07c8..30c2c17 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -18,21 +18,20 @@ tauri-build = { version = "1.0.0-beta.4" } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.0.0-beta.8", features = ["api-all"] } -rmp-ipc = "0.7.0" thiserror = "1.0.30" -directories = "4.0.1" -toml = "0.5.8" typemap_rev = "0.1.5" -[dependencies.tokio] -version = "1.12.0" -features = ["fs", "io-std", "io-util"] -[dependencies.mediarepo] -git = "https://github.com/Trivernis/mediarepo-daemon" -rev = "ce93a5793348a05052b324562730d97f5c6e2128" -features = ["library"] -default-features=false + + +[dependencies.tracing-subscriber] +version = "0.3.0" +features = ["env-filter"] + +[dependencies.mediarepo-api] +git = "https://github.com/Trivernis/mediarepo-api.git" +rev = "2b6a968e6d5343326e20c73f4fcbbb88848b0c35" +features = ["tauri-plugin"] [features] default = [ "custom-protocol" ] diff --git a/mediarepo-ui/src-tauri/src/commands/files.rs b/mediarepo-ui/src-tauri/src/commands/files.rs deleted file mode 100644 index 877ff10..0000000 --- a/mediarepo-ui/src-tauri/src/commands/files.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::commands::{add_once_buffer, get_ipc}; -use mediarepo::requests::{FindFilesByTagsRequest, GetFileThumbnailsRequest, ReadFileRequest}; -use mediarepo::responses::{FileResponse, ThumbnailResponse}; - -use crate::context::Context; -use crate::error::AppResult; - -#[tauri::command] -pub async fn get_all_files(context: tauri::State<'_, Context>) -> AppResult> { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to("files", "all_files", ()) - .await? - .await_reply(&ipc) - .await?; - - Ok(response.data::>()?) -} - -#[tauri::command] -pub async fn find_files( - tags: Vec, - context: tauri::State<'_, Context>, -) -> AppResult> { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to("files", "find_files", FindFilesByTagsRequest { tags }) - .await? - .await_reply(&ipc) - .await?; - Ok(response.data::>()?) -} - -#[tauri::command] -pub async fn read_file_by_hash( - hash: String, - mime: String, - context: tauri::State<'_, Context>, -) -> AppResult { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to("files", "read_file", ReadFileRequest::Hash(hash.clone())) - .await? - .await_reply(&ipc) - .await?; - let raw_data = response.data_raw().to_vec(); - let uri = add_once_buffer(&context, hash, mime, raw_data); - - Ok(uri) -} - -#[tauri::command] -pub async fn get_thumbnails( - hash: String, - context: tauri::State<'_, Context>, -) -> AppResult> { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to( - "files", - "get_thumbnails", - GetFileThumbnailsRequest::Hash(hash), - ) - .await? - .await_reply(&ipc) - .await?; - - Ok(response.data::>()?) -} - -#[tauri::command] -pub async fn read_thumbnail( - hash: String, - mime: String, - context: tauri::State<'_, Context>, -) -> AppResult { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to("files", "read_thumbnail", hash.clone()) - .await? - .await_reply(&ipc) - .await?; - let raw_data = response.data_raw().to_vec(); - let uri = add_once_buffer(&context, hash, mime, raw_data); - - Ok(uri) -} diff --git a/mediarepo-ui/src-tauri/src/commands/mod.rs b/mediarepo-ui/src-tauri/src/commands/mod.rs deleted file mode 100644 index 91aa347..0000000 --- a/mediarepo-ui/src-tauri/src/commands/mod.rs +++ /dev/null @@ -1,41 +0,0 @@ -use rmp_ipc::ipc::context::Context as IPCContext; - -use crate::context::{Context, OnceBuffer}; -use crate::error::{AppError, AppResult}; - -pub mod files; -pub mod repo; -pub mod tags; - -#[tauri::command] -pub async fn emit_info(context: tauri::State<'_, Context>) -> AppResult<()> { - let ipc = context.ipc.read().await; - if let Some(ipc) = &*ipc { - ipc.emitter.emit("info", ()).await?; - println!("Emitted info event."); - } else { - println!("No IPC Context"); - } - - Ok(()) -} - -pub async fn get_ipc(context: &tauri::State<'_, Context>) -> AppResult { - let ipc = context.ipc.read().await; - (ipc.clone()).ok_or(AppError::new("No ipc connection.")) -} - -/// Adds a once-buffer to the buffer store -pub fn add_once_buffer( - context: &tauri::State<'_, Context>, - key: String, - mime: String, - buf: Vec, -) -> String { - let uri = format!("once://{}", key); - let once_buffer = OnceBuffer { mime, buf }; - let mut once_buffers = context.once_buffers.lock().unwrap(); - once_buffers.insert(key, once_buffer); - - uri -} diff --git a/mediarepo-ui/src-tauri/src/commands/repo.rs b/mediarepo-ui/src-tauri/src/commands/repo.rs deleted file mode 100644 index 37ac99f..0000000 --- a/mediarepo-ui/src-tauri/src/commands/repo.rs +++ /dev/null @@ -1,104 +0,0 @@ -use crate::context::Context; -use crate::error::{AppError, AppResult}; -use crate::ipc::build_ipc_context; -use crate::settings::save_settings; -use rmp_ipc::ipc::context::Context as IPCContext; -use serde::{Deserialize, Serialize}; -use std::mem; -use std::path::PathBuf; -use tauri::Window; -use tokio::fs; - -static REPO_CONFIG_FILE: &str = "repo.toml"; - -#[derive(Serialize, Deserialize, Clone)] -pub struct Repository { - name: String, - path: Option, - address: String, -} - -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct RepoConfig { - pub listen_address: String, - pub database_path: String, - pub default_file_store: String, -} - -#[tauri::command] -pub async fn get_repositories(context: tauri::State<'_, Context>) -> AppResult> { - let settings = context.settings.read().await; - - Ok(settings.repositories.values().cloned().collect()) -} - -#[tauri::command] -pub async fn get_active_repository( - context: tauri::State<'_, Context>, -) -> AppResult> { - let repo = context.active_repository.read().await; - Ok(repo.clone()) -} - -#[tauri::command] -pub async fn add_repository( - name: String, - path: String, - context: tauri::State<'_, Context>, -) -> AppResult> { - let repo_path = path.clone(); - let path = PathBuf::from(path); - let RepoConfig { listen_address, .. } = read_repo_config(path.join(REPO_CONFIG_FILE)).await?; - - let repo = Repository { - name, - path: Some(repo_path), - address: listen_address, - }; - - let mut repositories = Vec::new(); - { - let mut settings = context.settings.write().await; - settings.repositories.insert(repo.name.clone(), repo); - save_settings(&settings)?; - repositories.append(&mut settings.repositories.values().cloned().collect()); - } - - Ok(repositories) -} - -#[tauri::command] -pub async fn select_repository( - window: Window, - name: String, - context: tauri::State<'_, Context>, -) -> AppResult<()> { - let settings = context.settings.read().await; - let repo = settings - .repositories - .get(&name) - .ok_or(AppError::new(format!("Repository '{}' not found", name)))?; - let ipc = connect(window, &repo.address).await?; - let mut ipc_ctx = context.ipc.write().await; - let old_ipc = mem::replace(&mut *ipc_ctx, Some(ipc)); - - if let Some(old_ctx) = old_ipc { - old_ctx.stop().await?; - } - let mut active_repo = context.active_repository.write().await; - *active_repo = Some(repo.clone()); - - Ok(()) -} - -async fn read_repo_config(path: PathBuf) -> AppResult { - let toml_str = fs::read_to_string(path).await?; - let config = toml::from_str(&toml_str)?; - - Ok(config) -} - -/// Connects to the IPC Server -async fn connect(window: Window, address: &str) -> AppResult { - build_ipc_context(window, address).await -} diff --git a/mediarepo-ui/src-tauri/src/commands/tags.rs b/mediarepo-ui/src-tauri/src/commands/tags.rs deleted file mode 100644 index 8d696ba..0000000 --- a/mediarepo-ui/src-tauri/src/commands/tags.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::commands::get_ipc; -use crate::context::Context; -use crate::error::AppResult; -use mediarepo::requests::FileIdentifier; -use mediarepo::responses::TagResponse; - -#[tauri::command] -pub async fn get_tags_for_file( - hash: String, - context: tauri::State<'_, Context>, -) -> AppResult> { - let ipc = get_ipc(&context).await?; - let response = ipc - .emitter - .emit_to("tags", "tags_for_file", FileIdentifier::Hash(hash)) - .await? - .await_reply(&ipc) - .await?; - - Ok(response.data::>()?) -} diff --git a/mediarepo-ui/src-tauri/src/context.rs b/mediarepo-ui/src-tauri/src/context.rs deleted file mode 100644 index 34ef383..0000000 --- a/mediarepo-ui/src-tauri/src/context.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::commands::repo::Repository; -use crate::settings::Settings; -use rmp_ipc::ipc::context::Context as IPCContext; -use std::collections::HashMap; -use std::sync::Arc; -use std::sync::Mutex as StdMutex; -use tokio::sync::RwLock; - -pub struct OnceBuffer { - pub mime: String, - pub buf: Vec, -} - -#[derive(Clone)] -pub struct Context { - pub active_repository: Arc>>, - pub ipc: Arc>>, - pub settings: Arc>, - pub once_buffers: Arc>>, -} - -impl Context { - pub fn new(settings: Settings) -> Self { - Self { - ipc: Arc::new(RwLock::new(None)), - active_repository: Arc::new(RwLock::new(None)), - settings: Arc::new(RwLock::new(settings)), - once_buffers: Arc::new(StdMutex::new(HashMap::new())), - } - } -} diff --git a/mediarepo-ui/src-tauri/src/error.rs b/mediarepo-ui/src-tauri/src/error.rs deleted file mode 100644 index cf00f76..0000000 --- a/mediarepo-ui/src-tauri/src/error.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::error::Error; -use std::fmt::{Display, Formatter}; -use serde::Serialize; - -pub type AppResult = Result; - -#[derive(Debug, Serialize)] -pub struct AppError { - message: String -} - -impl AppError { - pub fn new(msg: S) -> Self { - Self { - message: msg.to_string() - } - } -} - -impl Display for AppError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - self.message.fmt(f) - } -} - -impl Error for AppError {} - -impl From for AppError { - fn from(e: std::io::Error) -> Self { - Self::new(e) - } -} - -impl From for AppError { - fn from(e: toml::de::Error) -> Self { - Self::new(format!("Failed to deserialize toml: {:?}", e)) - } -} - -impl From for AppError { - fn from(e: toml::ser::Error) -> Self { - Self::new(format!("Failed to serialize to toml: {:?}", e)) - } -} - -impl From for AppError { - fn from(e: rmp_ipc::error::Error) -> Self { - Self::new(format!("Daemon Error: {:?}", e)) - } -} - -impl From for AppError { - fn from(e: tauri::Error) -> Self { - Self::new(format!("Tauri error: {:?}", e)) - } -} - -impl From for rmp_ipc::error::Error { - fn from(e: AppError) -> Self { - rmp_ipc::error::Error::Message(e.message) - } -} diff --git a/mediarepo-ui/src-tauri/src/ipc/files.rs b/mediarepo-ui/src-tauri/src/ipc/files.rs deleted file mode 100644 index e69de29..0000000 diff --git a/mediarepo-ui/src-tauri/src/ipc/mod.rs b/mediarepo-ui/src-tauri/src/ipc/mod.rs deleted file mode 100644 index 0ab5b7c..0000000 --- a/mediarepo-ui/src-tauri/src/ipc/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -mod files; - -use crate::error::AppResult; -use mediarepo::responses::InfoResponse; -use rmp_ipc::error::Result; -use rmp_ipc::error_event::{ErrorEventData, ERROR_EVENT_NAME}; -use rmp_ipc::event::Event; -use rmp_ipc::ipc::context::Context as IPCContext; -use rmp_ipc::IPCBuilder; -use tauri::Window; -use typemap_rev::TypeMapKey; - -pub struct WindowKey; - -impl TypeMapKey for WindowKey { - type Value = Window; -} - -pub async fn build_ipc_context(window: Window, address: &str) -> AppResult { - let ctx = IPCBuilder::new() - .address(address) - .insert::(window) - .on(ERROR_EVENT_NAME, |c, e| Box::pin(handle_error(c, e))) - .on("info", |c, e| Box::pin(handle_info(c, e))) - .build_client() - .await?; - - Ok(ctx) -} - -async fn handle_error(ctx: &IPCContext, event: Event) -> Result<()> { - let error_data = event.data::()?; - let data = ctx.data.read().await; - let window = data.get::().unwrap(); - window - .emit("error", error_data) - .expect("Failed to emit error event"); - - Ok(()) -} - -async fn handle_info(ctx: &IPCContext, event: Event) -> Result<()> { - let info_data = event.data::()?; - let data = ctx.data.read().await; - let window = data.get::().unwrap(); - window - .emit("info", info_data) - .expect("Failed to emit info event"); - - Ok(()) -} diff --git a/mediarepo-ui/src-tauri/src/main.rs b/mediarepo-ui/src-tauri/src/main.rs index 9ec99f2..0502136 100644 --- a/mediarepo-ui/src-tauri/src/main.rs +++ b/mediarepo-ui/src-tauri/src/main.rs @@ -3,61 +3,17 @@ windows_subsystem = "windows" )] -use crate::commands::emit_info; -use crate::commands::files::*; -use crate::commands::repo::{ - add_repository, get_active_repository, get_repositories, select_repository, -}; -use crate::commands::tags::*; -use crate::context::Context; -use crate::settings::load_settings; -use tauri::http::ResponseBuilder; -use tauri::Manager; - -mod commands; -pub mod context; -pub mod error; -mod ipc; -mod settings; +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::EnvFilter; fn main() { - let settings = load_settings().expect("Failed to load settings"); - let context = Context::new(settings); - - tauri::Builder::default() - .manage(context) - .register_uri_scheme_protocol("once", |app, request| { - let context = app.state::(); - let resource_key = request.uri().trim_start_matches("once://"); - let buffer = { - let mut buffers = context.once_buffers.lock().unwrap(); - buffers.remove(resource_key) - }; - if let Some(buffer) = buffer { - ResponseBuilder::new() - .mimetype(&buffer.mime) - .status(200) - .body(buffer.buf) - } else { - ResponseBuilder::new() - .mimetype("text/plain") - .status(404) - .body("Resource not found".as_bytes().to_vec()) - } - }) - .invoke_handler(tauri::generate_handler![ - get_repositories, - add_repository, - select_repository, - get_active_repository, - emit_info, - get_all_files, - read_file_by_hash, - get_thumbnails, - read_thumbnail, - get_tags_for_file, - find_files, - ]) + tracing_subscriber::fmt::SubscriberBuilder::default() + .with_env_filter(EnvFilter::from_default_env()) + .with_writer(std::io::stdout) + .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .compact() + .init(); + mediarepo_api::tauri_plugin::register_plugin(tauri::Builder::default()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/mediarepo-ui/src-tauri/src/settings.rs b/mediarepo-ui/src-tauri/src/settings.rs deleted file mode 100644 index 85eb7d4..0000000 --- a/mediarepo-ui/src-tauri/src/settings.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::collections::HashMap; -use serde::{Serialize, Deserialize}; -use crate::commands::repo::Repository; -use crate::error::AppResult; -use directories::ProjectDirs; -use std::fs; -use std::path::PathBuf; - -static SETTINGS_FILE: &str = "settings.toml"; - -#[derive(Default, Serialize, Deserialize)] -pub struct Settings { - pub repositories: HashMap, -} - -fn get_settings_path() -> PathBuf { - let dirs = ProjectDirs::from("com", "trivernis", "mediarepo").unwrap(); - let config_path = dirs.config_dir().to_path_buf(); - - config_path.join(SETTINGS_FILE) -} - -/// Writes the settings to the file -pub fn save_settings(settings: &Settings) -> AppResult<()> { - let settings_path = get_settings_path(); - let settings_string = toml::to_string(&settings)?; - fs::write(&settings_path, &settings_string.into_bytes())?; - - Ok(()) -} - -/// Loads the settings from the file -pub fn load_settings() -> AppResult { - let dirs = ProjectDirs::from("com", "trivernis", "mediarepo").unwrap(); - let config_path = dirs.config_dir().to_path_buf(); - if !config_path.exists() { - fs::create_dir_all(&config_path)?; - } - let settings_path = config_path.join(SETTINGS_FILE); - if !settings_path.exists() { - let settings = Settings::default(); - save_settings(&settings)?; - } - let config_str = fs::read_to_string(settings_path)?; - let settings = toml::from_str(&config_str)?; - - Ok(settings) -} diff --git a/mediarepo-ui/src/app/models/Thumbnail.ts b/mediarepo-ui/src/app/models/Thumbnail.ts index 8acbb90..18c7006 100644 --- a/mediarepo-ui/src/app/models/Thumbnail.ts +++ b/mediarepo-ui/src/app/models/Thumbnail.ts @@ -2,5 +2,5 @@ export type Thumbnail = { hash: string, height: number, width: number, - mime: string | undefined + mime_type: string | undefined } diff --git a/mediarepo-ui/src/app/pages/home/home.component.ts b/mediarepo-ui/src/app/pages/home/home.component.ts index 3a594c4..1b42431 100644 --- a/mediarepo-ui/src/app/pages/home/home.component.ts +++ b/mediarepo-ui/src/app/pages/home/home.component.ts @@ -98,8 +98,7 @@ export class HomeComponent implements OnInit { } private async openLightbox(file: File): Promise { - let url = await this.fileService.readFile(file.hash, - file.mime_type ?? "image/png"); + let url = await this.fileService.readFile(file); let albums = [ { diff --git a/mediarepo-ui/src/app/services/file/file.service.ts b/mediarepo-ui/src/app/services/file/file.service.ts index dd4d4a7..49f9bfd 100644 --- a/mediarepo-ui/src/app/services/file/file.service.ts +++ b/mediarepo-ui/src/app/services/file/file.service.ts @@ -17,31 +17,26 @@ export class FileService { } public async getFiles() { - let all_files = await invoke("get_all_files"); + let all_files = await invoke("plugin:mediarepo|get_all_files"); this.displayedFiles.next(all_files); } public async findFiles(tags: string[]) { - let files = await invoke("find_files", {tags}); + let files = await invoke("plugin:mediarepo|find_files", {tags}); this.displayedFiles.next(files); } - public async readFile(hash: string, mime: string): Promise { - const once_uri = await invoke("read_file_by_hash", {hash, mime}); + public async readFile(file: File): Promise { + const once_uri = await invoke("plugin:mediarepo|read_file_by_hash", {hash: file.hash, mimeType: file.mime_type}); return this.sanitizer.bypassSecurityTrustResourceUrl(once_uri); } public async readThumbnail(thumbnail: Thumbnail): Promise { - let once_uri = await invoke("read_thumbnail", {hash: thumbnail.hash, mime: thumbnail.mime}); + let once_uri = await invoke("plugin:mediarepo|read_thumbnail", {hash: thumbnail.hash, mimeType: thumbnail.mime_type }); return this.sanitizer.bypassSecurityTrustResourceUrl(once_uri); } public async getThumbnails(hash: string): Promise { - return await invoke("get_thumbnails", {hash}); - } - - createSafeObjectUrl(blob: Blob): SafeResourceUrl { - const url = URL?.createObjectURL(blob); - return this.sanitizer.bypassSecurityTrustResourceUrl(url); + return await invoke("plugin:mediarepo|get_file_thumbnails", {hash}); } } diff --git a/mediarepo-ui/src/app/services/repository/repository.service.ts b/mediarepo-ui/src/app/services/repository/repository.service.ts index e1b998c..e39f8af 100644 --- a/mediarepo-ui/src/app/services/repository/repository.service.ts +++ b/mediarepo-ui/src/app/services/repository/repository.service.ts @@ -25,21 +25,20 @@ export class RepositoryService { } public async loadRepositories() { - let active_repo = await invoke("get_active_repository"); + let active_repo = await invoke("plugin:mediarepo|get_active_repository"); this.selectedRepository.next(active_repo); - let repos = await invoke("get_repositories"); + let repos = await invoke("plugin:mediarepo|get_repositories"); this.repositories.next(repos); } public async setRepository(repo: Repository) { - await invoke("select_repository", {name: repo.name}); - await invoke("emit_info"); + await invoke("plugin:mediarepo|select_repository", {name: repo.name}); this.selectedRepository.next(repo); } public async addRepository(name: string, path: string) { - let repos = await invoke("add_repository", {name, path}); + let repos = await invoke("plugin:mediarepo|add_repository", {name, path}); this.repositories.next(repos); } } diff --git a/mediarepo-ui/src/app/services/tag/tag.service.ts b/mediarepo-ui/src/app/services/tag/tag.service.ts index 85f9046..4cb36e2 100644 --- a/mediarepo-ui/src/app/services/tag/tag.service.ts +++ b/mediarepo-ui/src/app/services/tag/tag.service.ts @@ -10,7 +10,7 @@ export class TagService { constructor() { } public async getTagsForFile(hash: string): Promise { - const tags = await invoke("get_tags_for_file", {hash}); + const tags = await invoke("plugin:mediarepo|get_tags_for_file", {hash}); return tags.map(t => new Tag(t.id, t.name, t.namespace)); } }