diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index c095862..b4dee04 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -216,23 +216,23 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "blake2b_simd" -version = "0.5.11" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", - "arrayvec 0.5.2", + "arrayvec 0.7.2", "constant_time_eq", ] [[package]] name = "blake2s_simd" -version = "0.5.11" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" +checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", - "arrayvec 0.5.2", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -255,15 +255,17 @@ 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" +name = "block-buffer" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +checksum = "03588e54c62ae6d763e2a80090d50353b785795361b4ff5b3bf0a5097fc31c0b" +dependencies = [ + "generic-array", +] [[package]] name = "bromine" @@ -407,9 +409,9 @@ dependencies = [ [[package]] name = "console-api" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f67643a7d716307ad10b3e3aef02826382acbe349a3e7605ac57556148bc87" +checksum = "cc347c19eb5b940f396ac155822caee6662f850d97306890ac3773ed76c90c5a" dependencies = [ "prost", "prost-types", @@ -462,6 +464,15 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -502,7 +513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", ] [[package]] @@ -513,17 +524,17 @@ checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", ] [[package]] name = "crossbeam-epoch" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762" +checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", "lazy_static", "memoffset", "scopeguard", @@ -531,12 +542,12 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b979d76c9fcb84dffc80a73f7290da0f83e4c95773494674cb44b76d13a7a110" +checksum = "4dd435b205a4842da59efd07628f921c096bc1cc0a156835b4fa0bcb9a19bcce" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", ] [[package]] @@ -552,14 +563,23 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" dependencies = [ "cfg-if 1.0.0", "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" +dependencies = [ + "generic-array", +] + [[package]] name = "data-encoding" version = "2.3.2" @@ -613,6 +633,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "digest" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" +dependencies = [ + "block-buffer 0.10.1", + "crypto-common", + "generic-array", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -1329,7 +1360,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" -version = "0.28.0" +version = "0.28.1" dependencies = [ "bromine", "chrono", @@ -1513,26 +1544,26 @@ dependencies = [ [[package]] name = "multihash" -version = "0.15.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e540106213dc639fe2b632a7d9e3525169ef081378a7c2da4457b84fec44c0" +checksum = "7392bffd88bc0c4f8297e36a777ab9f80b7127409c4a1acb8fee99c9f27addcd" dependencies = [ "blake2b_simd", "blake2s_simd", "blake3", - "digest", - "generic-array", + "core2", + "digest 0.10.1", "multihash-derive", - "sha2", + "sha2 0.10.1", "sha3", "unsigned-varint", ] [[package]] name = "multihash-derive" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" +checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -2048,7 +2079,7 @@ checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" dependencies = [ "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", "lazy_static", "num_cpus", ] @@ -2251,9 +2282,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fed7948b6c68acbb6e20c334f55ad635dc0f75506963de4464289fbd3b051ac" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -2264,9 +2295,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57321bf8bc2362081b2599912d2961fe899c0efadf1b4b2f8d48b3e253bb96c" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -2350,23 +2381,32 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha2" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.1", +] + [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" dependencies = [ - "block-buffer", - "digest", + "digest 0.10.1", "keccak", - "opaque-debug", ] [[package]] @@ -2460,7 +2500,7 @@ dependencies = [ "crc", "crossbeam-channel", "crossbeam-queue", - "crossbeam-utils 0.8.6", + "crossbeam-utils 0.8.7", "either", "flume", "futures-channel", @@ -2483,7 +2523,7 @@ dependencies = [ "rust_decimal", "serde 1.0.136", "serde_json", - "sha2", + "sha2 0.9.9", "smallvec", "sqlformat", "sqlx-rt", @@ -2507,7 +2547,7 @@ dependencies = [ "proc-macro2 1.0.36", "quote 1.0.15", "serde_json", - "sha2", + "sha2 0.9.9", "sqlx-core", "sqlx-rt", "syn 1.0.86", @@ -2921,9 +2961,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9" dependencies = [ "cfg-if 1.0.0", "log", @@ -2945,9 +2985,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" dependencies = [ "proc-macro2 1.0.36", "quote 1.0.15", @@ -2956,11 +2996,12 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" dependencies = [ "lazy_static", + "valuable", ] [[package]] @@ -2998,9 +3039,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" dependencies = [ "serde 1.0.136", "tracing-core", @@ -3008,9 +3049,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5312f325fe3588e277415f5a6cca1f4ccad0f248c4cd5a4bd33032d7286abc22" +checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" dependencies = [ "ansi_term", "lazy_static", @@ -3127,6 +3168,12 @@ dependencies = [ "serde 1.0.136", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/mediarepo-daemon/Cargo.toml b/mediarepo-daemon/Cargo.toml index f97dc99..b4fce69 100644 --- a/mediarepo-daemon/Cargo.toml +++ b/mediarepo-daemon/Cargo.toml @@ -16,17 +16,17 @@ name = "mediarepo-daemon" path = "src/main.rs" [dependencies] -tracing = "^0.1.29" -toml = "^0.5.8" -structopt ="^0.3.26" -glob = "^0.3.0" -tracing-flame = "^0.2.0" -tracing-appender = "^0.2.0" -tracing-log = "^0.1.2" -rolling-file = "^0.1.0" -num-integer = "^0.1.44" -console-subscriber = "^0.1.1" -log = "^0.4.14" +tracing = "0.1.30" +toml = "0.5.8" +structopt = "0.3.26" +glob = "0.3.0" +tracing-flame = "0.2.0" +tracing-appender = "0.2.0" +tracing-log = "0.1.2" +rolling-file = "0.1.0" +num-integer = "0.1.44" +console-subscriber = "0.1.1" +log = "0.4.14" [dependencies.mediarepo-core] path = "./mediarepo-core" @@ -42,9 +42,9 @@ version = "1.16.1" features = ["macros", "rt-multi-thread", "io-std", "io-util"] [dependencies.tracing-subscriber] -version="0.3.7" +version= "0.3.8" features = ["env-filter", "ansi", "json"] [features] default = ["ffmpeg"] -ffmpeg = ["mediarepo-core/ffmpeg", "mediarepo-logic/ffmpeg"] \ No newline at end of file +ffmpeg = ["mediarepo-core/ffmpeg", "mediarepo-logic/ffmpeg"] diff --git a/mediarepo-daemon/mediarepo-core/Cargo.toml b/mediarepo-daemon/mediarepo-core/Cargo.toml index 8960310..75034c6 100644 --- a/mediarepo-daemon/mediarepo-core/Cargo.toml +++ b/mediarepo-daemon/mediarepo-core/Cargo.toml @@ -7,39 +7,39 @@ workspace = ".." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -thiserror = "^1.0.30" -multihash = "^0.15.0" -multibase = "^0.9.1" -base64 = "^0.13.0" -toml = "^0.5.8" -serde = "^1.0.136" -typemap_rev = "^0.1.5" -futures = "^0.3.19" -itertools = "^0.10.3" -glob = "^0.3.0" -tracing = "^0.1.29" -data-encoding = "^2.3.2" -tokio-graceful-shutdown = "^0.4.3" +thiserror = "1.0.30" +multihash = "0.16.1" +multibase = "0.9.1" +base64 = "0.13.0" +toml = "0.5.8" +serde = "1.0.136" +typemap_rev = "0.1.5" +futures = "0.3.19" +itertools = "0.10.3" +glob = "0.3.0" +tracing = "0.1.30" +data-encoding = "2.3.2" +tokio-graceful-shutdown = "0.4.3" [dependencies.thumbnailer] -version = "^0.3" +version = "0.3.0" default-features = false [dependencies.sea-orm] -version = "^0.5.0" +version = "0.5.0" default-features = false [dependencies.sqlx] -version = "^0.5.10" +version = "0.5.10" default-features = false features = ["migrate"] [dependencies.tokio] -version = "^1.16.1" +version = "1.16.1" features = ["fs", "io-util", "io-std"] [dependencies.config] -version = "^0.11.0" +version = "0.11.0" features = ["toml"] [dependencies.mediarepo-api] @@ -48,4 +48,4 @@ features = ["bromine"] [features] default = [] -ffmpeg = ["thumbnailer/ffmpeg"] \ No newline at end of file +ffmpeg = ["thumbnailer/ffmpeg"] diff --git a/mediarepo-daemon/mediarepo-database/Cargo.toml b/mediarepo-daemon/mediarepo-database/Cargo.toml index 4a2e670..1e79ee4 100644 --- a/mediarepo-daemon/mediarepo-database/Cargo.toml +++ b/mediarepo-daemon/mediarepo-database/Cargo.toml @@ -7,17 +7,17 @@ workspace = ".." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -chrono = "^0.4.19" -tracing = "^0.1.29" +chrono = "0.4.19" +tracing = "0.1.30" [dependencies.mediarepo-core] path = "../mediarepo-core" [dependencies.sqlx] -version = "^0.5.10" +version = "0.5.10" features = ["migrate"] [dependencies.sea-orm] -version = "^0.5.0" +version = "0.5.0" features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros", "debug-print"] -default-features = false \ No newline at end of file +default-features = false diff --git a/mediarepo-daemon/mediarepo-logic/Cargo.toml b/mediarepo-daemon/mediarepo-logic/Cargo.toml index ca50233..08a02e6 100644 --- a/mediarepo-daemon/mediarepo-logic/Cargo.toml +++ b/mediarepo-daemon/mediarepo-logic/Cargo.toml @@ -7,13 +7,13 @@ workspace = ".." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -chrono = "^0.4.19" -typemap_rev = "^0.1.5" -serde = "^1.0.136" -mime_guess = "^2.0.3" -mime = "^0.3.16" -tracing = "^0.1.29" -async-trait = "^0.1.52" +chrono = "0.4.19" +typemap_rev = "0.1.5" +serde = "1.0.136" +mime_guess = "2.0.3" +mime = "0.3.16" +tracing = "0.1.30" +async-trait = "0.1.52" [dependencies.mediarepo-core] path = "../mediarepo-core" @@ -22,14 +22,14 @@ path = "../mediarepo-core" path = "../mediarepo-database" [dependencies.sea-orm] -version = "^0.5.0-rc.1" +version = "0.5.0" features = ["runtime-tokio-native-tls", "macros"] default-features = false [dependencies.tokio] -version = "^1.15.0" +version = "1.16.1" features = ["fs", "io-std", "io-util"] [features] -ffmpeg = ["mediarepo-core/ffmpeg"] \ No newline at end of file +ffmpeg = ["mediarepo-core/ffmpeg"] diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/sorting_preset.rs b/mediarepo-daemon/mediarepo-logic/src/dto/sorting_preset.rs index df413d7..f83eef4 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dto/sorting_preset.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dto/sorting_preset.rs @@ -23,6 +23,10 @@ impl SortingPresetDto { pub fn keys(&self) -> &Vec { &self.keys } + + pub fn into_keys(self) -> Vec { + self.keys + } } #[derive(Clone, Debug)] diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.toml b/mediarepo-daemon/mediarepo-socket/Cargo.toml index 2c56382..9f38030 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.toml +++ b/mediarepo-daemon/mediarepo-socket/Cargo.toml @@ -7,11 +7,11 @@ workspace = ".." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = "^1.0.136" -tracing = "^0.1.29" -compare = "^0.1.0" -port_check = "^0.1.5" -rayon = "^1.5.1" +serde = "1.0.136" +tracing = "0.1.30" +compare = "0.1.0" +port_check = "0.1.5" +rayon = "1.5.1" [dependencies.mediarepo-core] path = "../mediarepo-core" @@ -23,13 +23,13 @@ path = "../mediarepo-database" path = "../mediarepo-logic" [dependencies.tokio] -version = "^1.16.1" +version = "1.16.1" features = ["net"] [dependencies.chrono] -version = "^0.4.19" +version = "0.4.19" features = ["serde"] [dependencies.tracing-futures] -version = "^0.2.5" -features = ["tokio-executor"] \ No newline at end of file +version = "0.2.5" +features = ["tokio-executor"] diff --git a/mediarepo-daemon/mediarepo-socket/src/from_model.rs b/mediarepo-daemon/mediarepo-socket/src/from_model.rs index eeffd64..bf101e9 100644 --- a/mediarepo-daemon/mediarepo-socket/src/from_model.rs +++ b/mediarepo-daemon/mediarepo-socket/src/from_model.rs @@ -1,9 +1,13 @@ use mediarepo_core::mediarepo_api::types::files::{ FileBasicDataResponse, FileMetadataResponse, FileStatus, ThumbnailMetadataResponse, }; +use mediarepo_core::mediarepo_api::types::filtering::{ + SortDirection, SortKey, SortNamespace, SortingPreset, +}; use mediarepo_core::mediarepo_api::types::tags::{NamespaceResponse, TagResponse}; use mediarepo_logic::dto::{ - FileDto, FileMetadataDto, FileStatus as FileStatusModel, NamespaceDto, TagDto, ThumbnailDto, + FileDto, FileMetadataDto, FileStatus as FileStatusModel, KeyType, NamespaceDto, SortKeyDto, + SortingPresetDto, TagDto, ThumbnailDto, }; pub trait FromModel { @@ -73,3 +77,42 @@ impl FromModel for NamespaceResponse { } } } + +impl FromModel for SortingPreset { + fn from_model(model: SortingPresetDto) -> Self { + SortingPreset { + id: model.id(), + keys: model + .into_keys() + .into_iter() + .filter_map(map_sort_dto_to_key) + .collect(), + } + } +} + +fn map_sort_dto_to_key(dto: SortKeyDto) -> Option { + let direction = map_direction(dto.ascending()); + + match dto.key_type()? { + KeyType::Namespace => Some(SortKey::Namespace(SortNamespace { + name: dto.value()?.to_owned(), + direction, + })), + KeyType::FileName => Some(SortKey::FileName(direction)), + KeyType::FileSize => Some(SortKey::FileSize(direction)), + KeyType::FileImportedTime => Some(SortKey::FileImportedTime(direction)), + KeyType::FileCreatedTime => Some(SortKey::FileCreatedTime(direction)), + KeyType::FileChangeTime => Some(SortKey::FileChangeTime(direction)), + KeyType::FileType => Some(SortKey::FileType(direction)), + KeyType::NumTags => Some(SortKey::NumTags(direction)), + } +} + +fn map_direction(ascending: bool) -> SortDirection { + if ascending { + SortDirection::Ascending + } else { + SortDirection::Descending + } +} diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/mod.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/mod.rs index 3817972..164ad5f 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/mod.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/mod.rs @@ -3,6 +3,7 @@ use mediarepo_core::bromine::{namespace, namespace::Namespace, IPCBuilder}; pub mod files; pub mod jobs; +pub mod presets; pub mod repo; pub mod tags; @@ -12,4 +13,5 @@ pub fn build_namespaces(builder: IPCBuilder) .add_namespace(namespace!(tags::TagsNamespace)) .add_namespace(namespace!(repo::RepoNamespace)) .add_namespace(namespace!(jobs::JobsNamespace)) + .add_namespace(namespace!(presets::PresetsNamespace)) } diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/presets.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/presets.rs new file mode 100644 index 0000000..1e2ad3c --- /dev/null +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/presets.rs @@ -0,0 +1,116 @@ +use crate::from_model::FromModel; +use crate::utils::get_repo_from_context; +use mediarepo_core::bromine::prelude::*; +use mediarepo_core::mediarepo_api::types::filtering::{SortDirection, SortKey, SortingPreset}; +use mediarepo_logic::dao::DaoProvider; +use mediarepo_logic::dto::{AddSortKeyDto, AddSortingPresetDto, KeyType}; + +pub struct PresetsNamespace; + +impl NamespaceProvider for PresetsNamespace { + fn name() -> &'static str { + "presets" + } + + fn register(handler: &mut EventHandler) { + events!(handler, + "all_sorting_presets" => Self::all_sorting_presets, + "add_sorting_preset" => Self::add_sorting_preset, + "delete_sorting_preset" => Self::delete_sorting_preset + ); + } +} + +impl PresetsNamespace { + #[tracing::instrument(skip_all)] + pub async fn all_sorting_presets(ctx: &Context, _: Event) -> IPCResult<()> { + let repo = get_repo_from_context(ctx).await; + let sorting_presets: Vec = repo + .sorting_preset() + .all() + .await? + .into_iter() + .map(SortingPreset::from_model) + .collect(); + ctx.emit_to(Self::name(), "all_sorting_presets", sorting_presets) + .await?; + + Ok(()) + } + + #[tracing::instrument(skip_all)] + pub async fn add_sorting_preset(ctx: &Context, event: Event) -> IPCResult<()> { + let keys = event + .payload::>()? + .into_iter() + .map(sort_key_to_add_dto) + .collect(); + let repo = get_repo_from_context(ctx).await; + let preset = repo + .sorting_preset() + .add(AddSortingPresetDto { keys }) + .await?; + ctx.emit_to( + Self::name(), + "add_sorting_preset", + SortingPreset::from_model(preset), + ) + .await?; + + Ok(()) + } + + #[tracing::instrument(skip_all)] + pub async fn delete_sorting_preset(ctx: &Context, event: Event) -> IPCResult<()> { + let id = event.payload::()?; + let repo = get_repo_from_context(ctx).await; + repo.sorting_preset().delete(id).await?; + + Ok(()) + } +} + +fn sort_key_to_add_dto(key: SortKey) -> AddSortKeyDto { + match key { + SortKey::Namespace(namespace) => AddSortKeyDto { + ascending: namespace.direction == SortDirection::Ascending, + key_type: KeyType::Namespace, + value: Some(namespace.name), + }, + SortKey::FileName(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileName, + value: None, + }, + SortKey::FileSize(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileSize, + value: None, + }, + SortKey::FileImportedTime(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileImportedTime, + value: None, + }, + SortKey::FileCreatedTime(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileCreatedTime, + value: None, + }, + SortKey::FileChangeTime(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileChangeTime, + value: None, + }, + SortKey::FileType(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::FileType, + value: None, + }, + SortKey::NumTags(dir) => AddSortKeyDto { + ascending: dir == SortDirection::Ascending, + key_type: KeyType::NumTags, + value: None, + }, + } +}