dashboard-core/Routes/main.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-06-22 19:36:52 +05:00
const router = require("express").Router();
2023-06-19 12:35:11 +05:00
2023-06-22 19:36:52 +05:00
// eslint-disable-next-line no-unused-vars
2023-06-19 12:35:11 +05:00
module.exports = (app, config, themeConfig, modules) => {
2023-06-22 19:36:52 +05:00
router.get(themeConfig.landingPage?.enabled ? "/dash" : "/", async (req, res) => {
let customThemeOptions;
if (themeConfig?.customThemeOptions?.index) {
customThemeOptions = await themeConfig.customThemeOptions.index({
req: req,
res: res,
config: config,
});
}
res.render("index", {
req: req,
themeConfig: req.themeConfig,
bot: config.bot,
customThemeOptions: customThemeOptions || {},
config,
require,
});
});
if (themeConfig.landingPage?.enabled)
router.get("/", async (req, res) => {
res.setHeader("Content-Type", "text/html");
res.send(await themeConfig.landingPage.getLandingPage(req, res));
});
router.get("/loading", async (req, res) => {
if (!req.session?.discordAuthStatus?.loading)
return res.redirect("/manage");
res.render("loading", {
req,
themeConfig,
bot: config.bot,
});
});
router.get("/invite", (req, res) => {
const config = req.config;
2023-07-02 01:44:21 +05:00
const scopes = config.invite.scopes || ["bot"],
permissions = config.invite.permissions || "0",
other_params = config.invite.otherParams || "",
link = `https://discord.com/oauth2/authorize?client_id=${config.bot.user.id}&scope=${scopes.join("%20")}&permissions=${permissions}&response_type=code${req.query.g ? `&guild_id=${req.query.g}` : ""}${other_params}`;
2023-06-22 19:36:52 +05:00
2023-07-02 01:44:21 +05:00
res.redirect(link);
2023-06-22 19:36:52 +05:00
});
if (!config.supportServer) config.supportServer = {};
router.get(config.supportServer.slash || "/support-server", (req, res) => {
const config = req.config;
config.supportServer ? null : (config.supportServer = {});
if (!config.supportServer.inviteUrl)
return res.send({
error: true,
message: "No inviteUrl defined (discord-dashboard config.supportServer).",
});
if (!config.supportServer.inviteUrl
.toLowerCase()
.startsWith("https://discord.gg/") &&
!config.supportServer.inviteUrl
.toLowerCase()
.startsWith("https://discord.com/")
) return res.send({
error: true,
message: "Invite url should start with 'https://discord.gg/' or 'https://discord.com/'.",
});
res.redirect(config.supportServer.inviteUrl);
});
return router;
};