From 54ebf97e7822b479b8953dddc73fe85e9a71ec39 Mon Sep 17 00:00:00 2001 From: uurgothat Date: Wed, 17 Nov 2021 22:28:22 +0300 Subject: [PATCH 1/7] 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 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: { From 74dee34f69dfe138dcde43f09f77bf0329e2b3c8 Mon Sep 17 00:00:00 2001 From: uurgothat Date: Wed, 17 Nov 2021 22:28:41 +0300 Subject: [PATCH 2/7] 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 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; From 159c712c436a3e01166ed5912d69a17c0fee70e6 Mon Sep 17 00:00:00 2001 From: uurgothat Date: Wed, 17 Nov 2021 22:50:25 +0300 Subject: [PATCH 3/7] Add image field --- util/src/entities/Config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index fd83bc5a..2d4ad252 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; + image: string | null; instanceId: string; }; limits: { @@ -185,8 +186,9 @@ export const DefaultConfigOptions: ConfigValue = { general: { instanceName: "Fosscord Instance", instanceDescription: "This is a Fosscord instance made in pre-relase days", + frontPage: null, + image: null, instanceId: Snowflake.generate(), - frontPage: null }, limits: { user: { From 7681ea6d8ee7ce3af6a7287b22a60b214d9e0629 Mon Sep 17 00:00:00 2001 From: Thesourtimes Date: Thu, 18 Nov 2021 22:15:05 +0300 Subject: [PATCH 4/7] Fix the minor issues on route --- api/src/middlewares/Authentication.ts | 4 +++- api/src/routes/policies/instance/domains.ts | 14 ++++++++------ .../routes/policies/instance/{meta.ts => index.ts} | 6 +++--- api/src/routes/policies/instance/limits.ts | 4 ++-- util/src/entities/Config.ts | 2 ++ 5 files changed, 18 insertions(+), 12 deletions(-) rename api/src/routes/policies/instance/{meta.ts => index.ts} (82%) 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/meta.ts b/api/src/routes/policies/instance/index.ts similarity index 82% rename from api/src/routes/policies/instance/meta.ts rename to api/src/routes/policies/instance/index.ts index 7a998487..e3da014f 100644 --- a/api/src/routes/policies/instance/meta.ts +++ b/api/src/routes/policies/instance/index.ts @@ -1,12 +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) + 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/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(), }, From 2c93f1f121750e54f7f2c34feaed62b8491f5979 Mon Sep 17 00:00:00 2001 From: Kuna <65683493+Thesourtimes@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:35:51 +0000 Subject: [PATCH 5/7] Update util/src/entities/Config.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Erkin Alp Güney --- util/src/entities/Config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index d277c88c..56f6b741 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -53,6 +53,8 @@ export interface ConfigValue { instanceDescription: string | null; frontPage: string | null; tosPage: string | null; + correspondenceEmail: string | null; + correspondenceUserID: string | null; image: string | null; instanceId: string; }; From 5d2f92427db34ef47fc5042676deab15ef596ce1 Mon Sep 17 00:00:00 2001 From: Kuna <65683493+Thesourtimes@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:35:59 +0000 Subject: [PATCH 6/7] Update util/src/entities/Config.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Erkin Alp Güney --- util/src/entities/Config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index 56f6b741..492baa4c 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -191,6 +191,8 @@ export const DefaultConfigOptions: ConfigValue = { instanceDescription: "This is a Fosscord instance made in pre-relase days", frontPage: null, tosPage: null, + correspondenceEmail: "noreply@localhost.local", + correspondenceUserID: null, image: null, instanceId: Snowflake.generate(), }, From 49aae7b16ff6808f676e1ebbc972fb2c4940ac77 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: [PATCH 7/7] Update index.ts --- api/src/routes/guilds/templates/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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);