1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 19:02:33 +01:00

Merge pull request #510 from Thesourtimes/master

Add instance route
This commit is contained in:
Samuel 2021-11-21 21:03:21 +01:00 committed by GitHub
commit 2867d077a2
7 changed files with 73 additions and 4 deletions

View File

@ -11,6 +11,9 @@ export const NO_AUTHORIZATION_ROUTES = [
"/experiments",
"/-/readyz",
"/-/healthz",
"/science",
"/track",
"/policies/instance",
/\/guilds\/\d+\/widget\.(json|png)/
];

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

11
api/src/routes/track.ts Normal file
View File

@ -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;

View File

@ -49,6 +49,13 @@ export interface ConfigValue {
endpointPrivate: string | null;
};
general: {
instanceName: string;
instanceDescription: string | null;
frontPage: string | null;
tosPage: string | null;
correspondenceEmail: string | null;
correspondenceUserID: string | null;
image: string | null;
instanceId: string;
};
limits: {
@ -180,6 +187,13 @@ export const DefaultConfigOptions: ConfigValue = {
endpointPublic: null,
},
general: {
instanceName: "Fosscord Instance",
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(),
},
limits: {