refactor(api): unify Tauri command app param as app_type with backward-compatible app/appType; update front-end invocations accordingly
This commit is contained in:
@@ -12,9 +12,14 @@ use crate::store::AppState;
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_providers(
|
pub async fn get_providers(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
) -> Result<HashMap<String, Provider>, String> {
|
) -> Result<HashMap<String, Provider>, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let config = state
|
let config = state
|
||||||
.config
|
.config
|
||||||
@@ -32,9 +37,14 @@ pub async fn get_providers(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_current_provider(
|
pub async fn get_current_provider(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let config = state
|
let config = state
|
||||||
.config
|
.config
|
||||||
@@ -52,10 +62,15 @@ pub async fn get_current_provider(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn add_provider(
|
pub async fn add_provider(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
provider: Provider,
|
provider: Provider,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let mut config = state
|
let mut config = state
|
||||||
.config
|
.config
|
||||||
@@ -97,10 +112,15 @@ pub async fn add_provider(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn update_provider(
|
pub async fn update_provider(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
provider: Provider,
|
provider: Provider,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let mut config = state
|
let mut config = state
|
||||||
.config
|
.config
|
||||||
@@ -164,10 +184,15 @@ pub async fn update_provider(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn delete_provider(
|
pub async fn delete_provider(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
id: String,
|
id: String,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let mut config = state
|
let mut config = state
|
||||||
.config
|
.config
|
||||||
@@ -216,10 +241,15 @@ pub async fn delete_provider(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn switch_provider(
|
pub async fn switch_provider(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
id: String,
|
id: String,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
let mut config = state
|
let mut config = state
|
||||||
.config
|
.config
|
||||||
@@ -304,9 +334,14 @@ pub async fn switch_provider(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn import_default_config(
|
pub async fn import_default_config(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
|
app_type: Option<AppType>,
|
||||||
app: Option<String>,
|
app: Option<String>,
|
||||||
|
appType: Option<String>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude);
|
let app_type = app_type
|
||||||
|
.or_else(|| app.as_deref().map(|s| s.into()))
|
||||||
|
.or_else(|| appType.as_deref().map(|s| s.into()))
|
||||||
|
.unwrap_or(AppType::Claude);
|
||||||
|
|
||||||
// 若已存在 default 供应商,则直接返回,避免重复导入
|
// 若已存在 default 供应商,则直接返回,避免重复导入
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const tauriAPI = {
|
|||||||
// 获取所有供应商
|
// 获取所有供应商
|
||||||
getProviders: async (app?: AppType): Promise<Record<string, Provider>> => {
|
getProviders: async (app?: AppType): Promise<Record<string, Provider>> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("get_providers", { app });
|
return await invoke("get_providers", { app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取供应商列表失败:", error);
|
console.error("获取供应商列表失败:", error);
|
||||||
return {};
|
return {};
|
||||||
@@ -32,7 +32,7 @@ export const tauriAPI = {
|
|||||||
// 获取当前供应商ID
|
// 获取当前供应商ID
|
||||||
getCurrentProvider: async (app?: AppType): Promise<string> => {
|
getCurrentProvider: async (app?: AppType): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("get_current_provider", { app });
|
return await invoke("get_current_provider", { app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取当前供应商失败:", error);
|
console.error("获取当前供应商失败:", error);
|
||||||
return "";
|
return "";
|
||||||
@@ -42,7 +42,7 @@ export const tauriAPI = {
|
|||||||
// 添加供应商
|
// 添加供应商
|
||||||
addProvider: async (provider: Provider, app?: AppType): Promise<boolean> => {
|
addProvider: async (provider: Provider, app?: AppType): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("add_provider", { provider, app });
|
return await invoke("add_provider", { provider, app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("添加供应商失败:", error);
|
console.error("添加供应商失败:", error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -55,7 +55,7 @@ export const tauriAPI = {
|
|||||||
app?: AppType,
|
app?: AppType,
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("update_provider", { provider, app });
|
return await invoke("update_provider", { provider, app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("更新供应商失败:", error);
|
console.error("更新供应商失败:", error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -65,7 +65,7 @@ export const tauriAPI = {
|
|||||||
// 删除供应商
|
// 删除供应商
|
||||||
deleteProvider: async (id: string, app?: AppType): Promise<boolean> => {
|
deleteProvider: async (id: string, app?: AppType): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("delete_provider", { id, app });
|
return await invoke("delete_provider", { id, app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("删除供应商失败:", error);
|
console.error("删除供应商失败:", error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -78,7 +78,7 @@ export const tauriAPI = {
|
|||||||
app?: AppType,
|
app?: AppType,
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
return await invoke("switch_provider", { id: providerId, app });
|
return await invoke("switch_provider", { id: providerId, app_type: app, app });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("切换供应商失败:", error);
|
console.error("切换供应商失败:", error);
|
||||||
return false;
|
return false;
|
||||||
@@ -90,7 +90,7 @@ export const tauriAPI = {
|
|||||||
app?: AppType,
|
app?: AppType,
|
||||||
): Promise<ImportResult> => {
|
): Promise<ImportResult> => {
|
||||||
try {
|
try {
|
||||||
const success = await invoke<boolean>("import_default_config", { app });
|
const success = await invoke<boolean>("import_default_config", { app_type: app, app });
|
||||||
return {
|
return {
|
||||||
success,
|
success,
|
||||||
message: success ? "成功导入默认配置" : "导入失败",
|
message: success ? "成功导入默认配置" : "导入失败",
|
||||||
|
|||||||
Reference in New Issue
Block a user