summary refs log tree commit diff
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-12-20 03:01:16 -0500
committerPuyodead1 <puyodead@proton.me>2023-12-20 03:01:16 -0500
commitd3d828f41dd0da3a330a815fe5c25ef6ce08f9b5 (patch)
tree7fa9af0bc1ddd6da992d4b54bfe463fb824d9052
parentvalidation on updater platform and arch query (diff)
downloadserver-d3d828f41dd0da3a330a815fe5c25ef6ce08f9b5.tar.xz
update download route
-rw-r--r--src/api/routes/download.ts44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/api/routes/download.ts b/src/api/routes/download.ts

index 85fb41be..d5eb6cb4 100644 --- a/src/api/routes/download.ts +++ b/src/api/routes/download.ts
@@ -22,6 +22,9 @@ import { Request, Response, Router } from "express"; const router = Router(); +const PLATFORMS = ["linux", "windows", "darwin"]; +const ARCHS = ["x86_64", "i686", "aarch64", "armv7"]; + router.get( "/", route({ @@ -31,22 +34,53 @@ router.get( body: "APIErrorResponse", }, }, + query: { + platform: { + type: "string", + required: true, + description: "The platform to get the manifest for", + }, + arch: { + type: "string", + required: true, + description: "The architecture to get the manifest for", + }, + channel: { + type: "string", + required: true, + description: "The release channel to get the manifest for", + }, + }, }), async (req: Request, res: Response) => { - const { platform } = req.query; + const { platform, arch, channel } = req.query as Record<string, string>; - if (!platform) + if (PLATFORMS.indexOf(platform) == -1) throw FieldErrors({ platform: { - code: "BASE_TYPE_REQUIRED", - message: req.t("common:field.BASE_TYPE_REQUIRED"), + message: `Value must be one of (${PLATFORMS.map( + (x) => `'${x}'`, + ).join(", ")}).`, + code: "BASE_TYPE_CHOICES", + }, + }); + + if (ARCHS.indexOf(arch) == -1) + throw FieldErrors({ + arch: { + message: `Value must be one of (${ARCHS.map( + (x) => `'${x}'`, + ).join(", ")}).`, + code: "BASE_TYPE_CHOICES", }, }); const release = await Release.findOneOrFail({ where: { enabled: true, - platform: platform as string, + platform: platform, + arch: arch, + channel: channel, }, order: { pub_date: "DESC" }, });