mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.2 KiB
60 lines
1.2 KiB
'use strict';
|
|
|
|
const FileType = require('file-type')
|
|
, { allowMimeNoMatch } = require(__dirname+'/../../configs/main.js');
|
|
|
|
const image = new Set([
|
|
'image/jpeg',
|
|
'image/pjpeg',
|
|
'image/png',
|
|
'image/bmp',
|
|
]);
|
|
|
|
const animatedImage = new Set([
|
|
'image/gif',
|
|
'image/webp',
|
|
'image/apng',
|
|
]);
|
|
|
|
const video = new Set([
|
|
'video/mpeg',
|
|
'video/quicktime',
|
|
'video/mp4',
|
|
'video/webm',
|
|
'video/x-matroska',
|
|
'video/ogg',
|
|
]);
|
|
|
|
const audio = new Set([
|
|
'audio/flac',
|
|
'audio/mp3',
|
|
'audio/mpeg',
|
|
'audio/ogg',
|
|
'audio/wave',
|
|
'audio/wav',
|
|
]);
|
|
|
|
const other = new Set(require(__dirname+'/../../configs/main.js').otherMimeTypes);
|
|
|
|
module.exports = {
|
|
|
|
allowed: (mimetype, options) => {
|
|
return (options.image && image.has(mimetype)) ||
|
|
(options.animatedImage && animatedImage.has(mimetype)) ||
|
|
(options.video && video.has(mimetype)) ||
|
|
(options.audio && audio.has(mimetype)) ||
|
|
(options.other && other.has(mimetype));
|
|
},
|
|
|
|
realMimeCheck: async (file) => {
|
|
const supposedMimeType = file.mimetype;
|
|
const realMimeType = await FileType.fromFile(file.tempFilePath);
|
|
if (!realMimeType) {
|
|
return allowMimeNoMatch;
|
|
}
|
|
return supposedMimeType === realMimeType.mime;
|
|
},
|
|
|
|
image, animatedImage, video, audio, other
|
|
|
|
};
|
|
|