1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 10:52:31 +01:00

Add discord template support

This commit is contained in:
uurgothat 2021-10-17 23:20:46 +03:00
parent 6a565df575
commit 3b6fc60783
2 changed files with 20 additions and 1 deletions

View File

@ -3,7 +3,8 @@ const router: Router = Router();
import { Template, Guild, Role, Snowflake, Config, User, Member } from "@fosscord/util";
import { route } from "@fosscord/api";
import { DiscordApiErrors } from "@fosscord/util";
import fetch from "node-fetch";
import { HTTPError } from "lambert-server";
export interface GuildTemplateCreateSchema {
name: string;
avatar?: string | null;
@ -12,6 +13,18 @@ export interface GuildTemplateCreateSchema {
router.get("/:code", route({}), async (req: Request, res: Response) => {
const { code } = req.params;
if (code.startsWith("discord:")) {
const discordTemplateID = code.split("discord:", 2)[1];
if (Config.get().templates.allowDiscordTemplates == false) return res.json({ code: 403, message: "Discord templates are disabled on this instance."}).sendStatus(403)
const discordTemplateData = await fetch(`https://discord.com/api/v9/guilds/templates/${discordTemplateID}`, {
method: "get",
headers: { "Content-Type": "application/json" }
});
return res.json(await discordTemplateData.json());
}
const template = await Template.findOneOrFail({ code: code });
res.json(template);

View File

@ -160,6 +160,9 @@ export interface ConfigValue {
kafka: {
brokers: KafkaBroker[] | null;
};
templates: {
allowDiscordTemplates: Boolean
}
}
export const DefaultConfigOptions: ConfigValue = {
@ -321,4 +324,7 @@ export const DefaultConfigOptions: ConfigValue = {
kafka: {
brokers: null,
},
templates: {
allowDiscordTemplates: true
}
};