mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 00:35:32 +08:00
30c763ffe3
Address code review feedback for PR #214: - Replace hardcoded Chinese strings with English in auto-imported prompts - Prompt name: "Auto-imported Prompt" instead of "初始提示词" - Description: "Automatically imported on first launch" - Remove panic risk by replacing expect() with proper error propagation - Use AppError::localized for bilingual error messages - Extract get_base_dir_with_fallback() helper to eliminate code duplication - Update test assertions to match new English strings - Suppress false-positive dead_code warning on TempHome.dir field All 5 tests passing with zero compiler warnings.
65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
use std::collections::HashMap;
|
|
use std::str::FromStr;
|
|
|
|
use tauri::State;
|
|
|
|
use crate::app_config::AppType;
|
|
use crate::prompt::Prompt;
|
|
use crate::services::PromptService;
|
|
use crate::store::AppState;
|
|
|
|
#[tauri::command]
|
|
pub async fn get_prompts(
|
|
app: String,
|
|
state: State<'_, AppState>,
|
|
) -> Result<HashMap<String, Prompt>, String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::get_prompts(&state, app_type).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn upsert_prompt(
|
|
app: String,
|
|
id: String,
|
|
prompt: Prompt,
|
|
state: State<'_, AppState>,
|
|
) -> Result<(), String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::upsert_prompt(&state, app_type, &id, prompt).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn delete_prompt(
|
|
app: String,
|
|
id: String,
|
|
state: State<'_, AppState>,
|
|
) -> Result<(), String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::delete_prompt(&state, app_type, &id).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn enable_prompt(
|
|
app: String,
|
|
id: String,
|
|
state: State<'_, AppState>,
|
|
) -> Result<(), String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::enable_prompt(&state, app_type, &id).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn import_prompt_from_file(
|
|
app: String,
|
|
state: State<'_, AppState>,
|
|
) -> Result<String, String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::import_from_file(&state, app_type).map_err(|e| e.to_string())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn get_current_prompt_file_content(app: String) -> Result<Option<String>, String> {
|
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
|
PromptService::get_current_file_content(app_type).map_err(|e| e.to_string())
|
|
}
|