fix(route): line today publisher (#15126)
This commit is contained in:
parent
4eec3f6b2b
commit
d9712b7fcb
|
|
@ -1,6 +1,5 @@
|
|||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { baseUrl, parseList, parseItems } from './utils';
|
||||
|
||||
export const route: Route = {
|
||||
|
|
@ -8,14 +7,6 @@ export const route: Route = {
|
|||
categories: ['new-media'],
|
||||
example: '/line/today/th/publisher/101048',
|
||||
parameters: { edition: 'Edition, see table above', id: 'Channel ID, can be found in URL' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['today.line.me/:edition/v2/publisher/:id'],
|
||||
|
|
@ -29,44 +20,43 @@ export const route: Route = {
|
|||
async function handler(ctx) {
|
||||
const { edition, id } = ctx.req.param();
|
||||
|
||||
const { data: publisherInfo } = await got(`${baseUrl}/webapi/portal/page/setting`, {
|
||||
searchParams: {
|
||||
const publisherInfo = await ofetch(`${baseUrl}/webapi/portal/page/setting`, {
|
||||
query: {
|
||||
entityId: id,
|
||||
country: edition,
|
||||
pageType: 'CP',
|
||||
},
|
||||
});
|
||||
|
||||
let cpLatest;
|
||||
let thaiData;
|
||||
if (edition === 'th') {
|
||||
const { data } = await got(`${baseUrl}/webapi/portal/embedded/page/cplatest`, {
|
||||
searchParams: {
|
||||
thaiData = await ofetch(`${baseUrl}/webapi/portal/embedded/page/cplatest`, {
|
||||
query: {
|
||||
entityId: id,
|
||||
pageType: 'CP',
|
||||
country: edition,
|
||||
},
|
||||
});
|
||||
cpLatest = data;
|
||||
}
|
||||
|
||||
const modules = edition === 'th' ? cpLatest.modules : publisherInfo.modules;
|
||||
const modules = edition === 'th' ? thaiData.modules : publisherInfo.modules;
|
||||
const mod = modules.find((item) => item.source === 'CP_LATEST');
|
||||
const listing = mod.listings[0];
|
||||
|
||||
const { data: listResponse } = await got(`${baseUrl}/webapi/trending/cp/latest/listings/${mod.id}`, {
|
||||
searchParams: {
|
||||
const listResponse = await ofetch(`${baseUrl}/webapi/trending/cp/latest/listings/${mod.id}`, {
|
||||
query: {
|
||||
offset: listing.offset,
|
||||
length: listing.length,
|
||||
country: edition,
|
||||
targetContent: listing.params.targetContent,
|
||||
cps: listing.params.cps,
|
||||
publishedWithin: listing.params.publishedWithin,
|
||||
targetContent: listing.params?.targetContent,
|
||||
cps: listing.params?.cps,
|
||||
publishedWithin: listing.params?.publishedWithin,
|
||||
},
|
||||
});
|
||||
|
||||
const list = parseList(listResponse.items);
|
||||
|
||||
const items = await parseItems(list, cache.tryGet);
|
||||
const items = await parseItems(list);
|
||||
|
||||
return {
|
||||
title: `${publisherInfo.data.name} - Line Today`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { baseUrl as rootUrl, parseList, parseItems } from './utils';
|
||||
|
||||
|
|
@ -8,14 +7,6 @@ export const route: Route = {
|
|||
categories: ['new-media'],
|
||||
example: '/line/today',
|
||||
parameters: { edition: 'Edition, see below, Taiwan by default', tab: 'Tag, can be found in URL, `top` by default' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['today.line.me/'],
|
||||
|
|
@ -65,7 +56,7 @@ async function handler(ctx) {
|
|||
|
||||
const list = parseList(response.data.items);
|
||||
|
||||
const items = await parseItems(list, cache.tryGet);
|
||||
const items = await parseItems(list);
|
||||
|
||||
return {
|
||||
title: `${title} - Line Today`,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import got from '@/utils/got';
|
|||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import logger from '@/utils/logger';
|
||||
import cache from '@/utils/cache';
|
||||
const baseUrl = 'https://today.line.me';
|
||||
|
||||
const parseList = (items) =>
|
||||
|
|
@ -13,10 +14,10 @@ const parseList = (items) =>
|
|||
category: item.categoryName,
|
||||
}));
|
||||
|
||||
const parseItems = (list, tryGet) =>
|
||||
const parseItems = (list) =>
|
||||
Promise.all(
|
||||
list.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
const edition = item.link.match(/today\.line\.me\/(\w+?)\/v2\/.*$/)[1];
|
||||
let data;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue