用 jsDelivr 绕过 raw.githubusercontent.com 访问限制

安装一个为终端添加音效的小工具,进度条走到一半,停了。屏幕上逐行滚出警告:

Warning: failed to download peon/sounds/PeonWhat2.wav
Warning: failed to download peon/sounds/PeonWarcry1.wav

两个魔兽争霸的苦工音效文件,因为 raw.githubusercontent.com 的连接问题,没有下载下来。这个域名专门用来直连 GitHub 仓库里的原始文件,可谓"开门见山"的设计——门在那里,山在那里,路却断了。

URL 转换规则

raw.githubusercontent.com 在国内长期不稳定。jsDelivr 是一个在中国大陆有节点的全球 CDN,原生支持代理 GitHub 仓库文件,替换地址后无须其他配置即可访问。

转换规则只有一条:

场景格式
原始地址https://raw.githubusercontent.com/{owner}/{repo}/{ref}/{path}
jsDelivr 替换https://cdn.jsdelivr.net/gh/{owner}/{repo}@{ref}/{path}

几点注意:

  • {ref} 可以是 branch 名(如 main)、tag(如 v1.0.0)或完整 commit hash
  • 推荐使用 tag 或 commit hash,CDN 会对其进行长期缓存;使用 branch 名则缓存周期较短(约 12 小时)
  • jsDelivr 单文件大小限制为 50MB,超过此限制的文件无法通过该方式访问

实战示例

起因是安装 peon-ping——一个为 Claude Code 添加魔兽争霸苦工音效的工具。安装程序从 raw.githubusercontent.com 拉取音效包,部分文件卡住不动,最终报错退出。

失败的原始地址:

https://raw.githubusercontent.com/PeonPing/og-packs/v1.0.0/peon/sounds/PeonWhat2.wav
https://raw.githubusercontent.com/PeonPing/og-packs/v1.0.0/peon/sounds/PeonWarcry1.wav

替换为 jsDelivr 后:

1
2
3
4
5
curl -fL "https://cdn.jsdelivr.net/gh/PeonPing/[email protected]/peon/sounds/PeonWhat2.wav" \
  -o ~/.openpeon/packs/peon/sounds/PeonWhat2.wav

curl -fL "https://cdn.jsdelivr.net/gh/PeonPing/[email protected]/peon/sounds/PeonWarcry1.wav" \
  -o ~/.openpeon/packs/peon/sounds/PeonWarcry1.wav

下载速度正常,文件 SHA256 与仓库元数据完全吻合。绕了一圈,苦工终于说上了话。

通用转换脚本

批量将 raw.githubusercontent.com 链接转换为 jsDelivr 格式:

1
2
3
4
5
6
7
raw_to_jsdelivr() {
  echo "$1" | sed 's|https://raw.githubusercontent.com/\([^/]*\)/\([^/]*\)/\([^/]*\)/\(.*\)|https://cdn.jsdelivr.net/gh/\1/\2@\3/\4|'
}

# 示例
raw_to_jsdelivr "https://raw.githubusercontent.com/PeonPing/og-packs/v1.0.0/peon/sounds/PeonWhat2.wav"
# 输出:https://cdn.jsdelivr.net/gh/PeonPing/[email protected]/peon/sounds/PeonWhat2.wav

适用范围

凡是托管在 GitHub 仓库中的静态文件——代码、配置、音频、图片、字体——均可通过这个方式访问。依赖 raw.githubusercontent.com 的安装脚本如果卡住,也可以先把目标文件手动下载,再走后续流程。

局限性与备选方案

  • 文件大小上限 50MB
  • jsDelivr 本身偶有不稳定,备选方案:

工具在那里,绕一圈总能到。