feat: add s1/resources/upload

This commit is contained in:
2025-03-15 11:38:57 +08:00
parent d947043a16
commit 9b1045d456
4 changed files with 154 additions and 3 deletions

View File

@@ -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;
};