Skip to content

Commit ae93d4a

Browse files
fix(console): use v2 desktop downloads (#49931)
Co-authored-by: Brendonovich <14191578+Brendonovich@users.noreply.github.com>
1 parent 9a53565 commit ae93d4a

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

packages/console/app/src/routes/download/[channel]/[platform].ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export async function GET({ params: { platform, channel } }: APIEvent) {
3131
const assetName = channel === "stable" ? prodAssetNames[platform] : betaAssetNames[platform]
3232
if (!assetName) return new Response(null, { status: 404 })
3333

34-
const latest = await fetch(
35-
`https://github.com/anomalyco/${channel === "stable" ? "opencode" : "opencode-beta"}/releases/latest/download/${assetName}`,
36-
{ redirect: "manual" },
34+
const release = await fetch(
35+
`https://opencode.ai/update/api/${channel === "stable" ? "latest" : "beta"}/desktop/opencode`,
3736
)
38-
const location = latest.headers.get("location")
37+
if (!release.ok) return new Response(null, { status: release.status })
38+
const location = getAssetUrl(await release.json(), assetName)
3939
if (!location) return new Response(null, { status: 502 })
4040

4141
const key = new Request(location)
@@ -62,3 +62,14 @@ function download(resp: Response, platform: string, cache: "HIT" | "MISS") {
6262

6363
return new Response(resp.body, { status: resp.status, statusText: resp.statusText, headers })
6464
}
65+
66+
function getAssetUrl(input: unknown, assetName: string) {
67+
if (!isRecord(input) || !isRecord(input.metadata) || !isRecord(input.metadata.files)) return
68+
const asset = input.metadata.files[assetName]
69+
if (!isRecord(asset) || typeof asset.url !== "string") return
70+
return asset.url
71+
}
72+
73+
function isRecord(input: unknown): input is Record<string, unknown> {
74+
return typeof input === "object" && input !== null && !Array.isArray(input)
75+
}

0 commit comments

Comments
 (0)