in this file: src/controllers/uploads.js:154
uploadsController.uploadFile = async function (uid, uploadedFile) {
if (plugins.hooks.hasListeners('filter:uploadFile')) {
return await plugins.hooks.fire('filter:uploadFile', {
file: uploadedFile,
uid: uid,
folder: 'files',
});
}
if (!uploadedFile) {
throw new Error('[[error:invalid-file]]');
}
const isAdmin = await user.isAdministrator(uid);
if (!isAdmin && uploadedFile.size > meta.config.maximumFileSize * 1024) {
throw new Error(`[[error:file-too-big, ${meta.config.maximumFileSize}]]`);
}
const allowed = file.allowedExtensions();
const extension = path.extname(uploadedFile.name).toLowerCase();
if (allowed.length > 0 && (!extension || extension === '.' || !allowed.includes(extension))) {
throw new Error(`[[error:invalid-file-type, ${allowed.join(', ')}]]`);
}
const currentDate = new Date();
const year = currentDate.getFullYear() + '';
const month = String(currentDate.getMonth() + 1).padStart(2, '0') + '';
const date = String(currentDate.getDate()).padStart(2, '0') + '';
const random = Math.random().toString(36).substring(2, 4);
const dirPath = path.join('files', year, month, date, random);
return await saveFileToLocal(uid, dirPath, uploadedFile);
};
i thinks this is good for files manager