From 0e9fd025315e4c2bbf46ff72cd6db9841121215c Mon Sep 17 00:00:00 2001 From: zcw159357 Date: Mon, 18 Mar 2024 03:52:25 +0800 Subject: [PATCH] fix(route): Fix modian (#14784) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 迁移modian路由 * 迁移modian路由 * docs: fix category * feat: add radar rules --------- --- lib/router.js | 2 +- lib/routes-deprecated/modian/zhongchou.js | 57 ------------ lib/routes/modian/namespace.ts | 6 ++ lib/routes/modian/zhongchou.ts | 101 ++++++++++++++++++++++ lib/routes/nosec/index.ts | 6 ++ lib/routes/nosec/namespace.ts | 2 +- 6 files changed, 115 insertions(+), 59 deletions(-) delete mode 100644 lib/routes-deprecated/modian/zhongchou.js create mode 100644 lib/routes/modian/namespace.ts create mode 100644 lib/routes/modian/zhongchou.ts diff --git a/lib/router.js b/lib/router.js index 73dc2b2e8..007123cb8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1747,7 +1747,7 @@ router.get('/potplayer/update/:language?', lazyloadRouteHandler('./routes/potpla // router.get('/caus/:category?', lazyloadRouteHandler('./routes/caus')); // 摩点 -router.get('/modian/zhongchou/:category?/:sort?/:status?', lazyloadRouteHandler('./routes/modian/zhongchou')); +// router.get('/modian/zhongchou/:category?/:sort?/:status?', lazyloadRouteHandler('./routes/modian/zhongchou')); // 世界计划 多彩舞台 feat.初音未来 (ProjectSekai) // router.get('/pjsk/news', lazyloadRouteHandler('./routes/pjsk/news')); diff --git a/lib/routes-deprecated/modian/zhongchou.js b/lib/routes-deprecated/modian/zhongchou.js deleted file mode 100644 index d02782269..000000000 --- a/lib/routes-deprecated/modian/zhongchou.js +++ /dev/null @@ -1,57 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const category = ctx.params.category || 'all'; - const sort = ctx.params.sort || 'top_time'; - const status = ctx.params.status || 'all'; - - const rootUrl = 'https://zhongchou.modian.com'; - const currentUrl = `${rootUrl}/${category}/${sort}/${status}`; - - const response = await got({ - method: 'get', - url: currentUrl, - }); - - const $ = cheerio.load(response.data); - - const list = $('.pro_title') - .slice(0, 12) - .map((_, item) => { - item = $(item).parent(); - - return { - title: item.text(), - link: item.attr('href'), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - const startTime = detailResponse.data.match(/realtime_sync\.pro_time\('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'\);/); - - item.pubDate = startTime === null ? Date.parse(content('.start-time h3').text() || content('h3[start_time]').attr('start_time')) : Date.parse(startTime[1]); - - item.author = content('span[data-nickname]').text(); - item.description = `
` + content('.center-top').html() + content('#my_back_info').html() + content('#cont_match_htmlstr').html(); - - return item; - }) - ) - ); - - ctx.state.data = { - title: `${$('.category div span').text()} - ${$('.status div span').text()} - ${$('.sort div span').text()} - 摩点众筹`, - link: currentUrl, - item: items, - }; -}; diff --git a/lib/routes/modian/namespace.ts b/lib/routes/modian/namespace.ts new file mode 100644 index 000000000..16e1daa8d --- /dev/null +++ b/lib/routes/modian/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '摩点', + url: 'modian.com', +}; diff --git a/lib/routes/modian/zhongchou.ts b/lib/routes/modian/zhongchou.ts new file mode 100644 index 000000000..24d1d779b --- /dev/null +++ b/lib/routes/modian/zhongchou.ts @@ -0,0 +1,101 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/zhongchou/:category?/:sort?/:status?', + categories: ['shopping'], + example: '/modian/zhongchou', + parameters: { category: '分类,见下表,默认为全部', sort: '排序,见下表,默认为最新上线', status: '状态,见下表,默认为全部' }, + name: '众筹', + maintainers: ['nczitzk'], + description: `分类 + + | 全部 | 游戏 | 动漫 | 出版 | 桌游 | + | ---- | ----- | ------ | ---------- | ---------- | + | all | games | comics | publishing | tablegames | + + | 卡牌 | 潮玩模型 | 影视 | 音乐 | 活动 | + | ----- | -------- | ---------- | ----- | ---------- | + | cards | toys | film-video | music | activities | + + | 设计 | 科技 | 食品 | 爱心通道 | 动物救助 | + | ------ | ---------- | ---- | -------- | -------- | + | design | technology | food | charity | animals | + + | 个人愿望 | 其他 | + | -------- | ------ | + | wishes | others | + + 排序 + + | 最新上线 | 金额最高 | 评论最多 | + | --------- | ---------- | ------------ | + | top\_time | top\_money | top\_comment | + + 状态 + + | 全部 | 创意 | 预热 | 众筹中 | 众筹成功 | + | ---- | ---- | ------- | ------ | -------- | + | all | idea | preheat | going | success |`, + handler, + radar: [ + { + source: ['zhongchou.modian.com/:category/:sort/:status'], + }, + ], +}; + +async function handler(ctx) { + const { category = 'all', sort = 'top_time', status = 'all' } = ctx.req.param(); + + const rootUrl = 'https://zhongchou.modian.com'; + const currentUrl = `${rootUrl}/${category}/${sort}/${status}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = load(response.data); + + const list = $('.pro_title') + .slice(0, 12) + .map((_, item) => { + item = $(item).parent(); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = load(detailResponse.data); + + const startTime = detailResponse.data.match(/realtime_sync\.pro_time\('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})', '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'\);/); + + item.pubDate = startTime === null ? Date.parse(content('.start-time h3').text() || content('h3[start_time]').attr('start_time')) : Date.parse(startTime[1]); + + item.author = content('span[data-nickname]').text(); + item.description = `
` + content('.center-top').html() + content('#my_back_info').html() + content('#cont_match_htmlstr').html(); + + return item; + }) + ) + ); + + return { + title: `${$('.category div span').text()} - ${$('.status div span').text()} - ${$('.sort div span').text()} - 摩点众筹`, + link: currentUrl, + item: items, + }; +} diff --git a/lib/routes/nosec/index.ts b/lib/routes/nosec/index.ts index f22df84c9..d768ca95f 100644 --- a/lib/routes/nosec/index.ts +++ b/lib/routes/nosec/index.ts @@ -30,6 +30,12 @@ export const route: Route = { | 技术分析 | \`skill\` | | 安全工具 | \`tool\` |`, handler, + radar: [ + { + source: ['nosec.org/home/index/:keykind', 'nosec.org/home/index'], + target: (params) => `/nosec${params.keykind ? `/${params.keybind.replace('.html', '')}` : ''}`, + }, + ], }; async function handler(ctx) { diff --git a/lib/routes/nosec/namespace.ts b/lib/routes/nosec/namespace.ts index 1a78a3c8e..d00b7bf40 100644 --- a/lib/routes/nosec/namespace.ts +++ b/lib/routes/nosec/namespace.ts @@ -1,6 +1,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'NOSEC.org', + name: 'NOSEC 安全讯息平台', url: 'nosec.org', };