2021-06-23 14:15:14 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const multer = require('multer');
|
2021-06-24 12:53:45 +02:00
|
|
|
|
|
|
|
if (!fs.existsSync('data/uploads')) {
|
2021-06-25 10:42:44 +02:00
|
|
|
fs.mkdirSync('data/uploads', { recursive: true });
|
2021-06-24 12:53:45 +02:00
|
|
|
}
|
2021-06-23 14:15:14 +02:00
|
|
|
|
|
|
|
const storage = multer.diskStorage({
|
|
|
|
destination: (req, file, cb) => {
|
|
|
|
cb(null, './data/uploads');
|
|
|
|
},
|
|
|
|
filename: (req, file, cb) => {
|
|
|
|
cb(null, Date.now() + '--' + file.originalname);
|
2021-10-22 14:00:38 +02:00
|
|
|
},
|
2021-08-06 15:15:54 +02:00
|
|
|
});
|
2021-06-23 14:15:14 +02:00
|
|
|
|
2022-02-06 08:21:01 -05:00
|
|
|
const supportedTypes = [
|
|
|
|
'jpg',
|
|
|
|
'jpeg',
|
|
|
|
'png',
|
|
|
|
'svg',
|
|
|
|
'svg+xml',
|
|
|
|
'x-icon',
|
|
|
|
'html',
|
|
|
|
];
|
2021-06-23 14:15:14 +02:00
|
|
|
|
|
|
|
const fileFilter = (req, file, cb) => {
|
|
|
|
if (supportedTypes.includes(file.mimetype.split('/')[1])) {
|
|
|
|
cb(null, true);
|
|
|
|
} else {
|
|
|
|
cb(null, false);
|
|
|
|
}
|
2021-08-06 15:15:54 +02:00
|
|
|
};
|
2021-06-23 14:15:14 +02:00
|
|
|
|
|
|
|
const upload = multer({ storage, fileFilter });
|
|
|
|
|
2022-02-06 08:21:01 -05:00
|
|
|
module.exports = {
|
|
|
|
icon: upload.single('icon'),
|
|
|
|
bookmark: upload.single('file'),
|
|
|
|
};
|