From a1d6e612a5d826ec16a41b475108e7cd7833c116 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Sun, 14 Jul 2024 22:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20pref:=20=E4=BC=98=E5=8C=96X?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 7 ++++++- utils/common.js | 17 +++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 6077f04..fae300c 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -770,7 +770,12 @@ export class tools extends plugin { e.reply(segment.image(url)); } else { // 非海外使用🪜下载 - downloadImg(url, this.getCurDownloadPath(e), "", !isOversea).then(path => { + const proxy = this.myProxy; + const port = this.proxyPort; + downloadImg(url, this.getCurDownloadPath(e), "", !isOversea, {}, { + proxyAddr: proxy, + proxyPort: port + }).then(path => { e.reply(segment.image(fs.readFileSync(path))); }); } diff --git a/utils/common.js b/utils/common.js index 2877167..0168a0c 100644 --- a/utils/common.js +++ b/utils/common.js @@ -185,14 +185,15 @@ export async function downloadAudio(mp3Url, path, title = "temp", redirect = "ma /** * 下载一张网络图片(自动以url的最后一个为名字) - * @param img - * @param dir - * @param fileName - * @param isProxy - * @param headersExt + * @param {string} img + * @param {string} dir + * @param {string} fileName + * @param {boolean} isProxy + * @param {Object} headersExt + * @param {Object} proxyInfo 参数:proxyAddr=地址,proxyPort=端口 * @returns {Promise} */ -export async function downloadImg(img, dir, fileName = "", isProxy = false, headersExt = {}) { +export async function downloadImg(img, dir, fileName = "", isProxy = false, headersExt = {}, proxyInfo = {}) { if (fileName === "") { fileName = img.split("/").pop(); } @@ -210,10 +211,10 @@ export async function downloadImg(img, dir, fileName = "", isProxy = false, head if (isProxy) { axiosConfig.httpAgent = tunnel.httpOverHttp({ - proxy: { host: this.proxyAddr, port: this.proxyPort }, + proxy: { host: proxyInfo.proxyAddr, port: proxyInfo.proxyPort }, }); axiosConfig.httpsAgent = tunnel.httpOverHttp({ - proxy: { host: this.proxyAddr, port: this.proxyPort }, + proxy: { host: proxyInfo.proxyAddr, port: proxyInfo.proxyPort }, }); } try {