No
This commit is contained in:
parent
e625a33cee
commit
e8744777fa
1 changed files with 0 additions and 23 deletions
23
index.js
23
index.js
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue