Implement api to get metadata on a single file

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

@ -855,8 +855,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.6.0" version = "0.7.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=ddebf4bf0c3e96ede64182ff52bd84f134acc33a#ddebf4bf0c3e96ede64182ff52bd84f134acc33a" source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=3275c328fa6ac362f71fc548301b7c7c70725ca8#3275c328fa6ac362f71fc548301b7c7c70725ca8"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

@ -796,8 +796,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.6.0" version = "0.7.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=ddebf4bf0c3e96ede64182ff52bd84f134acc33a#ddebf4bf0c3e96ede64182ff52bd84f134acc33a" source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=3275c328fa6ac362f71fc548301b7c7c70725ca8#3275c328fa6ac362f71fc548301b7c7c70725ca8"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

@ -34,4 +34,4 @@ features = ["tokio-executor"]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "ddebf4bf0c3e96ede64182ff52bd84f134acc33a" rev = "3275c328fa6ac362f71fc548301b7c7c70725ca8"

@ -6,6 +6,7 @@ use mediarepo_api::types::files::{
GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, SortDirection, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, SortDirection,
SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest,
}; };
use mediarepo_api::types::identifier::FileIdentifier;
use mediarepo_core::error::RepoError; use mediarepo_core::error::RepoError;
use mediarepo_core::itertools::Itertools; use mediarepo_core::itertools::Itertools;
use mediarepo_core::rmp_ipc::prelude::*; use mediarepo_core::rmp_ipc::prelude::*;
@ -27,6 +28,7 @@ impl NamespaceProvider for FilesNamespace {
fn register<S: AsyncProtocolStream>(handler: &mut EventHandler<S>) { fn register<S: AsyncProtocolStream>(handler: &mut EventHandler<S>) {
events!(handler, events!(handler,
"all_files" => Self::all_files, "all_files" => Self::all_files,
"get_file" => Self::get_file,
"find_files" => Self::find_files, "find_files" => Self::find_files,
"add_file" => Self::add_file, "add_file" => Self::add_file,
"read_file" => Self::read_file, "read_file" => Self::read_file,
@ -57,6 +59,20 @@ impl FilesNamespace {
Ok(()) Ok(())
} }
/// Returns a file by id
#[tracing::instrument(skip_all)]
async fn get_file<S: AsyncProtocolStream>(ctx: &Context<S>, event: Event) -> IPCResult<()> {
let id = event.data::<FileIdentifier>()?;
let repo = get_repo_from_context(ctx).await;
let file = file_by_identifier(id, &repo).await?;
let response = FileMetadataResponse::from_model(file);
ctx.emitter
.emit_response_to(event.id(), Self::name(), "get_file", response)
.await?;
Ok(())
}
/// Searches for files by tags /// Searches for files by tags
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn find_files<S: AsyncProtocolStream>(ctx: &Context<S>, event: Event) -> IPCResult<()> { async fn find_files<S: AsyncProtocolStream>(ctx: &Context<S>, event: Event) -> IPCResult<()> {

Loading…
Cancel
Save