refactor: migrate all Tauri commands to camelCase parameters

This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.

Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
  * provider.rs: providerId (×4), timeoutSecs
  * import_export.rs: filePath (×2), defaultName
  * config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct

Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
  * usage.ts: removed debug logs, unified to providerId
  * vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
  * settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively

Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests

Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.

BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.

Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
This commit is contained in:
Jason
2025-11-03 16:50:23 +08:00
parent 85334d8dce
commit 36fd61b2a2
8 changed files with 57 additions and 52 deletions

View File

@@ -11,14 +11,17 @@ use crate::store::AppState;
/// 导出配置文件
#[tauri::command]
pub async fn export_config_to_file(file_path: String) -> Result<Value, String> {
pub async fn export_config_to_file(
#[allow(non_snake_case)]
filePath: String
) -> Result<Value, String> {
tauri::async_runtime::spawn_blocking(move || {
let target_path = PathBuf::from(&file_path);
let target_path = PathBuf::from(&filePath);
ConfigService::export_config_to_path(&target_path)?;
Ok::<_, AppError>(json!({
"success": true,
"message": "Configuration exported successfully",
"filePath": file_path
"filePath": filePath
}))
})
.await
@@ -29,11 +32,12 @@ pub async fn export_config_to_file(file_path: String) -> Result<Value, String> {
/// 从文件导入配置
#[tauri::command]
pub async fn import_config_from_file(
file_path: String,
#[allow(non_snake_case)]
filePath: String,
state: State<'_, AppState>,
) -> Result<Value, String> {
let (new_config, backup_id) = tauri::async_runtime::spawn_blocking(move || {
let path_buf = PathBuf::from(&file_path);
let path_buf = PathBuf::from(&filePath);
ConfigService::load_config_for_import(&path_buf)
})
.await
@@ -77,13 +81,14 @@ pub async fn sync_current_providers_live(state: State<'_, AppState>) -> Result<V
#[tauri::command]
pub async fn save_file_dialog<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
default_name: String,
#[allow(non_snake_case)]
defaultName: String,
) -> Result<Option<String>, String> {
let dialog = app.dialog();
let result = dialog
.file()
.add_filter("JSON", &["json"])
.set_file_name(&default_name)
.set_file_name(&defaultName)
.blocking_save_file();
Ok(result.map(|p| p.to_string()))