Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/note.picotech.app/public_html/src/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const UserUploadLimit = sequelize.define('UserUploadLimit', {
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
references: {
model: 'users',
key: 'id'
},
onDelete: 'CASCADE'
},
files_count: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
validate: {
min: 0
}
},
total_size_bytes: {
type: DataTypes.BIGINT,
allowNull: false,
defaultValue: 0,
validate: {
min: 0
}
},
reset_at: {
type: DataTypes.DATE,
allowNull: true
}
}, {
sequelize,
modelName: 'UserUploadLimit',
tableName: 'user_upload_limits',
timestamps: true,
indexes: [
{
unique: true,
fields: ['user_id']
}
]
});
// Static methods for managing upload limits
UserUploadLimit.getOrCreateUserLimits = async function(userId) {
const [limit, created] = await this.findOrCreate({
where: { user_id: userId },
defaults: {
user_id: userId,
files_count: 0,
total_size_bytes: 0
}
});
return limit;
};
UserUploadLimit.checkAndUpdateLimits = async function(userId, fileSize) {
const limit = await this.getOrCreateUserLimits(userId);
const MAX_FILES = 10;
const MAX_TOTAL_SIZE = 500 * 1024 * 1024; // 500MB
if (limit.files_count >= MAX_FILES) {
throw new Error('Maximum number of files per user exceeded');
}
if (limit.total_size_bytes + fileSize > MAX_TOTAL_SIZE) {
throw new Error('Maximum upload size per user exceeded');
}
// Update limits
limit.files_count += 1;
limit.total_size_bytes += fileSize;
await limit.save();
return limit;
};
UserUploadLimit.resetUserLimits = async function(userId) {
const limit = await this.findOne({ where: { user_id: userId } });
if (limit) {
limit.files_count = 0;
limit.total_size_bytes = 0;
limit.reset_at = new Date();
await limit.save();
}
};
UserUploadLimit.getUserLimits = async function(userId) {
return await this.getOrCreateUserLimits(userId);
};
// Clean up old reset records (optional maintenance)
UserUploadLimit.cleanupOldResets = async function() {
const cutoffDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); // 30 days ago
await this.update(
{ reset_at: null },
{
where: {
reset_at: { [sequelize.Op.lt]: cutoffDate }
}
}
);
};
module.exports = UserUploadLimit; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0034 ]-- |