Skip to content

Commit e3b0ca6

Browse files
authored
fix(www): link the production update API for desktop downloads (#62198)
1 parent 54cf5f8 commit e3b0ca6

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎services/www/script/build.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ const entry = await Bun.build({
9191
external: ["./docs/*", "./site/*"],
9292
})
9393
if (!entry.success) throw new AggregateError(entry.logs, "worker.ts build failed")
94-
await writeWorkerConfig({ root, config: config.worker, manifest: { type: "partial", mainModule: "worker.mjs", modules: {} } })
94+
await writeWorkerConfig({
95+
root,
96+
config: config.worker,
97+
manifest: { type: "partial", mainModule: "worker.mjs", modules: {} },
98+
})
9599
console.log(`www: built ${config.worker.name} (${mode})`)
96100

97101
/** Copies the site's assets over the docs', refusing a path both write with different bytes. */

‎services/www/site/src/lib/download.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ export const desktopAssets = {
8686
"linux-x64-rpm": "opencode-desktop-linux-x86_64.rpm",
8787
} as const satisfies Record<DownloadPlatform, string>
8888

89+
/**
90+
* The update API (services/update). Always production's: there is one release service, and it has
91+
* no route on dev.opencode.ai.
92+
*/
93+
export const updateApi = "https://opencode.ai/update/api"
94+
8995
/**
9096
* A desktop build's download: the update API answers it with a 302 to the file in the files bucket.
91-
* Not locale-prefixed, so never pass it through `route()`.
97+
* Absolute, so never pass it through `route()`.
9298
*/
9399
export function getDownloadHref(platform: DownloadPlatform, channel: "latest" | "beta" = "latest") {
94-
return `/update/api/${channel}/desktop/opencode/${desktopAssets[platform]}`
100+
return `${updateApi}/${channel}/desktop/opencode/${desktopAssets[platform]}`
95101
}
96102

97103
/** The desktop builds, in order. The .AppImage build stays out until it works. */

‎services/www/site/src/lib/legacy.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Locale } from "~/lib/language"
2-
import { desktopAssets } from "~/lib/download"
2+
import { desktopAssets, updateApi } from "~/lib/download"
33

44
// LEGACY REDIRECTS, every one to be removed later. Old URLs that outside links, bookmarks, scripts
55
// and older app versions still request, answered here so they keep working. Nothing in this repo may
@@ -24,7 +24,7 @@ export function legacyRedirect(request: Legacy): Response | undefined {
2424
const channel = download[1] === "stable" ? "latest" : download[1]
2525
return redirect(
2626
302,
27-
`/update/api/${channel}/desktop/opencode/${desktopAssets[platform as keyof typeof desktopAssets]}`,
27+
`${updateApi}/${channel}/desktop/opencode/${desktopAssets[platform as keyof typeof desktopAssets]}`,
2828
)
2929
}
3030

‎services/www/site/test/legacy.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@ import { describe, expect, test } from "bun:test"
22
import { legacyRedirect } from "../src/lib/legacy"
33

44
const get = (path: string, options: { search?: string; method?: string; locale?: "de" | null } = {}) =>
5-
legacyRedirect({ path, search: options.search ?? "", method: options.method ?? "GET", locale: options.locale ?? null })
5+
legacyRedirect({
6+
path,
7+
search: options.search ?? "",
8+
method: options.method ?? "GET",
9+
locale: options.locale ?? null,
10+
})
611

712
describe("legacy redirects", () => {
813
test("desktop downloads go straight to the update API, HEAD included", () => {
914
for (const method of ["GET", "HEAD"]) {
1015
const response = get("/download/latest/windows-x64-nsis", { method })
1116
expect(response?.status).toBe(302)
12-
expect(response?.headers.get("Location")).toBe("/update/api/latest/desktop/opencode/opencode-desktop-win-x64.exe")
17+
expect(response?.headers.get("Location")).toBe(
18+
"https://opencode.ai/update/api/latest/desktop/opencode/opencode-desktop-win-x64.exe",
19+
)
1320
}
1421
expect(get("/download/stable/linux-x64-deb")?.headers.get("Location")).toBe(
15-
"/update/api/latest/desktop/opencode/opencode-desktop-linux-amd64.deb",
22+
"https://opencode.ai/update/api/latest/desktop/opencode/opencode-desktop-linux-amd64.deb",
1623
)
1724
expect(get("/download/beta/darwin-aarch64-dmg")?.headers.get("Location")).toBe(
18-
"/update/api/beta/desktop/opencode/opencode-desktop-mac-arm64.dmg",
25+
"https://opencode.ai/update/api/beta/desktop/opencode/opencode-desktop-mac-arm64.dmg",
1926
)
2027
expect(get("/download/latest/not-a-platform")?.status).toBe(404)
2128
expect(get("/download/latest/toString")?.status).toBe(404)

0 commit comments

Comments
 (0)