Skip to content

Commit

Permalink
✨ support image hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
XiYang6666 committed Jul 6, 2024
1 parent d3f05bc commit 1fad83c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ NUXT_AVATAR_CACHE_TIME = 3600000
NUXT_LINKS = {"blog":"https://blog.example.com","forum":"https://forum.example.com"}
NUXT_SOCIALS = {"github":{"link":"https://github.com/","icon":"fa-brands fa-github"},"bilibili":{"link":"https://www.bilibili.com/","icon":"fa-brands fa-bilibili"},"email":{"link":"mailto:[email protected]","icon":"fa-solid fa-envelope"}}

NUXT_KEYWORDS = ["main page"]
NUXT_KEYWORDS = ["main page"]

NUXT_IMAGE_HOSTING = false
NUXT_IMAGE_LINKS = []
2 changes: 2 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export default defineNuxtConfig({
links: {},
socials: {},
keywords: ["main page"],
imageHosting: false,
imageLinks: [],
},
});
Binary file modified public/favicon.ico
Binary file not shown.
14 changes: 11 additions & 3 deletions server/api/getRandomBackground.ts
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}`);
}
});

0 comments on commit 1fad83c

Please sign in to comment.