Add api to update a files name

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent df2cbe94e0
commit b402fab697

@ -1,6 +1,6 @@
[package]
name = "mediarepo-api"
version = "0.3.0"
version = "0.4.0"
edition = "2018"
license = "gpl-3"

@ -2,7 +2,7 @@ use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi;
use crate::types::files::{
FileMetadataResponse, FindFilesByTagsRequest, GetFileThumbnailsRequest, ReadFileRequest,
SortKey, TagQuery, ThumbnailMetadataResponse,
SortKey, TagQuery, ThumbnailMetadataResponse, UpdateFileNameRequest,
};
use crate::types::identifier::FileIdentifier;
use async_trait::async_trait;
@ -81,4 +81,13 @@ impl FileApi {
let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?;
Ok(payload.to_payload_bytes()?)
}
/// Updates a files name
#[tracing::instrument(level = "debug", skip(self))]
pub async fn update_file_name(&self, file_id: FileIdentifier, name: String) -> ApiResult<()> {
self.emit("update_file_name", UpdateFileNameRequest { file_id, name })
.await?;
Ok(())
}
}

@ -70,3 +70,13 @@ pub async fn read_thumbnail(
Ok(uri)
}
}
#[tauri::command]
pub async fn update_file_name(api_state: ApiAccess<'_>, id: i64, name: String) -> PluginResult<()> {
let api = api_state.api().await?;
api.file
.update_file_name(FileIdentifier::ID(id), name)
.await?;
Ok(())
}

@ -50,7 +50,8 @@ impl<R: Runtime> MediarepoPlugin<R> {
check_local_repository_exists,
remove_repository,
change_file_tags,
create_tags
create_tags,
update_file_name
]),
}
}

@ -86,3 +86,9 @@ pub struct ThumbnailMetadataResponse {
pub width: i32,
pub mime_type: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UpdateFileNameRequest {
pub file_id: FileIdentifier,
pub name: String,
}

Loading…
Cancel
Save