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