Skip to content

Commit 321af19

Browse files
authored
Merge pull request cmliu#905 from cmliu/beta2.0
Beta2.0
2 parents b5b9992 + 7c16ca4 commit 321af19

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 🚀 edgetunnel 2.0
22
![后台页面](./img.png)
33

4-
- **edgetunnel 最新教程**https://www.youtube.com/watch?v=tKe9xUuFODA ***必看内容!必看内容!必看内容!!!***
4+
- **Edgetunnel 图文教程**https://cmliussss.com/p/edt2 ***必看内容!必看内容!必看内容!!!***
55
- **报错 Error 1101 详解**https://www.youtube.com/watch?v=r4uVTEJptdE
66

77
- Telegram交流群:[@CMLiussss](https://t.me/CMLiussss)
@@ -32,7 +32,7 @@
3232
- 另外,您也可以选择自行部署 [WorkerVless2sub 订阅生成服务](https://github.com/cmliu/WorkerVless2sub),这样既可以利用订阅生成器的便利。
3333

3434
## 💡 如何使用?
35-
### ⚙️ Workers 部署方法 [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=191s)
35+
### ⚙️ Workers 部署方法
3636

3737
<details>
3838
<summary><code><strong>「 Workers 部署文字教程 」</strong></code></summary>
@@ -50,14 +50,13 @@
5050
3. 给 Workers绑定 自定义域:
5151
- 在 workers控制台的 `触发器`选项卡,下方点击 `添加自定义域`
5252
- 填入你已转入 CF 域名解析服务的次级域名,例如:`vless.google.com`后 点击`添加自定义域`,等待证书生效即可。
53-
- **如果你是小白,你现在可以直接起飞,不用再往下看了!!!**
5453

5554
4. 访问后台:
5655
- 访问 `https://vless.google.com/admin` 输入管理员密码即可登录后台。
5756

5857
</details>
5958

60-
### 🛠 Pages 上传 部署方法 **最佳推荐!!!** [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=436s)
59+
### 🛠 Pages 上传 部署方法 **最佳推荐!!!** [图文教程](https://cmliussss.com/p/edt2/)
6160

6261
<details>
6362
<summary><code><strong>「 Pages 上传文件部署文字教程 」</strong></code></summary>
@@ -78,14 +77,13 @@
7877
- 填入你的自定义次级域名,注意不要使用你的根域名,例如:
7978
您分配到的域名是 `fuck.cloudns.biz`,则添加自定义域填入 `lizi.fuck.cloudns.biz`即可;
8079
- 按照 CF 的要求将返回你的域名DNS服务商,添加 该自定义域 `lizi`的 CNAME记录 `edgetunnel.pages.dev` 后,点击 `激活域`即可。
81-
- **如果你是小白,那么你的 pages 绑定`自定义域`之后即可直接起飞,不用再往下看了!!!**
8280

8381
4. 访问后台:
8482
- 访问 `https://lizi.fuck.cloudns.biz/admin` 输入管理员密码即可登录后台。
8583

8684
</details>
8785

88-
### 🛠 Pages GitHub 部署方法 [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=317s)
86+
### 🛠 Pages GitHub 部署方法
8987

9088
<details>
9189
<summary><code><strong>「 Pages GitHub 部署文字教程 」</strong></code></summary>
@@ -105,7 +103,6 @@
105103
- 填入你的自定义次级域名,注意不要使用你的根域名,例如:
106104
您分配到的域名是 `fuck.cloudns.biz`,则添加自定义域填入 `lizi.fuck.cloudns.biz`即可;
107105
- 按照 CF 的要求将返回你的域名DNS服务商,添加 该自定义域 `lizi`的 CNAME记录 `edgetunnel.pages.dev` 后,点击 `激活域`即可。
108-
- **如果你是小白,那么你的 pages 绑定`自定义域`之后即可直接起飞,不用再往下看了!!!**
109106

110107
4. 访问后台:
111108
- 访问 `https://lizi.fuck.cloudns.biz/admin` 输入管理员密码即可登录后台。
@@ -126,7 +123,7 @@
126123
| GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` || 设置`SOCKS5``HTTP`变量之后,可设置强制使用socks5访问名单(设置为`*`可作为全局代理) |
127124

128125
## 🔧 实用技巧
129-
该项目部署的节点可通过节点PATH(路径)的方式,使用指定的`PROXYIP``SOCKS5`!!!**
126+
该项目部署的节点可通过节点PATH(路径)的方式,使用指定的`PROXYIP``SOCKS5`!!!
130127

131128
- 指定 `PROXYIP` 案例
132129
```url

_worker.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,20 @@ export default {
122122
} else if (访问路径 === 'admin/cf.json') { // 保存cf.json配置
123123
try {
124124
const newConfig = await request.json();
125-
const CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null };
125+
const CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null, UsageAPI: null };
126126
if (!newConfig.init || newConfig.init !== true) {
127127
if (newConfig.Email && newConfig.GlobalAPIKey) {
128128
CF_JSON.Email = newConfig.Email;
129129
CF_JSON.GlobalAPIKey = newConfig.GlobalAPIKey;
130130
CF_JSON.AccountID = null;
131131
CF_JSON.APIToken = null;
132+
CF_JSON.UsageAPI = null;
132133
} else if (newConfig.AccountID && newConfig.APIToken) {
133134
CF_JSON.Email = null;
134135
CF_JSON.GlobalAPIKey = null;
135136
CF_JSON.AccountID = newConfig.AccountID;
136137
CF_JSON.APIToken = newConfig.APIToken;
138+
CF_JSON.UsageAPI = null;
137139
} else {
138140
return new Response(JSON.stringify({ error: '配置不完整' }), { status: 400, headers: { 'Content-Type': 'application/json;charset=utf-8' } });
139141
}
@@ -205,7 +207,7 @@ export default {
205207
if (config_JSON.CF.Usage.success) {
206208
pagesSum = config_JSON.CF.Usage.pages;
207209
workersSum = config_JSON.CF.Usage.workers;
208-
total = 1024 * 100;
210+
total = Number.isFinite(config_JSON.CF.Usage.max) ? (config_JSON.CF.Usage.max / 1000) * 1024 : 1024 * 100;
209211
}
210212
const responseHeaders = {
211213
"content-type": "text/plain; charset=utf-8",
@@ -330,7 +332,6 @@ export default {
330332
}
331333
return new Response(订阅内容, { status: 200, headers: responseHeaders });
332334
}
333-
return new Response('无效的订阅TOKEN', { status: 403 });
334335
} else if (访问路径 === 'locations') {//反代locations列表
335336
const cookies = request.headers.get('Cookie') || '';
336337
const authCookie = cookies.split(';').find(c => c.trim().startsWith('auth='))?.split('=')[1];
@@ -1125,11 +1126,13 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal
11251126
GlobalAPIKey: null,
11261127
AccountID: null,
11271128
APIToken: null,
1129+
UsageAPI: null,
11281130
Usage: {
11291131
success: false,
11301132
pages: 0,
11311133
workers: 0,
11321134
total: 0,
1135+
max: 100000,
11331136
},
11341137
}
11351138
};
@@ -1171,20 +1174,31 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal
11711174
console.error(`读取tg.json出错: ${error.message}`);
11721175
}
11731176

1174-
const 初始化CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null };
1175-
config_JSON.CF = { ...初始化CF_JSON, Usage: { success: false, pages: 0, workers: 0, total: 0 } };
1177+
const 初始化CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null, UsageAPI: null };
1178+
config_JSON.CF = { ...初始化CF_JSON, Usage: { success: false, pages: 0, workers: 0, total: 0, max: 100000 } };
11761179
try {
11771180
const CF_TXT = await env.KV.get('cf.json');
11781181
if (!CF_TXT) {
11791182
await env.KV.put('cf.json', JSON.stringify(初始化CF_JSON, null, 2));
11801183
} else {
11811184
const CF_JSON = JSON.parse(CF_TXT);
1182-
config_JSON.CF.Email = CF_JSON.Email ? CF_JSON.Email : null;
1183-
config_JSON.CF.GlobalAPIKey = CF_JSON.GlobalAPIKey ? 掩码敏感信息(CF_JSON.GlobalAPIKey) : null;
1184-
config_JSON.CF.AccountID = CF_JSON.AccountID ? 掩码敏感信息(CF_JSON.AccountID) : null;
1185-
config_JSON.CF.APIToken = CF_JSON.APIToken ? 掩码敏感信息(CF_JSON.APIToken) : null;
1186-
const Usage = await getCloudflareUsage(CF_JSON.Email, CF_JSON.GlobalAPIKey, CF_JSON.AccountID, CF_JSON.APIToken);
1187-
config_JSON.CF.Usage = Usage;
1185+
if (CF_JSON.UsageAPI) {
1186+
try {
1187+
const response = await fetch(CF_JSON.UsageAPI);
1188+
const Usage = await response.json();
1189+
config_JSON.CF.Usage = Usage;
1190+
} catch (err) {
1191+
console.error(`请求 CF_JSON.UsageAPI 失败: ${err.message}`);
1192+
}
1193+
} else {
1194+
config_JSON.CF.Email = CF_JSON.Email ? CF_JSON.Email : null;
1195+
config_JSON.CF.GlobalAPIKey = CF_JSON.GlobalAPIKey ? 掩码敏感信息(CF_JSON.GlobalAPIKey) : null;
1196+
config_JSON.CF.AccountID = CF_JSON.AccountID ? 掩码敏感信息(CF_JSON.AccountID) : null;
1197+
config_JSON.CF.APIToken = CF_JSON.APIToken ? 掩码敏感信息(CF_JSON.APIToken) : null;
1198+
config_JSON.CF.UsageAPI = null;
1199+
const Usage = await getCloudflareUsage(CF_JSON.Email, CF_JSON.GlobalAPIKey, CF_JSON.AccountID, CF_JSON.APIToken);
1200+
config_JSON.CF.Usage = Usage;
1201+
}
11881202
}
11891203
} catch (error) {
11901204
console.error(`读取cf.json出错: ${error.message}`);
@@ -1466,7 +1480,7 @@ async function getCloudflareUsage(Email, GlobalAPIKey, AccountID, APIToken) {
14661480
const cfg = { "Content-Type": "application/json" };
14671481

14681482
try {
1469-
if (!AccountID && (!Email || !GlobalAPIKey)) return { success: false, pages: 0, workers: 0, total: 0 };
1483+
if (!AccountID && (!Email || !GlobalAPIKey)) return { success: false, pages: 0, workers: 0, total: 0, max: 100000 };
14701484

14711485
if (!AccountID) {
14721486
const r = await fetch(`${API}/accounts`, {
@@ -1508,12 +1522,13 @@ async function getCloudflareUsage(Email, GlobalAPIKey, AccountID, APIToken) {
15081522
const pages = sum(acc.pagesFunctionsInvocationsAdaptiveGroups);
15091523
const workers = sum(acc.workersInvocationsAdaptive);
15101524
const total = pages + workers;
1511-
console.log(`统计结果 - Pages: ${pages}, Workers: ${workers}, 总计: ${total}`);
1512-
return { success: true, pages, workers, total };
1525+
const max = 100000;
1526+
console.log(`统计结果 - Pages: ${pages}, Workers: ${workers}, 总计: ${total}, 上限: 100000`);
1527+
return { success: true, pages, workers, total, max };
15131528

15141529
} catch (error) {
15151530
console.error('获取使用量错误:', error.message);
1516-
return { success: false, pages: 0, workers: 0, total: 0 };
1531+
return { success: false, pages: 0, workers: 0, total: 0, max: 100000 };
15171532
}
15181533
}
15191534

img.png

79.4 KB
Loading

0 commit comments

Comments
 (0)