diff --git a/README.md b/README.md index 839248e..e2ec1b7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 🚀 edgetunnel 2.0 ![后台页面](./img.png) -- **edgetunnel 最新教程**:https://www.youtube.com/watch?v=tKe9xUuFODA ***必看内容!必看内容!必看内容!!!*** +- **Edgetunnel 图文教程**:https://cmliussss.com/p/edt2 ***必看内容!必看内容!必看内容!!!*** - **报错 Error 1101 详解**:https://www.youtube.com/watch?v=r4uVTEJptdE - Telegram交流群:[@CMLiussss](https://t.me/CMLiussss) @@ -32,7 +32,7 @@ - 另外,您也可以选择自行部署 [WorkerVless2sub 订阅生成服务](https://github.com/cmliu/WorkerVless2sub),这样既可以利用订阅生成器的便利。 ## 💡 如何使用? -### ⚙️ Workers 部署方法 [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=191s) +### ⚙️ Workers 部署方法
「 Workers 部署文字教程 」 @@ -50,14 +50,13 @@ 3. 给 Workers绑定 自定义域: - 在 workers控制台的 `触发器`选项卡,下方点击 `添加自定义域`。 - 填入你已转入 CF 域名解析服务的次级域名,例如:`vless.google.com`后 点击`添加自定义域`,等待证书生效即可。 - - **如果你是小白,你现在可以直接起飞,不用再往下看了!!!** 4. 访问后台: - 访问 `https://vless.google.com/admin` 输入管理员密码即可登录后台。
-### 🛠 Pages 上传 部署方法 **最佳推荐!!!** [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=436s) +### 🛠 Pages 上传 部署方法 **最佳推荐!!!** [图文教程](https://cmliussss.com/p/edt2/)
「 Pages 上传文件部署文字教程 」 @@ -78,14 +77,13 @@ - 填入你的自定义次级域名,注意不要使用你的根域名,例如: 您分配到的域名是 `fuck.cloudns.biz`,则添加自定义域填入 `lizi.fuck.cloudns.biz`即可; - 按照 CF 的要求将返回你的域名DNS服务商,添加 该自定义域 `lizi`的 CNAME记录 `edgetunnel.pages.dev` 后,点击 `激活域`即可。 - - **如果你是小白,那么你的 pages 绑定`自定义域`之后即可直接起飞,不用再往下看了!!!** 4. 访问后台: - 访问 `https://lizi.fuck.cloudns.biz/admin` 输入管理员密码即可登录后台。
-### 🛠 Pages GitHub 部署方法 [视频教程](https://www.youtube.com/watch?v=tKe9xUuFODA&t=317s) +### 🛠 Pages GitHub 部署方法
「 Pages GitHub 部署文字教程 」 @@ -105,7 +103,6 @@ - 填入你的自定义次级域名,注意不要使用你的根域名,例如: 您分配到的域名是 `fuck.cloudns.biz`,则添加自定义域填入 `lizi.fuck.cloudns.biz`即可; - 按照 CF 的要求将返回你的域名DNS服务商,添加 该自定义域 `lizi`的 CNAME记录 `edgetunnel.pages.dev` 后,点击 `激活域`即可。 - - **如果你是小白,那么你的 pages 绑定`自定义域`之后即可直接起飞,不用再往下看了!!!** 4. 访问后台: - 访问 `https://lizi.fuck.cloudns.biz/admin` 输入管理员密码即可登录后台。 @@ -126,7 +123,7 @@ | GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` |❌| 设置`SOCKS5`或`HTTP`变量之后,可设置强制使用socks5访问名单(设置为`*`可作为全局代理) | ## 🔧 实用技巧 -该项目部署的节点可通过节点PATH(路径)的方式,使用指定的`PROXYIP`或`SOCKS5`!!!** +该项目部署的节点可通过节点PATH(路径)的方式,使用指定的`PROXYIP`或`SOCKS5`!!! - 指定 `PROXYIP` 案例 ```url diff --git a/_worker.js b/_worker.js index 34fda08..4556ec0 100644 --- a/_worker.js +++ b/_worker.js @@ -122,18 +122,20 @@ export default { } else if (访问路径 === 'admin/cf.json') { // 保存cf.json配置 try { const newConfig = await request.json(); - const CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null }; + const CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null, UsageAPI: null }; if (!newConfig.init || newConfig.init !== true) { if (newConfig.Email && newConfig.GlobalAPIKey) { CF_JSON.Email = newConfig.Email; CF_JSON.GlobalAPIKey = newConfig.GlobalAPIKey; CF_JSON.AccountID = null; CF_JSON.APIToken = null; + CF_JSON.UsageAPI = null; } else if (newConfig.AccountID && newConfig.APIToken) { CF_JSON.Email = null; CF_JSON.GlobalAPIKey = null; CF_JSON.AccountID = newConfig.AccountID; CF_JSON.APIToken = newConfig.APIToken; + CF_JSON.UsageAPI = null; } else { return new Response(JSON.stringify({ error: '配置不完整' }), { status: 400, headers: { 'Content-Type': 'application/json;charset=utf-8' } }); } @@ -205,7 +207,7 @@ export default { if (config_JSON.CF.Usage.success) { pagesSum = config_JSON.CF.Usage.pages; workersSum = config_JSON.CF.Usage.workers; - total = 1024 * 100; + total = Number.isFinite(config_JSON.CF.Usage.max) ? (config_JSON.CF.Usage.max / 1000) * 1024 : 1024 * 100; } const responseHeaders = { "content-type": "text/plain; charset=utf-8", @@ -330,7 +332,6 @@ export default { } return new Response(订阅内容, { status: 200, headers: responseHeaders }); } - return new Response('无效的订阅TOKEN', { status: 403 }); } else if (访问路径 === 'locations') {//反代locations列表 const cookies = request.headers.get('Cookie') || ''; 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 GlobalAPIKey: null, AccountID: null, APIToken: null, + UsageAPI: null, Usage: { success: false, pages: 0, workers: 0, total: 0, + max: 100000, }, } }; @@ -1171,20 +1174,31 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal console.error(`读取tg.json出错: ${error.message}`); } - const 初始化CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null }; - config_JSON.CF = { ...初始化CF_JSON, Usage: { success: false, pages: 0, workers: 0, total: 0 } }; + const 初始化CF_JSON = { Email: null, GlobalAPIKey: null, AccountID: null, APIToken: null, UsageAPI: null }; + config_JSON.CF = { ...初始化CF_JSON, Usage: { success: false, pages: 0, workers: 0, total: 0, max: 100000 } }; try { const CF_TXT = await env.KV.get('cf.json'); if (!CF_TXT) { await env.KV.put('cf.json', JSON.stringify(初始化CF_JSON, null, 2)); } else { const CF_JSON = JSON.parse(CF_TXT); - config_JSON.CF.Email = CF_JSON.Email ? CF_JSON.Email : null; - config_JSON.CF.GlobalAPIKey = CF_JSON.GlobalAPIKey ? 掩码敏感信息(CF_JSON.GlobalAPIKey) : null; - config_JSON.CF.AccountID = CF_JSON.AccountID ? 掩码敏感信息(CF_JSON.AccountID) : null; - config_JSON.CF.APIToken = CF_JSON.APIToken ? 掩码敏感信息(CF_JSON.APIToken) : null; - const Usage = await getCloudflareUsage(CF_JSON.Email, CF_JSON.GlobalAPIKey, CF_JSON.AccountID, CF_JSON.APIToken); - config_JSON.CF.Usage = Usage; + if (CF_JSON.UsageAPI) { + try { + const response = await fetch(CF_JSON.UsageAPI); + const Usage = await response.json(); + config_JSON.CF.Usage = Usage; + } catch (err) { + console.error(`请求 CF_JSON.UsageAPI 失败: ${err.message}`); + } + } else { + config_JSON.CF.Email = CF_JSON.Email ? CF_JSON.Email : null; + config_JSON.CF.GlobalAPIKey = CF_JSON.GlobalAPIKey ? 掩码敏感信息(CF_JSON.GlobalAPIKey) : null; + config_JSON.CF.AccountID = CF_JSON.AccountID ? 掩码敏感信息(CF_JSON.AccountID) : null; + config_JSON.CF.APIToken = CF_JSON.APIToken ? 掩码敏感信息(CF_JSON.APIToken) : null; + config_JSON.CF.UsageAPI = null; + const Usage = await getCloudflareUsage(CF_JSON.Email, CF_JSON.GlobalAPIKey, CF_JSON.AccountID, CF_JSON.APIToken); + config_JSON.CF.Usage = Usage; + } } } catch (error) { console.error(`读取cf.json出错: ${error.message}`); @@ -1466,7 +1480,7 @@ async function getCloudflareUsage(Email, GlobalAPIKey, AccountID, APIToken) { const cfg = { "Content-Type": "application/json" }; try { - if (!AccountID && (!Email || !GlobalAPIKey)) return { success: false, pages: 0, workers: 0, total: 0 }; + if (!AccountID && (!Email || !GlobalAPIKey)) return { success: false, pages: 0, workers: 0, total: 0, max: 100000 }; if (!AccountID) { const r = await fetch(`${API}/accounts`, { @@ -1508,12 +1522,13 @@ async function getCloudflareUsage(Email, GlobalAPIKey, AccountID, APIToken) { const pages = sum(acc.pagesFunctionsInvocationsAdaptiveGroups); const workers = sum(acc.workersInvocationsAdaptive); const total = pages + workers; - console.log(`统计结果 - Pages: ${pages}, Workers: ${workers}, 总计: ${total}`); - return { success: true, pages, workers, total }; + const max = 100000; + console.log(`统计结果 - Pages: ${pages}, Workers: ${workers}, 总计: ${total}, 上限: 100000`); + return { success: true, pages, workers, total, max }; } catch (error) { console.error('获取使用量错误:', error.message); - return { success: false, pages: 0, workers: 0, total: 0 }; + return { success: false, pages: 0, workers: 0, total: 0, max: 100000 }; } } diff --git a/img.png b/img.png index 15ad512..c4ece45 100644 Binary files a/img.png and b/img.png differ