Add plugin config management to backend and frontend

Introduces a unified plugin configuration schema and API in the backend, with endpoints for getting and setting plugin config. Updates the frontend to support plugin config modals, including a UI for editing plugin settings. Also adds support for uninstalling plugins with optional data cleanup, and updates dependencies to use napcat-types@0.0.5.
This commit is contained in:
手瓜一十雪
2026-01-28 13:56:40 +08:00
parent 40e11b9d29
commit 89bac8f6e3
10 changed files with 482 additions and 44 deletions

View File

@@ -8,6 +8,7 @@ export interface PluginItem {
author: string;
status: 'active' | 'disabled' | 'stopped';
filename?: string;
hasConfig?: boolean;
}
export interface PluginListResponse {
@@ -15,6 +16,21 @@ export interface PluginListResponse {
pluginManagerNotFound: boolean;
}
export interface PluginConfigSchemaItem {
key: string;
type: 'string' | 'number' | 'boolean' | 'select' | 'multi-select' | 'html' | 'text';
label: string;
description?: string;
default?: any;
options?: { label: string; value: string | number; }[];
placeholder?: string;
}
export interface PluginConfigResponse {
schema: PluginConfigSchemaItem[];
config: any;
}
export interface ServerResponse<T> {
code: number;
message: string;
@@ -35,8 +51,8 @@ export default class PluginManager {
await serverRequest.post<ServerResponse<void>>('/Plugin/SetStatus', { name, enable, filename });
}
public static async uninstallPlugin (name: string, filename?: string) {
await serverRequest.post<ServerResponse<void>>('/Plugin/Uninstall', { name, filename });
public static async uninstallPlugin (name: string, filename?: string, cleanData?: boolean) {
await serverRequest.post<ServerResponse<void>>('/Plugin/Uninstall', { name, filename, cleanData });
}
// 插件商店相关方法
@@ -56,4 +72,14 @@ export default class PluginManager {
timeout: 300000, // 5分钟
});
}
// 插件配置相关方法
public static async getPluginConfig (name: string) {
const { data } = await serverRequest.get<ServerResponse<PluginConfigResponse>>('/Plugin/Config', { params: { name } });
return data.data;
}
public static async setPluginConfig (name: string, config: any) {
await serverRequest.post<ServerResponse<void>>('/Plugin/Config', { name, config });
}
}