summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 14:35:08 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-10-24 14:35:08 +1100
commit0be194913036735b5bc97d74a37550d2bd099f13 (patch)
tree56a277b9d4b76966e1046f3fed2a110dc4c3dee3 /src
parentremove self_edit_guilds, was dumb (diff)
downloadserver-0be194913036735b5bc97d74a37550d2bd099f13.tar.xz
Change android and ios client downloads to use /download endpoint, update Release entity to suck less
Diffstat (limited to 'src')
-rw-r--r--src/api/middlewares/Authentication.ts2
-rw-r--r--src/api/routes/download/index.ts33
-rw-r--r--src/api/routes/downloads.ts23
-rw-r--r--src/api/routes/updates.ts16
-rw-r--r--src/util/entities/ClientRelease.ts9
5 files changed, 51 insertions, 32 deletions
diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts
index 50048b12..ecde7fb4 100644
--- a/src/api/middlewares/Authentication.ts
+++ b/src/api/middlewares/Authentication.ts
@@ -15,7 +15,7 @@ export const NO_AUTHORIZATION_ROUTES = [
 	"/gateway",
 	"/experiments",
 	"/updates",
-	"/downloads/",
+	"/download",
 	"/scheduled-maintenances/upcoming.json",
 	// Public kubernetes integration
 	"/-/readyz",
diff --git a/src/api/routes/download/index.ts b/src/api/routes/download/index.ts
new file mode 100644
index 00000000..371c0fd7
--- /dev/null
+++ b/src/api/routes/download/index.ts
@@ -0,0 +1,33 @@
+import { Router, Response, Request } from "express";
+import { route } from "@fosscord/api";
+import { FieldErrors, Release } from "@fosscord/util";
+
+const router = Router();
+
+/*
+	TODO: Putting the download route in /routes/download.ts doesn't register the route, for some reason
+	But putting it here *does*
+*/
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+	const { platform } = req.query;
+
+	if (!platform) throw FieldErrors({
+		platform: {
+			code: "BASE_TYPE_REQUIRED",
+			message: req.t("common:field.BASE_TYPE_REQUIRED"),
+		}
+	});
+
+	const release = await Release.findOneOrFail({
+		where: {
+			enabled: true,
+			platform: platform as string,
+		},
+		order: { pub_date: "DESC" }
+	});
+
+	res.redirect(release.url);
+});
+
+export default router;
diff --git a/src/api/routes/downloads.ts b/src/api/routes/downloads.ts
deleted file mode 100644
index bc0750f7..00000000
--- a/src/api/routes/downloads.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { Router, Response, Request } from "express";
-import { route } from "@fosscord/api";
-import { Release, Config } from "@fosscord/util";
-
-const router = Router();
-
-router.get("/:branch", route({}), async (req: Request, res: Response) => {
-	const { client } = Config.get();
-	const { branch } = req.params;
-	const { platform } = req.query;
-	//TODO
-
-	if (!platform || !["linux", "osx", "win"].includes(platform.toString()))
-		return res.status(404);
-
-	const release = await Release.findOneOrFail({
-		where: { name: client.releases.upstreamVersion },
-	});
-
-	res.redirect(release[`win_url`]);
-});
-
-export default router;
diff --git a/src/api/routes/updates.ts b/src/api/routes/updates.ts
index 8fe6fc2a..275c458b 100644
--- a/src/api/routes/updates.ts
+++ b/src/api/routes/updates.ts
@@ -1,14 +1,26 @@
 import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
-import { Config, Release } from "@fosscord/util";
+import { Config, FieldErrors, Release } from "@fosscord/util";
 
 const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
 	const { client } = Config.get();
+	const platform = req.query.platform;
+
+	if (!platform) throw FieldErrors({
+		platform: {
+			code: "BASE_TYPE_REQUIRED",
+			message: req.t("common:field.BASE_TYPE_REQUIRED"),
+		}
+	});
 
 	const release = await Release.findOneOrFail({
-		where: { name: client.releases.upstreamVersion },
+		where: {
+			enabled: true,
+			platform: platform as string,
+		},
+		order: { pub_date: "DESC" }
 	});
 
 	res.json({
diff --git a/src/util/entities/ClientRelease.ts b/src/util/entities/ClientRelease.ts
index 2723ab67..ff7ff716 100644
--- a/src/util/entities/ClientRelease.ts
+++ b/src/util/entities/ClientRelease.ts
@@ -7,19 +7,16 @@ export class Release extends BaseClass {
 	name: string;
 
 	@Column()
-	pub_date: string;
+	pub_date: Date;
 
 	@Column()
 	url: string;
 
 	@Column()
-	deb_url: string;
+	platform: string;
 
 	@Column()
-	osx_url: string;
-
-	@Column()
-	win_url: string;
+	enabled: boolean;
 
 	@Column({ nullable: true })
 	notes?: string;