From 31d8c7d6fdf9f7170f643cca588826207b63b84e Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 6 Nov 2021 14:00:10 +0100 Subject: [PATCH] Implement api to change the name of a file Signed-off-by: trivernis --- mediarepo-daemon/Cargo.lock | 4 ++-- mediarepo-daemon/mediarepo-socket/Cargo.lock | 4 ++-- mediarepo-daemon/mediarepo-socket/Cargo.toml | 2 +- .../mediarepo-socket/src/namespaces/files.rs | 24 +++++++++++++++++-- .../mediarepo-socket/src/namespaces/tags.rs | 10 ++++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index 23adadc..ad66230 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -828,8 +828,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" -version = "0.3.0" -source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=6cd483a4a7d0a101f391b755b73fa253e70b4a29#6cd483a4a7d0a101f391b755b73fa253e70b4a29" +version = "0.4.1" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=b123e69d92dfd384d37b9005c8e261c69fddfcc5#b123e69d92dfd384d37b9005c8e261c69fddfcc5" dependencies = [ "chrono", "serde", diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.lock b/mediarepo-daemon/mediarepo-socket/Cargo.lock index 243e0e7..6a33607 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.lock +++ b/mediarepo-daemon/mediarepo-socket/Cargo.lock @@ -769,8 +769,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" -version = "0.3.0" -source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=6cd483a4a7d0a101f391b755b73fa253e70b4a29#6cd483a4a7d0a101f391b755b73fa253e70b4a29" +version = "0.4.1" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=b123e69d92dfd384d37b9005c8e261c69fddfcc5#b123e69d92dfd384d37b9005c8e261c69fddfcc5" dependencies = [ "chrono", "serde", diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.toml b/mediarepo-daemon/mediarepo-socket/Cargo.toml index 10fc4ec..d629b8f 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.toml +++ b/mediarepo-daemon/mediarepo-socket/Cargo.toml @@ -33,4 +33,4 @@ features = ["tokio-executor"] [dependencies.mediarepo-api] git = "https://github.com/Trivernis/mediarepo-api.git" -rev = "6cd483a4a7d0a101f391b755b73fa253e70b4a29" \ No newline at end of file +rev = "b123e69d92dfd384d37b9005c8e261c69fddfcc5" \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs index 3255507..fb6ffb4 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs @@ -3,7 +3,7 @@ use crate::utils::{file_by_identifier, get_repo_from_context}; use compare::Compare; use mediarepo_api::types::files::{ AddFileRequest, FileMetadataResponse, FindFilesByTagsRequest, GetFileThumbnailsRequest, - ReadFileRequest, SortDirection, SortKey, ThumbnailMetadataResponse, + ReadFileRequest, SortDirection, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest, }; use mediarepo_core::error::RepoError; use mediarepo_core::rmp_ipc::prelude::*; @@ -28,7 +28,8 @@ impl NamespaceProvider for FilesNamespace { "add_file" => Self::add_file, "read_file" => Self::read_file, "get_thumbnails" => Self::thumbnails, - "read_thumbnail" => Self::read_thumbnail + "read_thumbnail" => Self::read_thumbnail, + "update_file_name" => Self::update_file_name ); } } @@ -175,6 +176,25 @@ impl FilesNamespace { Ok(()) } + + /// Updates the name of a file + #[tracing::instrument(skip_all)] + async fn update_file_name(ctx: &Context, event: Event) -> IPCResult<()> { + let repo = get_repo_from_context(ctx).await; + let request = event.data::()?; + let mut file = file_by_identifier(request.file_id, &repo).await?; + file.set_name(request.name).await?; + ctx.emitter + .emit_response_to( + event.id(), + Self::name(), + "update_file_name", + FileMetadataResponse::from_model(file), + ) + .await?; + + Ok(()) + } } #[tracing::instrument(level = "trace", skip_all)] diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs index 7609339..b8e9922 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs @@ -103,8 +103,14 @@ impl TagsNamespace { let repo = get_repo_from_context(ctx).await; let request = event.data::()?; let file = file_by_identifier(request.file_id, &repo).await?; - file.add_tags(request.added_tags).await?; - file.remove_tags(request.removed_tags).await?; + + if !request.added_tags.is_empty() { + file.add_tags(request.added_tags).await?; + } + if !request.removed_tags.is_empty() { + file.remove_tags(request.removed_tags).await?; + } + let responses: Vec = file .tags() .await?