Format the file
This commit is contained in:
parent
7c724175ce
commit
7825ce6ce9
@ -16,7 +16,8 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
|
|
||||||
if (code.startsWith("discord:")) {
|
if (code.startsWith("discord:")) {
|
||||||
if (allowDiscordTemplates == false) return res.json({ code: 403, message: "Discord templates are disabled on this instance."}).sendStatus(403);
|
if (allowDiscordTemplates == false)
|
||||||
|
return res.json({ code: 403, message: "Discord templates are disabled on this instance." }).sendStatus(403);
|
||||||
const discordTemplateID = code.split("discord:", 2)[1];
|
const discordTemplateID = code.split("discord:", 2)[1];
|
||||||
|
|
||||||
const discordTemplateData = await fetch(`https://discord.com/api/v9/guilds/templates/${discordTemplateID}`, {
|
const discordTemplateData = await fetch(`https://discord.com/api/v9/guilds/templates/${discordTemplateID}`, {
|
||||||
@ -25,27 +26,33 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
res.json(await discordTemplateData.json());
|
res.json(await discordTemplateData.json());
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
if (code.startsWith("fosscord:")) {
|
if (code.startsWith("fosscord:")) {
|
||||||
if (allowOtherInstancesTemplates == false) return res.json({ code: 403, message: "Other instance templates are disabled on this instance."}).sendStatus(403);
|
if (allowOtherInstancesTemplates == false)
|
||||||
|
return res.json({ code: 403, message: "Other instance templates are disabled on this instance." }).sendStatus(403);
|
||||||
//TODO: TBD when federation came out
|
//TODO: TBD when federation came out
|
||||||
res.json({}).sendStatus(200)
|
res.json({}).sendStatus(200);
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Validation
|
//TODO: Validation
|
||||||
if (code.startsWith("external:")) {
|
if (code.startsWith("external:")) {
|
||||||
if (allowExternalRaws == false) return res.json({ code: 403, message: "Importing templates from raws is disabled on this instance."}).sendStatus(403);
|
if (allowExternalRaws == false)
|
||||||
const url = code.split("external:", 2)[1]
|
return res.json({ code: 403, message: "Importing templates from raws is disabled on this instance." }).sendStatus(403);
|
||||||
|
const url = code.split("external:", 2)[1];
|
||||||
|
|
||||||
const rawTemplateData = await fetch(`${url}`, {
|
const rawTemplateData =
|
||||||
|
(await fetch(`${url}`, {
|
||||||
method: "get",
|
method: "get",
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
}) || null;
|
})) || null;
|
||||||
|
|
||||||
res.json(rawTemplateData !== null ? await rawTemplateData.json(): { code: 500, message: "An error occurred while trying to fetch the raw."});
|
res.json(
|
||||||
}
|
rawTemplateData !== null
|
||||||
|
? await rawTemplateData.json()
|
||||||
|
: { code: 500, message: "An error occurred while trying to fetch the raw." }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const template = await Template.findOneOrFail({ code: code });
|
const template = await Template.findOneOrFail({ code: code });
|
||||||
|
|
||||||
@ -54,7 +61,8 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => {
|
router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => {
|
||||||
if (enabled == false) return res.json({ code: 403, message: "Templates are disabled on this instance." }).sendStatus(403);
|
if (enabled == false) return res.json({ code: 403, message: "Templates are disabled on this instance." }).sendStatus(403);
|
||||||
if(allowTemplateCreation == false) return res.json({ code: 403, message: "Template creation is disabled on this instance."}).sendStatus(403);
|
if (allowTemplateCreation == false)
|
||||||
|
return res.json({ code: 403, message: "Template creation is disabled on this instance." }).sendStatus(403);
|
||||||
|
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
const body = req.body as GuildTemplateCreateSchema;
|
const body = req.body as GuildTemplateCreateSchema;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user