refactor(web): align resource APIs and forms with the starter conventions

Centralize typed resource functions under common/apis and return complete JSON envelopes while preserving raw responses, bearer session isolation, and single-owner errors.

Keep settings state and queues inside the setup store. Use Element Plus forms and dialogs for login, settings, imports, moves, and images; preserve editor interactions and themes. Update callers, tests, generated declarations, and request import constraints together.
This commit is contained in:
eezd committed 2026-10-26 11:53:37 +08:00
1 parent cef0298c34
commit 6b537c03e0
114 files changed
+2876 -2217

No files matched your search

+59 -13
View File
@@ -1,15 +1,61 @@
import type { InstalledPlugin } from './type'
import { requestJSON } from '@/http/axios'
import type * as Plugins from './type'
import { request } from '@/http/axios'
export const pluginsApi = {
plugins: async () => (await requestJSON<{ plugins: InstalledPlugin[] }>('GET', '/plugins', { errorOwner: 'caller' })).plugins,
installPlugin: (file: File) => {
const body = new FormData()
body.append('file', file)
return requestJSON<InstalledPlugin>('POST', '/plugins', { errorOwner: 'caller', body })
},
togglePlugin: (id: string, enabled: boolean) => requestJSON<InstalledPlugin>('PATCH', `/plugins/${encodeURIComponent(id)}`, { errorOwner: 'caller', json: { enabled } }),
uninstallPlugin: (id: string) => requestJSON('DELETE', `/plugins/${encodeURIComponent(id)}`, { errorOwner: 'caller' }),
pluginData: (id: string) => requestJSON<{ data: unknown }>('GET', `/plugins/${encodeURIComponent(id)}/data`, { errorOwner: 'caller' }),
savePluginData: (id: string, data: unknown) => requestJSON('PUT', `/plugins/${encodeURIComponent(id)}/data`, { errorOwner: 'caller', json: { data } }),
/** 读取已安装插件。 */
export function getPluginsApi() {
return request<Plugins.PluginsResponseData>({
url: 'plugins',
method: 'get',
errorOwner: 'caller',
})
}
/** 安装插件 ZIP。 */
export function installPluginApi(file: File) {
const data = new FormData()
data.append('file', file)
return request<Plugins.PluginResponseData>({
url: 'plugins',
method: 'post',
data,
errorOwner: 'caller',
})
}
/** 启用或停用插件。 */
export function togglePluginApi(data: Plugins.TogglePluginRequestData) {
return request<Plugins.PluginResponseData>({
url: `plugins/${encodeURIComponent(data.id)}`,
method: 'patch',
data: { enabled: data.enabled },
errorOwner: 'caller',
})
}
/** 卸载插件并保留插件数据。 */
export function uninstallPluginApi(id: string) {
return request<Plugins.PluginOperationResponseData>({
url: `plugins/${encodeURIComponent(id)}`,
method: 'delete',
errorOwner: 'caller',
})
}
/** 读取插件存储。 */
export function getPluginDataApi(id: string) {
return request<Plugins.PluginDataResponseData>({
url: `plugins/${encodeURIComponent(id)}/data`,
method: 'get',
errorOwner: 'caller',
})
}
/** 保存插件存储。 */
export function savePluginDataApi(data: Plugins.PluginDataRequestData) {
return request<Plugins.PluginDataResponseData>({
url: `plugins/${encodeURIComponent(data.id)}/data`,
method: 'put',
data: { data: data.data },
errorOwner: 'caller',
})
}
+7
View File
@@ -6,3 +6,10 @@ export interface InstalledPlugin {
revision: string
enabled: boolean
}
export interface TogglePluginRequestData { id: string, enabled: boolean }
export interface PluginDataRequestData { id: string, data: unknown }
export type PluginsResponseData = ApiResponseData<{ plugins: InstalledPlugin[] }>
export type PluginResponseData = ApiResponseData<InstalledPlugin>
export type PluginDataResponseData = ApiResponseData<{ data: unknown }>
export type PluginOperationResponseData = ApiResponseData<{ ok: boolean }>