mirror of
https://github.com/plankanban/planka.git
synced 2025-12-23 09:15:09 +03:00
feat: Track storage usage
This commit is contained in:
@@ -51,13 +51,11 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
const { attachment, fileReference } = await Attachment.qm.deleteOne(inputs.record.id, {
|
||||
isFile: inputs.record.type === Attachment.Types.FILE,
|
||||
});
|
||||
const { attachment, uploadedFile } = await Attachment.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (attachment) {
|
||||
if (fileReference) {
|
||||
sails.helpers.attachments.removeUnreferencedFiles(fileReference);
|
||||
if (uploadedFile) {
|
||||
sails.helpers.utils.removeUnreferencedUploadedFiles(uploadedFile);
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
...inputs.record,
|
||||
data: {
|
||||
..._.omit(inputs.record.data, [
|
||||
'fileReferenceId',
|
||||
'uploadedFileId',
|
||||
'filename',
|
||||
'image.thumbnailsExtension',
|
||||
]),
|
||||
|
||||
@@ -10,7 +10,7 @@ const mime = require('mime');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const filenamify = require('../../../utils/filenamify');
|
||||
const { MAX_SIZE_IN_BYTES_TO_GET_ENCODING } = require('../../../constants');
|
||||
const { MAX_SIZE_TO_GET_ENCODING } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
@@ -23,17 +23,22 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
const { id: fileReferenceId } = await FileReference.create().fetch();
|
||||
const dirPathSegment = `${sails.config.custom.attachmentsPathSegment}/${fileReferenceId}`;
|
||||
const filename = filenamify(inputs.file.filename);
|
||||
|
||||
const mimeType = mime.getType(filename);
|
||||
const sizeInBytes = inputs.file.size;
|
||||
const { size } = inputs.file;
|
||||
|
||||
const { id: uploadedFileId } = await UploadedFile.qm.createOne({
|
||||
mimeType,
|
||||
size,
|
||||
type: UploadedFile.Types.ATTACHMENT,
|
||||
});
|
||||
|
||||
const dirPathSegment = `${sails.config.custom.attachmentsPathSegment}/${uploadedFileId}`;
|
||||
|
||||
let buffer;
|
||||
let encoding = null;
|
||||
|
||||
if (sizeInBytes <= MAX_SIZE_IN_BYTES_TO_GET_ENCODING) {
|
||||
if (size <= MAX_SIZE_TO_GET_ENCODING) {
|
||||
try {
|
||||
buffer = await fsPromises.readFile(inputs.file.fd);
|
||||
} catch (error) {
|
||||
@@ -52,10 +57,10 @@ module.exports = {
|
||||
);
|
||||
|
||||
const data = {
|
||||
fileReferenceId,
|
||||
uploadedFileId,
|
||||
filename,
|
||||
mimeType,
|
||||
sizeInBytes,
|
||||
size,
|
||||
encoding,
|
||||
image: null,
|
||||
};
|
||||
|
||||
@@ -1,35 +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: {
|
||||
fileReferenceOrFileReferences: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const fileReferences = _.isPlainObject(inputs.fileReferenceOrFileReferences)
|
||||
? [inputs.fileReferenceOrFileReferences]
|
||||
: inputs.fileReferenceOrFileReferences;
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
fileReferences.forEach(async (fileReference) => {
|
||||
if (fileReference.total !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await fileManager.deleteDir(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${fileReference.id}`,
|
||||
);
|
||||
|
||||
await FileReference.destroyOne(fileReference.id);
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user