|
|
@ -10,6 +10,7 @@ use async_trait::async_trait;
|
|
|
|
use bromine::context::{PoolGuard, PooledContext};
|
|
|
|
use bromine::context::{PoolGuard, PooledContext};
|
|
|
|
use bromine::payload::BytePayload;
|
|
|
|
use bromine::payload::BytePayload;
|
|
|
|
use bromine::prelude::*;
|
|
|
|
use bromine::prelude::*;
|
|
|
|
|
|
|
|
use tokio::time::Duration;
|
|
|
|
|
|
|
|
|
|
|
|
pub struct FileApi {
|
|
|
|
pub struct FileApi {
|
|
|
|
ctx: PooledContext,
|
|
|
|
ctx: PooledContext,
|
|
|
@ -43,12 +44,12 @@ impl FileApi {
|
|
|
|
/// Returns all known files
|
|
|
|
/// Returns all known files
|
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
|
|
|
pub async fn all_files(&self) -> ApiResult<Vec<FileMetadataResponse>> {
|
|
|
|
pub async fn all_files(&self) -> ApiResult<Vec<FileMetadataResponse>> {
|
|
|
|
self.emit_and_get("all_files", ()).await
|
|
|
|
self.emit_and_get("all_files", (), Some(Duration::from_secs(30))).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns a file by identifier
|
|
|
|
/// Returns a file by identifier
|
|
|
|
pub async fn get_file(&self, id: FileIdentifier) -> ApiResult<FileMetadataResponse> {
|
|
|
|
pub async fn get_file(&self, id: FileIdentifier) -> ApiResult<FileMetadataResponse> {
|
|
|
|
self.emit_and_get("get_file", id).await
|
|
|
|
self.emit_and_get("get_file", id, Some(Duration::from_secs(2))).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Searches for a file by a list of tags
|
|
|
|
/// Searches for a file by a list of tags
|
|
|
@ -64,6 +65,7 @@ impl FileApi {
|
|
|
|
filters,
|
|
|
|
filters,
|
|
|
|
sort_expression,
|
|
|
|
sort_expression,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(Duration::from_secs(20))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,7 +74,7 @@ impl FileApi {
|
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
|
|
|
pub async fn read_file(&self, id: FileIdentifier) -> ApiResult<Vec<u8>> {
|
|
|
|
pub async fn read_file(&self, id: FileIdentifier) -> ApiResult<Vec<u8>> {
|
|
|
|
let payload: BytePayload = self
|
|
|
|
let payload: BytePayload = self
|
|
|
|
.emit_and_get("read_file", ReadFileRequest { id })
|
|
|
|
.emit_and_get("read_file", ReadFileRequest { id }, Some(Duration::from_secs(10)))
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(payload.into_inner())
|
|
|
|
Ok(payload.into_inner())
|
|
|
@ -84,7 +86,7 @@ impl FileApi {
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
id: FileIdentifier,
|
|
|
|
id: FileIdentifier,
|
|
|
|
) -> ApiResult<Vec<ThumbnailMetadataResponse>> {
|
|
|
|
) -> ApiResult<Vec<ThumbnailMetadataResponse>> {
|
|
|
|
self.emit_and_get("get_thumbnails", GetFileThumbnailsRequest { id })
|
|
|
|
self.emit_and_get("get_thumbnails", GetFileThumbnailsRequest { id }, Some(Duration::from_secs(2)))
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -104,6 +106,7 @@ impl FileApi {
|
|
|
|
min_size,
|
|
|
|
min_size,
|
|
|
|
max_size,
|
|
|
|
max_size,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Some(Duration::from_secs(2))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
let (metadata, bytes) = payload.into_inner();
|
|
|
|
let (metadata, bytes) = payload.into_inner();
|
|
|
@ -118,7 +121,7 @@ impl FileApi {
|
|
|
|
file_id: FileIdentifier,
|
|
|
|
file_id: FileIdentifier,
|
|
|
|
name: String,
|
|
|
|
name: String,
|
|
|
|
) -> ApiResult<FileMetadataResponse> {
|
|
|
|
) -> ApiResult<FileMetadataResponse> {
|
|
|
|
self.emit_and_get("update_file_name", UpdateFileNameRequest { file_id, name })
|
|
|
|
self.emit_and_get("update_file_name", UpdateFileNameRequest { file_id, name }, Some(Duration::from_secs(1)))
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +138,7 @@ impl FileApi {
|
|
|
|
BytePayload::new(bytes),
|
|
|
|
BytePayload::new(bytes),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
self.emit_and_get("add_file", payload).await
|
|
|
|
self.emit_and_get("add_file", payload, Some(Duration::from_secs(5))).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Deletes all thumbnails of a file to regenerate them when requested
|
|
|
|
/// Deletes all thumbnails of a file to regenerate them when requested
|
|
|
|