()
| 163 | } |
| 164 | |
| 165 | private async getRandomPhotoSet(): Promise<PhotoSet> { |
| 166 | return withRetry(async () => { |
| 167 | const randomPage = Math.floor(Math.random() * CONFIG.MAX_PAGES) + 1; |
| 168 | const pageUrl = |
| 169 | randomPage === 1 ? CONFIG.BASE_URL : `${CONFIG.BASE_URL}page/${randomPage}/`; |
| 170 | |
| 171 | const html = await this.client.get(pageUrl).then((r) => r.data); |
| 172 | const links = this.extractLinks(html); |
| 173 | |
| 174 | if (!links.length) { |
| 175 | throw new Error(`第${randomPage}页没有找到套图链接`); |
| 176 | } |
| 177 | |
| 178 | const randomLink = links[Math.floor(Math.random() * links.length)]; |
| 179 | const title = randomLink.split("/").filter(Boolean).pop() || "未知套图"; |
| 180 | |
| 181 | return { url: randomLink, title: title.replace(/-/g, " ") }; |
| 182 | }); |
| 183 | } |
| 184 | |
| 185 | private extractLinks(html: string): string[] { |
| 186 | const $ = cheerio.load(html); |
no test coverage detected