π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use scoped Tauri filesystem APIs in Ensu
Manav Rathif802b30f7a07
diff --git a/rust/apps/ensu/src-tauri/capabilities/default.json b/rust/apps/ensu/src-tauri/capabilities/default.jsonindex 8c79dec1ae..4b1d24150a 100644--- a/rust/apps/ensu/src-tauri/capabilities/default.json+++ b/rust/apps/ensu/src-tauri/capabilities/default.json@@ -8,8 +8,11 @@"dialog:default","fs:allow-exists","fs:allow-mkdir",+ "fs:allow-open",+ "fs:allow-read","fs:allow-read-file","fs:allow-remove",+ "fs:allow-stat","fs:allow-write-file","opener:allow-default-urls","opener:allow-open-url",diff --git a/rust/apps/ensu/src-tauri/src/commands/fs.rs b/rust/apps/ensu/src-tauri/src/commands/fs.rsdeleted file mode 100644index 4c8726bc9e..0000000000--- a/rust/apps/ensu/src-tauri/src/commands/fs.rs+++ /dev/null@@ -1,39 +0,0 @@-use std::fs;-use std::io::Read;--use tauri::async_runtime;--use crate::commands::common::ApiError;--fn fs_thread_error() -> ApiError {- ApiError::new("io_thread", "FS task failed")-}--#[tauri::command]-pub async fn fs_file_size(path: String) -> Result<Option<u64>, ApiError> {- async_runtime::spawn_blocking(move || match fs::metadata(&path) {- Ok(metadata) => Ok(Some(metadata.len())),- Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),- Err(err) => Err(ApiError::new("io", err.to_string())),- })- .await- .map_err(|_| fs_thread_error())?-}--#[tauri::command]-pub async fn fs_read_head(path: String, length: usize) -> Result<Vec<u8>, ApiError> {- async_runtime::spawn_blocking(move || {- if length == 0 {- return Ok(Vec::new());- }- let mut file = fs::File::open(&path).map_err(|err| ApiError::new("io", err.to_string()))?;- let mut buffer = vec![0u8; length];- let bytes_read = file- .read(&mut buffer)- .map_err(|err| ApiError::new("io", err.to_string()))?;- buffer.truncate(bytes_read);- Ok(buffer)- })- .await- .map_err(|_| fs_thread_error())?-}diff --git a/rust/apps/ensu/src-tauri/src/commands/mod.rs b/rust/apps/ensu/src-tauri/src/commands/mod.rsindex 07315f31b8..8898522ab7 100644--- a/rust/apps/ensu/src-tauri/src/commands/mod.rs+++ b/rust/apps/ensu/src-tauri/src/commands/mod.rs@@ -2,7 +2,6 @@ pub(crate) mod chat_db;mod common;pub(crate) mod config;pub(crate) mod crypto;-pub(crate) mod fs;pub(crate) mod llm;pub(crate) mod secure_storage;pub(crate) mod system;diff --git a/rust/apps/ensu/src-tauri/src/main.rs b/rust/apps/ensu/src-tauri/src/main.rsindex eb7ffddcdc..8e19543ae5 100644--- a/rust/apps/ensu/src-tauri/src/main.rs+++ b/rust/apps/ensu/src-tauri/src/main.rs@@ -67,8 +67,6 @@ fn main() {commands::config::config_defaults,commands::llm::llm_download_model_files,commands::llm::llm_cancel_model_download,- commands::fs::fs_file_size,- commands::fs::fs_read_head,]).build(tauri::generate_context!()).unwrap_or_else(|err| {diff --git a/web/apps/ensu/src/services/llm/inference.ts b/web/apps/ensu/src/services/llm/inference.tsindex a8d04785be..cc5d059203 100644--- a/web/apps/ensu/src/services/llm/inference.ts+++ b/web/apps/ensu/src/services/llm/inference.ts@@ -537,21 +537,22 @@ class TauriInference implements InferenceBackend {}async isModelAvailable(modelPath: string): Promise<boolean> {- const { exists } = await import("@tauri-apps/plugin-fs");+ const { exists, open, stat } = await import("@tauri-apps/plugin-fs");if (!(await exists(modelPath))) return false;try {- const size = await invoke<number | null>("fs_file_size", {- path: modelPath,- });- if (size !== null && size < MIN_GGUF_BYTES) {+ const { size } = await stat(modelPath);+ if (size < MIN_GGUF_BYTES) {return false;}- const head = await invoke<number[]>("fs_read_head", {- path: modelPath,- length: 4,- });- if (!isGgufHeader(new Uint8Array(head))) {- return false;+ const file = await open(modelPath, { read: true });+ try {+ const head = new Uint8Array(4);+ const bytesRead = await file.read(head);+ if (bytesRead !== 4 || !isGgufHeader(head)) {+ return false;+ }+ } finally {+ await file.close();}} catch {// ignore validation failures