diff --git a/src/routes-simple/code/upload.ts b/src/routes-simple/code/upload.ts index b646d9c..48ae9af 100644 --- a/src/routes-simple/code/upload.ts +++ b/src/routes-simple/code/upload.ts @@ -20,7 +20,7 @@ router.post('/api/micro-app/upload', async (req, res) => { if (!tokenUser) return; // 使用 busboy 解析 multipart/form-data - const busboy = Busboy({ headers: req.headers }); + const busboy = Busboy({ headers: req.headers, preservePath: true }); const fields: any = {}; let file: any = null; let filePromise: Promise | null = null; @@ -33,7 +33,7 @@ router.post('/api/micro-app/upload', async (req, res) => { busboy.on('file', (fieldname, fileStream, info) => { const { filename, encoding, mimeType } = info; - const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}-${filename}`); + const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`); const writeStream = createWriteStream(tempPath); const hash = crypto.createHash('md5'); let size = 0; diff --git a/src/routes-simple/handle-request.ts b/src/routes-simple/handle-request.ts index 67564ca..a3f8830 100644 --- a/src/routes-simple/handle-request.ts +++ b/src/routes-simple/handle-request.ts @@ -28,7 +28,7 @@ router.post('/api/app/upload', async (req, res) => { if (!tokenUser) return; // 使用 busboy 解析 multipart/form-data - const busboy = Busboy({ headers: req.headers }); + const busboy = Busboy({ headers: req.headers, preservePath: true }); const fields: any = {}; const files: any = []; const filePromises: Promise[] = []; @@ -41,7 +41,7 @@ router.post('/api/app/upload', async (req, res) => { busboy.on('file', (fieldname, fileStream, info) => { const { filename, encoding, mimeType } = info; - const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}-${filename}`); + const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`); const writeStream = createWriteStream(tempPath); const filePromise = new Promise((resolve, reject) => { diff --git a/src/routes-simple/resources/chunk.ts b/src/routes-simple/resources/chunk.ts index 604838c..4bad8e5 100644 --- a/src/routes-simple/resources/chunk.ts +++ b/src/routes-simple/resources/chunk.ts @@ -35,7 +35,7 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => { } // 使用 busboy 解析 multipart/form-data - const busboy = Busboy({ headers: req.headers }); + const busboy = Busboy({ headers: req.headers, preservePath: true }); const fields: any = {}; let file: any = null; let tempPath = ''; @@ -47,7 +47,7 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => { busboy.on('file', (fieldname, fileStream, info) => { const { filename, encoding, mimeType } = info; - tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}-${filename}`); + tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`); const writeStream = createWriteStream(tempPath); filePromise = new Promise((resolve, reject) => { diff --git a/src/routes-simple/resources/upload.ts b/src/routes-simple/resources/upload.ts index a1d91f5..193ac8e 100644 --- a/src/routes-simple/resources/upload.ts +++ b/src/routes-simple/resources/upload.ts @@ -107,22 +107,20 @@ router.post('/api/s1/resources/upload', async (req, res) => { const meta = parseIfJson(url.searchParams.get('meta')); const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles'); // 使用 busboy 解析 multipart/form-data - const busboy = Busboy({ headers: req.headers }); + const busboy = Busboy({ headers: req.headers, preservePath: true }); const fields: any = {}; const files: any[] = []; const filePromises: Promise[] = []; let bytesReceived = 0; let bytesExpected = parseInt(req.headers['content-length'] || '0'); - busboy.on('field', (fieldname, value) => { fields[fieldname] = value; }); busboy.on('file', (fieldname, fileStream, info) => { const { filename, encoding, mimeType } = info; - const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}-${filename}`); + const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`); const writeStream = createWriteStream(tempPath); - const filePromise = new Promise((resolve, reject) => { fileStream.on('data', (chunk) => { bytesReceived += chunk.length; diff --git a/src/utils/sleep.ts b/src/utils/sleep.ts new file mode 100644 index 0000000..461b12f --- /dev/null +++ b/src/utils/sleep.ts @@ -0,0 +1,3 @@ +export const sleep = (ms: number = 1000) => { + return new Promise((resolve) => setTimeout(resolve, ms)); +} \ No newline at end of file