This commit is contained in:
2025-03-14 01:41:53 +08:00
parent efef48a1b0
commit d947043a16
12 changed files with 284 additions and 65 deletions

View File

@@ -1,9 +1,8 @@
import { IncomingForm } from 'formidable';
import { checkAuth } from '../middleware/auth.ts';
import { router } from '../router.ts';
import { router, clients, writeEvents } from '../router.ts';
import { error } from '../middleware/auth.ts';
import fs from 'fs';
import { clients } from '../upload.ts';
import { useFileStore } from '@kevisual/use-config/file-store';
import { app, minioClient } from '@/app.ts';
import { bucketName } from '@/modules/minio.ts';
@@ -29,7 +28,6 @@ router.post('/api/micro-app/upload', async (req, res) => {
keepExtensions: true, // 保留文件
hashAlgorithm: 'md5', // 文件哈希算法
});
const taskId = req.headers['task-id'] as string;
form.on('progress', (bytesReceived, bytesExpected) => {
const progress = (bytesReceived / bytesExpected) * 100;
console.log(`Upload progress: ${progress.toFixed(2)}%`);
@@ -37,7 +35,7 @@ router.post('/api/micro-app/upload', async (req, res) => {
progress: progress.toFixed(2),
message: `Upload progress: ${progress.toFixed(2)}%`,
};
clients.get(taskId)?.client?.write?.(`${JSON.stringify(data)}\n`);
writeEvents(req, data);
});
// 解析上传的文件
form.parse(req, async (err, fields, files) => {