#2422 Move uploads under the data root

This commit is contained in:
Cohee
2024-06-26 23:22:42 +03:00
parent 54fb7a9030
commit 5b002c6e46
10 changed files with 27 additions and 24 deletions

View File

@@ -136,7 +136,7 @@ const disableCsrf = cliArguments.disableCsrf ?? getConfigValue('disableCsrfProte
const basicAuthMode = cliArguments.basicAuthMode ?? getConfigValue('basicAuthMode', DEFAULT_BASIC_AUTH);
const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
const { UPLOADS_PATH } = require('./src/constants');
const uploadsPath = path.join(dataRoot, require('./src/constants').UPLOADS_DIRECTORY);
// CORS Settings //
const CORS = cors({
@@ -286,7 +286,7 @@ app.use(userModule.requireLoginMiddleware);
app.get('/api/ping', (_, response) => response.sendStatus(204));
// File uploads
app.use(multer({ dest: UPLOADS_PATH, limits: { fieldSize: 10 * 1024 * 1024 } }).single('avatar'));
app.use(multer({ dest: uploadsPath, limits: { fieldSize: 10 * 1024 * 1024 } }).single('avatar'));
app.use(require('./src/middleware/multerMonkeyPatch'));
// User data mount
@@ -303,8 +303,8 @@ app.get('/version', async function (_, response) {
function cleanUploads() {
try {
if (fs.existsSync(UPLOADS_PATH)) {
const uploads = fs.readdirSync(UPLOADS_PATH);
if (fs.existsSync(uploadsPath)) {
const uploads = fs.readdirSync(uploadsPath);
if (!uploads.length) {
return;
@@ -312,7 +312,7 @@ function cleanUploads() {
console.debug(`Cleaning uploads folder (${uploads.length} files)`);
uploads.forEach(file => {
const pathToFile = path.join(UPLOADS_PATH, file);
const pathToFile = path.join(uploadsPath, file);
fs.unlinkSync(pathToFile);
});
}