feat: change query-config

This commit is contained in:
xion 2025-04-03 15:35:50 +08:00
parent 20688920b8
commit 862b29cfa4
2 changed files with 24 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@kevisual/query-config", "name": "@kevisual/query-config",
"version": "0.0.1", "version": "0.0.2",
"description": "", "description": "",
"main": "dist/query-config.js", "main": "dist/query-config.js",
"types": "dist/query-config.d.ts", "types": "dist/query-config.d.ts",

View File

@ -16,6 +16,9 @@ export type UploadConfig = {
key?: string; key?: string;
version?: string; version?: string;
}; };
type PostOpts = {
token?: string;
};
export class QueryConfig { export class QueryConfig {
query: Query; query: Query;
constructor(opts?: QueryConfigOpts) { constructor(opts?: QueryConfigOpts) {
@ -24,39 +27,43 @@ export class QueryConfig {
async post<T = Config>(data: any) { async post<T = Config>(data: any) {
return this.query.post<T>({ path: 'config', ...data }); return this.query.post<T>({ path: 'config', ...data });
} }
async getConfig({ id, key }: { id?: string; key?: string }) { async getConfig({ id, key }: { id?: string; key?: string }, opts?: PostOpts) {
return this.post({ return this.post({
key: 'get', key: 'get',
data: { data: {
id, id,
key, key,
}, },
...opts,
}); });
} }
async updateConfig(data: Config) { async updateConfig(data: Config, opts?: PostOpts) {
return this.post({ return this.post({
key: 'update', key: 'update',
data, data,
...opts,
}); });
} }
async deleteConfig(id: string) { async deleteConfig(id: string, opts?: PostOpts) {
return this.post({ return this.post({
key: 'delete', key: 'delete',
data: { id }, data: { id },
}); });
} }
async listConfig() { async listConfig(opts?: PostOpts) {
return this.post<{ list: Config[] }>({ return this.post<{ list: Config[] }>({
key: 'list', key: 'list',
...opts,
}); });
} }
/** /**
* *
* @returns * @returns
*/ */
async getUploadConfig() { async getUploadConfig(opts?: PostOpts) {
return this.post<Result<Config<UploadConfig>>>({ return this.post<Result<Config<UploadConfig>>>({
key: 'getUploadConfig', key: 'getUploadConfig',
...opts,
}); });
} }
/** /**
@ -64,10 +71,11 @@ export class QueryConfig {
* @param data * @param data
* @returns * @returns
*/ */
async updateUploadConfig(data: Config) { async updateUploadConfig(data: Config, opts?: PostOpts) {
return this.post<Result<Config<UploadConfig>>>({ return this.post<Result<Config<UploadConfig>>>({
key: 'updateUploadConfig', key: 'updateUploadConfig',
data, data,
...opts,
}); });
} }
@ -76,15 +84,22 @@ export class QueryConfig {
* @param id * @param id
* @returns * @returns
*/ */
async detectConfig() { async detectConfig(opts?: PostOpts) {
return this.post<{ updateList: Config[] }>({ return this.post<{ updateList: Config[] }>({
key: 'detect', key: 'detect',
...opts,
}); });
} }
async getConfigByKey(key: string) { /**
* ,
* @param key
* @returns
*/
async getConfigByKey(key: string, opts?: PostOpts) {
return this.post<Result<Config>>({ return this.post<Result<Config>>({
key: 'defaultConfig', key: 'defaultConfig',
configKey: key, configKey: key,
...opts,
}); });
} }
} }