|
|
@ -1,6 +1,7 @@
|
|
|
|
use crate::tauri_plugin::commands::{add_once_buffer, ApiAccess, BufferAccess};
|
|
|
|
use crate::tauri_plugin::commands::{add_once_buffer, ApiAccess, BufferAccess};
|
|
|
|
use crate::tauri_plugin::error::PluginResult;
|
|
|
|
use crate::tauri_plugin::error::PluginResult;
|
|
|
|
use crate::types::files::{FileMetadataResponse, SortKey, TagQuery, ThumbnailMetadataResponse};
|
|
|
|
use crate::types::files::{FileMetadataResponse, SortKey, TagQuery, ThumbnailMetadataResponse};
|
|
|
|
|
|
|
|
use crate::types::identifier::FileIdentifier;
|
|
|
|
|
|
|
|
|
|
|
|
#[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<FileMetadataResponse>> {
|
|
|
@ -24,16 +25,17 @@ pub async fn find_files(
|
|
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
#[tauri::command]
|
|
|
|
pub async fn read_file_by_hash(
|
|
|
|
pub async fn read_file_by_hash(
|
|
|
|
hash: String,
|
|
|
|
|
|
|
|
mime_type: String,
|
|
|
|
|
|
|
|
api_state: ApiAccess<'_>,
|
|
|
|
api_state: ApiAccess<'_>,
|
|
|
|
buffer_state: BufferAccess<'_>,
|
|
|
|
buffer_state: BufferAccess<'_>,
|
|
|
|
|
|
|
|
id: i64,
|
|
|
|
|
|
|
|
hash: String,
|
|
|
|
|
|
|
|
mime_type: String,
|
|
|
|
) -> PluginResult<String> {
|
|
|
|
) -> PluginResult<String> {
|
|
|
|
if buffer_state.reserve_entry(&hash) {
|
|
|
|
if buffer_state.reserve_entry(&hash) {
|
|
|
|
Ok(format!("once://{}", hash)) // entry has been cached
|
|
|
|
Ok(format!("once://{}", hash)) // entry has been cached
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let api = api_state.api().await?;
|
|
|
|
let api = api_state.api().await?;
|
|
|
|
let content = api.file.read_file_by_hash(hash.clone()).await?;
|
|
|
|
let content = api.file.read_file_by_hash(FileIdentifier::ID(id)).await?;
|
|
|
|
let uri = add_once_buffer(buffer_state, hash, mime_type, content);
|
|
|
|
let uri = add_once_buffer(buffer_state, hash, mime_type, content);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(uri)
|
|
|
|
Ok(uri)
|
|
|
@ -42,11 +44,11 @@ pub async fn read_file_by_hash(
|
|
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
#[tauri::command]
|
|
|
|
pub async fn get_file_thumbnails(
|
|
|
|
pub async fn get_file_thumbnails(
|
|
|
|
hash: String,
|
|
|
|
|
|
|
|
api_state: ApiAccess<'_>,
|
|
|
|
api_state: ApiAccess<'_>,
|
|
|
|
|
|
|
|
id: i64,
|
|
|
|
) -> PluginResult<Vec<ThumbnailMetadataResponse>> {
|
|
|
|
) -> PluginResult<Vec<ThumbnailMetadataResponse>> {
|
|
|
|
let api = api_state.api().await?;
|
|
|
|
let api = api_state.api().await?;
|
|
|
|
let thumbs = api.file.get_file_thumbnails(hash).await?;
|
|
|
|
let thumbs = api.file.get_file_thumbnails(FileIdentifier::ID(id)).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(thumbs)
|
|
|
|
Ok(thumbs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|