offload-r2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOffload R2 Asset
卸载 R2 资产
Host media on , update every in-scope source reference to the public object, and remove the repository-local copy after verification.
https://remotion.media/将媒体托管在 上,将所有范围内的源引用更新为公开对象,并在验证后删除仓库中的本地副本。
https://remotion.media/Workflow
工作流
-
Find the main worktree with. Prefer the worktree on
git worktree list --porcelain, normallyrefs/heads/main./Users/jonathanburger/remotion -
Choose a stable, descriptive object key. Use a feature-specific directory prefix when it prevents collisions, for example. When replacing an asset, prefer a new versioned key so browser and Studio caches cannot serve the previous bytes.
studio-close-ups/demo.mp4 -
Load credentials from the main worktree without printing them:bash
--env-file=/Users/jonathanburger/remotion/packages/remotion-media/.envThe required variables areandAWS_ACCESS_KEY_ID.AWS_SECRET_ACCESS_KEY -
Upload to thebucket with Bun's S3-compatible client:
parser-mediabashbun --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);" -
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)" -
Replace every in-scope source usage with the public URL. Do not wrap remote URLs inbecause it rejects
staticFile()andhttp://URLs.https:// -
After the public hash matches and source references are remote, remove the local copy. Usefor a tracked file or remove the exact untracked/ignored file directly. Remove obsolete asset-specific
git rm -- <local-file>entries and empty asset directories. Do not use recursive deletion or broad globs..gitignore -
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> -
Run focused lint or style checks for touched packages. Commit or push only when requested.
-
使用查找主工作树。优先选择位于
git worktree list --porcelain的工作树,通常是refs/heads/main。/Users/jonathanburger/remotion -
选择稳定且具有描述性的对象键。如果使用特定功能的目录前缀可以避免冲突,则优先使用,例如。替换资产时,优先使用新的版本化键,以防浏览器和 Studio 缓存返回旧内容。
studio-close-ups/demo.mp4 -
从主工作树加载凭据,且不要打印凭据:bash
--env-file=/Users/jonathanburger/remotion/packages/remotion-media/.env必需的变量为和AWS_ACCESS_KEY_ID。AWS_SECRET_ACCESS_KEY -
使用 Bun 的 S3 兼容客户端上传到存储桶:
parser-mediabashbun --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);" -
验证公开对象,并在删除任何内容之前,将其 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)" -
将所有范围内的源文件使用位置替换为公开 URL。不要用包装远程 URL,因为它会拒绝
staticFile()和http://URL。https:// -
确认公开对象的哈希匹配且源引用已指向远程资源后,删除本地副本。对于已跟踪文件,使用;对于未跟踪或被忽略的文件,直接删除准确的文件路径。删除过时的资产专用
git rm -- <local-file>条目和空的资产目录。不要使用递归删除或宽泛的 glob。.gitignore -
验证本地副本已删除,并搜索受影响包中是否仍存在对本地文件的引用:bash
test ! -e <local-file> rg -n '<local-filename>|staticFile\(' <affected-package> -
对涉及修改的包运行有针对性的 lint 或格式检查。仅在收到要求时提交或推送。