Skip to content

Commit

Permalink
fix(route): 2048 jump logic (#18221)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Jan 26, 2025
1 parent a8bf6e6 commit 07f728b
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions lib/routes/2048/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
import ofetch from '@/utils/ofetch';

export const route: Route = {
path: '/:id?',
Expand Down Expand Up @@ -65,25 +64,37 @@ export const route: Route = {
};

async function handler(ctx) {
const id = ctx.req.param('id') ?? '2';
const id = ctx.req.param('id') ?? '3';

const rootUrl = 'https://hjd2048.com';

const entranceDomain = await cache.tryGet('2048:entranceDomain', async () => {
const { data: response } = await got('https://hjd.tw', {
const domainInfo = (await cache.tryGet('2048:domainInfo', async () => {
const response = await ofetch('https://hjd.tw', {
headers: {
accept: '*/*',
},
});
const $ = load(response);
const targetLink = new URL($('table.group-table tr').eq(1).find('td a').eq(0).attr('href')).href;
return targetLink;
let $ = load(response);
const targetLink = new URL($('.address-list a').eq(0).attr('href'), 'https://hjd.tw').href;
const redirectResponse = await ofetch.raw(targetLink);
$ = load(redirectResponse._data);
return {
url: redirectResponse.url,
cookie:
$('script')
.text()
.match(/var safeid='(.*?)',/)?.[1] ?? '',
};
})) as { url: string; cookie: string };

const currentUrl = `${domainInfo.url}thread.php?fid-${id}.html`;

const response = await ofetch.raw(currentUrl, {
headers: {
cookie: `_safe=${domainInfo.cookie}`,
},
});

const currentUrl = `${entranceDomain}2048/thread.php?fid-${id}.html`;

const response = await ofetch.raw(currentUrl);

const $ = load(response._data);
const currentHost = `https://${new URL(response.url).host}`; // redirected host

Expand All @@ -99,7 +110,7 @@ async function handler(ctx) {

return {
title: item.text(),
link: `${currentHost}/2048/${item.attr('href')}`,
link: `${currentHost}/${item.attr('href')}`,
guid: `${rootUrl}/2048/${item.attr('href')}`,
};
})
Expand All @@ -108,12 +119,13 @@ async function handler(ctx) {
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.guid, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await ofetch(item.link, {
headers: {
cookie: `_safe=${domainInfo.cookie}`,
},
});

const content = load(detailResponse.data);
const content = load(detailResponse);

content('.ads, .tips').remove();

Expand All @@ -126,17 +138,14 @@ async function handler(ctx) {

const downloadLink = content('#read_tpc').first().find('a').last();
const copyLink = content('#copytext')?.first()?.text();
if (downloadLink?.text()?.startsWith('http') && /down2048\.com$/.test(new URL(downloadLink.text()).hostname)) {
const torrentResponse = await got({
method: 'get',
url: downloadLink.text(),
});
if (downloadLink?.text()?.startsWith('http') && /bt\.azvmw\.com$/.test(new URL(downloadLink.text()).hostname)) {
const torrentResponse = await ofetch(downloadLink.text());

const torrent = load(torrentResponse.data);
const torrent = load(torrentResponse);

item.enclosure_type = 'application/x-bittorrent';
const ahref = torrent('.uk-button').last().attr('href');
item.enclosure_url = ahref?.startsWith('http') ? ahref : `https://data.datapps.org/${ahref}`;
item.enclosure_url = ahref?.startsWith('http') ? ahref : `https://bt.azvmw.com/${ahref}`;

const magnet = torrent('.uk-button').first().attr('href');

Expand Down

0 comments on commit 07f728b

Please sign in to comment.