From f2d11794c50beccb486d912692f9bd5ace93f15a Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Sat, 10 Aug 2024 22:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=20`x`?= =?UTF-8?q?=20=E5=9B=BD=E5=86=85=E6=97=A0=E6=B3=95=E5=8F=91=E5=87=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复 `x` 国内无法发出问题 2. 清理tunnel --- apps/tools.js | 20 ++++++++------------ package.json | 1 - utils/common.js | 14 ++------------ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 465b7a8..3126114 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -888,6 +888,8 @@ export class tools extends plugin { const twitterUrl = reg.exec(e.msg)[0]; // 检测 const isOversea = await this.isOverseasServer(); + logger.info(!isOversea); + logger.info(!(await testProxy(this.proxyAddr, this.proxyPort))); if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) { e.reply("检测到没有梯子,无法解析小蓝鸟"); return false; @@ -915,18 +917,17 @@ export class tools extends plugin { axios.get(videoUrl, config).then(resp => { const url = resp.data.data?.url; if (url && (url.endsWith(".jpg") || url.endsWith(".png"))) { + logger.info(url); if (isOversea) { // 海外直接下载 e.reply(segment.image(url)); } else { // 非海外使用🪜下载 - const proxy = this.proxyAddr; - const port = this.proxyPort; const localPath = this.getCurDownloadPath(e); - downloadImg(url, localPath, "", isOversea, {}, { - proxyAddr: proxy, - proxyPort: port - }).then(_ => { + downloadImg(url, localPath, "", !isOversea, {}, { + proxyAddr: this.proxyAddr, + proxyPort: this.proxyPort + }).then(async _ => { e.reply(segment.image(fs.readFileSync(localPath + "/" + url.split("/").pop()))); }); } @@ -1868,12 +1869,7 @@ export class tools extends plugin { // 构造代理参数 const proxyOption = { ...(isProxy && { - httpAgent: tunnel.httpOverHttp({ - proxy: { host: this.proxyAddr, port: this.proxyPort }, - }), - httpsAgent: tunnel.httpsOverHttp({ - proxy: { host: this.proxyAddr, port: this.proxyPort }, - }), + httpAgent: new HttpsProxyAgent(`http://${ this.proxyAddr }:${ this.proxyPort }`), }), } diff --git a/package.json b/package.json index 92420a7..fa04722 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "type": "module", "dependencies": { "axios": "^1.3.4", - "tunnel": "^0.0.6", "qrcode": "^1.5.3", "p-queue": "^8.0.1", "ws": "^8.17.0", diff --git a/utils/common.js b/utils/common.js index 6abf56d..8a8860e 100644 --- a/utils/common.js +++ b/utils/common.js @@ -326,23 +326,13 @@ export function truncateString(inputString, maxLength = 50) { * @returns {Promise} */ export async function testProxy(host='127.0.0.1', port=7890) { - // 配置代理服务器 - const proxyOptions = { - host: host, - port: port, - // 如果你的代理服务器需要认证 - // auth: 'username:password', // 取消注释并提供实际的用户名和密码 - }; - // 创建一个代理隧道 - const httpsAgent = tunnel.httpsOverHttp({ - proxy: proxyOptions - }); + const httpsAgent = new HttpsProxyAgent(`http://${host}:${port}`); try { // 通过代理服务器发起请求 await axios.get('https://www.google.com', { httpsAgent }); - logger.mark('[R插件][梯子测试模块] 检测到梯子'); + logger.mark(logger.yellow('[R插件][梯子测试模块] 检测到梯子')); return true; } catch (error) { logger.error('[R插件][梯子测试模块] 检测不到梯子');