Change android and ios client downloads to use /download endpoint, update Release entity to suck less

This commit is contained in:
Madeline 2022-10-24 14:35:08 +11:00
parent 0e315d27ab
commit 0be1949130
6 changed files with 68 additions and 32 deletions

View File

@ -63,6 +63,23 @@ const doPatch = (content) => {
'e.exports = "/assets/', '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; return content;
}; };

View File

@ -15,7 +15,7 @@ export const NO_AUTHORIZATION_ROUTES = [
"/gateway", "/gateway",
"/experiments", "/experiments",
"/updates", "/updates",
"/downloads/", "/download",
"/scheduled-maintenances/upcoming.json", "/scheduled-maintenances/upcoming.json",
// Public kubernetes integration // Public kubernetes integration
"/-/readyz", "/-/readyz",

View File

@ -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;

View File

@ -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;

View File

@ -1,14 +1,26 @@
import { Router, Response, Request } from "express"; import { Router, Response, Request } from "express";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
import { Config, Release } from "@fosscord/util"; import { Config, FieldErrors, Release } from "@fosscord/util";
const router = Router(); const router = Router();
router.get("/", route({}), async (req: Request, res: Response) => { router.get("/", route({}), async (req: Request, res: Response) => {
const { client } = Config.get(); 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({ const release = await Release.findOneOrFail({
where: { name: client.releases.upstreamVersion }, where: {
enabled: true,
platform: platform as string,
},
order: { pub_date: "DESC" }
}); });
res.json({ res.json({

View File

@ -7,19 +7,16 @@ export class Release extends BaseClass {
name: string; name: string;
@Column() @Column()
pub_date: string; pub_date: Date;
@Column() @Column()
url: string; url: string;
@Column() @Column()
deb_url: string; platform: string;
@Column() @Column()
osx_url: string; enabled: boolean;
@Column()
win_url: string;
@Column({ nullable: true }) @Column({ nullable: true })
notes?: string; notes?: string;