From 6422474dcf3b08d3813dcce00247517bc12fa24f Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 20 Aug 2023 02:35:48 +0800 Subject: [PATCH] fix(route): 2048 (#13079) * fix(route): 2048 * fix: codeql * fix: empty link * fix: url condition --- lib/v2/2048/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/v2/2048/index.js b/lib/v2/2048/index.js index 3fca88656..0dc4bb9de 100644 --- a/lib/v2/2048/index.js +++ b/lib/v2/2048/index.js @@ -9,7 +9,16 @@ module.exports = async (ctx) => { const id = ctx.params.id ?? '2'; const rootUrl = 'https://hjd2048.com'; - const currentUrl = `${rootUrl}/2048/thread.php?fid-${id}.html`; + + const entranceDomain = await ctx.cache.tryGet('2048:entranceDomain', async () => { + const { data: response } = await got('https://hjd.tw'); + const $ = cheerio.load(response); + return $('ul li a') + .toArray() + .find((item) => $(item).text() === '最新線路1').attribs.href; + }); + + const currentUrl = `${entranceDomain}/2048/thread.php?fid-${id}.html`; const response = await got({ method: 'get', @@ -35,7 +44,6 @@ module.exports = async (ctx) => { guid: `${rootUrl}/2048/${item.attr('href')}`, }; }); - const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.guid, async () => { @@ -64,7 +72,7 @@ module.exports = async (ctx) => { const downloadLink = content('#read_tpc').first().find('a').last(); - if (downloadLink.text().indexOf('elsbbus.com') > -1) { + if (downloadLink?.text()?.startsWith('http') && new URL(downloadLink.text()).hostname.match(/datapps\.org$/)) { const torrentResponse = await got({ method: 'get', url: downloadLink.text(), @@ -73,7 +81,7 @@ module.exports = async (ctx) => { const torrent = cheerio.load(torrentResponse.data); item.enclosure_type = 'application/x-bittorrent'; - item.enclosure_url = `https://data.elsbbus.com/${torrent('.uk-button').last().attr('href')}`; + item.enclosure_url = `https://data.datapps.org/${torrent('.uk-button').last().attr('href')}`; const magnet = torrent('.uk-button').first().attr('href');