From 68d61c259a4cf1b6e2ac691ac2d788388351e2ad Mon Sep 17 00:00:00 2001 From: Martin Schibel Date: Mon, 19 Oct 2020 12:26:21 +0200 Subject: [PATCH] default to smartcrop if facecrop fails #25 --- controllers/api/v1image.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/controllers/api/v1image.js b/controllers/api/v1image.js index a39e867..e0718e3 100644 --- a/controllers/api/v1image.js +++ b/controllers/api/v1image.js @@ -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) => { @@ -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)); + } }