summary refs log tree commit diff
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
commitfc2ccc0b25ac1e31ef2a1cacbcc190d7debef7c2 (patch)
treec08f948ec56783754bc380eda529199e9c41ced5
parentremove self_edit_guilds, was dumb (diff)
downloadserver-fc2ccc0b25ac1e31ef2a1cacbcc190d7debef7c2.tar.xz
Change android and ios client downloads to use /download endpoint, update Release entity to suck less
-rw-r--r--scripts/client.js17
-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
6 files changed, 68 insertions, 32 deletions
diff --git a/scripts/client.js b/scripts/client.js
index cba36170..6ec17341 100644
--- a/scripts/client.js
+++ b/scripts/client.js
@@ -63,6 +63,23 @@ const doPatch = (content) => {
 		'e.exports = "/assets/',
 	);
 
+	// app download links
+	content = content.replaceAll(
+		"https://play.google.com/store/apps/details?id=com.discord",
+		"https://slowcord.understars.dev/api/download?platform=android",
+	);
+
+	content = content.replaceAll(
+		"https://itunes.apple.com/app/discord/id985746746",
+		"https://slowcord.understars.dev/api/download?platform=ios"
+	)
+
+	// TODO change public test build link
+	// content = content.replaceAll(
+	// 	"https://discord.com/download#ptb-card",
+	//	""
+	// )
+
 	return content;
 };
 
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;