feat: Track storage usage

This commit is contained in:
Maksim Eltyshev
2025-08-23 00:03:20 +02:00
parent 2f4bcb0583
commit 4d77a1f596
89 changed files with 1052 additions and 304 deletions

View File

@@ -16,18 +16,13 @@ module.exports = {
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
dirname: {
type: 'string',
required: true,
},
extension: {
type: 'string',
required: true,
},
sizeInBytes: {
type: 'string', // TODO: should be number somehow
size: {
type: 'string',
required: true,
columnName: 'size_in_bytes',
},
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
@@ -38,6 +33,11 @@ module.exports = {
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
uploadedFileId: {
model: 'UploadedFile',
required: true,
columnName: 'uploaded_file_id',
},
projectId: {
model: 'Project',
required: true,

View File

@@ -4,22 +4,40 @@
*/
/**
* FileReference.js
* StorageUsage.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
const MAIN_ID = '1';
module.exports = {
MAIN_ID,
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
total: {
type: 'number',
allowNull: true,
defaultsTo: 0,
type: 'string',
required: true,
},
userAvatars: {
type: 'string',
required: true,
columnName: 'user_avatars',
},
backgroundImages: {
type: 'string',
required: true,
columnName: 'background_images',
},
attachments: {
type: 'string',
required: true,
columnName: 'attachments',
},
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
@@ -31,5 +49,5 @@ module.exports = {
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
},
tableName: 'file_reference',
tableName: 'storage_usage',
};

View File

@@ -0,0 +1,59 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* UploadedFile.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
const Types = {
USER_AVATAR: 'userAvatar',
BACKGROUND_IMAGE: 'backgroundImage',
ATTACHMENT: 'attachment',
};
module.exports = {
Types,
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
type: {
type: 'string',
isIn: Object.values(Types),
required: true,
},
referencesTotal: {
type: 'number',
allowNull: true,
defaultsTo: 0,
columnName: 'references_total',
},
mimeType: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
columnName: 'mime_type',
},
size: {
type: 'string',
required: true,
},
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
},
tableName: 'uploaded_file',
};