refactor(dashboard): migrate plugin-api HTTP functions to ApiResponse pattern
- Migrate 14 HTTP functions in plugin-api.ts to return ApiResponse<T> - fetchPluginList, checkGitStatus, getMaimaiVersion - getInstalledPlugins, installPlugin, uninstallPlugin, updatePlugin - getPluginConfigSchema, getPluginConfig, getPluginConfigRaw - updatePluginConfig, updatePluginConfigRaw, resetPluginConfig, togglePlugin - Update 3 caller files to handle ApiResponse pattern: - plugins.tsx: 5 function calls updated - plugin-config.tsx: 5 function calls updated - plugin-detail.tsx: 5 function calls updated - All callers now check .success before accessing .data - Preserve WebSocket and utility functions unchanged - Build verification: npm run build succeeds with 0 errors
This commit is contained in:
@@ -341,16 +341,44 @@ function PluginConfigEditor({ plugin, onBack }: PluginConfigEditorProps) {
|
||||
const loadConfig = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const [schemaData, configData, rawConfigData] = await Promise.all([
|
||||
const [schemaResult, configResult, rawResult] = await Promise.all([
|
||||
getPluginConfigSchema(plugin.id),
|
||||
getPluginConfig(plugin.id),
|
||||
getPluginConfigRaw(plugin.id)
|
||||
])
|
||||
setSchema(schemaData)
|
||||
setConfig(configData)
|
||||
setOriginalConfig(JSON.parse(JSON.stringify(configData)))
|
||||
setSourceCode(rawConfigData)
|
||||
setOriginalSourceCode(rawConfigData)
|
||||
|
||||
if (!schemaResult.success) {
|
||||
toast({
|
||||
title: '加载配置架构失败',
|
||||
description: schemaResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!configResult.success) {
|
||||
toast({
|
||||
title: '加载配置数据失败',
|
||||
description: configResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!rawResult.success) {
|
||||
toast({
|
||||
title: '加载原始配置失败',
|
||||
description: rawResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
setSchema(schemaResult.data)
|
||||
setConfig(configResult.data)
|
||||
setOriginalConfig(JSON.parse(JSON.stringify(configResult.data)))
|
||||
setSourceCode(rawResult.data)
|
||||
setOriginalSourceCode(rawResult.data)
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: '加载配置失败',
|
||||
@@ -433,7 +461,15 @@ function PluginConfigEditor({ plugin, onBack }: PluginConfigEditorProps) {
|
||||
// 重置配置
|
||||
const handleReset = async () => {
|
||||
try {
|
||||
await resetPluginConfig(plugin.id)
|
||||
const resetResult = await resetPluginConfig(plugin.id)
|
||||
if (!resetResult.success) {
|
||||
toast({
|
||||
title: '重置失败',
|
||||
description: resetResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
toast({
|
||||
title: '配置已重置',
|
||||
description: '下次加载插件时将使用默认配置'
|
||||
@@ -452,10 +488,18 @@ function PluginConfigEditor({ plugin, onBack }: PluginConfigEditorProps) {
|
||||
// 切换启用状态
|
||||
const handleToggle = async () => {
|
||||
try {
|
||||
const result = await togglePlugin(plugin.id)
|
||||
const toggleResult = await togglePlugin(plugin.id)
|
||||
if (!toggleResult.success) {
|
||||
toast({
|
||||
title: '切换失败',
|
||||
description: toggleResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
toast({
|
||||
title: result.message,
|
||||
description: result.note
|
||||
title: toggleResult.data.message,
|
||||
description: toggleResult.data.note
|
||||
})
|
||||
loadConfig()
|
||||
} catch (error) {
|
||||
@@ -723,8 +767,16 @@ function PluginConfigPageContent() {
|
||||
const loadPlugins = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await getInstalledPlugins()
|
||||
setPlugins(data)
|
||||
const installedResult = await getInstalledPlugins()
|
||||
if (!installedResult.success) {
|
||||
toast({
|
||||
title: '加载插件列表失败',
|
||||
description: installedResult.error,
|
||||
variant: 'destructive'
|
||||
})
|
||||
return
|
||||
}
|
||||
setPlugins(installedResult.data)
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: '加载插件列表失败',
|
||||
|
||||
Reference in New Issue
Block a user