From b0de5ab10a0daefb7b04c757ab283ed78679f8b1 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 15 Jan 2022 18:39:20 +0100 Subject: [PATCH] Add api to change the status of a file and delete it permanently Signed-off-by: trivernis --- mediarepo-api/Cargo.toml | 2 +- mediarepo-api/src/client_api/file.rs | 90 +++++++++++++++++----------- mediarepo-api/src/types/files.rs | 6 ++ 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/mediarepo-api/Cargo.toml b/mediarepo-api/Cargo.toml index 928d3cc..e350b59 100644 --- a/mediarepo-api/Cargo.toml +++ b/mediarepo-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mediarepo-api" -version = "0.26.0" +version = "0.27.0" edition = "2018" license = "gpl-3" diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index 1ef4a2f..b0fb29b 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -1,9 +1,9 @@ use crate::client_api::error::ApiResult; use crate::client_api::IPCApi; use crate::types::files::{ - AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, + AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, FileStatus, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, - ThumbnailMetadataResponse, UpdateFileNameRequest, + ThumbnailMetadataResponse, UpdateFileNameRequest, UpdateFileStatusRequest, }; use crate::types::filtering::{FilterExpression, FindFilesRequest, SortKey}; use crate::types::identifier::FileIdentifier; @@ -103,6 +103,60 @@ impl FileApi { Ok(payload.into_inner()) } + /// Adds a file with predefined tags + #[tracing::instrument(level = "debug", skip(self, bytes))] + pub async fn add_file( + &self, + metadata: FileOSMetadata, + tags: Vec, + bytes: Vec, + ) -> ApiResult { + let payload = TandemPayload::new( + AddFileRequestHeader { metadata, tags }, + BytePayload::new(bytes), + ); + + self.emit_and_get("add_file", payload, Some(Duration::from_secs(5))) + .await + } + + /// 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_and_get( + "update_file_name", + UpdateFileNameRequest { file_id, name }, + Some(Duration::from_secs(1)), + ) + .await + } + + /// Updates the status of a file + #[tracing::instrument(level = "debug", skip(self))] + pub async fn update_file_status( + &self, + file_id: FileIdentifier, + status: FileStatus, + ) -> ApiResult { + self.emit_and_get( + "update_file_status", + UpdateFileStatusRequest { status, file_id }, + Some(Duration::from_secs(1)), + ) + .await + } + + /// Permanently deletes a file from the disk and database + #[tracing::instrument(level = "debug", skip(self))] + pub async fn delete_file(&self, file_id: FileIdentifier) -> ApiResult<()> { + self.emit_and_get("delete_file", file_id, Some(Duration::from_secs(10))) + .await + } + /// Returns a list of all thumbnails of the file #[tracing::instrument(level = "debug", skip(self))] pub async fn get_file_thumbnails( @@ -141,38 +195,6 @@ impl FileApi { Ok((metadata.data(), bytes.into_inner())) } - /// 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_and_get( - "update_file_name", - UpdateFileNameRequest { file_id, name }, - Some(Duration::from_secs(1)), - ) - .await - } - - /// Adds a file with predefined tags - #[tracing::instrument(level = "debug", skip(self, bytes))] - pub async fn add_file( - &self, - metadata: FileOSMetadata, - tags: Vec, - bytes: Vec, - ) -> ApiResult { - let payload = TandemPayload::new( - AddFileRequestHeader { metadata, tags }, - BytePayload::new(bytes), - ); - - self.emit_and_get("add_file", payload, Some(Duration::from_secs(5))) - .await - } - /// Deletes all thumbnails of a file to regenerate them when requested #[tracing::instrument(level = "debug", skip(self))] pub async fn delete_thumbnails(&self, file_id: FileIdentifier) -> ApiResult<()> { diff --git a/mediarepo-api/src/types/files.rs b/mediarepo-api/src/types/files.rs index 7a67630..bb8146e 100644 --- a/mediarepo-api/src/types/files.rs +++ b/mediarepo-api/src/types/files.rs @@ -78,6 +78,12 @@ pub struct UpdateFileNameRequest { pub name: String, } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct UpdateFileStatusRequest { + pub file_id: FileIdentifier, + pub status: FileStatus, +} + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AddFileRequestHeader { pub metadata: FileOSMetadata,