Skip to content

Commit

Permalink
ref: Rename folder to dir for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Nov 12, 2024
1 parent 917dcf3 commit 9794919
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server/api/helpers/attachments/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions server/api/helpers/attachments/process-uploaded-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = {
.toBuffer();

await fileManager.save(
`${folderPathSegment}/thumbnails/cover-256.${thumbnailsExtension}`,
`${dirPathSegment}/thumbnails/cover-256.${thumbnailsExtension}`,
resizeBuffer,
inputs.file.type,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -46,7 +46,7 @@ module.exports = {
const originalBuffer = await image.toBuffer();

await fileManager.save(
`${folderPathSegment}/original.${extension}`,
`${dirPathSegment}/original.${extension}`,
originalBuffer,
inputs.file.type,
);
Expand All @@ -64,15 +64,15 @@ module.exports = {
.toBuffer();

await fileManager.save(
`${folderPathSegment}/cover-336.${extension}`,
`${dirPathSegment}/cover-336.${extension}`,
cover336Buffer,
inputs.file.type,
);
} catch (error1) {
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
}
Expand Down
2 changes: 1 addition & 1 deletion server/api/helpers/projects/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions server/api/helpers/users/process-uploaded-avatar-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -46,7 +46,7 @@ module.exports = {
const originalBuffer = await image.toBuffer();

await fileManager.save(
`${folderPathSegment}/original.${extension}`,
`${dirPathSegment}/original.${extension}`,
originalBuffer,
inputs.file.type,
);
Expand All @@ -64,15 +64,15 @@ module.exports = {
.toBuffer();

await fileManager.save(
`${folderPathSegment}/square-100.${extension}`,
`${dirPathSegment}/square-100.${extension}`,
square100Buffer,
inputs.file.type,
);
} catch (error1) {
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
}
Expand Down
2 changes: 1 addition & 1 deletion server/api/helpers/users/update-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions server/api/hooks/file-manager/LocalFileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/api/hooks/file-manager/S3FileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9794919

Please sign in to comment.