🎈 pref: 优化X解析逻辑

This commit is contained in:
zhiyu1998 2024-07-14 22:31:50 +08:00
parent f6541d512b
commit a1d6e612a5
2 changed files with 15 additions and 9 deletions

View File

@ -770,7 +770,12 @@ export class tools extends plugin {
e.reply(segment.image(url)); e.reply(segment.image(url));
} else { } 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))); e.reply(segment.image(fs.readFileSync(path)));
}); });
} }

View File

@ -185,14 +185,15 @@ export async function downloadAudio(mp3Url, path, title = "temp", redirect = "ma
/** /**
* 下载一张网络图片(自动以url的最后一个为名字) * 下载一张网络图片(自动以url的最后一个为名字)
* @param img * @param {string} img
* @param dir * @param {string} dir
* @param fileName * @param {string} fileName
* @param isProxy * @param {boolean} isProxy
* @param headersExt * @param {Object} headersExt
* @param {Object} proxyInfo 参数proxyAddr=地址proxyPort=端口
* @returns {Promise<unknown>} * @returns {Promise<unknown>}
*/ */
export async function downloadImg(img, dir, fileName = "", isProxy = false, headersExt = {}) { export async function downloadImg(img, dir, fileName = "", isProxy = false, headersExt = {}, proxyInfo = {}) {
if (fileName === "") { if (fileName === "") {
fileName = img.split("/").pop(); fileName = img.split("/").pop();
} }
@ -210,10 +211,10 @@ export async function downloadImg(img, dir, fileName = "", isProxy = false, head
if (isProxy) { if (isProxy) {
axiosConfig.httpAgent = tunnel.httpOverHttp({ axiosConfig.httpAgent = tunnel.httpOverHttp({
proxy: { host: this.proxyAddr, port: this.proxyPort }, proxy: { host: proxyInfo.proxyAddr, port: proxyInfo.proxyPort },
}); });
axiosConfig.httpsAgent = tunnel.httpOverHttp({ axiosConfig.httpsAgent = tunnel.httpOverHttp({
proxy: { host: this.proxyAddr, port: this.proxyPort }, proxy: { host: proxyInfo.proxyAddr, port: proxyInfo.proxyPort },
}); });
} }
try { try {