fix gifv to have a failover and to use videoExtensions to compare

This commit is contained in:
waveringana 2025-05-14 17:50:12 -04:00
parent 06efb67198
commit e8c05667d0

View file

@ -121,36 +121,53 @@ router.get(
const [filename, fileExtension] = extension(`uploads/${req.params.file}`); const [filename, fileExtension] = extension(`uploads/${req.params.file}`);
if ( if (
fileExtension == ".mp4" || videoExtensions.includes(fileExtension)
fileExtension == ".mov" ||
fileExtension == ".webm" ||
fileExtension == ".gif"
) { ) {
const imageData = ffProbe( try {
`uploads/${req.params.file}`, const imageData = ffProbe(
filename, `uploads/${req.params.file}`,
fileExtension filename,
); fileExtension
);
width = (await imageData).streams[0].width; width = (await imageData).streams[0].width;
height = (await imageData).streams[0].height; height = (await imageData).streams[0].height;
return res.render("gifv", { return res.render("gifv", {
url: url, url: url,
host: `${req.protocol}://${req.get("host")}`, host: `${req.protocol}://${req.get("host")}`,
width: width, width: width,
height: height, 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 { } else {
const imageData = await imageProbe( try {
fs.createReadStream(`uploads/${req.params.file}`) const imageData = await imageProbe(
); fs.createReadStream(`uploads/${req.params.file}`)
return res.render("gifv", { );
url: url, return res.render("gifv", {
host: `${req.protocol}://${req.get("host")}`, url: url,
width: imageData.width, host: `${req.protocol}://${req.get("host")}`,
height: imageData.height, 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,
});
}
} }
} }
); );