diff --git a/mediarepo-api/Cargo.toml b/mediarepo-api/Cargo.toml index 113ce18..4793bf5 100644 --- a/mediarepo-api/Cargo.toml +++ b/mediarepo-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mediarepo-api" -version = "0.7.0" +version = "0.8.0" edition = "2018" license = "gpl-3" diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index 27f7657..dba44f3 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -97,13 +97,6 @@ where .await } - /// Reads the thumbnail of the file and returns its contents in bytes - #[tracing::instrument(level = "debug", skip(self))] - pub async fn read_thumbnail(&self, hash: String) -> ApiResult> { - let payload: BytePayload = self.emit_and_get("read_thumbnail", hash).await?; - 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( diff --git a/mediarepo-api/src/tauri_plugin/commands/file.rs b/mediarepo-api/src/tauri_plugin/commands/file.rs index a075c96..0d4116c 100644 --- a/mediarepo-api/src/tauri_plugin/commands/file.rs +++ b/mediarepo-api/src/tauri_plugin/commands/file.rs @@ -1,4 +1,4 @@ -use crate::tauri_plugin::commands::{add_once_buffer, ApiAccess, BufferAccess}; +use crate::tauri_plugin::commands::ApiAccess; use crate::tauri_plugin::error::PluginResult; use crate::tauri_plugin::utils::system_time_to_naive_date_time; use crate::types::files::{ @@ -66,25 +66,6 @@ pub async fn find_files( Ok(files) } -#[tauri::command] -pub async fn read_file_by_hash( - api_state: ApiAccess<'_>, - buffer_state: BufferAccess<'_>, - id: i64, - hash: String, - mime_type: String, -) -> PluginResult { - if buffer_state.reserve_entry(&hash) { - Ok(format!("once://{}", hash)) // entry has been cached - } else { - let api = api_state.api().await?; - let content = api.file.read_file_by_hash(FileIdentifier::ID(id)).await?; - let uri = add_once_buffer(buffer_state, hash, mime_type, content); - - Ok(uri) - } -} - #[tauri::command] pub async fn get_file_thumbnails( api_state: ApiAccess<'_>, @@ -96,47 +77,6 @@ pub async fn get_file_thumbnails( Ok(thumbs) } -#[tauri::command] -pub async fn read_thumbnail( - hash: String, - mime_type: String, - api_state: ApiAccess<'_>, - buffer_state: BufferAccess<'_>, -) -> PluginResult { - if buffer_state.reserve_entry(&hash) { - Ok(format!("once://{}", hash)) // entry has been cached - } else { - let api = api_state.api().await?; - let content = api.file.read_thumbnail(hash.clone()).await?; - let uri = add_once_buffer(buffer_state, hash, mime_type, content); - - Ok(uri) - } -} - -#[tauri::command] -pub async fn get_thumbnail_of_size( - api_state: ApiAccess<'_>, - buffer_state: BufferAccess<'_>, - file_id: i64, - min_size: (u32, u32), - max_size: (u32, u32), -) -> PluginResult { - let api = api_state.api().await?; - let (thumb, data) = api - .file - .get_thumbnail_of_size(FileIdentifier::ID(file_id), min_size, max_size) - .await?; - let uri = add_once_buffer( - buffer_state, - thumb.hash, - thumb.mime_type.unwrap_or(String::from("image/png")), - data, - ); - - Ok(uri) -} - #[tauri::command] pub async fn update_file_name( api_state: ApiAccess<'_>, diff --git a/mediarepo-api/src/tauri_plugin/commands/mod.rs b/mediarepo-api/src/tauri_plugin/commands/mod.rs index 42f6626..106a4d2 100644 --- a/mediarepo-api/src/tauri_plugin/commands/mod.rs +++ b/mediarepo-api/src/tauri_plugin/commands/mod.rs @@ -1,4 +1,3 @@ -use parking_lot::lock_api::Mutex; use tauri::State; pub use daemon::*; @@ -6,7 +5,7 @@ pub use file::*; pub use repo::*; pub use tag::*; -use crate::tauri_plugin::state::{ApiState, AppState, BufferState, VolatileBuffer}; +use crate::tauri_plugin::state::{ApiState, AppState}; pub mod daemon; pub mod file; @@ -14,20 +13,4 @@ pub mod repo; pub mod tag; pub type ApiAccess<'a> = State<'a, ApiState>; -pub type BufferAccess<'a> = State<'a, BufferState>; pub type AppAccess<'a> = State<'a, AppState>; - -/// Adds a once-buffer to the buffer store -fn add_once_buffer( - buffer_state: BufferAccess<'_>, - key: String, - mime: String, - buf: Vec, -) -> String { - let uri = format!("once://{}", key); - let once_buffer = VolatileBuffer::new(mime, buf); - let mut once_buffers = buffer_state.buffer.write(); - once_buffers.insert(key, Mutex::new(once_buffer)); - - uri -} diff --git a/mediarepo-api/src/tauri_plugin/custom_schemes.rs b/mediarepo-api/src/tauri_plugin/custom_schemes.rs index c2913fe..0200e79 100644 --- a/mediarepo-api/src/tauri_plugin/custom_schemes.rs +++ b/mediarepo-api/src/tauri_plugin/custom_schemes.rs @@ -99,6 +99,7 @@ fn thumb_scheme(app: &AppHandle, request: &Request) -> Result MediarepoPlugin { invoke_handler: Box::new(tauri::generate_handler![ get_all_files, find_files, - read_file_by_hash, get_file_thumbnails, - read_thumbnail, - get_thumbnail_of_size, get_repositories, get_all_tags, get_tags_for_file, diff --git a/mediarepo-api/src/tauri_plugin/state.rs b/mediarepo-api/src/tauri_plugin/state.rs index 821975b..27afd8b 100644 --- a/mediarepo-api/src/tauri_plugin/state.rs +++ b/mediarepo-api/src/tauri_plugin/state.rs @@ -90,21 +90,6 @@ impl BufferState { buffers.insert(key, Mutex::new(buffer)); } - /// Checks if an entry for the specific key exists and resets - /// its state so that it can safely be accessed again. - pub fn reserve_entry(&self, key: &String) -> bool { - let buffers = self.buffer.read(); - let entry = buffers.get(key); - - if let Some(entry) = entry { - let mut entry = entry.lock(); - entry.valid_until = Instant::now() + Duration::from_secs(120); // reset the timer so that it can be accessed again - true - } else { - false - } - } - /// Returns the cloned buffer entry and flags it for expiration pub fn get_entry(&self, key: &str) -> Option { let buffers = self.buffer.read(); diff --git a/mediarepo-api/src/types/files.rs b/mediarepo-api/src/types/files.rs index 5bccab0..ab27f11 100644 --- a/mediarepo-api/src/types/files.rs +++ b/mediarepo-api/src/types/files.rs @@ -91,9 +91,7 @@ pub struct FileOSMetadata { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ThumbnailMetadataResponse { - pub id: i64, pub file_id: i64, - pub hash: String, pub height: i32, pub width: i32, pub mime_type: Option,