From 9d236eb0c8befba0b8c847ed7a8310d4bfd38f70 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Thu, 12 Nov 2026 04:56:04 -0600 Subject: [PATCH] fix(site): ship the link-card videos with the site's static assets (#63459) --- services/site/MEDIA.md | 1 + services/site/script/build.ts | 7 ++++--- services/site/script/upload-media.ts | 8 +++----- services/site/src/lib/media.ts | 7 +++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/services/site/MEDIA.md b/services/site/MEDIA.md index f195681c58e..562eaab3df7 100644 --- a/services/site/MEDIA.md +++ b/services/site/MEDIA.md @@ -9,6 +9,7 @@ The site's heavy media (product videos, arcade sounds, 3D models and download zi - The build (`script/build.ts`) drops every `mediaFile` from the Worker's assets, so a local copy in `public/` never ships. - In development, `vite dev` proxies `/files` to `https://dev.opencode.ai`, so pages play the dev bucket's copies. - Images (`png`, `jpg`, `webp`, `avif`, `svg`), posters, fonts and the 3D decoders (`arcade3d/draco`, `arcade3d/basis`) stay in git and in the static assets. +- The link-card videos in `og/` (`og:video`, from `script/og.ts`) are the exception: they are small and ship as static assets with their cards. - `videoSources()` offers a video's AV1 and HEVC copies (`media/....mp4`, listed in `src/component/site/media-manifest.json`) before the H.264 original. The manifest lists only copies that are in the bucket; a video without copies plays its original. | Folder | Files | diff --git a/services/site/script/build.ts b/services/site/script/build.ts index 08db04c6188..3a075904763 100644 --- a/services/site/script/build.ts +++ b/services/site/script/build.ts @@ -14,7 +14,7 @@ import { writeWorkerConfig, } from "@cloudflare/build-output-utils" import { resolveAndParseConfig } from "@cloudflare/config" -import { mediaFile } from "../src/lib/media" +import { inBucket } from "../src/lib/media" import { stageHeaders } from "../src/lib/noindex" import { retainAssets } from "./retain-assets" @@ -57,10 +57,11 @@ await writeRootConfig( // Heavy media is never a Worker asset; it is served from the files bucket (src/lib/media.ts). const assets = path.join(root, "dist", "assets") +const output = path.join(root, ".output", "public") await rm(assets, { recursive: true, force: true }) -await cp(path.join(root, ".output", "public"), assets, { +await cp(output, assets, { recursive: true, - filter: (file) => !mediaFile.test(file), + filter: (file) => !inBucket(path.relative(output, file)), }) const shipped = await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: assets, dot: true })) // Every opencode.json and V1 TUI config names these as its $schema; /openapi.json is the protocol's. diff --git a/services/site/script/upload-media.ts b/services/site/script/upload-media.ts index 14be56b7796..32a1c456a54 100644 --- a/services/site/script/upload-media.ts +++ b/services/site/script/upload-media.ts @@ -1,4 +1,4 @@ -// Uploads the heavy media in public/ (src/lib/media.ts `mediaFile`) to the existing files bucket, +// Uploads the heavy media in public/ (src/lib/media.ts `inBucket`) to the existing files bucket, // which the /files route serves (services/files), under site/2026-11 at the same path, and writes // media-manifest.txt. Not part of the build. // @@ -11,7 +11,7 @@ import { createHash } from "node:crypto" import path from "node:path" import { Glob } from "bun" -import { mediaBase, mediaFile } from "../src/lib/media" +import { inBucket, mediaBase } from "../src/lib/media" const root = path.resolve(import.meta.dir, "..") const publicDir = path.join(root, "public") @@ -21,9 +21,7 @@ const prefix = mediaBase.replace(/^\/files\//, "") const run = process.argv.includes("--run") const writeManifest = process.argv.includes("--manifest") -const files = (await Array.fromAsync(new Glob("**/*").scan({ cwd: publicDir }))) - .filter((file) => mediaFile.test(file)) - .sort() +const files = (await Array.fromAsync(new Glob("**/*").scan({ cwd: publicDir }))).filter(inBucket).sort() const types: Record = { mp4: "video/mp4", diff --git a/services/site/src/lib/media.ts b/services/site/src/lib/media.ts index d59cbca0a10..f287bf0655b 100644 --- a/services/site/src/lib/media.ts +++ b/services/site/src/lib/media.ts @@ -9,6 +9,13 @@ export const mediaBase = "/files/site/2026-11" /** File types that live in the files bucket rather than in the Worker's static assets. */ export const mediaFile = /\.(mp4|webm|mov|mp3|wav|ogg|m4a|zip|glb|gltf)$/i +/** + * Whether a file under public/ (its path from there) goes to the files bucket. The link-card videos + * script/og.ts writes to og/ (og:video, under 100 kB each) are the exception: they ship as static + * assets with the cards that name them. + */ +export const inBucket = (file: string) => mediaFile.test(file) && !/^og[\\/]/.test(file) + /** The files-bucket URL for a media site path, for example `mediaUrl("/arcade3d/cabinet.glb")`. Other paths pass through. */ export function mediaUrl(path: string) { if (!path.startsWith("/") || path.startsWith(mediaBase) || !mediaFile.test(path.split(/[?#]/)[0])) return path