50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const multer = require('multer');
|
|
const { v4: uuidv4 } = require('uuid');
|
|
const path = require('path');
|
|
const configService = require('./configService');
|
|
|
|
// ? users
|
|
const entryPicturesUpload = multer({
|
|
storage:
|
|
multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
let folder = 'posters';
|
|
if (file.fieldname == 'backdrop') folder = 'backdrops';
|
|
if (file.fieldname == 'logo') folder = 'logos';
|
|
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
|
|
cb(null, path.join(dataPath, 'images', 'entries', folder));
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split('.').pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
}
|
|
})
|
|
});
|
|
|
|
const collectionPicturesUpload = multer({
|
|
storage:
|
|
multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
let folder = 'posters';
|
|
if (file.fieldname == 'backdrop') folder = 'backdrops';
|
|
if (file.fieldname == 'logo') folder = 'logos';
|
|
|
|
const dataPath = configService.getSettings().userDataPath;
|
|
|
|
cb(null, path.join(dataPath, 'images', 'collections', folder));
|
|
},
|
|
filename: function (req, file, cb) {
|
|
const uniqueFilename = uuidv4();
|
|
const extension = file.originalname.split('.').pop();
|
|
cb(null, `${uniqueFilename}.${extension}`);
|
|
}
|
|
})
|
|
});
|
|
|
|
module.exports = {
|
|
entryPicturesUpload,
|
|
collectionPicturesUpload,
|
|
} |