utils/image.js: fix getType on local files

This commit is contained in:
Samuel Hernandez 2020-11-07 20:50:32 -05:00
parent 0600cf230f
commit 66cf9dc518
No known key found for this signature in database
GPG key ID: 4AF549A5EA2C4132
2 changed files with 13 additions and 3 deletions

View file

@ -20,7 +20,10 @@ app.post("/run", express.json(), async (req, res, next) => {
try { try {
let type; let type;
if (object.path) { if (object.path) {
type = object.type ? object.type : await magick.getType(object.path); type = object.type;
if (!object.type) {
type = await magick.getType(object.path);
}
if (!type) { if (!type) {
return res.sendStatus(400); return res.sendStatus(400);
} }

View file

@ -64,6 +64,13 @@ exports.check = (cmd) => {
}; };
exports.getType = async (image) => { exports.getType = async (image) => {
if (!image.startsWith("http")) {
imageType = await fileType.fromFile(image)
if (imageType && formats.includes(imageType.mime)) {
return imageType.mime;
}
return undefined
}
let type; let type;
const controller = new AbortController(); const controller = new AbortController();
const timeout = setTimeout(() => { const timeout = setTimeout(() => {