mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(site): ship the link-card videos with the site's static assets (#63459)
This commit is contained in:
@@ -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/<base>.<width>.<codec>.<hash>.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 |
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<string, string> = {
|
||||
mp4: "video/mp4",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user