fix(route): 2048 (#13079)

* fix(route): 2048

* fix: codeql

* fix: empty link

* fix: url condition
This commit is contained in:
Tony
2023-08-20 02:35:48 +08:00
committed by GitHub
parent 24cc5fdd5b
commit 6422474dcf
+12 -4
View File
@@ -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');