From e8c05667d0a5d66df41f51dc36dddfb845c459ef Mon Sep 17 00:00:00 2001 From: waveringana Date: Wed, 14 May 2025 17:50:12 -0400 Subject: [PATCH] fix gifv to have a failover and to use videoExtensions to compare --- app/routes/index.ts | 69 ++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/app/routes/index.ts b/app/routes/index.ts index 33c5b8a..8278602 100644 --- a/app/routes/index.ts +++ b/app/routes/index.ts @@ -121,36 +121,53 @@ router.get( const [filename, fileExtension] = extension(`uploads/${req.params.file}`); if ( - fileExtension == ".mp4" || - fileExtension == ".mov" || - fileExtension == ".webm" || - fileExtension == ".gif" + videoExtensions.includes(fileExtension) ) { - const imageData = ffProbe( - `uploads/${req.params.file}`, - filename, - fileExtension - ); + try { + const imageData = ffProbe( + `uploads/${req.params.file}`, + filename, + fileExtension + ); - width = (await imageData).streams[0].width; - height = (await imageData).streams[0].height; + width = (await imageData).streams[0].width; + height = (await imageData).streams[0].height; - return res.render("gifv", { - url: url, - host: `${req.protocol}://${req.get("host")}`, - width: width, - height: height, - }); + return res.render("gifv", { + url: url, + host: `${req.protocol}://${req.get("host")}`, + width: width, + height: height, + }); + } catch (error) { + console.error("Error processing video:", error); + return res.render("gifv", { + url: url, + host: `${req.protocol}://${req.get("host")}`, + width: 800, + height: 600, + }); + } } else { - const imageData = await imageProbe( - fs.createReadStream(`uploads/${req.params.file}`) - ); - return res.render("gifv", { - url: url, - host: `${req.protocol}://${req.get("host")}`, - width: imageData.width, - height: imageData.height, - }); + try { + const imageData = await imageProbe( + fs.createReadStream(`uploads/${req.params.file}`) + ); + return res.render("gifv", { + url: url, + host: `${req.protocol}://${req.get("host")}`, + width: imageData.width, + height: imageData.height, + }); + } catch (error) { + console.error("Error processing image:", error); + return res.render("gifv", { + url: url, + host: `${req.protocol}://${req.get("host")}`, + width: 800, + height: 600, + }); + } } } );