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.
21 lines
622 B
21 lines
622 B
'use strict';
|
|
|
|
const imageHash = require('imghash').hash
|
|
, config = require(__dirname+'/../config.js');
|
|
|
|
module.exports = async (req, res, next) => {
|
|
const { hashImages } = config.get;
|
|
if (hashImages && res.locals.numFiles > 0 && res.locals.permLevel > 1) {
|
|
const hashPromises = [];
|
|
for (let i = 0; i < res.locals.numFiles; i++) {
|
|
const mainType = req.files.file[i].mimetype.split('/')[0];
|
|
if (mainType === 'image') {
|
|
hashPromises.push(imageHash(req.files.file[i].tempFilePath, 8, 'hex').then(res => {
|
|
req.files.file[i].phash = res;
|
|
}));
|
|
}
|
|
}
|
|
await Promise.all(hashPromises);
|
|
}
|
|
next();
|
|
}
|
|
|