diff --git a/src/index.tsx b/src/index.tsx index cc33c5c..3ba765e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -123,8 +123,10 @@ const server = Bun.serve({ }, "/api/club/:clubid/events": { async GET(req) { - const page = Number(new URL(req.url).searchParams.get('page')) ?? 1; - const data = await KaiqiuService.listClubEvents(req.params.clubid, page); + const searchParams = new URL(req.url).searchParams; + const page = Number(searchParams.get('page')) ?? 1; + const force = Boolean(searchParams.get('force')) ?? false; + const data = await KaiqiuService.listClubEvents(req.params.clubid, page, force); return Response.json(data); } }, @@ -134,11 +136,11 @@ const server = Bun.serve({ const clubInfo = await KaiqiuService.getClubInfo(id); let allEvents: IEventInfo[] = []; let page = 1; - let events = await KaiqiuService.listClubEvents(id, page); + let events = await KaiqiuService.listClubEvents(id, page, true); allEvents = allEvents.concat(...events.data); while (events.data.every(e => !e.isFinished)) { page += 1; - events = await KaiqiuService.listClubEvents(id, page); + events = await KaiqiuService.listClubEvents(id, page, true); allEvents = allEvents.concat(...events.data); } const configs: ics.EventAttributes[] = allEvents.filter(e => !e.isFinished).map(e => ({ diff --git a/src/schedules/EventWatchSchedule.ts b/src/schedules/EventWatchSchedule.ts index 1eeafef..4d337a8 100644 --- a/src/schedules/EventWatchSchedule.ts +++ b/src/schedules/EventWatchSchedule.ts @@ -26,6 +26,10 @@ export class EventWatchSchedule implements Schedule { } async diffEvent(event: EventDetail) { + if (event.players.length === 0) { + console.debug('名单为空,可能请求过于频繁,跳过处理...', event.title, event.eventId); + return; + } const key = `my-kaiqiuwang:watch:${event.eventId}`; const oldPlayers = await redis.get(key).then(s => s ? JSON.parse(s) as Player[] : []); await redis.set(key, JSON.stringify(event.players)); diff --git a/src/services/KaiqiuService.ts b/src/services/KaiqiuService.ts index 89b160a..b75c412 100644 --- a/src/services/KaiqiuService.ts +++ b/src/services/KaiqiuService.ts @@ -61,14 +61,18 @@ export class KaiqiuService { return resp.text(); } - public static async listClubEvents(clubId: string, page = 1) { + public static async listClubEvents(clubId: string, page = 1, force?: boolean) { if (!clubId) return { data: [], total: 0, }; - const html = await this.#fetchEventListHTML(clubId, page); + let html = await redis.get(`my-kaiqiuwang:events:${clubId}:${page}`); + if (!html || html.includes('连接超时') || force) { + html = await this.#fetchEventListHTML(clubId, page); + await redis.setex(`my-kaiqiuwang:events:${clubId}:${page}`, 60 * 3, html); + } const data = await this.#parseEventList(html); - return data; + return data; } static async #parseEventList(html: string) {