From 891697fd0f6df835b8c18499a5f13b3ed476a8da Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Sat, 6 Jul 2024 11:05:57 +0100 Subject: [PATCH] Update formidable 3.2.4 => 3.5.1 --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 2 +- uploader.js | 16 ++++++++-------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 79080955..47fabc6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "docker-secret": "1.1.2", "express": "4.19.2", "express-urlrewrite": "1.2.0", - "formidable": "3.2.4", + "formidable": "3.5.1", "gm": "1.23.1", "got": "11.8.5", "http-proxy-middleware": "0.20.0", @@ -8762,9 +8762,9 @@ } }, "node_modules/dezalgo": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz", - "integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", "dependencies": { "asap": "^2.0.0", "wrappy": "1" @@ -10009,13 +10009,13 @@ } }, "node_modules/formidable": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.2.4.tgz", - "integrity": "sha512-8/5nJsq+o2o1+Dryx1k5gLTDaw0dNE9kL4P3srKArO6zhoerGm42/R8zq+L5EkV7kckNTvJpJke0kI8JseL3RQ==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.1.tgz", + "integrity": "sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==", "dependencies": { - "dezalgo": "1.0.3", - "hexoid": "1.0.0", - "once": "1.4.0" + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0" }, "funding": { "url": "https://ko-fi.com/tunnckoCore/commissions" @@ -26308,9 +26308,9 @@ "dev": true }, "dezalgo": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz", - "integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", "requires": { "asap": "^2.0.0", "wrappy": "1" @@ -27261,13 +27261,13 @@ } }, "formidable": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.2.4.tgz", - "integrity": "sha512-8/5nJsq+o2o1+Dryx1k5gLTDaw0dNE9kL4P3srKArO6zhoerGm42/R8zq+L5EkV7kckNTvJpJke0kI8JseL3RQ==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.1.tgz", + "integrity": "sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==", "requires": { - "dezalgo": "1.0.3", - "hexoid": "1.0.0", - "once": "1.4.0" + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0" } }, "forwarded": { diff --git a/package.json b/package.json index 82b31ff8..bafff599 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "docker-secret": "1.1.2", "express": "4.19.2", "express-urlrewrite": "1.2.0", - "formidable": "3.2.4", + "formidable": "3.5.1", "gm": "1.23.1", "got": "11.8.5", "http-proxy-middleware": "0.20.0", diff --git a/uploader.js b/uploader.js index 874cb069..b5fbff63 100644 --- a/uploader.js +++ b/uploader.js @@ -43,9 +43,10 @@ export function configure(startStamp) { class FileInfo { constructor(file, targetDir, nameLen, dirDepth) { - this.name = file.name; + this.name = file.originalFilename; this.size = file.size; - this.mime = file.type; + this.mime = file.mimetype; + this.path = file.filepath; this.createFileName(targetDir, nameLen, dirDepth); } @@ -193,7 +194,7 @@ export function configure(startStamp) { } const postHandler = (req, res) => { - const form = new formidable.IncomingForm(); + const form = formidable({uploadDir: incomeDir}); const isAvatar = req.url === '/uploadava'; const maxPostSize = isAvatar ? maxAvaPostSize : maxPhotoPostSize; const targetDir = isAvatar ? targetDirAvatar : targetDirPhoto; @@ -210,22 +211,21 @@ export function configure(startStamp) { tooBigPostDestroy(req, isAvatar, 0, contentLength); } - form.uploadDir = incomeDir; form .on('fileBegin', (name, file) => { - tmpFiles.push(file.path); + tmpFiles.push(file.filepath); const fileInfo = new FileInfo(file, targetDir, isAvatar ? 10 : 18, isAvatar ? 2 : 3); - map[path.basename(file.path)] = fileInfo; + map[path.basename(file.filepath)] = fileInfo; files.push(fileInfo); }) .on('file', (name, file) => { - const fileInfo = map[path.basename(file.path)]; + const fileInfo = map[path.basename(file.filepath)]; fileInfo.size = file.size; fileInfo.path = path.join(incomeDir, fileInfo.file); - mv(file.path, fileInfo.path, { clobber: false }, err => { + mv(file.filepath, fileInfo.path, { clobber: false }, err => { if (err) { logger.error('MV error:', err); }