@kne/fastify-file-manager 3.0.1-alpha.3 → 3.0.1
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 +16 -9
- package/package.json +1 -1
|
@@ -381,15 +381,22 @@ module.exports = fp(async (fastify, fastifyOptions) => {
|
|
|
381
381
|
await fs.mkdir(tmpPath);
|
|
382
382
|
const files = [];
|
|
383
383
|
for (const file of fileList) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
384
|
+
try {
|
|
385
|
+
const fileStream = await getFileReadStream(file);
|
|
386
|
+
const filepath = path.resolve(tmpPath, file.filename);
|
|
387
|
+
const writeStream = fs.createWriteStream(filepath);
|
|
388
|
+
fileStream.pipe(writeStream);
|
|
389
|
+
await new Promise((resolve, reject) => {
|
|
390
|
+
writeStream.on('finish', resolve);
|
|
391
|
+
writeStream.on('error', reject);
|
|
392
|
+
});
|
|
393
|
+
files.push(filepath);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
console.warn(`skip invalid file: ${file.uuid}`, error.message);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (files.length === 0) {
|
|
399
|
+
throw new Error('No valid files to compress');
|
|
393
400
|
}
|
|
394
401
|
const compressStream = new compressing[type].Stream();
|
|
395
402
|
files.forEach(filepath => {
|