mirror of
https://github.com/plankanban/planka.git
synced 2025-12-22 09:15:37 +03:00
feat: Track storage usage
This commit is contained in:
@@ -43,10 +43,10 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
const backgroundImage = await BackgroundImage.qm.deleteOne(inputs.record.id);
|
||||
const { backgroundImage, uploadedFile } = await BackgroundImage.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (backgroundImage) {
|
||||
sails.helpers.backgroundImages.removeRelatedFiles(backgroundImage);
|
||||
sails.helpers.utils.removeUnreferencedUploadedFiles(uploadedFile);
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ module.exports = {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
return {
|
||||
..._.omit(inputs.record, ['dirname', 'extension']),
|
||||
url: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/original.${inputs.record.extension}`)}`,
|
||||
..._.omit(inputs.record, ['uploadedFileId', 'extension']),
|
||||
url: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.uploadedFileId}/original.${inputs.record.extension}`)}`,
|
||||
thumbnailUrls: {
|
||||
outside360: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/outside-360.${inputs.record.extension}`)}`,
|
||||
outside360: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.uploadedFileId}/outside-360.${inputs.record.extension}`)}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { v4: uuid } = require('uuid');
|
||||
const { rimraf } = require('rimraf');
|
||||
const mime = require('mime');
|
||||
const { v4: uuid } = require('uuid');
|
||||
const sharp = require('sharp');
|
||||
|
||||
module.exports = {
|
||||
@@ -32,8 +32,16 @@ module.exports = {
|
||||
});
|
||||
|
||||
let metadata;
|
||||
let originalBuffer;
|
||||
|
||||
try {
|
||||
metadata = await image.metadata();
|
||||
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
image = image.rotate();
|
||||
}
|
||||
|
||||
originalBuffer = await image.toBuffer();
|
||||
} catch (error) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'fileIsNotImage';
|
||||
@@ -41,20 +49,19 @@ module.exports = {
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
const dirname = uuid();
|
||||
const dirPathSegment = `${sails.config.custom.backgroundImagesPathSegment}/${dirname}`;
|
||||
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
image = image.rotate();
|
||||
}
|
||||
|
||||
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
const size = originalBuffer.length;
|
||||
|
||||
const { id: uploadedFileId } = await UploadedFile.qm.createOne({
|
||||
mimeType,
|
||||
size,
|
||||
id: uuid(),
|
||||
type: UploadedFile.Types.BACKGROUND_IMAGE,
|
||||
});
|
||||
|
||||
const dirPathSegment = `${sails.config.custom.backgroundImagesPathSegment}/${uploadedFileId}`;
|
||||
|
||||
let sizeInBytes;
|
||||
try {
|
||||
const originalBuffer = await image.toBuffer();
|
||||
sizeInBytes = originalBuffer.length;
|
||||
|
||||
await fileManager.save(
|
||||
`${dirPathSegment}/original.${extension}`,
|
||||
originalBuffer,
|
||||
@@ -82,6 +89,7 @@ module.exports = {
|
||||
|
||||
await fileManager.deleteDir(dirPathSegment);
|
||||
await rimraf(inputs.file.fd);
|
||||
await UploadedFile.qm.deleteOne(uploadedFileId);
|
||||
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
@@ -89,9 +97,9 @@ module.exports = {
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
return {
|
||||
dirname,
|
||||
uploadedFileId,
|
||||
extension,
|
||||
sizeInBytes,
|
||||
size,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const backgroundImages = _.isPlainObject(inputs.recordOrRecords)
|
||||
? [inputs.recordOrRecords]
|
||||
: inputs.recordOrRecords;
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
backgroundImages.forEach(async (backgroundImage) => {
|
||||
await fileManager.deleteDir(
|
||||
`${sails.config.custom.backgroundImagesPathSegment}/${backgroundImage.dirname}`,
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user