Merge pull request #23 from samhza/fix-gettype

utils/image.js: fix getType on local files
This commit is contained in:
Essem 2020-11-09 22:08:22 -06:00 committed by GitHub
commit 02bd4c6fd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 {
let type;
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) {
return res.sendStatus(400);
}
@ -92,4 +95,4 @@ app.get("/image", (req, res) => {
app.listen(port, () => {
console.log(`Started image API on port ${port}.`);
});
});

View file

@ -64,6 +64,13 @@ exports.check = (cmd) => {
};
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;
const controller = new AbortController();
const timeout = setTimeout(() => {
@ -86,4 +93,4 @@ exports.getType = async (image) => {
clearTimeout(timeout);
}
return type;
};
};