@opengis/fastify-table 1.4.32 → 1.4.34
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/package.json
CHANGED
|
@@ -51,18 +51,20 @@ export default async function uploadMultiPart(req) {
|
|
|
51
51
|
const parts = req.parts();
|
|
52
52
|
const part = await parts.next();
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const value = part?.value?.fields?.file || part?.value;
|
|
55
|
+
|
|
56
|
+
if (!value?.filename) {
|
|
55
57
|
throw new Error('upload error');
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
const ext = path.extname(
|
|
60
|
+
const ext = path.extname(value.filename).toLowerCase();
|
|
59
61
|
|
|
60
62
|
// check extension
|
|
61
63
|
if (!allowedExtensions.includes(ext.substring(1))) {
|
|
62
64
|
throw new Error('file extension is not allowed');
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
const buffer = await
|
|
67
|
+
const buffer = await value.toBuffer();
|
|
66
68
|
|
|
67
69
|
if (!buffer?.length) {
|
|
68
70
|
throw new Error('file buffer is empty');
|
|
@@ -80,11 +82,11 @@ export default async function uploadMultiPart(req) {
|
|
|
80
82
|
const newFilename = `${randomUUID()}${ext}`;
|
|
81
83
|
|
|
82
84
|
const file = {
|
|
83
|
-
originalFilename:
|
|
85
|
+
originalFilename: value.filename,
|
|
84
86
|
filepath: path.join(folder, newFilename).replace(/\\/g, '/'),
|
|
85
87
|
relativeFilepath: path.join(reldirpath, newFilename).replace(/\\/g, '/'),
|
|
86
88
|
size: Buffer.byteLength(buffer),
|
|
87
|
-
mimetype:
|
|
89
|
+
mimetype: value.mimetype,
|
|
88
90
|
extension: ext.substring(1),
|
|
89
91
|
};
|
|
90
92
|
|
|
@@ -63,7 +63,7 @@ export default async function getFile({
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const headers = {
|
|
66
|
-
'Content-Disposition':
|
|
66
|
+
'Content-Disposition': `inline; filename=${path.basename(filepath)}`,
|
|
67
67
|
'Cache-Control': 'max-age=86400',
|
|
68
68
|
'Content-Type': `${mime(filepath)}`, // ; charset=utf-8 --- untested
|
|
69
69
|
};
|