summary refs log tree commit diff
path: root/api/src/routes/guilds
diff options
context:
space:
mode:
authoruurgothat <cckhmck@gmail.com>2021-10-18 04:38:26 +0300
committeruurgothat <cckhmck@gmail.com>2021-10-18 04:38:26 +0300
commit7825ce6ce9840dd5fdea25acc2d01f68dc9947e5 (patch)
tree98e1b7b805541b6d3579d0f3f7dc6ef3a3882bb8 /api/src/routes/guilds
parentexternal templates + fosscord draft and more configs (diff)
downloadserver-7825ce6ce9840dd5fdea25acc2d01f68dc9947e5.tar.xz
Format the file
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r--api/src/routes/guilds/templates/index.ts46
1 files changed, 27 insertions, 19 deletions
diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts
index c275d5da..b82fb102 100644
--- a/api/src/routes/guilds/templates/index.ts
+++ b/api/src/routes/guilds/templates/index.ts
@@ -12,11 +12,12 @@ export interface GuildTemplateCreateSchema {
 }
 
 router.get("/:code", route({}), 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);
 	const { code } = req.params;
 
 	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 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());
-	}
-
+	};
 
 	if (code.startsWith("fosscord:")) {
-		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
-			res.json({}).sendStatus(200)
+		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
+		res.json({}).sendStatus(200);
 	};
 
-		//TODO: Validation
-		if (code.startsWith("external:")) {
-			if (allowExternalRaws == false) 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}`, {
+	//TODO: Validation
+	if (code.startsWith("external:")) {
+		if (allowExternalRaws == false)
+			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}`, {
 				method: "get",
 				headers: { "Content-Type": "application/json" }
-			}) || null;
-	
-			res.json(rawTemplateData !== null ? await rawTemplateData.json(): { code: 500, message: "An error occurred while trying to fetch the raw."});
-		}
+			})) || null;
+
+		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 });
 
@@ -53,8 +60,9 @@ router.get("/:code", route({}), 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(allowTemplateCreation == false) return res.json({ code: 403, message: "Template creation is 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);
 
 	const { code } = req.params;
 	const body = req.body as GuildTemplateCreateSchema;