11import type { APIEvent } from "@solidjs/start"
2- import { waitUntil } from "@opencode-ai/console-resource"
32import type { DownloadPlatform } from "../types"
43
54const prodAssetNames : Record < string , string > = {
@@ -20,13 +19,6 @@ const betaAssetNames: Record<string, string> = {
2019 "linux-x64-rpm" : "opencode-desktop-linux-x86_64.rpm" ,
2120} satisfies Record < DownloadPlatform , string >
2221
23- // Doing this on the server lets us preserve the original name for platforms we don't care to rename for
24- const downloadNames : Record < string , string > = {
25- "darwin-aarch64-dmg" : "OpenCode Desktop.dmg" ,
26- "darwin-x64-dmg" : "OpenCode Desktop.dmg" ,
27- "windows-x64-nsis" : "OpenCode Desktop Installer.exe" ,
28- } satisfies { [ K in DownloadPlatform ] ?: string }
29-
3022export async function GET ( { params : { platform, channel } } : APIEvent ) {
3123 const assetName = channel === "stable" ? prodAssetNames [ platform ] : betaAssetNames [ platform ]
3224 if ( ! assetName ) return new Response ( null , { status : 404 } )
@@ -37,30 +29,7 @@ export async function GET({ params: { platform, channel } }: APIEvent) {
3729 if ( ! release . ok ) return new Response ( null , { status : release . status } )
3830 const location = getAssetUrl ( await release . json ( ) , assetName )
3931 if ( ! location ) return new Response ( null , { status : 502 } )
40-
41- const key = new Request ( location )
42- const cache = ( caches as CacheStorage & { default : Cache } ) . default
43- const cached = await cache . match ( key )
44- if ( cached ) return download ( cached , platform , "HIT" )
45-
46- const resp = await fetch ( location )
47- if ( ! resp . ok ) return resp
48-
49- const headers = new Headers ( resp . headers )
50- headers . set ( "cache-control" , "public, max-age=31536000, immutable" )
51- headers . delete ( "set-cookie" )
52- const result = new Response ( resp . body , { status : resp . status , statusText : resp . statusText , headers } )
53- waitUntil ( cache . put ( key , result . clone ( ) ) )
54- return download ( result , platform , "MISS" )
55- }
56-
57- function download ( resp : Response , platform : string , cache : "HIT" | "MISS" ) {
58- const downloadName = downloadNames [ platform ]
59- const headers = new Headers ( resp . headers )
60- if ( downloadName ) headers . set ( "content-disposition" , `attachment; filename="${ downloadName } "` )
61- headers . set ( "x-opencode-cache" , cache )
62-
63- return new Response ( resp . body , { status : resp . status , statusText : resp . statusText , headers } )
32+ return Response . redirect ( location , 302 )
6433}
6534
6635function getAssetUrl ( input : unknown , assetName : string ) {
0 commit comments