Former-commit-id: 2ce8c50f5e79263ce3cc9f3f08ce0d78893284c7
This commit is contained in:
Ben
2022-04-29 19:13:27 +01:00
parent 5840972dc2
commit 79100988c1
2 changed files with 13 additions and 2 deletions

BIN
README.md

Binary file not shown.

View File

@@ -19,12 +19,23 @@ function Get(req, res) {
// TODO: bricks with a modifier should show the modified colour in the thumbnail
// I HAVE NO IDEA HOW TO DO THIS WITHOUT A LOT OF WORK
// if linux
const defaultFile = `${process.cwd()}\\db\\img\\default.png`;
if (process.platform === 'linux') {
defaultFile.replace('\\', '/');
}
// this very randomly fails sometimes
try {
// work out hash from id
const hash = md5(id.split('.png')[0]);
const bucket = hash.substring(0, 4);
// if linux
const file = `${process.cwd()}\\db\\img\\${bucket[0]}\\${bucket[1]}\\${bucket[2]}\\${bucket[3]}\\${id}`;
if (process.platform === 'linux') {
file.replace('\\', '/');
}
if (fs.existsSync(file)) {
if (thumbnail) {
@@ -47,7 +58,7 @@ function Get(req, res) {
res.sendFile(file);
} else {
if (thumbnail) {
sharp(`${process.cwd()}\\db\\img\\default.png`)
sharp(defaultFile)
.resize({
height: 50,
}) // keep aspect ratio
@@ -62,7 +73,7 @@ function Get(req, res) {
});
return;
}
res.sendFile(`${process.cwd()}\\db\\img\\default.png`);
res.sendFile(defaultFile);
}
} catch (err) {
Logger.Error(err);