From eca14d74207a5b7857e933c9ecba341a3c8c2350 Mon Sep 17 00:00:00 2001 From: amclubs Date: Thu, 15 Aug 2024 09:32:50 +0000 Subject: [PATCH] See https://github.com/ansoncloud8/am-cf-speed-test-url/commit/28de9d6a9256c61b594bcdcf2255af38df564d5e from refs/heads/main --- .github/workflows/ci.yml | 34 +++++++++++++++++ README.md | 75 ++++++++++++++++++++++++++++++++++++- _worker.js | 49 ++++++++++++++++++++++++ build.sh | 18 +++++++++ output_temp/.build_date.txt | 1 + variables.yml | 1 + 6 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 _worker.js create mode 100644 build.sh create mode 100644 output_temp/.build_date.txt create mode 100644 variables.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4e116c7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + container: pandoc/latex + steps: + - uses: actions/checkout@v2 + - name: Install mustache (to update the date) + run: apk add ruby && gem install mustache + - name: creates output + run: sh ./build.sh + - name: Pushes to another repository + id: push_directory + uses: cpina/github-action-push-to-another-repository@target-branch + env: + SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} + with: + source-directory: . + destination-github-username: 'amclubs' + destination-repository-name: 'am-cf-speed-test-url' + user-email: action@ci.github + commit-message: See ORIGIN_COMMIT from $GITHUB_REF + target-branch: main + - name: Test get variable exported by push-to-another-repository + run: echo $DESTINATION_CLONED_DIRECTORY diff --git a/README.md b/README.md index 5b20745..a3c4b47 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,73 @@ -# am-cf-speed-test-url -使用Cloudflare的Worker搭建SpeedTest测速地址的工程,通过本项目,你可以很容易地在Cloudflare上搭建起自己的测速服务。 +# [am-cf-speed-test-url](https://github.com/ansoncloud8/am-cf-speed-test-url) +▶️ **新人[YouTube](https://youtube.com/@AM_CLUB)** 需要您的支持,请务必帮我**点赞**、**关注**、**打开小铃铛**,***十分感谢!!!*** ✅ +
🎁 不要只是下载或Fork。请 **follow** 我的GitHub、给我所有项目一个 **Star** 星星(拜托了)!你的支持是我不断前进的动力! 💖 +
✅**解锁更多技术请访问[【个人博客】](https://am.809098.xyz)** + +# 免责声明 + +### 用途 +该项目被设计和开发仅供学习、研究和安全测试目的。它旨在为安全研究者、学术界人士和技术爱好者提供一个了解和实践网络通信技术的工具。 + +### 合法性 +使用者在下载和使用该项目时,必须遵守当地法律和规定。使用者有责任确保他们的行为符合其所在地区的法律、规章以及其他适用的规定。 + +### 免责 +1. 作为该项目的作者,我(以下简称“作者”)强调该项目应仅用于合法、道德和教育目的。 +2. 作者不鼓励、不支持也不促进任何形式的非法使用该项目。如果发现该项目被用于非法或不道德的活动,作者将强烈谴责这种行为。 +3. 作者对任何人或团体使用该项目进行的任何非法活动不承担责任。使用者使用该项目时产生的任何后果由使用者本人承担。 +4. 作者不对使用该项目可能引起的任何直接或间接损害负责。 +5. 通过使用该项目,使用者表示理解并同意本免责声明的所有条款。如果使用者不同意这些条款,应立即停止使用该项目。 + +作者保留随时更新本免责声明的权利,且不另行通知。最新的免责声明版本将会在该项目的 GitHub 页面上发布。 + +## 一、项目简介 + +本项目是一个使用Cloudflare的Worker搭建SpeedTest测速地址的工程,主要代码在`worker.js`文件中。通过本项目,你可以很容易地在Cloudflare上搭建起自己的测速服务。 + +## 二、功能介绍 + +例如您的项目域名为 `speedtest.am.workers.dev` + +1. **默认测速大小为200MB**:当未在路径中指定测速大小时,项目会默认进行200MB的测速。 + +- 200M 默认测试下载地址: `https://speedtest.am.workers.dev` + + +2. **自定义测速大小**:通过在路径中指定数字和单位(可选的单位包括 K,M,G),可以设定想要进行测速的数据大小,如“/500M”表示进行500MB的测速。 + +- 1024K 测试下载地址: `https://speedtest.am.workers.dev/1024k` +- 200M 测试下载地址: `https://speedtest.am.workers.dev/200m` +- 1G 测试下载地址: `https://speedtest.am.workers.dev/1g` + +3. **推荐使用workers部署方案并绑定自定义域,即可同时具备 http/https 两种测速途径。** + +## 三、使用指南 + +1. 克隆或下载本项目到你的本地设备。 + +2. 在Cloudflare的Worker中创建一个新的项目,并将`worker.js`文件中的代码复制粘贴到你的项目中。 + +3. 部署你的Worker项目。 + +现在,你可以访问你的Worker的URL,进行网速测试了。 + +## 四、注意事项 + +- 代码中的路径需要做适当修改,以反映你自己的Cloudflare Worker的URL。 +- 当路径不符合预设的格式时,程序将返回400错误。 + +希望这个星级的项目能对你有所帮助,如果你喜欢或用到了本项目,希望能给我一个星级鼓励一下。 + + # +▶️ **新人[YouTube](https://youtube.com/@AM_CLUB)** 需要您的支持,请务必帮我**点赞**、**关注**、**打开小铃铛**,***十分感谢!!!*** ✅ +
🎁 不要只是下载或Fork。请 **follow** 我的GitHub、给我所有项目一个 **Star** 星星(拜托了)!你的支持是我不断前进的动力! 💖 + + # +
[点击展开] 赞赏支持 ~🧧 +*我非常感谢您的赞赏和支持,它们将极大地激励我继续创新,持续产生有价值的工作。* + +- **USDT-TRC20:** `TWTxUyay6QJN3K4fs4kvJTT8Zfa2mWTwDD` + +
+ + diff --git a/_worker.js b/_worker.js new file mode 100644 index 0000000..611759e --- /dev/null +++ b/_worker.js @@ -0,0 +1,49 @@ +export default { + async fetch(request) { + // 创建一个新的 URL 对象 + let url = new URL(request.url); + let path = url.pathname.substring(1); + let isSecure = url.protocol.startsWith("https"); + let bytes; + // 判断路径是否为空 + if (!path) { + // 路径为空,将 bytes 赋值为 200MB + bytes = 200000000; + } else if (path === "locations") { + let targetUrl = `http${isSecure ? 's' : ''}://speed.cloudflare.com/locations`; + let cfRequest = new Request(targetUrl, request); + let response = await fetch(cfRequest); + return response; + } else { + // 其他路径,进行正常的处理 + const regex = /^(\d+)([a-z]?)$/i; + const match = path.match(regex); + if (!match) { + // 路径格式不正确,返回错误 + return new Response("路径格式不正确", { + status: 400, + }); + } + + const bytesStr = match[1]; + const unit = match[2].toLowerCase(); + + // 转换单位 + bytes = parseInt(bytesStr, 10); + if (unit === "k") { + bytes *= 1000; + } else if (unit === "m") { + bytes *= 1000000; + } else if (unit === "g") { + bytes *= 1000000000; + } + } + + let targetUrl = `http${isSecure ? 's' : ''}://speed.cloudflare.com/__down?bytes=${bytes}`; + let cfRequest = new Request(targetUrl, request); + let response = await fetch(cfRequest); + + // 将测试结果反馈给用户 + return response; + } +}; diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..a4a7cd6 --- /dev/null +++ b/build.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# build.sh +# This is an example of some "process". Here it uses +# pandoc to convert from MarkDown to different formats +# and saves the output into "output_temp" + +OUTPUT_DIR="output_temp" + +mkdir "$OUTPUT_DIR" + + +date > "$OUTPUT_DIR"/.build_date.txt + +echo "generated_at: $(date)" > variables.yml + +#mustache variables.yml index.output.html > "$OUTPUT_DIR"/index.html +#mustache variables.yml README.output.md > "$OUTPUT_DIR"/README.md diff --git a/output_temp/.build_date.txt b/output_temp/.build_date.txt new file mode 100644 index 0000000..7714cab --- /dev/null +++ b/output_temp/.build_date.txt @@ -0,0 +1 @@ +Thu Aug 15 09:32:49 UTC 2024 diff --git a/variables.yml b/variables.yml new file mode 100644 index 0000000..12fe0af --- /dev/null +++ b/variables.yml @@ -0,0 +1 @@ +generated_at: Thu Aug 15 09:32:49 UTC 2024