(message: Api.Message, r18 = 0, tag = "", num = 1)
| 425 | if (!client) { |
| 426 | return [null, "❌ 客户端未初始化"]; |
| 427 | } |
| 428 | |
| 429 | const des = "出错了,没有纸片人看了。"; |
| 430 | |
| 431 | // 获取所有可用的代理主机 |
| 432 | const allProxies = Object.values(PROXY_HOSTS); |
| 433 | const currentProxy = await ZprConfigManager.getProxyHost(); |
| 434 | |
| 435 | try { |
| 436 | await editHtmlMessage(message, `🔄 正在连接API...`); |
| 437 | |
| 438 | // 直接调用API,使用当前配置的代理参数 |
| 439 | const controller = new AbortController(); |
| 440 | const clearApiTimeout = scheduleAbort(controller, 10000, "zpr:api-timeout"); |
| 441 | |
| 442 | let response; |
| 443 | try { |
| 444 | response = await axios.get( |
| 445 | `https://api.lolicon.app/setu/v2?num=${num}&r18=${r18}&tag=${tag}&size=regular&size=original&proxy=${currentProxy}&excludeAI=true`, |
| 446 | { |
| 447 | headers: baseHeaders, |
| 448 | timeout: 10000, |
| 449 | signal: controller.signal |
| 450 | } |
| 451 | ); |
| 452 | } finally { |
| 453 | clearApiTimeout(); |
| 454 | } |
| 455 | |
| 456 | if (response.status !== 200) { |
| 457 | return [null, `API请求失败: HTTP ${response.status}`]; |
| 458 | } |
| 459 | |
| 460 | await editHtmlMessage(message, "🔍 已进入二次元 . . ."); |
| 461 | |
| 462 | const result: SetuData[] = (response.data as ApiResponse).data; |
| 463 | if (!result.length) { |
| 464 | return [null, "未找到符合条件的图片"]; |
| 465 | } |
| 466 | |
| 467 | await editHtmlMessage(message, "📥 努力获取中 。。。"); |
| 468 | |
| 469 | // 并发下载所有图片,每张图片都有自己的代理重试机制 |
| 470 | const downloadPromises = result.slice(0, num).map((item, index) => |
| 471 | downloadSingleImage(item, index, r18, currentProxy, allProxies) |
| 472 | ); |
| 473 | |
| 474 | const downloadResults = await Promise.all(downloadPromises); |
| 475 | |
| 476 | // 统计下载结果 |
| 477 | const successfulDownloads = downloadResults |
| 478 | .filter(result => result.mediaGroup !== null) |
| 479 | .map(result => result.mediaGroup!); |
| 480 | |
| 481 | const failedCount = downloadResults.length - successfulDownloads.length; |
| 482 | const networkFailures = downloadResults.filter(result => result.failureReason === 'network').length; |
| 483 | const error404Count = downloadResults.filter(result => result.failureReason === '404').length; |
| 484 |
no test coverage detected