Add api to request thumbnails of specific sizes

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

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

@ -1,8 +1,9 @@
use crate::client_api::error::ApiResult; use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi; use crate::client_api::IPCApi;
use crate::types::files::{ use crate::types::files::{
FileMetadataResponse, FindFilesByTagsRequest, GetFileThumbnailsRequest, ReadFileRequest, FileMetadataResponse, FindFilesByTagsRequest, GetFileThumbnailOfSizeRequest,
SortKey, TagQuery, ThumbnailMetadataResponse, UpdateFileNameRequest, GetFileThumbnailsRequest, ReadFileRequest, SortKey, TagQuery, ThumbnailFullResponse,
ThumbnailMetadataResponse, UpdateFileNameRequest,
}; };
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use async_trait::async_trait; use async_trait::async_trait;
@ -95,7 +96,30 @@ where
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub async fn read_thumbnail(&self, hash: String) -> ApiResult<Vec<u8>> { pub async fn read_thumbnail(&self, hash: String) -> ApiResult<Vec<u8>> {
let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?; let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?;
Ok(payload.to_payload_bytes()?) Ok(payload.into_inner())
}
/// Returns a thumbnail of size that is within the specified range
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_thumbnail_of_size(
&self,
file_id: FileIdentifier,
min_size: (u32, u32),
max_size: (u32, u32),
) -> ApiResult<(ThumbnailMetadataResponse, Vec<u8>)> {
let payload: ThumbnailFullResponse = self
.emit_and_get(
"get_thumbnail_of_size",
GetFileThumbnailOfSizeRequest {
id: file_id,
min_size,
max_size,
},
)
.await?;
let (metadata, bytes) = payload.into_inner();
Ok((metadata, bytes.into_inner()))
} }
/// Updates a files name /// Updates a files name

@ -35,10 +35,7 @@ pub trait IPCApi<S: AsyncProtocolStream> {
Ok(meta) Ok(meta)
} }
async fn emit_and_get< async fn emit_and_get<T: EventSendPayload + Debug + Send, R: EventReceivePayload + Send>(
T: EventSendPayload + Debug + Send,
R: EventReceivePayload + Debug + Send,
>(
&self, &self,
event_name: &str, event_name: &str,
data: T, data: T,

@ -1,5 +1,6 @@
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use rmp_ipc::payload::{BytePayload, TandemPayload};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -101,8 +102,4 @@ pub struct UpdateFileNameRequest {
pub name: String, pub name: String,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] pub type ThumbnailFullResponse = TandemPayload<ThumbnailMetadataResponse, BytePayload>;
pub struct ThumbnailFullResponse {
pub metadata: ThumbnailMetadataResponse,
pub data: Vec<u8>,
}

Loading…
Cancel
Save