This commit is contained in:
Violet 2024-02-02 19:26:28 +00:00 committed by GitHub
parent e625a33cee
commit e8744777fa

View file

@ -23,29 +23,6 @@ app.listen(PORT, () => {
console.log("Now listening on PORT: " + PORT) console.log("Now listening on PORT: " + PORT)
}) })
app.get("/api/v1/randomIMG*", (req, res) => {
var folder = req.params[0]
var dirContent = fs.readdirSync(path.join(directory, folder))
var files = []
var imageFormats = [".png", ".jpg", ".jpeg", ".webp", ".gif"]
for (let index = 0; index < dirContent.length; index++) {
const file = dirContent[index];
for (let index = 0; index < imageFormats.length; index++) {
const extension = imageFormats[index];
if (file.includes(extension)) {
files.push(file)
break
}
}
}
if (files.length > 0) {
res.redirect(path.join('/', folder, files[Math.floor(Math.random() * files.length)]))
} else {
res.send("No Images in this directory")
}
})
app.get("/*", (req, res) => { app.get("/*", (req, res) => {
var file = req.params[0] var file = req.params[0]
var absPath = path.join(directory, file) var absPath = path.join(directory, file)