Implement api to change the name of a file

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 0d3fffe980
commit 31d8c7d6fd

@ -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",

@ -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",

@ -33,4 +33,4 @@ features = ["tokio-executor"]
[dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "6cd483a4a7d0a101f391b755b73fa253e70b4a29"
rev = "b123e69d92dfd384d37b9005c8e261c69fddfcc5"

@ -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::<UpdateFileNameRequest>()?;
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)]

@ -103,8 +103,14 @@ impl TagsNamespace {
let repo = get_repo_from_context(ctx).await;
let request = event.data::<ChangeFileTagsRequest>()?;
let file = file_by_identifier(request.file_id, &repo).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<TagResponse> = file
.tags()
.await?

Loading…
Cancel
Save