Add api to change the status of a file and delete it permanently

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

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

@ -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<String>,
bytes: Vec<u8>,
) -> ApiResult<FileBasicDataResponse> {
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<FileMetadataResponse> {
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<FileBasicDataResponse> {
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<FileMetadataResponse> {
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<String>,
bytes: Vec<u8>,
) -> ApiResult<FileBasicDataResponse> {
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<()> {

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

Loading…
Cancel
Save