From 4106594d167ab498249a599d357a7967aa0305c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?da=CC=8Ashua=CC=8Ang=20li?= Date: Wed, 4 Dec 2024 18:17:26 +0800 Subject: [PATCH 1/3] feat(route): add amz123.com --- lib/routes/amz123/kx.ts | 65 ++++++++++++++++++++++++++++++++++ lib/routes/amz123/namespace.ts | 9 +++++ 2 files changed, 74 insertions(+) create mode 100644 lib/routes/amz123/kx.ts create mode 100644 lib/routes/amz123/namespace.ts diff --git a/lib/routes/amz123/kx.ts b/lib/routes/amz123/kx.ts new file mode 100644 index 00000000000000..329b764b3fd7ed --- /dev/null +++ b/lib/routes/amz123/kx.ts @@ -0,0 +1,65 @@ +import { Route, ViewType } from '@/types'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/kx', + categories: ['new-media'], + example: '/amz123/kx', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['amz123.com/kx'], + target: '/kx', + }, + ], + name: 'AMZ123 快讯', + maintainers: ['defp'], + handler, + url: 'amz123.com/kx', + view: ViewType.Articles, +}; + +async function handler() { + const limit = 12; + const apiRootUrl = 'https://api.amz123.com'; + const rootUrl = 'https://www.amz123.com'; + + const { data: response } = await got.post(`${apiRootUrl}/ugc/v1/user_content/forum_list`, { + json: { + page: 1, + page_size: limit, + tag_id: 0, + fid: 4, + ban: 0, + is_new: 1, + }, + headers: { + 'content-type': 'application/json', + }, + }); + + const items = response.data.rows.map((item) => ({ + title: item.title, + description: item.description, + pubDate: parseDate(item.published_at * 1000), + link: `${rootUrl}/kx/${item.id}`, + author: item.author?.username, + category: item.tags.map((tag) => tag.name), + guid: item.resource_id, + })); + + return { + title: 'AMZ123 快讯', + link: `${rootUrl}/kx`, + item: items, + }; +} diff --git a/lib/routes/amz123/namespace.ts b/lib/routes/amz123/namespace.ts new file mode 100644 index 00000000000000..289242d2dd8894 --- /dev/null +++ b/lib/routes/amz123/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Amz123', + url: 'www.amz123.com', + categories: ['new-media'], + description: '跨境电商平台', + lang: 'zh-CN', +}; From 86530dd1a2433da328581445c5d7ffed63e354b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?da=CC=8Ashua=CC=8Ang=20li?= Date: Tue, 10 Dec 2024 18:55:55 +0800 Subject: [PATCH 2/3] fix(/mittrchina/breaking): check var null TypeError: Cannot read properties of null (reading 'content') --- lib/routes/mittrchina/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/routes/mittrchina/index.ts b/lib/routes/mittrchina/index.ts index d9e30b68604cfb..91caf7c98d1d84 100644 --- a/lib/routes/mittrchina/index.ts +++ b/lib/routes/mittrchina/index.ts @@ -97,6 +97,10 @@ async function handler(ctx) { data: { data: details }, } = await got(`https://apii.web.mittrchina.com/information/details?id=${item.id}`); + if (details === null) { + return null; + } + item.description = details.content; if (!item.author) { @@ -115,6 +119,7 @@ async function handler(ctx) { }) ) ); + items = items.filter((item) => item !== null); } return { From ff1addf168dfcca16c3e4494b83e557c09214561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?da=CC=8Ashua=CC=8Ang=20li?= Date: Wed, 11 Dec 2024 11:50:17 +0800 Subject: [PATCH 3/3] fix(/mittrchina): breaking url null properties --- lib/routes/mittrchina/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/routes/mittrchina/index.ts b/lib/routes/mittrchina/index.ts index 91caf7c98d1d84..ef392a47eac108 100644 --- a/lib/routes/mittrchina/index.ts +++ b/lib/routes/mittrchina/index.ts @@ -82,14 +82,16 @@ async function handler(ctx) { type: article.address.split('.').pop(), }, }) - : article.summary, - pubDate: article.start_time ? parseDate(article.start_time, 'X') : undefined, + : type === 'breaking' + ? article.content + : article.summary, + pubDate: article.start_time ? parseDate(article.start_time, 'X') : article.push_time ? parseDate(article.push_time, 'X') : undefined, id: article.id, link: `https://www.mittrchina.com/news/detail/${article.id}`, })); let items = list; - if (type !== 'video') { + if (type !== 'video' && type !== 'breaking') { items = await Promise.all( list.map((item) => cache.tryGet(item.link, async () => { @@ -97,10 +99,6 @@ async function handler(ctx) { data: { data: details }, } = await got(`https://apii.web.mittrchina.com/information/details?id=${item.id}`); - if (details === null) { - return null; - } - item.description = details.content; if (!item.author) { @@ -119,7 +117,6 @@ async function handler(ctx) { }) ) ); - items = items.filter((item) => item !== null); } return {