summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rw-r--r--api/src/Server.ts2
-rw-r--r--api/src/middlewares/Authentication.ts3
-rw-r--r--api/src/middlewares/TestClient.ts19
-rw-r--r--api/src/routes/guilds/templates/index.ts8
-rw-r--r--api/src/routes/policies/instance/domains.ts18
-rw-r--r--api/src/routes/policies/instance/index.ts12
-rw-r--r--api/src/routes/policies/instance/limits.ts11
-rw-r--r--api/src/routes/track.ts11
8 files changed, 79 insertions, 5 deletions
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 diff --git a/api/src/middlewares/Authentication.ts b/api/src/middlewares/Authentication.ts
index 59a181e6..8fbdd2b7 100644 --- a/api/src/middlewares/Authentication.ts +++ b/api/src/middlewares/Authentication.ts
@@ -11,6 +11,9 @@ export const NO_AUTHORIZATION_ROUTES = [ "/experiments", "/-/readyz", "/-/healthz", + "/science", + "/track", + "/policies/instance", /\/guilds\/\d+\/widget\.(json|png)/ ]; diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts
index b718bdab..b50f4e5c 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts
@@ -23,9 +23,26 @@ export default function TestClient(app: Application) { if (GATEWAY_ENDPOINT) { html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); } + // inline plugins + var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + var plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; }); + html = html.replaceAll("<!-- preload plugin marker -->", plugins); + + // plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; }); + html = html.replaceAll("<!-- plugin marker -->", plugins); + //preload plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; }); + html = html.replaceAll("<!-- preload plugin marker -->", plugins); - app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + 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/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts
index dd906198..3d922e85 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/api/src/routes/guilds/templates/index.ts
@@ -1,11 +1,9 @@ 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(); export interface GuildTemplateCreateSchema { name: string; @@ -13,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]; @@ -39,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); diff --git a/api/src/routes/policies/instance/domains.ts b/api/src/routes/policies/instance/domains.ts new file mode 100644
index 00000000..20cd07ba --- /dev/null +++ b/api/src/routes/policies/instance/domains.ts
@@ -0,0 +1,18 @@ +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; +import { Config } from "@fosscord/util"; +import { config } from "dotenv" +const router = Router(); + +router.get("/",route({}), async (req: Request, res: Response) => { + 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 new file mode 100644
index 00000000..7de1476b --- /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(); + +router.get("/",route({}), async (req: Request, res: Response) => { + const { limits } = Config.get(); + res.json(limits); +}); + +export default router; 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;