Skip to content

Commit

Permalink
See ansoncloud8/am-cf-speed-test-url@28de9d6 from refs/heads/main
Browse files Browse the repository at this point in the history
  • Loading branch information
amclubs committed Aug 15, 2024
1 parent dcf312d commit eca14d7
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)** 需要您的支持,请务必帮我**点赞****关注****打开小铃铛*****十分感谢!!!***
</br>🎁 不要只是下载或Fork。请 **follow** 我的GitHub、给我所有项目一个 **Star** 星星(拜托了)!你的支持是我不断前进的动力! 💖
</br>✅**解锁更多技术请访问[【个人博客】](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)** 需要您的支持,请务必帮我**点赞****关注****打开小铃铛*****十分感谢!!!***
</br>🎁 不要只是下载或Fork。请 **follow** 我的GitHub、给我所有项目一个 **Star** 星星(拜托了)!你的支持是我不断前进的动力! 💖

#
<center><details><summary><strong> [点击展开] 赞赏支持 ~🧧</strong></summary>
*我非常感谢您的赞赏和支持,它们将极大地激励我继续创新,持续产生有价值的工作。*

- **USDT-TRC20:** `TWTxUyay6QJN3K4fs4kvJTT8Zfa2mWTwDD`

</details></center>


49 changes: 49 additions & 0 deletions _worker.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
18 changes: 18 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions output_temp/.build_date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thu Aug 15 09:32:49 UTC 2024
1 change: 1 addition & 0 deletions variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated_at: Thu Aug 15 09:32:49 UTC 2024

0 comments on commit eca14d7

Please sign in to comment.