From 5b64d465e2ab28ef70c20f0c223709ff6931d727 Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Fri, 26 Aug 2022 16:02:47 +0200 Subject: [PATCH] fix: Use move-file instead of rename --- .../attachments/process-uploaded-file.js | 6 +-- server/package-lock.json | 38 +++++++++++++++++++ server/package.json | 1 + 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/server/api/helpers/attachments/process-uploaded-file.js b/server/api/helpers/attachments/process-uploaded-file.js index 21b7b270..c692be51 100644 --- a/server/api/helpers/attachments/process-uploaded-file.js +++ b/server/api/helpers/attachments/process-uploaded-file.js @@ -1,13 +1,11 @@ const fs = require('fs'); const path = require('path'); -const util = require('util'); const rimraf = require('rimraf'); +const moveFile = require('move-file'); const filenamify = require('filenamify'); const { v4: uuid } = require('uuid'); const sharp = require('sharp'); -const rename = util.promisify(fs.rename); - module.exports = { inputs: { file: { @@ -26,7 +24,7 @@ module.exports = { const filePath = path.join(rootPath, filename); fs.mkdirSync(rootPath); - await rename(inputs.file.fd, filePath); + await moveFile(inputs.file.fd, filePath); const image = sharp(filePath); let metadata; diff --git a/server/package-lock.json b/server/package-lock.json index fdc7fe1a..baac2088 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -14,6 +14,7 @@ "knex": "^2.2.0", "lodash": "^4.17.21", "moment": "^2.29.4", + "move-file": "^2.1.0", "rimraf": "^3.0.2", "sails": "^1.5.2", "sails-hook-orm": "^4.0.1", @@ -4398,6 +4399,28 @@ "node": "*" } }, + "node_modules/move-file": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/move-file/-/move-file-2.1.0.tgz", + "integrity": "sha512-i9qLW6gqboJ5Ht8bauZi7KlTnQ3QFpBCvMvFfEcHADKgHGeJ9BZMO7SFCTwHPV9Qa0du9DYY1Yx3oqlGt30nXA==", + "dependencies": { + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10.17" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/move-file/node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "engines": { + "node": ">=8" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -11370,6 +11393,21 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" }, + "move-file": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/move-file/-/move-file-2.1.0.tgz", + "integrity": "sha512-i9qLW6gqboJ5Ht8bauZi7KlTnQ3QFpBCvMvFfEcHADKgHGeJ9BZMO7SFCTwHPV9Qa0du9DYY1Yx3oqlGt30nXA==", + "requires": { + "path-exists": "^4.0.0" + }, + "dependencies": { + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" + } + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/server/package.json b/server/package.json index bc032fca..52c143a4 100644 --- a/server/package.json +++ b/server/package.json @@ -46,6 +46,7 @@ "knex": "^2.2.0", "lodash": "^4.17.21", "moment": "^2.29.4", + "move-file": "^2.1.0", "rimraf": "^3.0.2", "sails": "^1.5.2", "sails-hook-orm": "^4.0.1",