Update API types for new database schema

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 9fe670a648
commit 6085bed8de

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

@ -1,9 +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::{
AddFileRequestHeader, FileMetadataResponse, FileOSMetadata, FilterExpression, FindFilesRequest, AddFileRequestHeader, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata,
GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, SortKey, FilterExpression, FindFilesRequest, GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest,
ThumbnailMetadataResponse, UpdateFileNameRequest, ReadFileRequest, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest,
}; };
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use async_trait::async_trait; use async_trait::async_trait;
@ -42,22 +42,26 @@ 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<FileBasicDataResponse>> {
self.emit_and_get("all_files", ()).await self.emit_and_get("all_files", ()).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<FileBasicDataResponse> {
self.emit_and_get("get_file", id).await self.emit_and_get("get_file", id).await
} }
pub async fn get_file_metadata(&self, id: FileIdentifier) -> ApiResult<FileMetadataResponse> {
self.emit_and_get("get_file_metadata", id).await
}
/// Searches for a file by a list of tags /// Searches for a file by a list of tags
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub async fn find_files( pub async fn find_files(
&self, &self,
filters: Vec<FilterExpression>, filters: Vec<FilterExpression>,
sort_expression: Vec<SortKey>, sort_expression: Vec<SortKey>,
) -> ApiResult<Vec<FileMetadataResponse>> { ) -> ApiResult<Vec<FileBasicDataResponse>> {
self.emit_and_get( self.emit_and_get(
"find_files", "find_files",
FindFilesRequest { FindFilesRequest {
@ -129,7 +133,7 @@ impl FileApi {
metadata: FileOSMetadata, metadata: FileOSMetadata,
tags: Vec<String>, tags: Vec<String>,
bytes: Vec<u8>, bytes: Vec<u8>,
) -> ApiResult<FileMetadataResponse> { ) -> ApiResult<FileBasicDataResponse> {
let payload = TandemPayload::new( let payload = TandemPayload::new(
AddFileRequestHeader { metadata, tags }, AddFileRequestHeader { metadata, tags },
BytePayload::new(bytes), BytePayload::new(bytes),

@ -50,8 +50,8 @@ impl TagApi {
/// Returns a list of all tags that are assigned to the list of files /// Returns a list of all tags that are assigned to the list of files
#[tracing::instrument(level = "debug", skip_all)] #[tracing::instrument(level = "debug", skip_all)]
pub async fn get_tags_for_files(&self, hashes: Vec<String>) -> ApiResult<Vec<TagResponse>> { pub async fn get_tags_for_files(&self, hashes: Vec<i64>) -> ApiResult<Vec<TagResponse>> {
self.emit_and_get("tags_for_files", GetFilesTagsRequest { hashes }) self.emit_and_get("tags_for_files", GetFilesTagsRequest { ids: hashes })
.await .await
} }

@ -2,7 +2,8 @@ use crate::tauri_plugin::commands::{ApiAccess, BufferAccess};
use crate::tauri_plugin::error::PluginResult; use crate::tauri_plugin::error::PluginResult;
use crate::tauri_plugin::utils::system_time_to_naive_date_time; use crate::tauri_plugin::utils::system_time_to_naive_date_time;
use crate::types::files::{ use crate::types::files::{
FileMetadataResponse, FileOSMetadata, FilterExpression, SortKey, ThumbnailMetadataResponse, FileBasicDataResponse, FileMetadataResponse, FileOSMetadata, FilterExpression, SortKey,
ThumbnailMetadataResponse,
}; };
use crate::types::identifier::FileIdentifier; use crate::types::identifier::FileIdentifier;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -18,7 +19,7 @@ pub struct AddFileOptions {
} }
#[tauri::command] #[tauri::command]
pub async fn get_all_files(api_state: ApiAccess<'_>) -> PluginResult<Vec<FileMetadataResponse>> { pub async fn get_all_files(api_state: ApiAccess<'_>) -> PluginResult<Vec<FileBasicDataResponse>> {
let api = api_state.api().await?; let api = api_state.api().await?;
let all_files = api.file.all_files().await?; let all_files = api.file.all_files().await?;
@ -30,7 +31,7 @@ pub async fn add_local_file(
api_state: ApiAccess<'_>, api_state: ApiAccess<'_>,
metadata: FileOSMetadata, metadata: FileOSMetadata,
options: AddFileOptions, options: AddFileOptions,
) -> PluginResult<FileMetadataResponse> { ) -> PluginResult<FileBasicDataResponse> {
let api = api_state.api().await?; let api = api_state.api().await?;
let path = PathBuf::from(&metadata.path); let path = PathBuf::from(&metadata.path);
let mut tags = Vec::new(); let mut tags = Vec::new();
@ -66,7 +67,7 @@ pub async fn find_files(
filters: Vec<FilterExpression>, filters: Vec<FilterExpression>,
sort_by: Vec<SortKey>, sort_by: Vec<SortKey>,
api_state: ApiAccess<'_>, api_state: ApiAccess<'_>,
) -> PluginResult<Vec<FileMetadataResponse>> { ) -> PluginResult<Vec<FileBasicDataResponse>> {
let api = api_state.api().await?; let api = api_state.api().await?;
let files = api.file.find_files(filters, sort_by).await?; let files = api.file.find_files(filters, sort_by).await?;
@ -111,7 +112,7 @@ pub async fn read_file(
let api = api_state.api().await?; let api = api_state.api().await?;
let content = api let content = api
.file .file
.read_file(FileIdentifier::Hash(hash.clone())) .read_file(FileIdentifier::CID(hash.clone()))
.await?; .await?;
Ok(content) Ok(content)

@ -24,11 +24,11 @@ pub async fn get_tags_for_file(
#[tauri::command] #[tauri::command]
pub async fn get_tags_for_files( pub async fn get_tags_for_files(
hashes: Vec<String>, ids: Vec<i64>,
api_state: ApiAccess<'_>, api_state: ApiAccess<'_>,
) -> PluginResult<Vec<TagResponse>> { ) -> PluginResult<Vec<TagResponse>> {
let api = api_state.api().await?; let api = api_state.api().await?;
let tags = api.tag.get_tags_for_files(hashes).await?; let tags = api.tag.get_tags_for_files(ids).await?;
Ok(tags) Ok(tags)
} }

@ -69,12 +69,12 @@ async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Re
let api = api_state.api().await?; let api = api_state.api().await?;
let file = api let file = api
.file .file
.get_file(FileIdentifier::Hash(hash.to_string())) .get_file(FileIdentifier::CID(hash.to_string()))
.await?; .await?;
let mime = file.mime_type.unwrap_or("image/png".to_string()); let mime = file.mime_type;
let bytes = api let bytes = api
.file .file
.read_file(FileIdentifier::Hash(hash.to_string())) .read_file(FileIdentifier::CID(hash.to_string()))
.await?; .await?;
tracing::debug!("Received {} content bytes", bytes.len()); tracing::debug!("Received {} content bytes", bytes.len());
buf_state.add_entry(hash.to_string(), mime.clone(), bytes.clone()); buf_state.add_entry(hash.to_string(), mime.clone(), bytes.clone());
@ -121,7 +121,7 @@ async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Resu
let (thumb, bytes) = api let (thumb, bytes) = api
.file .file
.get_thumbnail_of_size( .get_thumbnail_of_size(
FileIdentifier::Hash(hash.to_string()), FileIdentifier::CID(hash.to_string()),
((height as f32 * 0.8) as u32, (width as f32 * 0.8) as u32), ((height as f32 * 0.8) as u32, (width as f32 * 0.8) as u32),
((height as f32 * 1.2) as u32, (width as f32 * 1.2) as u32), ((height as f32 * 1.2) as u32, (width as f32 * 1.2) as u32),
) )

@ -26,7 +26,7 @@ pub struct GetFileTagsRequest {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GetFilesTagsRequest { pub struct GetFilesTagsRequest {
pub hashes: Vec<String>, pub ids: Vec<i64>,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -74,13 +74,26 @@ pub enum SortDirection {
impl Eq for SortDirection {} impl Eq for SortDirection {}
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FileMetadataResponse { pub struct FileBasicDataResponse {
pub id: i64, pub id: i64,
pub status: FileStatus,
pub cid: String,
pub mime_type: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum FileStatus {
Imported,
Archived,
Deleted,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FileMetadataResponse {
pub file_id: i64,
pub name: Option<String>, pub name: Option<String>,
pub comment: Option<String>, pub comment: Option<String>,
pub hash: String,
pub file_type: u32, pub file_type: u32,
pub mime_type: Option<String>,
pub creation_time: NaiveDateTime, pub creation_time: NaiveDateTime,
pub change_time: NaiveDateTime, pub change_time: NaiveDateTime,
pub import_time: NaiveDateTime, pub import_time: NaiveDateTime,

@ -1,7 +1,7 @@
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum FileIdentifier { pub enum FileIdentifier {
ID(i64), ID(i64),
Hash(String), CID(String),
} }
Loading…
Cancel
Save