Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
resolve rust clippy warnings (#6888)
Roushan Kumar Singh58525eaa5db2
diff --git a/src-tauri/src/core/downloads/helpers.rs b/src-tauri/src/core/downloads/helpers.rsindex 3ce1d89fa..c357ae6e1 100644--- a/src-tauri/src/core/downloads/helpers.rs+++ b/src-tauri/src/core/downloads/helpers.rs@@ -292,6 +292,15 @@ pub async fn _get_file_size(// ===== MAIN DOWNLOAD FUNCTIONS =====+// Context passed to `download_single_file` to reduce the number of arguments+struct DownloadCtx {+ header_map: HeaderMap,+ resume: bool,+ cancel_token: CancellationToken,+ evt_name: String,+ progress_tracker: ProgressTracker,+}+/// Downloads multiple files in parallel with individual progress trackingpub async fn _download_files_internal(app: tauri::AppHandle<impl Runtime>,@@ -344,25 +353,25 @@ pub async fn _download_files_internal(// Spawn download task for each filelet item_clone = item.clone();let app_clone = app.clone();- let header_map_clone = header_map.clone();- let cancel_token_clone = cancel_token.clone();- let evt_name_clone = evt_name.clone();- let progress_tracker_clone = progress_tracker.clone();let file_id = format!("{task_id}-{index}");let file_size = file_sizes.get(&item.url).copied().unwrap_or(0);+ let ctx = DownloadCtx {+ header_map: header_map.clone(),+ resume,+ cancel_token: cancel_token.clone(),+ evt_name: evt_name.clone(),+ progress_tracker: progress_tracker.clone(),+ };+let task = tokio::spawn(async move {download_single_file(app_clone,&item_clone,- &header_map_clone,&save_path,- resume,- cancel_token_clone,- evt_name_clone,- progress_tracker_clone,file_id,file_size,+ ctx,).await});@@ -421,15 +430,18 @@ pub async fn _download_files_internal(async fn download_single_file(app: tauri::AppHandle<impl Runtime>,item: &DownloadItem,- header_map: &HeaderMap,save_path: &std::path::Path,- resume: bool,- cancel_token: CancellationToken,- evt_name: String,- progress_tracker: ProgressTracker,file_id: String,_file_size: u64,+ ctx: DownloadCtx,) -> Result<std::path::PathBuf, String> {+ let DownloadCtx {+ header_map,+ resume,+ cancel_token,+ evt_name,+ progress_tracker,+ } = ctx;// Create parent directories if they don't existif let Some(parent) = save_path.parent() {if !parent.exists() {@@ -466,7 +478,7 @@ async fn download_single_file(.map(|u| u.to_string()).unwrap_or_else(|_| item.url.clone());log::info!("Started downloading: {decoded_url}");- let client = _get_client_for_item(item, header_map).map_err(err_to_string)?;+ let client = _get_client_for_item(item, &header_map).map_err(err_to_string)?;let mut download_delta = 0u64;let mut initial_progress = 0u64;diff --git a/src-tauri/src/core/extensions/commands.rs b/src-tauri/src/core/extensions/commands.rsindex e416a03a3..b8983df37 100644--- a/src-tauri/src/core/extensions/commands.rs+++ b/src-tauri/src/core/extensions/commands.rs@@ -58,6 +58,6 @@ pub fn get_active_extensions<R: Runtime>(app: AppHandle<R>) -> Vec<serde_json::Vvec![]}};- return contents;+ contents}}diff --git a/src-tauri/src/core/server/commands.rs b/src-tauri/src/core/server/commands.rsindex 286d40cc1..61478f7fc 100644--- a/src-tauri/src/core/server/commands.rs+++ b/src-tauri/src/core/server/commands.rs@@ -4,17 +4,30 @@ use tauri_plugin_llamacpp::state::LlamacppState;use crate::core::server::proxy;use crate::core::state::AppState;+#[derive(serde::Deserialize)]+pub struct StartServerConfig {+ pub host: String,+ pub port: u16,+ pub prefix: String,+ pub api_key: String,+ pub trusted_hosts: Vec<String>,+ pub proxy_timeout: u64,+}+#[tauri::command]pub async fn start_server<R: Runtime>(app_handle: AppHandle<R>,state: State<'_, AppState>,- host: String,- port: u16,- prefix: String,- api_key: String,- trusted_hosts: Vec<String>,- proxy_timeout: u64,+ config: StartServerConfig,) -> Result<u16, String> {+ let StartServerConfig {+ host,+ port,+ prefix,+ api_key,+ trusted_hosts,+ proxy_timeout,+ } = config;let server_handle = state.server_handle.clone();let plugin_state: State<LlamacppState> = app_handle.state();let sessions = plugin_state.llama_server_process.clone();diff --git a/src-tauri/src/core/setup.rs b/src-tauri/src/core/setup.rsindex 7ba8f2f74..21fbf7895 100644--- a/src-tauri/src/core/setup.rs+++ b/src-tauri/src/core/setup.rs@@ -294,7 +294,7 @@ fn setup_window_theme_listener<R: Runtime>(tauri::Theme::Dark => "dark",_ => "auto",};- log::info!("System theme changed to: {} for window: {}", theme_str, window_label);+ log::info!("System theme changed to: {theme_str} for window: {window_label}");let _ = app_handle_clone.emit("theme-changed", theme_str);}});diff --git a/src-tauri/src/core/threads/tests.rs b/src-tauri/src/core/threads/tests.rsindex 15c91de85..2b5243d07 100644--- a/src-tauri/src/core/threads/tests.rs+++ b/src-tauri/src/core/threads/tests.rs@@ -432,7 +432,7 @@ async fn test_concurrent_message_operations() {let app_h = app_handle.clone();let tid = thread_id.clone();tokio::spawn(async move {- create_message(app_h, create_test_message(&tid, &format!("Message {}", i))).await+ create_message(app_h, create_test_message(&tid, &format!("Message {i}"))).await})}).collect();diff --git a/web-app/src/lib/service.ts b/web-app/src/lib/service.tsindex a35d99636..0e7273d4e 100644--- a/web-app/src/lib/service.ts+++ b/web-app/src/lib/service.ts@@ -44,10 +44,55 @@ export const APIs = {[proxy.route]: (args?: InvokeArgs) => {if (isPlatformTauri()) {// For Tauri platform, use the service hub to invoke commands- return getServiceHub().core().invoke(- proxy.route.replace(/([A-Z])/g, '_$1').toLowerCase(),- args- )+ const command = proxy.route.replace(/([A-Z])/g, '_$1').toLowerCase()++ // Backward-compatible shim for start_server: wrap args into { config }+ if (command === 'start_server') {+ // If already using new shape, pass through+ if (args && 'config' in args) {+ return getServiceHub().core().invoke(command, args)+ }++ const raw: Record<string, unknown> = (args || {}) as Record<string, unknown>++ const pickString = (obj: Record<string, unknown>, keys: string[]): string | undefined => {+ for (const key of keys) {+ const value = obj[key]+ if (typeof value === 'string') return value+ }+ return undefined+ }++ const pickNumber = (obj: Record<string, unknown>, keys: string[]): number | undefined => {+ for (const key of keys) {+ const value = obj[key]+ if (typeof value === 'number') return value+ }+ return undefined+ }++ const pickStringArray = (obj: Record<string, unknown>, keys: string[]): string[] | undefined => {+ for (const key of keys) {+ const value = obj[key]+ if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {+ return value as string[]+ }+ }+ return undefined+ }++ const config = {+ host: pickString(raw, ['host']),+ port: pickNumber(raw, ['port']),+ prefix: pickString(raw, ['prefix']),+ api_key: pickString(raw, ['api_key', 'apiKey']),+ trusted_hosts: pickStringArray(raw, ['trusted_hosts', 'trustedHosts']),+ proxy_timeout: pickNumber(raw, ['proxy_timeout', 'proxyTimeout']),+ }+ return getServiceHub().core().invoke(command, { config })+ }++ return getServiceHub().core().invoke(command, args)} else {// For Web platform, provide fallback implementationsconsole.warn(`API call '${proxy.route}' not supported in web environment`, args)