import { Query } from '@kevisual/query'; import type { Result } from '@kevisual/query/query'; type QueryConfigOpts = { query?: Query; }; export type Config = { id?: string; title?: string; key?: string; description?: string; data?: T; createdAt?: string; updatedAt?: string; }; export type UploadConfig = { key?: string; version?: string; }; type PostOpts = { token?: string; }; export const defaultConfigKeys = ['upload.json', 'workspace.json', 'ai.json', 'user.json', 'life.json'] as const; type DefaultConfigKey = (typeof defaultConfigKeys)[number]; export class QueryConfig { query: Query; constructor(opts?: QueryConfigOpts) { this.query = opts?.query || new Query(); } async post(data: any) { return this.query.post({ path: 'config', ...data }); } async getConfig({ id, key }: { id?: string; key?: string }, opts?: PostOpts) { return this.post({ key: 'get', data: { id, key, }, ...opts, }); } async updateConfig(data: Config, opts?: PostOpts) { return this.post({ key: 'update', data, ...opts, }); } async deleteConfig(id: string, opts?: PostOpts) { return this.post({ key: 'delete', data: { id }, }); } async listConfig(opts?: PostOpts) { return this.post<{ list: Config[] }>({ key: 'list', ...opts, }); } /** * 获取上传配置 * @returns */ async getUploadConfig(opts?: PostOpts) { return this.post>>({ key: 'getUploadConfig', ...opts, }); } /** * 更新上传配置 * @param data * @returns */ async updateUploadConfig(data: Config, opts?: PostOpts) { return this.post>>({ key: 'updateUploadConfig', data, ...opts, }); } /** * 检测配置是否存在 * @param id * @returns */ async detectConfig(opts?: PostOpts) { return this.post<{ updateList: Config[] }>({ key: 'detect', ...opts, }); } /** * 获取配置, 获取默认的配置项 * @param key * @returns */ async getConfigByKey(key: DefaultConfigKey, opts?: PostOpts) { return this.post>({ key: 'defaultConfig', configKey: key, ...opts, }); } }