2023-08-15 00:22:55 +02:00
|
|
|
const multer = require("multer");
|
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
|
|
|
|
2023-06-17 01:01:27 +02:00
|
|
|
function setupMulter() {
|
|
|
|
// Handle File uploads for auto-uploading.
|
|
|
|
const storage = multer.diskStorage({
|
|
|
|
destination: function (_, _, cb) {
|
|
|
|
const uploadOutput =
|
|
|
|
process.env.NODE_ENV === "development"
|
|
|
|
? path.resolve(__dirname, `../../../collector/hotdir`)
|
|
|
|
: path.resolve(process.env.STORAGE_DIR, `../../collector/hotdir`);
|
|
|
|
cb(null, uploadOutput);
|
|
|
|
},
|
|
|
|
filename: function (_, file, cb) {
|
|
|
|
cb(null, file.originalname);
|
|
|
|
},
|
|
|
|
});
|
2023-08-15 00:22:55 +02:00
|
|
|
|
|
|
|
return { handleUploads: multer({ storage }) };
|
2023-06-17 01:01:27 +02:00
|
|
|
}
|
|
|
|
|
2023-07-15 02:32:30 +02:00
|
|
|
function setupDataImports() {
|
|
|
|
// Handle File uploads for auto-uploading.
|
|
|
|
const storage = multer.diskStorage({
|
|
|
|
destination: function (_, _, cb) {
|
|
|
|
const uploadOutput = path.resolve(__dirname, `../../storage/imports`);
|
|
|
|
fs.mkdirSync(uploadOutput, { recursive: true });
|
|
|
|
return cb(null, uploadOutput);
|
|
|
|
},
|
|
|
|
filename: function (_, file, cb) {
|
|
|
|
cb(null, file.originalname);
|
|
|
|
},
|
|
|
|
});
|
2023-08-15 00:22:55 +02:00
|
|
|
|
|
|
|
return { handleImports: multer({ storage }) };
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupLogoUploads() {
|
|
|
|
// Handle Logo uploads.
|
|
|
|
const storage = multer.diskStorage({
|
|
|
|
destination: function (_, _, cb) {
|
|
|
|
const uploadOutput = path.resolve(__dirname, `../../storage/assets`);
|
|
|
|
fs.mkdirSync(uploadOutput, { recursive: true });
|
|
|
|
return cb(null, uploadOutput);
|
|
|
|
},
|
|
|
|
filename: function (_, file, cb) {
|
|
|
|
cb(null, file.originalname);
|
|
|
|
},
|
2023-07-15 02:32:30 +02:00
|
|
|
});
|
2023-08-15 00:22:55 +02:00
|
|
|
|
|
|
|
return { handleLogoUploads: multer({ storage }) };
|
2023-07-15 02:32:30 +02:00
|
|
|
}
|
|
|
|
|
2023-06-17 01:01:27 +02:00
|
|
|
module.exports = {
|
|
|
|
setupMulter,
|
2023-07-15 02:32:30 +02:00
|
|
|
setupDataImports,
|
2023-08-15 00:22:55 +02:00
|
|
|
setupLogoUploads,
|
2023-06-17 01:01:27 +02:00
|
|
|
};
|