feat: add s1/resources/upload
This commit is contained in:
@@ -2,6 +2,7 @@ import { router } from '@/app.ts';
|
||||
import http from 'http';
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
import { checkAuth, error } from './middleware/auth.ts';
|
||||
import formidable from 'formidable';
|
||||
export { router, checkAuth, error };
|
||||
|
||||
/**
|
||||
@@ -29,3 +30,22 @@ export const writeEvents = (req: http.IncomingMessage, data: any) => {
|
||||
const taskId = getTaskId(req);
|
||||
taskId && clients.get(taskId)?.client?.write?.(`${JSON.stringify(data)}\n`);
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析表单数据, 如果表单数据是数组, 则取第一个,appKey, version, username 等
|
||||
* @param fields 表单数据
|
||||
* @param parseKeys 需要解析的键
|
||||
* @returns 解析后的数据
|
||||
*/
|
||||
export const getKey = (fields: formidable.Fields<string>, parseKeys: string[]) => {
|
||||
let value: Record<string, any> = {};
|
||||
for (const key of parseKeys) {
|
||||
const v = fields[key];
|
||||
if (Array.isArray(v)) {
|
||||
value[key] = v[0];
|
||||
} else {
|
||||
value[key] = v;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user