diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-24 14:35:08 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-10-24 14:35:08 +1100 |
commit | 0be194913036735b5bc97d74a37550d2bd099f13 (patch) | |
tree | 56a277b9d4b76966e1046f3fed2a110dc4c3dee3 /src/api/routes | |
parent | remove self_edit_guilds, was dumb (diff) | |
download | server-0be194913036735b5bc97d74a37550d2bd099f13.tar.xz |
Change android and ios client downloads to use /download endpoint, update Release entity to suck less
Diffstat (limited to 'src/api/routes')
-rw-r--r-- | src/api/routes/download/index.ts | 33 | ||||
-rw-r--r-- | src/api/routes/downloads.ts | 23 | ||||
-rw-r--r-- | src/api/routes/updates.ts | 16 |
3 files changed, 47 insertions, 25 deletions
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({ |