1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00

fix: Secure S3 attachments, bump SDK, refactoring

Closes #673
This commit is contained in:
Maksim Eltyshev 2024-11-12 15:58:22 +01:00
parent f20a3d50f5
commit 97f4c0ab0d
27 changed files with 2180 additions and 702 deletions

View file

@ -1,6 +1,3 @@
const path = require('path');
const rimraf = require('rimraf');
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
@ -86,27 +83,11 @@ module.exports = {
(!project.backgroundImage ||
project.backgroundImage.dirname !== inputs.record.backgroundImage.dirname)
) {
const fileManager = sails.hooks['file-manager'].getInstance();
try {
if (sails.config.custom.s3Config) {
const client = await sails.helpers.utils.getSimpleStorageServiceClient();
if (client && inputs.record.backgroundImage && inputs.record.backgroundImage.original) {
const parsedUrl = new URL(inputs.record.backgroundImage.original);
await client.delete({ Key: parsedUrl.pathname.replace(/^\/+/, '') });
}
if (client && inputs.record.backgroundImage && inputs.record.backgroundImage.thumb) {
const parsedUrl = new URL(inputs.record.backgroundImage.thumb);
await client.delete({ Key: parsedUrl.pathname.replace(/^\/+/, '') });
}
}
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console
}
try {
rimraf.sync(
path.join(
sails.config.custom.projectBackgroundImagesPath,
inputs.record.backgroundImage.dirname,
),
await fileManager.deleteFolder(
`${sails.config.custom.projectBackgroundImagesPathSegment}/${inputs.record.backgroundImage.dirname}`,
);
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console