From 9794919fd299798d6aef9b24a9ad5221a3dde8ce Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Tue, 12 Nov 2024 17:07:04 +0100 Subject: [PATCH] ref: Rename folder to dir for consistency --- server/api/helpers/attachments/delete-one.js | 2 +- .../api/helpers/attachments/process-uploaded-file.js | 6 +++--- .../projects/process-uploaded-background-image-file.js | 8 ++++---- server/api/helpers/projects/update-one.js | 2 +- .../api/helpers/users/process-uploaded-avatar-file.js | 8 ++++---- server/api/helpers/users/update-one.js | 2 +- server/api/hooks/file-manager/LocalFileManager.js | 10 +++++----- server/api/hooks/file-manager/S3FileManager.js | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/server/api/helpers/attachments/delete-one.js b/server/api/helpers/attachments/delete-one.js index 56d01748..eb9c1dca 100644 --- a/server/api/helpers/attachments/delete-one.js +++ b/server/api/helpers/attachments/delete-one.js @@ -50,7 +50,7 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); try { - await fileManager.deleteFolder( + await fileManager.deleteDir( `${sails.config.custom.attachmentsPathSegment}/${attachment.dirname}`, ); } catch (error) { diff --git a/server/api/helpers/attachments/process-uploaded-file.js b/server/api/helpers/attachments/process-uploaded-file.js index 216dcf86..695084d1 100644 --- a/server/api/helpers/attachments/process-uploaded-file.js +++ b/server/api/helpers/attachments/process-uploaded-file.js @@ -16,12 +16,12 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); const dirname = uuid(); - const folderPathSegment = `${sails.config.custom.attachmentsPathSegment}/${dirname}`; + const dirPathSegment = `${sails.config.custom.attachmentsPathSegment}/${dirname}`; const filename = filenamify(inputs.file.filename); const filePath = await fileManager.move( inputs.file.fd, - `${folderPathSegment}/${filename}`, + `${dirPathSegment}/${filename}`, inputs.file.type, ); @@ -64,7 +64,7 @@ module.exports = { .toBuffer(); await fileManager.save( - `${folderPathSegment}/thumbnails/cover-256.${thumbnailsExtension}`, + `${dirPathSegment}/thumbnails/cover-256.${thumbnailsExtension}`, resizeBuffer, inputs.file.type, ); diff --git a/server/api/helpers/projects/process-uploaded-background-image-file.js b/server/api/helpers/projects/process-uploaded-background-image-file.js index 4237435a..8b5aafb6 100644 --- a/server/api/helpers/projects/process-uploaded-background-image-file.js +++ b/server/api/helpers/projects/process-uploaded-background-image-file.js @@ -33,7 +33,7 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); const dirname = uuid(); - const folderPathSegment = `${sails.config.custom.projectBackgroundImagesPathSegment}/${dirname}`; + const dirPathSegment = `${sails.config.custom.projectBackgroundImagesPathSegment}/${dirname}`; let { width, pageHeight: height = metadata.height } = metadata; if (metadata.orientation && metadata.orientation > 4) { @@ -46,7 +46,7 @@ module.exports = { const originalBuffer = await image.toBuffer(); await fileManager.save( - `${folderPathSegment}/original.${extension}`, + `${dirPathSegment}/original.${extension}`, originalBuffer, inputs.file.type, ); @@ -64,7 +64,7 @@ module.exports = { .toBuffer(); await fileManager.save( - `${folderPathSegment}/cover-336.${extension}`, + `${dirPathSegment}/cover-336.${extension}`, cover336Buffer, inputs.file.type, ); @@ -72,7 +72,7 @@ module.exports = { console.warn(error1.stack); // eslint-disable-line no-console try { - fileManager.deleteFolder(folderPathSegment); + fileManager.deleteDir(dirPathSegment); } catch (error2) { console.warn(error2.stack); // eslint-disable-line no-console } diff --git a/server/api/helpers/projects/update-one.js b/server/api/helpers/projects/update-one.js index c7386e6c..eb5b18c8 100644 --- a/server/api/helpers/projects/update-one.js +++ b/server/api/helpers/projects/update-one.js @@ -86,7 +86,7 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); try { - await fileManager.deleteFolder( + await fileManager.deleteDir( `${sails.config.custom.projectBackgroundImagesPathSegment}/${inputs.record.backgroundImage.dirname}`, ); } catch (error) { diff --git a/server/api/helpers/users/process-uploaded-avatar-file.js b/server/api/helpers/users/process-uploaded-avatar-file.js index aec33610..0cf34342 100644 --- a/server/api/helpers/users/process-uploaded-avatar-file.js +++ b/server/api/helpers/users/process-uploaded-avatar-file.js @@ -33,7 +33,7 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); const dirname = uuid(); - const folderPathSegment = `${sails.config.custom.userAvatarsPathSegment}/${dirname}`; + const dirPathSegment = `${sails.config.custom.userAvatarsPathSegment}/${dirname}`; let { width, pageHeight: height = metadata.height } = metadata; if (metadata.orientation && metadata.orientation > 4) { @@ -46,7 +46,7 @@ module.exports = { const originalBuffer = await image.toBuffer(); await fileManager.save( - `${folderPathSegment}/original.${extension}`, + `${dirPathSegment}/original.${extension}`, originalBuffer, inputs.file.type, ); @@ -64,7 +64,7 @@ module.exports = { .toBuffer(); await fileManager.save( - `${folderPathSegment}/square-100.${extension}`, + `${dirPathSegment}/square-100.${extension}`, square100Buffer, inputs.file.type, ); @@ -72,7 +72,7 @@ module.exports = { console.warn(error1.stack); // eslint-disable-line no-console try { - fileManager.deleteFolder(folderPathSegment); + fileManager.deleteDir(dirPathSegment); } catch (error2) { console.warn(error2.stack); // eslint-disable-line no-console } diff --git a/server/api/helpers/users/update-one.js b/server/api/helpers/users/update-one.js index 2793ea56..0be20b40 100644 --- a/server/api/helpers/users/update-one.js +++ b/server/api/helpers/users/update-one.js @@ -102,7 +102,7 @@ module.exports = { const fileManager = sails.hooks['file-manager'].getInstance(); try { - await fileManager.deleteFolder( + await fileManager.deleteDir( `${sails.config.custom.userAvatarsPathSegment}/${inputs.record.avatar.dirname}`, ); } catch (error) { diff --git a/server/api/hooks/file-manager/LocalFileManager.js b/server/api/hooks/file-manager/LocalFileManager.js index 8c7c31d2..707d3f8e 100644 --- a/server/api/hooks/file-manager/LocalFileManager.js +++ b/server/api/hooks/file-manager/LocalFileManager.js @@ -12,10 +12,10 @@ class LocalFileManager { async move(sourceFilePath, filePathSegment) { const { dir, base } = path.parse(filePathSegment); - const folderPath = buildPath(dir); - const filePath = path.join(folderPath, base); + const dirPath = buildPath(dir); + const filePath = path.join(dirPath, base); - await fs.promises.mkdir(folderPath); + await fs.promises.mkdir(dirPath); await fse.move(sourceFilePath, filePath); return filePath; @@ -38,8 +38,8 @@ class LocalFileManager { } // eslint-disable-next-line class-methods-use-this - async deleteFolder(folderPathSegment) { - await rimraf(buildPath(folderPathSegment)); + async deleteDir(dirPathSegment) { + await rimraf(buildPath(dirPathSegment)); } // eslint-disable-next-line class-methods-use-this diff --git a/server/api/hooks/file-manager/S3FileManager.js b/server/api/hooks/file-manager/S3FileManager.js index 7c645c7f..3a0f426d 100644 --- a/server/api/hooks/file-manager/S3FileManager.js +++ b/server/api/hooks/file-manager/S3FileManager.js @@ -45,10 +45,10 @@ class S3FileManager { return result.Body; } - async deleteFolder(folderPathSegment) { + async deleteDir(dirPathSegment) { const listObjectsCommand = new ListObjectsV2Command({ Bucket: sails.config.custom.s3Bucket, - Prefix: folderPathSegment, + Prefix: dirPathSegment, }); const result = await this.client.send(listObjectsCommand);