Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

servless/fastfile

Repository files navigation

fastfile

基于 CloudFlare Workers / Pages 的文件加速下载

注意:本项目内置我自己的 51 网站统计代码,请自行删除或修改 src/index.js

部署教程 - Workers

Deploy to Cloudflare Workers

通过 GitHub Actions 发布至 CloudFlare

从 CloudFlare 获取 CLOUDFLARE_API_TOKEN 值(编辑 Cloudflare Workers),并设置到项目。

https://github.com/<ORG>/dchere/settings/secrets/actions

本地部署到 CloudFlare

  1. 注册 CloudFlare 账号,并且设置 Workers 域名 (比如:abcd.workers.dev)

  2. 安装 Wrangler 命令行工具

    npm install -g wrangler
  3. 登录 Wrangler(可能需要扶梯):

    # 登录,可能登录不成功
    # 若登录不成功,可能需要使用代理。
    wrangler login
  4. 拉取本项目:

    git clone https://github.com/servless/fastfile.git
  5. 修改 wrangler.toml 文件中的 name(fastfile)为服务名 myfastfile(访问域名为:myfastfile.abcd.workers.dev)。

  6. 发布

     wrangler deploy

    发布成功将会显示对应的网址

     Proxy environment variables detected. We'll use your proxy for fetch requests.
    ⛅️ wrangler 3.99.0
    	--------------------
    	Total Upload: 0.66 KiB / gzip: 0.35 KiB
    	Uploaded myfastfile (1.38 sec)
    	Published myfastfile (4.55 sec)
    		https://myfastfile.abcd.workers.dev
    	Current Deployment ID: xxxx.xxxx.xxxx.xxxx

    由于某些原因,workers.dev 可能无法正常访问,建议绑定自有域名。

  7. 绑定域名

    Compute (Workers) -> Workers & Pages -> Settings -> Domains & Routes -> Add -> Custom Domain(仅支持解析在 CF 的域名),按钮以绑定域名。

部署教程 - Pages

直接连接到 GitHub 后,一键部署

本地部署到 CloudFlare

  • 修改代码 [pages/_worker.js]
  1. 登录请参考 Workers 中的本地部署的步骤 1~4

  2. 发布

     wrangler pages deploy pages --project-name fastfile

    发布成功将会显示对应的网址

    	さんかく [WARNING] Pages now has wrangler.toml support.
    		We detected a configuration file at
    		Ignoring configuration file for now, and proceeding with project deploy.
    		To silence this warning, pass in --commit-dirty=true
    	✨ Success! Uploaded 0 files (11 already uploaded) (0.38 sec)
    	✨ Compiled Worker successfully
    	✨ Uploading Worker bundle
    	🌎 Deploying...
    	✨ Deployment complete! Take a peek over at https://2e4bd9c5.dcba.pages.dev

    由于某些原因,pages.dev 可能无法正常访问,建议绑定自有域名。

  3. 绑定域名

    Compute (Workers) -> Workers & Pages -> Custom domains -> Add Custom Domain(支持解析不在 CF 的域名),按钮以绑定域名。

配置 GitHub Token (可选)

为了避免 GitHub API 的速率限制(Rate Limit),建议配置 GITHUB_TOKEN:

  1. 生成 Token:

    • 访问 GitHub Personal Access Tokens (classic)
    • 点击 Generate new token (classic)
    • 填写 Note(如 fastfile-worker),过期时间建议选择 No expiration(或根据需要选择)。
    • Scopes:无需勾选任何权限(仅用于提高公共 API 的访问限额)。
    • 点击底部的 Generate token 并复制生成的 Token。
  2. 设置 Secret:

    • 对于 Workers,在本地项目目录下执行:
      wrangler secret put GITHUB_TOKEN
    • 对于 Pages,在本地项目目录下执行:
      wrangler pages secret put GITHUB_TOKEN --project-name fastfile
    • 提示输入时,粘贴刚才复制的 Token 并回车。

仓库镜像

MyCode くろまる GitCode くろまる GitHub

About

基于 CloudFlare Workers / Pages 的文件加速下载

Resources

License

Stars

Watchers

Forks

Contributors

AltStyle によって変換されたページ (->オリジナル) /