diff --git a/src/services/EventSubscribeService.ts b/src/services/EventSubscribeService.ts index df083aa..fa04f65 100644 --- a/src/services/EventSubscribeService.ts +++ b/src/services/EventSubscribeService.ts @@ -57,7 +57,7 @@ export class EventSubscribeService { } }); const [requests] = await Promise.all([ - beforeEvents.map(e => KaiqiuService.getMatchDetail(e.eventId)), + beforeEvents.map(e => KaiqiuService.getMatchDetail(e.eventId, true)), ]); const details = await Promise.all(requests); return details; diff --git a/src/services/KaiqiuService.ts b/src/services/KaiqiuService.ts index 0a16da8..76057c5 100644 --- a/src/services/KaiqiuService.ts +++ b/src/services/KaiqiuService.ts @@ -42,10 +42,15 @@ export class KaiqiuService { return { clubs, total }; } - public static async getClubInfo(clubId: string) { + public static async getClubInfo(clubId: string, force?: boolean) { if (!clubId) return null; const url = `${this.#baseURL}/home/space-mtag-tagid-${clubId}.html`; - const html = await fetch(url, { headers: htmlRequestHeaders }).then(res => res.text()); + const key = `my-kaiqiuwang:club:${clubId}`; + let html = await redis.get(key) ?? ''; + if (!html || html.includes('连接超时') || force) { + html = await fetch(url, { headers: htmlRequestHeaders }).then(res => res.text()); + await redis.setex(key, 60 * 60 * 24, html); + } const $ = cheerio.load(html); const name = $('h2.title a:nth-of-type(2)').text().trim(); const src = $('#space_avatar img').attr('src') ?? ''; @@ -135,7 +140,7 @@ export class KaiqiuService { let eventPage = await redis.get(key) ?? ''; if (!eventPage || eventPage.includes('连接超时') || force) { eventPage = await fetch(eventURL, { headers: htmlRequestHeaders }).then(res => res.text() ?? ''); - await redis.setex(key, 60 * 1, eventPage); + await redis.setex(key, 60 * 3, eventPage); } const $ = cheerio.load(eventPage); const eventContent = $('.event_content').text().replace(/(\r|\n)/g, ',').split(',').filter(Boolean).join(' '); @@ -165,9 +170,14 @@ export class KaiqiuService { } } - public static async getMatchDetail(eventId: string) { + public static async getMatchDetail(eventId: string, force?: boolean) { const url = `${this.#baseURL}/home/space.php?do=event&id=${eventId}&view=member&status=2`; - const html = await fetch(url, { headers: htmlRequestHeaders }).then(res => res.text() || ''); + const key = `my-kaiqiuwang:match-detail:${eventId}`; + let html = await redis.get(key) ?? ''; + if (!html || html.includes('连接超时') || force) { + html = await fetch(url, { headers: htmlRequestHeaders }).then(res => res.text() || ''); + await redis.setex(key, 60 * 5, html); + } return parseEventInfo(html, eventId); }