mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-01 00:05:43 +08:00
### What problem does this PR solve? feat: render stats charts feat: create api token feat: delete api token feat: add ChatApiKeyModal feat: add RagLineChart Issue link: #345 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
34 lines
889 B
TypeScript
34 lines
889 B
TypeScript
import { RequestMethod } from 'umi-request';
|
|
|
|
type Service<T extends string> = Record<T, (params: any) => any>;
|
|
|
|
const registerServer = <T extends string>(
|
|
opt: Record<T, { url: string; method: string }>,
|
|
request: RequestMethod,
|
|
) => {
|
|
const server: Service<T> = {} as Service<T>;
|
|
for (let key in opt) {
|
|
server[key] = (params: any, urlAppendix?: string) => {
|
|
let url = opt[key].url;
|
|
if (urlAppendix) {
|
|
url = url + '/' + urlAppendix;
|
|
}
|
|
if (opt[key].method === 'post' || opt[key].method === 'POST') {
|
|
return request(url, {
|
|
method: opt[key].method,
|
|
data: params,
|
|
});
|
|
}
|
|
|
|
if (opt[key].method === 'get' || opt[key].method === 'GET') {
|
|
return request.get(url, {
|
|
params,
|
|
});
|
|
}
|
|
};
|
|
}
|
|
return server;
|
|
};
|
|
|
|
export default registerServer;
|