Less code

This commit is contained in:
bingus_violet 2024-10-16 10:30:34 -05:00
parent 71862d8254
commit 405e10289f

View file

@ -29,6 +29,26 @@ var app = express()
const imgWaitMax = 2
function sendImg(res, imgData, imgURL) {
var imgWait = 0
function waitForImage() {
if (imgWait < imgWaitMax) {
imgWait += 0.1
imgData = cachedImages.imgs[imgURL]
if (imgData) {
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
} else {
setTimeout(() => {
waitForImage()
}, 100);
}
} else {
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
}
}
waitForImage()
}
app.get("/cached/byID/*", (req, res) => {
var imgURL = req.originalUrl
imgURL = imgURL.substring(imgURL.indexOf("/", 8) + 1, imgURL.lastIndexOf("?"))
@ -45,23 +65,7 @@ app.get("/cached/byID/*", (req, res) => {
var imgData = cachedImages.imgs[imgURL]
var imgWait = 0
function waitForImage() {
if (imgWait < imgWaitMax) {
imgWait += 0.1
imgData = cachedImages.imgs[imgURL]
if (imgData) {
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
} else {
setTimeout(() => {
waitForImage()
}, 100);
}
} else {
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
}
}
waitForImage()
sendImg(res, imgData, imgURL)
})
app.get("/cached/byURL/*", (req, res) => {
@ -69,23 +73,7 @@ app.get("/cached/byURL/*", (req, res) => {
imgURL = imgURL.substring(imgURL.indexOf("/", 8) + 1)
var imgData = cachedImages.imgs[imgURL]
var imgWait = 0
function waitForImage() {
if (imgWait < imgWaitMax) {
imgWait += 0.1
imgData = cachedImages.imgs[imgURL]
if (imgData) {
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
} else {
setTimeout(() => {
waitForImage()
}, 100);
}
} else {
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
}
}
waitForImage()
sendImg(res, imgData, imgURL)
})
app.get("/cached/*", (req, res) => {