offload-r2

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Offload R2 Asset

卸载 R2 资产

Host media on
https://remotion.media/
, update every in-scope source reference to the public object, and remove the repository-local copy after verification.
将媒体托管在
https://remotion.media/
上,将所有范围内的源引用更新为公开对象,并在验证后删除仓库中的本地副本。

Workflow

工作流

  1. Find the main worktree with
    git worktree list --porcelain
    . Prefer the worktree on
    refs/heads/main
    , normally
    /Users/jonathanburger/remotion
    .
  2. Choose a stable, descriptive object key. Use a feature-specific directory prefix when it prevents collisions, for example
    studio-close-ups/demo.mp4
    . When replacing an asset, prefer a new versioned key so browser and Studio caches cannot serve the previous bytes.
  3. Load credentials from the main worktree without printing them:
    bash
    --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env
    The required variables are
    AWS_ACCESS_KEY_ID
    and
    AWS_SECRET_ACCESS_KEY
    .
  4. Upload to the
    parser-media
    bucket with Bun's S3-compatible client:
    bash
    bun --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env -e "import {S3Client} from 'bun'; const filePath='<local-file>'; const key='<object-key>'; const client=new S3Client({accessKeyId:Bun.env.AWS_ACCESS_KEY_ID,secretAccessKey:Bun.env.AWS_SECRET_ACCESS_KEY,endpoint:'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com',bucket:'parser-media'}); const bytes=new Uint8Array(await Bun.file(filePath).arrayBuffer()); await client.write(key,bytes); const remote=await client.file(key).arrayBuffer(); if (remote.byteLength!==bytes.byteLength) throw new Error('Size mismatch'); console.log('uploaded',key,remote.byteLength);"
  5. Verify the public object and compare its SHA-256 hash with the local file before removing anything:
    bash
    curl -I --fail https://remotion.media/<object-key>
    test "$(shasum -a 256 <local-file> | cut -d' ' -f1)" = "$(curl --fail --silent https://remotion.media/<object-key> | shasum -a 256 | cut -d' ' -f1)"
  6. Replace every in-scope source usage with the public URL. Do not wrap remote URLs in
    staticFile()
    because it rejects
    http://
    and
    https://
    URLs.
  7. After the public hash matches and source references are remote, remove the local copy. Use
    git rm -- <local-file>
    for a tracked file or remove the exact untracked/ignored file directly. Remove obsolete asset-specific
    .gitignore
    entries and empty asset directories. Do not use recursive deletion or broad globs.
  8. Verify the local copy is gone and search the affected package for remaining local references:
    bash
    test ! -e <local-file>
    rg -n '<local-filename>|staticFile\(' <affected-package>
  9. Run focused lint or style checks for touched packages. Commit or push only when requested.
  1. 使用
    git worktree list --porcelain
    查找主工作树。优先选择位于
    refs/heads/main
    的工作树,通常是
    /Users/jonathanburger/remotion
    。
  2. 选择稳定且具有描述性的对象键。如果使用特定功能的目录前缀可以避免冲突,则优先使用,例如
    studio-close-ups/demo.mp4
    。替换资产时,优先使用新的版本化键,以防浏览器和 Studio 缓存返回旧内容。
  3. 从主工作树加载凭据,且不要打印凭据:
    bash
    --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env
    必需的变量为
    AWS_ACCESS_KEY_ID
    和
    AWS_SECRET_ACCESS_KEY
    。
  4. 使用 Bun 的 S3 兼容客户端上传到
    parser-media
    存储桶:
    bash
    bun --env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env -e "import {S3Client} from 'bun'; const filePath='<local-file>'; const key='<object-key>'; const client=new S3Client({accessKeyId:Bun.env.AWS_ACCESS_KEY_ID,secretAccessKey:Bun.env.AWS_SECRET_ACCESS_KEY,endpoint:'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com',bucket:'parser-media'}); const bytes=new Uint8Array(await Bun.file(filePath).arrayBuffer()); await client.write(key,bytes); const remote=await client.file(key).arrayBuffer(); if (remote.byteLength!==bytes.byteLength) throw new Error('Size mismatch'); console.log('uploaded',key,remote.byteLength);"
  5. 验证公开对象,并在删除任何内容之前,将其 SHA-256 哈希与本地文件进行比较:
    bash
    curl -I --fail https://remotion.media/<object-key>
    test "$(shasum -a 256 <local-file> | cut -d' ' -f1)" = "$(curl --fail --silent https://remotion.media/<object-key> | shasum -a 256 | cut -d' ' -f1)"
  6. 将所有范围内的源文件使用位置替换为公开 URL。不要用
    staticFile()
    包装远程 URL,因为它会拒绝
    http://
    和
    https://
    URL。
  7. 确认公开对象的哈希匹配且源引用已指向远程资源后,删除本地副本。对于已跟踪文件,使用
    git rm -- <local-file>
    ;对于未跟踪或被忽略的文件,直接删除准确的文件路径。删除过时的资产专用
    .gitignore
    条目和空的资产目录。不要使用递归删除或宽泛的 glob。
  8. 验证本地副本已删除,并搜索受影响包中是否仍存在对本地文件的引用:
    bash
    test ! -e <local-file>
    rg -n '<local-filename>|staticFile\(' <affected-package>
  9. 对涉及修改的包运行有针对性的 lint 或格式检查。仅在收到要求时提交或推送。