Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
default to smartcrop if facecrop fails #25
Browse files Browse the repository at this point in the history
  • Loading branch information
mshd committed Oct 19, 2020
1 parent 1f7fa3b commit 68d61c2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions controllers/api/v1image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
const ImageModel = require('../../models/Image');
const path = require('path');
const fs = require('fs');
const uploadController = require('../upload');

exports.showImageByWikidata = async (req, res) => {
Expand Down Expand Up @@ -51,8 +52,12 @@ function outputImage(res,id,type,factor,mimeType = "image/jpeg"){
ext = (factor ? '-'+ parseFloat(factor).toFixed(1) : '');
}
res.setHeader('content-type', mimeType);
res.sendFile(path.resolve('uploads/'+type+'/' + id + ext));

const reqFile = 'uploads/'+type+'/' + id + ext;
if (fs.existsSync(reqFile)) {
res.sendFile(path.resolve(reqFile));
}else {
res.sendFile(path.resolve('uploads/thumbnail/' + id));
}
}


Expand Down

0 comments on commit 68d61c2

Please sign in to comment.