-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3f05bc
commit 1fad83c
Showing
4 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import fs from "fs"; | ||
import { randomInt } from "crypto"; | ||
|
||
const config = useRuntimeConfig(); | ||
|
||
export default defineEventHandler((event) => { | ||
const imgList = fs.readdirSync("public/backgrounds"); | ||
const imgName = imgList[randomInt(imgList.length)]; | ||
return sendRedirect(event, `/backgrounds/${imgName}`); | ||
if (config.imageHosting) { | ||
const imgList: string[] = config.imageLinks; | ||
const imgLink = imgList[randomInt(imgList.length)]; | ||
return sendRedirect(event, imgLink); | ||
} else { | ||
const imgList = fs.readdirSync("public/backgrounds"); | ||
const imgName = imgList[randomInt(imgList.length)]; | ||
return sendRedirect(event, `/backgrounds/${imgName}`); | ||
} | ||
}); |