📘 PicList + Cloudflare Worker + GitHub 多仓库 配置文档
适用场景:已部署 CF Worker,使用自定义域名反代多个 GitHub 仓库,替换原有 gh-proxy
一、基础信息
- 用户名:
xx00 - 自定义域名:
https://cdn.你的域名.com - 已配置仓库:
img-q/img/files/videos
二、Cloudflare Worker 最终代码(可直接部署)
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
const path = url.pathname;
const REPO_MAP = {
"/img-q/": "xx00/img-q/main",
"/img/": "xx00/img/main",
"/file/": "xx00/files/main",
"/video/": "xx00/videos/main"
};
let match = null;
for (const prefix in REPO_MAP) {
if (path.startsWith(prefix)) {
match = prefix;
break;
}
}
if (!match) {
return new Response("Not Found", { status: 404 });
}
const repoPath = REPO_MAP[match];
const filePath = path.slice(match.length);
const target = `https://raw.githubusercontent.com/${repoPath}/${filePath}`;
const response = await fetch(target, {
method: request.method,
headers: request.headers
});
const headers = new Headers(response.headers);
headers.set("Cache-Control", "public, max-age=31536000");
return new Response(response.body, {
status: response.status,
headers: headers
});
}三、CF Worker 部署步骤
- 进入 Cloudflare → Workers & Pages → Create application
- 新建 Worker,清空默认代码
- 粘贴上方完整代码 → Deploy
- Triggers → Add Custom Domain → 绑定
cdn.你的域名.com - 等待 1 分钟解析生效
四、PicList 完整配置(替换旧配置)
旧配置(废弃)
https://gh-proxy.com/https://raw.githubusercontent.com/xx00/q/main新统一配置
自定义域名:https://cdn.你的域名.com
五、多仓库 PicList 路径对照表
| 仓库名称 | PicList 目录/路径 | 访问链接示例 |
|---|---|---|
| img-q | /img-q/ | https://cdn.你的域名.com/img-q/xxx.png |
| img | /img/ | https://cdn.你的域名.com/img/xxx.png |
| files | /file/ | https://cdn.你的域名.com/file/xxx.zip |
| videos | /video/ | https://cdn.你的域名.com/video/xxx.mp4 |
六、使用说明
- 上传时只需要切换路径,无需改动自定义域名
- 链接格式永久固定,不会失效
- Cloudflare 自动缓存,国内访问高速
- GitHub 公共仓库合规使用,无封号风险
七、架构优势
✅ 自有域名,永久链接
✅ Cloudflare 国内加速
✅ 一域名管理多仓库
✅ 无流量限制、免费使用
✅ 防盗链、防攻击、强缓存
(注:文档部分内容可能由 AI 生成)
评论 (0)