Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: auto format
  • Loading branch information
github-actions[bot] committed Apr 22, 2026
commit cf78d1e2e06e0db56b290a216f77709459f2f4f7
19 changes: 8 additions & 11 deletions lib/routes/baidu/tieba/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {config} from '@/config';
import { Cookie } from 'tough-cookie';

import { config } from '@/config';
import ConfigNotFoundError from '@/errors/types/config-not-found';
import cache from '@/utils/cache';
import {getPuppeteerPage} from '@/utils/puppeteer';
import {Cookie} from 'tough-cookie';
import { getPuppeteerPage } from '@/utils/puppeteer';

/**
* 解析百度 cookie 字符串为 Puppeteer 可用的 cookie 对象数组
Expand Down Expand Up @@ -50,11 +51,7 @@ export async function getTiebaPageContent(
}

const cookies = parseBaiduCookies(cookie);
const {
waitForSelector = '.thread-card-wrapper, .virtual-list-item, .thread-content-box, .thread-card',
timeout = 3000,
retries = 3
} = options;
const { waitForSelector = '.thread-card-wrapper, .virtual-list-item, .thread-content-box, .thread-card', timeout = 3000, retries = 3 } = options;

const data = await cache.tryGet(
cacheKey,
Expand All @@ -63,13 +60,13 @@ export async function getTiebaPageContent(

/* eslint-disable no-await-in-loop -- Intentional sequential retry logic */
for (let attempt = 0; attempt < retries; attempt++) {
const {page, destroy} = await getPuppeteerPage(url, {
const { page, destroy } = await getPuppeteerPage(url, {
onBeforeLoad: async (page) => {
if (cookies.length > 0) {
await page.setCookie(...cookies);
}
},
gotoConfig: {waitUntil: 'domcontentloaded'},
gotoConfig: { waitUntil: 'domcontentloaded' },
});

try {
Expand All @@ -78,7 +75,7 @@ export async function getTiebaPageContent(

// 动态等待内容加载
try {
await page.waitForSelector(waitForSelector, {timeout});
await page.waitForSelector(waitForSelector, { timeout });
} catch {
// 如果超时,继续执行
}
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/baidu/tieba/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {CheerioAPI} from 'cheerio';
import type { CheerioAPI } from 'cheerio';

import {parseRelativeDate} from '@/utils/parse-date';
import { parseRelativeDate } from '@/utils/parse-date';

/**
* 解析相对时间(如"回复于4小时前")为实际日期
Expand Down