From ac1d7fbbaf2f3e97f0988d9daa47576b7883b555 Mon Sep 17 00:00:00 2001 From: Thesourtimes Date: Wed, 10 Nov 2021 19:44:11 +0300 Subject: API versions 6 & 7 with minor logging additions --- api/src/Server.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'api/src') diff --git a/api/src/Server.ts b/api/src/Server.ts index a6887fd4..c16bac5c 100644 --- a/api/src/Server.ts +++ b/api/src/Server.ts @@ -85,6 +85,8 @@ export class FosscordServer extends Server { }); this.app = app; + app.use("/api/v6", api); + app.use("/api/v7", api); app.use("/api/v8", api); app.use("/api/v9", api); app.use("/api", api); // allow unversioned requests -- cgit 1.5.1 From ed133380fbc74ef3b6930d1ea125205ffe2e36fc Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Wed, 20 Oct 2021 17:54:54 +0200 Subject: Add plugin & css support, add styling to differentiate from discord.com --- .gitignore | 2 + api/assets/autoRegister.js | 57 -------------------- api/assets/preload-plugins/autoRegister.js | 62 ++++++++++++++++++++++ api/client_test/index.html | 27 +++++++++- api/src/middlewares/TestClient.ts | 14 ++++- bundle/scripts/build.js | 84 +++++++++++++++--------------- 6 files changed, 145 insertions(+), 101 deletions(-) delete mode 100644 api/assets/autoRegister.js create mode 100644 api/assets/preload-plugins/autoRegister.js (limited to 'api/src') diff --git a/.gitignore b/.gitignore index 6e6de8d2..ca5886e1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ tsconfig.tsbuildinfo files/ .env config.json + +.vscode/settings.json diff --git a/api/assets/autoRegister.js b/api/assets/autoRegister.js deleted file mode 100644 index 29f93370..00000000 --- a/api/assets/autoRegister.js +++ /dev/null @@ -1,57 +0,0 @@ - // Auto register guest account: - const prefix = [ - "mysterious", - "adventurous", - "courageous", - "precious", - "cynical", - "despicable", - "suspicious", - "gorgeous", - "lovely", - "stunning", - "based", - "keyed", - "ratioed", - "twink", - "phoned" - ]; - const suffix = [ - "Anonymous", - "Lurker", - "User", - "Enjoyer", - "Hunk", - "Top", - "Bottom", - "Sub", - "Coolstar", - "Wrestling", - "TylerTheCreator", - "Ad" - ]; - - Array.prototype.random = function () { - return this[Math.floor(Math.random() * this.length)]; - }; - - function _generateName() { - return `${prefix.random()}${suffix.random()}`; - } - - const token = JSON.parse(localStorage.getItem("token")); - if (!token && location.pathname !== "/login" && location.pathname !== "/register") { - fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { - method: "POST", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} - }) - .then((x) => x.json()) - .then((x) => { - localStorage.setItem("token", `"${x.token}"`); - if (!window.localStorage) { - // client already loaded -> need to reload to apply the newly registered user token - location.reload(); - } - }); - } diff --git a/api/assets/preload-plugins/autoRegister.js b/api/assets/preload-plugins/autoRegister.js new file mode 100644 index 00000000..bb0b903d --- /dev/null +++ b/api/assets/preload-plugins/autoRegister.js @@ -0,0 +1,62 @@ +// Auto register guest account: +const prefix = [ + "mysterious", + "adventurous", + "courageous", + "precious", + "cynical", + "flamer ", + "despicable", + "suspicious", + "gorgeous", + "impeccable", + "lovely", + "stunning", + "keyed", + "phoned", + "glorious", + "amazing", + "strange", + "arcane" +]; +const suffix = [ + "Anonymous", + "Boy", + "Lurker", + "Keyhitter", + "User", + "Enjoyer", + "Hunk", + "Coolstar", + "Wrestling", + "TylerTheCreator", + "Ad", + "Gamer", + "Games", + "Programmer" +]; + +Array.prototype.random = function () { + return this[Math.floor(Math.random() * this.length)]; +}; + +function _generateName() { + return `${prefix.random()}${suffix.random()}`; +} + +var token = JSON.parse(localStorage.getItem("token")); +if (!token && location.pathname !== "/login" && location.pathname !== "/register") { + fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} + }) + .then((x) => x.json()) + .then((x) => { + localStorage.setItem("token", `"${x.token}"`); + if (!window.localStorage) { + // client already loaded -> need to reload to apply the newly registered user token + location.reload(); + } + }); +} diff --git a/api/client_test/index.html b/api/client_test/index.html index 92499034..2ff0b469 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -4,6 +4,10 @@ Discord Test Client + + + + @@ -38,12 +42,33 @@ ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0" }; GLOBAL_ENV.MEDIA_PROXY_ENDPOINT = location.protocol + "//" + GLOBAL_ENV.CDN_HOST; + const localStorage = window.localStorage; + // TODO: remote auth + // window.GLOBAL_ENV.REMOTE_AUTH_ENDPOINT = window.GLOBAL_ENV.GATEWAY_ENDPOINT.replace(/wss?:/, ""); + localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT); + localStorage.setItem( + "DeveloperOptionsStore", + `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` + ); + + + const token = JSON.parse(localStorage.getItem("token")); + if(token) { + document.querySelector("#logincss").remove(); + } + + const settings = JSON.parse(localStorage.getItem("UserSettingsStore")); + if (settings && settings.locale.length <= 2) { + // fix client locale wrong and client not loading at all + settings.locale = "en-US"; + localStorage.setItem("UserSettingsStore", JSON.stringify(settings)); + } - + diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index b718bdab..7d981f0c 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -24,8 +24,20 @@ export default function TestClient(app: Application) { html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); } - app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + //plugins + var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + var plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + //preload plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + + app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + app.get("/assets/:file", async (req: Request, res: Response) => { delete req.headers.host; var response: FetchResponse; diff --git a/bundle/scripts/build.js b/bundle/scripts/build.js index affd7892..c00c2eaa 100644 --- a/bundle/scripts/build.js +++ b/bundle/scripts/build.js @@ -9,57 +9,57 @@ const dirs = ["api", "util", "cdn", "gateway", "bundle"]; const verbose = argv.includes("verbose") || argv.includes("v"); if (argv.includes("clean")) { - dirs.forEach((a) => { - var d = "../" + a + "/dist"; - if (fse.existsSync(d)) { - fse.rmSync(d, { recursive: true }); - if (verbose) console.log(`Deleted ${d}!`); - } - }); + dirs.forEach((a) => { + var d = "../" + a + "/dist"; + if (fse.existsSync(d)) { + fse.rmSync(d, { recursive: true }); + if (verbose) console.log(`Deleted ${d}!`); + } + }); } fse.copySync( - path.join(__dirname, "..", "..", "api", "assets"), - path.join(__dirname, "..", "dist", "api", "assets") + path.join(__dirname, "..", "..", "api", "assets"), + path.join(__dirname, "..", "dist", "api", "assets") ); fse.copySync( - path.join(__dirname, "..", "..", "api", "client_test"), - path.join(__dirname, "..", "dist", "api", "client_test") + path.join(__dirname, "..", "..", "api", "client_test"), + path.join(__dirname, "..", "dist", "api", "client_test") ); fse.copySync( - path.join(__dirname, "..", "..", "api", "locales"), - path.join(__dirname, "..", "dist", "api", "locales") + path.join(__dirname, "..", "..", "api", "locales"), + path.join(__dirname, "..", "dist", "api", "locales") ); dirs.forEach((a) => { - fse.copySync("../" + a + "/src", "dist/" + a + "/src"); - if (verbose) - console.log( - `Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!` - ); + fse.copySync("../" + a + "/src", "dist/" + a + "/src"); + if (verbose) + console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`); }); -console.log("[1/2] Copying src files done"); -console.log("[2/2] Compiling src files ..."); +console.log("Copying src files done"); +if (!argv.includes("copyonly")) { + console.log("Compiling src files ..."); -console.log( - execSync( - 'node "' + - path.join( - __dirname, - "..", - "node_modules", - "typescript", - "lib", - "tsc.js" - ) + - '" -p "' + - path.join(__dirname, "..") + - '"', - { - cwd: path.join(__dirname, ".."), - shell: true, - env: process.env, - encoding: "utf8", - } - ) -); + console.log( + execSync( + 'node "' + + path.join( + __dirname, + "..", + "node_modules", + "typescript", + "lib", + "tsc.js" + ) + + '" -p "' + + path.join(__dirname, "..") + + '"', + { + cwd: path.join(__dirname, ".."), + shell: true, + env: process.env, + encoding: "utf8", + } + ) + ); +} -- cgit 1.5.1 From a61bba7e27a0d0081d176aac6900c09f7d695428 Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Thu, 11 Nov 2021 22:17:21 +0100 Subject: Inline plugin support --- api/client_test/index.html | 6 +++--- api/package-lock.json | 2 ++ api/src/middlewares/TestClient.ts | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'api/src') diff --git a/api/client_test/index.html b/api/client_test/index.html index b19d5f0d..0b3a775a 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -4,9 +4,9 @@ Discord Test Client - - - + + + diff --git a/api/package-lock.json b/api/package-lock.json index e8ebd5bf..a4ad6b2b 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -84,6 +84,7 @@ "pg": "^8.7.1", "proxy-agent": "^5.0.0", "reflect-metadata": "^0.1.13", + "sqlite3": "^5.0.2", "typeorm": "^0.2.38", "typescript": "^4.4.2", "typescript-json-schema": "^0.50.1" @@ -16162,6 +16163,7 @@ "pg": "^8.7.1", "proxy-agent": "^5.0.0", "reflect-metadata": "^0.1.13", + "sqlite3": "^5.0.2", "ts-node": "^10.2.1", "typeorm": "^0.2.38", "typescript": "^4.4.2", diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index 7d981f0c..b50f4e5c 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -23,10 +23,15 @@ export default function TestClient(app: Application) { if (GATEWAY_ENDPOINT) { html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); } - - //plugins - var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + // inline plugins + var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); var plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + + // plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); html = html.replaceAll("", plugins); //preload plugins -- cgit 1.5.1 From 39aebb2cfc053c1cf8837738ac4154a454e44ff1 Mon Sep 17 00:00:00 2001 From: uurgothat Date: Wed, 17 Nov 2021 22:28:22 +0300 Subject: Add instance route --- api/src/middlewares/Authentication.ts | 1 + api/src/routes/policies/instance/domains.ts | 16 ++++++++++++++++ api/src/routes/policies/instance/limits.ts | 11 +++++++++++ api/src/routes/policies/instance/meta.ts | 12 ++++++++++++ util/src/entities/Config.ts | 6 ++++++ 5 files changed, 46 insertions(+) create mode 100644 api/src/routes/policies/instance/domains.ts create mode 100644 api/src/routes/policies/instance/limits.ts create mode 100644 api/src/routes/policies/instance/meta.ts (limited to 'api/src') diff --git a/api/src/middlewares/Authentication.ts b/api/src/middlewares/Authentication.ts index 59a181e6..e6df6eeb 100644 --- a/api/src/middlewares/Authentication.ts +++ b/api/src/middlewares/Authentication.ts @@ -11,6 +11,7 @@ export const NO_AUTHORIZATION_ROUTES = [ "/experiments", "/-/readyz", "/-/healthz", + "/policies/instance/", /\/guilds\/\d+\/widget\.(json|png)/ ]; diff --git a/api/src/routes/policies/instance/domains.ts b/api/src/routes/policies/instance/domains.ts new file mode 100644 index 00000000..b68763cc --- /dev/null +++ b/api/src/routes/policies/instance/domains.ts @@ -0,0 +1,16 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { Config } from "@fosscord/util"; +import { config } from "dotenv" +const router = Router(); +const { cdn } = Config.get(); + +const IdentityForm = { + cdn: cdn.endpointPublic || process.env.CDN || "http://localhost:3001", +} + +router.get("/",route({}), async (req: Request, res: Response) => { + res.json(IdentityForm) +}); + +export default router; diff --git a/api/src/routes/policies/instance/limits.ts b/api/src/routes/policies/instance/limits.ts new file mode 100644 index 00000000..912908b7 --- /dev/null +++ b/api/src/routes/policies/instance/limits.ts @@ -0,0 +1,11 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { Config } from "@fosscord/util"; +const router = Router(); +const { limits } = Config.get(); + +router.get("/",route({}), async (req: Request, res: Response) => { + res.json(limits) +}); + +export default router; diff --git a/api/src/routes/policies/instance/meta.ts b/api/src/routes/policies/instance/meta.ts new file mode 100644 index 00000000..7a998487 --- /dev/null +++ b/api/src/routes/policies/instance/meta.ts @@ -0,0 +1,12 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { Config } from "@fosscord/util"; + +const router = Router(); +const { general } = Config.get(); + +router.get("/",route({}), async (req: Request, res: Response) => { + res.json(general) +}); + +export default router; diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index cac5d4da..fd83bc5a 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -49,6 +49,9 @@ export interface ConfigValue { endpointPrivate: string | null; }; general: { + instanceName: string; + instanceDescription: string | null; + frontPage: string | null; instanceId: string; }; limits: { @@ -180,7 +183,10 @@ export const DefaultConfigOptions: ConfigValue = { endpointPublic: null, }, general: { + instanceName: "Fosscord Instance", + instanceDescription: "This is a Fosscord instance made in pre-relase days", instanceId: Snowflake.generate(), + frontPage: null }, limits: { user: { -- cgit 1.5.1 From bdc447e44848bba307d7fabc6e31c98fa3f6a4c4 Mon Sep 17 00:00:00 2001 From: uurgothat Date: Wed, 17 Nov 2021 22:28:41 +0300 Subject: Minor API stuff --- api/src/routes/guilds/templates/index.ts | 5 ++--- api/src/routes/track.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 api/src/routes/track.ts (limited to 'api/src') diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts index dd906198..98e42d1c 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/api/src/routes/guilds/templates/index.ts @@ -1,11 +1,10 @@ import { Request, Response, Router } from "express"; -const router: Router = Router(); import { Template, Guild, Role, Snowflake, Config, User, Member } from "@fosscord/util"; -const { enabled, allowTemplateCreation, allowDiscordTemplates, allowRaws } = Config.get().templates; import { route } from "@fosscord/api"; import { DiscordApiErrors } from "@fosscord/util"; import fetch from "node-fetch"; - +const router: Router = Router(); +const { enabled, allowTemplateCreation, allowDiscordTemplates, allowRaws } = Config.get().templates; export interface GuildTemplateCreateSchema { name: string; diff --git a/api/src/routes/track.ts b/api/src/routes/track.ts new file mode 100644 index 00000000..8556a3ad --- /dev/null +++ b/api/src/routes/track.ts @@ -0,0 +1,11 @@ +import { Router, Response, Request } from "express"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.post("/", route({}), (req: Request, res: Response) => { + // TODO: + res.sendStatus(204); +}); + +export default router; -- cgit 1.5.1 From 17684a14fda0bb0f066efe31273dc55f3298e7d8 Mon Sep 17 00:00:00 2001 From: Thesourtimes Date: Thu, 18 Nov 2021 22:15:05 +0300 Subject: Fix the minor issues on route --- api/src/middlewares/Authentication.ts | 4 +++- api/src/routes/policies/instance/domains.ts | 14 ++++++++------ api/src/routes/policies/instance/index.ts | 12 ++++++++++++ api/src/routes/policies/instance/limits.ts | 4 ++-- api/src/routes/policies/instance/meta.ts | 12 ------------ util/src/entities/Config.ts | 2 ++ 6 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 api/src/routes/policies/instance/index.ts delete mode 100644 api/src/routes/policies/instance/meta.ts (limited to 'api/src') diff --git a/api/src/middlewares/Authentication.ts b/api/src/middlewares/Authentication.ts index e6df6eeb..8fbdd2b7 100644 --- a/api/src/middlewares/Authentication.ts +++ b/api/src/middlewares/Authentication.ts @@ -11,7 +11,9 @@ export const NO_AUTHORIZATION_ROUTES = [ "/experiments", "/-/readyz", "/-/healthz", - "/policies/instance/", + "/science", + "/track", + "/policies/instance", /\/guilds\/\d+\/widget\.(json|png)/ ]; diff --git a/api/src/routes/policies/instance/domains.ts b/api/src/routes/policies/instance/domains.ts index b68763cc..20cd07ba 100644 --- a/api/src/routes/policies/instance/domains.ts +++ b/api/src/routes/policies/instance/domains.ts @@ -3,14 +3,16 @@ import { route } from "@fosscord/api"; import { Config } from "@fosscord/util"; import { config } from "dotenv" const router = Router(); -const { cdn } = Config.get(); - -const IdentityForm = { - cdn: cdn.endpointPublic || process.env.CDN || "http://localhost:3001", -} router.get("/",route({}), async (req: Request, res: Response) => { - res.json(IdentityForm) + const { cdn, gateway } = Config.get(); + + const IdentityForm = { + cdn: cdn.endpointPublic || process.env.CDN || "http://localhost:3001", + gateway: gateway.endpointPublic || process.env.GATEWAY || "ws://localhost:3002" + }; + + res.json(IdentityForm); }); export default router; diff --git a/api/src/routes/policies/instance/index.ts b/api/src/routes/policies/instance/index.ts new file mode 100644 index 00000000..e3da014f --- /dev/null +++ b/api/src/routes/policies/instance/index.ts @@ -0,0 +1,12 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { Config } from "@fosscord/util"; +const router = Router(); + + +router.get("/",route({}), async (req: Request, res: Response) => { + const { general } = Config.get(); + res.json(general); +}); + +export default router; diff --git a/api/src/routes/policies/instance/limits.ts b/api/src/routes/policies/instance/limits.ts index 912908b7..7de1476b 100644 --- a/api/src/routes/policies/instance/limits.ts +++ b/api/src/routes/policies/instance/limits.ts @@ -2,10 +2,10 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import { Config } from "@fosscord/util"; const router = Router(); -const { limits } = Config.get(); router.get("/",route({}), async (req: Request, res: Response) => { - res.json(limits) + const { limits } = Config.get(); + res.json(limits); }); export default router; diff --git a/api/src/routes/policies/instance/meta.ts b/api/src/routes/policies/instance/meta.ts deleted file mode 100644 index 7a998487..00000000 --- a/api/src/routes/policies/instance/meta.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Router, Request, Response } from "express"; -import { route } from "@fosscord/api"; -import { Config } from "@fosscord/util"; - -const router = Router(); -const { general } = Config.get(); - -router.get("/",route({}), async (req: Request, res: Response) => { - res.json(general) -}); - -export default router; diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index 2d4ad252..d277c88c 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -52,6 +52,7 @@ export interface ConfigValue { instanceName: string; instanceDescription: string | null; frontPage: string | null; + tosPage: string | null; image: string | null; instanceId: string; }; @@ -187,6 +188,7 @@ export const DefaultConfigOptions: ConfigValue = { instanceName: "Fosscord Instance", instanceDescription: "This is a Fosscord instance made in pre-relase days", frontPage: null, + tosPage: null, image: null, instanceId: Snowflake.generate(), }, -- cgit 1.5.1 From b47a812ac7a9b3b6e88520333f1184a32122cd8b Mon Sep 17 00:00:00 2001 From: Samuel <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 21 Nov 2021 21:03:13 +0100 Subject: Update index.ts --- api/src/routes/guilds/templates/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'api/src') diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts index 98e42d1c..3d922e85 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/api/src/routes/guilds/templates/index.ts @@ -4,7 +4,6 @@ import { route } from "@fosscord/api"; import { DiscordApiErrors } from "@fosscord/util"; import fetch from "node-fetch"; const router: Router = Router(); -const { enabled, allowTemplateCreation, allowDiscordTemplates, allowRaws } = Config.get().templates; export interface GuildTemplateCreateSchema { name: string; @@ -12,10 +11,11 @@ export interface GuildTemplateCreateSchema { } router.get("/:code", route({}), async (req: Request, res: Response) => { + const { allowDiscordTemplates, allowRaws, enabled } = Config.get().templates; if (!enabled) res.json({ code: 403, message: "Template creation & usage is disabled on this instance." }).sendStatus(403); const { code } = req.params; - + if (code.startsWith("discord:")) { if (!allowDiscordTemplates) return res.json({ code: 403, message: "Discord templates cannot be used on this instance." }).sendStatus(403); const discordTemplateID = code.split("discord:", 2)[1]; @@ -38,6 +38,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { }); router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => { + const { enabled, allowTemplateCreation, allowDiscordTemplates, allowRaws } = Config.get().templates; if (!enabled) return res.json({ code: 403, message: "Template creation & usage is disabled on this instance." }).sendStatus(403); if (!allowTemplateCreation) return res.json({ code: 403, message: "Template creation is disabled on this instance." }).sendStatus(403); -- cgit 1.5.1