🐞 fix: 修复 x 国内无法发出问题

1. 修复 `x` 国内无法发出问题
2. 清理tunnel
This commit is contained in:
zhiyu1998 2024-08-10 22:19:13 +08:00
parent 6eb3689d99
commit f2d11794c5
3 changed files with 10 additions and 25 deletions

View File

@ -888,6 +888,8 @@ export class tools extends plugin {
const twitterUrl = reg.exec(e.msg)[0]; const twitterUrl = reg.exec(e.msg)[0];
// 检测 // 检测
const isOversea = await this.isOverseasServer(); const isOversea = await this.isOverseasServer();
logger.info(!isOversea);
logger.info(!(await testProxy(this.proxyAddr, this.proxyPort)));
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) { if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
e.reply("检测到没有梯子,无法解析小蓝鸟"); e.reply("检测到没有梯子,无法解析小蓝鸟");
return false; return false;
@ -915,18 +917,17 @@ export class tools extends plugin {
axios.get(videoUrl, config).then(resp => { axios.get(videoUrl, config).then(resp => {
const url = resp.data.data?.url; const url = resp.data.data?.url;
if (url && (url.endsWith(".jpg") || url.endsWith(".png"))) { if (url && (url.endsWith(".jpg") || url.endsWith(".png"))) {
logger.info(url);
if (isOversea) { if (isOversea) {
// 海外直接下载 // 海外直接下载
e.reply(segment.image(url)); e.reply(segment.image(url));
} else { } else {
// 非海外使用🪜下载 // 非海外使用🪜下载
const proxy = this.proxyAddr;
const port = this.proxyPort;
const localPath = this.getCurDownloadPath(e); const localPath = this.getCurDownloadPath(e);
downloadImg(url, localPath, "", isOversea, {}, { downloadImg(url, localPath, "", !isOversea, {}, {
proxyAddr: proxy, proxyAddr: this.proxyAddr,
proxyPort: port proxyPort: this.proxyPort
}).then(_ => { }).then(async _ => {
e.reply(segment.image(fs.readFileSync(localPath + "/" + url.split("/").pop()))); e.reply(segment.image(fs.readFileSync(localPath + "/" + url.split("/").pop())));
}); });
} }
@ -1868,12 +1869,7 @@ export class tools extends plugin {
// 构造代理参数 // 构造代理参数
const proxyOption = { const proxyOption = {
...(isProxy && { ...(isProxy && {
httpAgent: tunnel.httpOverHttp({ httpAgent: new HttpsProxyAgent(`http://${ this.proxyAddr }:${ this.proxyPort }`),
proxy: { host: this.proxyAddr, port: this.proxyPort },
}),
httpsAgent: tunnel.httpsOverHttp({
proxy: { host: this.proxyAddr, port: this.proxyPort },
}),
}), }),
} }

View File

@ -4,7 +4,6 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"axios": "^1.3.4", "axios": "^1.3.4",
"tunnel": "^0.0.6",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
"p-queue": "^8.0.1", "p-queue": "^8.0.1",
"ws": "^8.17.0", "ws": "^8.17.0",

View File

@ -326,23 +326,13 @@ export function truncateString(inputString, maxLength = 50) {
* @returns {Promise<Boolean>} * @returns {Promise<Boolean>}
*/ */
export async function testProxy(host='127.0.0.1', port=7890) { export async function testProxy(host='127.0.0.1', port=7890) {
// 配置代理服务器
const proxyOptions = {
host: host,
port: port,
// 如果你的代理服务器需要认证
// auth: 'username:password', // 取消注释并提供实际的用户名和密码
};
// 创建一个代理隧道 // 创建一个代理隧道
const httpsAgent = tunnel.httpsOverHttp({ const httpsAgent = new HttpsProxyAgent(`http://${host}:${port}`);
proxy: proxyOptions
});
try { try {
// 通过代理服务器发起请求 // 通过代理服务器发起请求
await axios.get('https://www.google.com', { httpsAgent }); await axios.get('https://www.google.com', { httpsAgent });
logger.mark('[R插件][梯子测试模块] 检测到梯子'); logger.mark(logger.yellow('[R插件][梯子测试模块] 检测到梯子'));
return true; return true;
} catch (error) { } catch (error) {
logger.error('[R插件][梯子测试模块] 检测不到梯子'); logger.error('[R插件][梯子测试模块] 检测不到梯子');