fix(console): use v2 desktop downloads (#49931)
Co-authored-by: Brendonovich <14191578+Brendonovich@users.noreply.github.com>
This commit is contained in:
parent
9a53565790
commit
ae93d4afb3
1 changed files with 15 additions and 4 deletions
|
|
@ -31,11 +31,11 @@ export async function GET({ params: { platform, channel } }: APIEvent) {
|
|||
const assetName = channel === "stable" ? prodAssetNames[platform] : betaAssetNames[platform]
|
||||
if (!assetName) return new Response(null, { status: 404 })
|
||||
|
||||
const latest = await fetch(
|
||||
`https://github.com/anomalyco/${channel === "stable" ? "opencode" : "opencode-beta"}/releases/latest/download/${assetName}`,
|
||||
{ redirect: "manual" },
|
||||
const release = await fetch(
|
||||
`https://opencode.ai/update/api/${channel === "stable" ? "latest" : "beta"}/desktop/opencode`,
|
||||
)
|
||||
const location = latest.headers.get("location")
|
||||
if (!release.ok) return new Response(null, { status: release.status })
|
||||
const location = getAssetUrl(await release.json(), assetName)
|
||||
if (!location) return new Response(null, { status: 502 })
|
||||
|
||||
const key = new Request(location)
|
||||
|
|
@ -62,3 +62,14 @@ function download(resp: Response, platform: string, cache: "HIT" | "MISS") {
|
|||
|
||||
return new Response(resp.body, { status: resp.status, statusText: resp.statusText, headers })
|
||||
}
|
||||
|
||||
function getAssetUrl(input: unknown, assetName: string) {
|
||||
if (!isRecord(input) || !isRecord(input.metadata) || !isRecord(input.metadata.files)) return
|
||||
const asset = input.metadata.files[assetName]
|
||||
if (!isRecord(asset) || typeof asset.url !== "string") return
|
||||
return asset.url
|
||||
}
|
||||
|
||||
function isRecord(input: unknown): input is Record<string, unknown> {
|
||||
return typeof input === "object" && input !== null && !Array.isArray(input)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue