Fix: Choose different request methods based on the platform.

This commit is contained in:
gdjdkid committed 2026-03-21 16:57:01 +08:00
1 parent b71e1271c3
commit 9e9bd2ec83
2 files changed
+39 -25

No files matched your search

+38 -24
View File
@@ -156,33 +156,47 @@ async function searchJavdb(id) {
const session = decodeURIComponent(config.session);
const cookie = `locale=zh; over18=1; _jdb_session=${session}`;
const isWindows = process.platform === 'win32';
// 用 Node.js 原生 https 发请求,不依赖 curl,跨平台兼容
// Linux 用 curl(OpenSSL TLS,Cloudflare 接受)
// Windows 用 Node.js https(绕过 Schannel 问题)
async function fetchJavdbHtml(url) {
const { default: https } = await import('https');
const { default: http } = await import('http');
return new Promise((resolve, reject) => {
const client = url.startsWith('https') ? https : http;
const req = client.get(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': cookie,
},
}, (res) => {
// 处理重定向
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
resolve(fetchJavdbHtml(res.headers.location));
return;
}
const chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
if (!isWindows) {
// Linux/Mac:用 curl
return execSync(
`curl -sL "${url}" \
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" \
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \
-H "Accept-Language: zh-CN,zh;q=0.9" \
-H "Cookie: ${cookie}"`,
{ timeout: 15000, maxBuffer: 1024 * 1024 * 10 }
).toString();
} else {
// Windows:用 Node.js https
const { default: https } = await import('https');
const { default: http } = await import('http');
return new Promise((resolve, reject) => {
const client = url.startsWith('https') ? https : http;
const req = client.get(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': cookie,
},
}, (res) => {
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
resolve(fetchJavdbHtml(res.headers.location));
return;
}
const chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
});
req.on('error', reject);
req.setTimeout(15000, () => { req.destroy(); reject(new Error('timeout')); });
});
req.on('error', reject);
req.setTimeout(15000, () => { req.destroy(); reject(new Error('timeout')); });
});
}
}
const searchUrl = `https://javdb.com/search?q=${encodeURIComponent(id)}&f=all`;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javinfo",
"version": "1.1.10",
"version": "1.1.11",
"description": "AV番号命令行查询工具",
"main": "./index.js",
"type": "module",