@kne/fastify-file-manager 3.0.0-alpha.1 → 3.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/services/file-record.js +27 -28
- package/package.json +1 -1
|
@@ -83,7 +83,7 @@ module.exports = fp(async (fastify, fastifyOptions) => {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
//清除临时文件
|
|
86
|
-
|
|
86
|
+
fs.remove(tmpPath).catch(console.error);
|
|
87
87
|
|
|
88
88
|
const outputFile = await (async create => {
|
|
89
89
|
if (!id) {
|
|
@@ -364,10 +364,10 @@ module.exports = fp(async (fastify, fastifyOptions) => {
|
|
|
364
364
|
compressStream.addEntry(path.resolve(filepath));
|
|
365
365
|
});
|
|
366
366
|
compressStream.on('error', () => {
|
|
367
|
-
fs.remove(tmpPath);
|
|
367
|
+
fs.remove(tmpPath).catch(console.error);
|
|
368
368
|
});
|
|
369
369
|
compressStream.on('end', () => {
|
|
370
|
-
fs.remove(tmpPath);
|
|
370
|
+
fs.remove(tmpPath).catch(console.error);
|
|
371
371
|
});
|
|
372
372
|
return compressStream;
|
|
373
373
|
};
|
|
@@ -392,33 +392,32 @@ module.exports = fp(async (fastify, fastifyOptions) => {
|
|
|
392
392
|
cwd: tmpPath,
|
|
393
393
|
nodir: true
|
|
394
394
|
});
|
|
395
|
+
console.log('---->1:', files);
|
|
395
396
|
//将文件上传到文件系统
|
|
396
|
-
const fileList =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
filename,
|
|
406
|
-
mimetype,
|
|
407
|
-
encoding: 'binary',
|
|
408
|
-
file: fileStream
|
|
409
|
-
},
|
|
397
|
+
const fileList = [];
|
|
398
|
+
for (let dir of files) {
|
|
399
|
+
const filepath = path.resolve(tmpPath, dir);
|
|
400
|
+
const filename = path.basename(dir);
|
|
401
|
+
const fileStream = fs.createReadStream(filepath);
|
|
402
|
+
const mimetype = MimeTypes.lookup(filepath) || 'application/octet-stream';
|
|
403
|
+
console.log(filename, mimetype);
|
|
404
|
+
const file = await uploadToFileSystem({
|
|
405
|
+
file: {
|
|
410
406
|
filename,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
407
|
+
mimetype,
|
|
408
|
+
encoding: 'binary',
|
|
409
|
+
file: fileStream
|
|
410
|
+
},
|
|
411
|
+
filename,
|
|
412
|
+
namespace
|
|
413
|
+
});
|
|
414
|
+
console.log('---->2:', dir, file);
|
|
415
|
+
fileList.push({
|
|
416
|
+
dir,
|
|
417
|
+
file
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
fs.remove(tmpPath).catch(console.error);
|
|
422
421
|
return fileList;
|
|
423
422
|
};
|
|
424
423
|
|