From 937e55b14fc836c8b41cb76e2a518bac0bfb864c Mon Sep 17 00:00:00 2001 From: ueiu <39592269+ueiu@users.noreply.github.com> Date: Sun, 11 Aug 2024 00:50:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(route/t66y):=20=E6=94=AF=E6=8C=81=E8=8D=89?= =?UTF-8?q?=E6=A6=B4=E7=A4=BE=E5=8C=BA=E7=9A=84=20search=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8C=BA=E5=88=86=E4=B8=BB=E9=A2=98=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=20(#16370)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route/t66y): 支持草榴社区的 search 参数区分主体类型 * feat(route/t66y): 支持草榴社区的 search 参数区分主题类型 * feat(route/t66y): 支持草榴社区 的 search 参数区分主题类型 --- lib/routes/t66y/index.ts | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/routes/t66y/index.ts b/lib/routes/t66y/index.ts index e316d4084e..e4e779a30a 100644 --- a/lib/routes/t66y/index.ts +++ b/lib/routes/t66y/index.ts @@ -6,10 +6,10 @@ import { parseDate } from '@/utils/parse-date'; import { baseUrl, parseContent } from './utils'; export const route: Route = { - path: '/:id/:type?', + path: '/:id/:type?/:search?', categories: ['multimedia'], example: '/t66y/20/2', - parameters: { id: '分区 id, 可在分区页 URL 中找到', type: '类型 id, 可在分区类型过滤后的 URL 中找到' }, + parameters: { id: '分区 id, 可在分区页 URL 中找到', type: '类型 id, 可在分区类型过滤后的 URL 中找到', search: '主题类型筛选,可在分区主题类型筛选后的 URL 中找到,默认为 `today`' }, features: { requireConfig: false, requirePuppeteer: false, @@ -33,14 +33,35 @@ export const route: Route = { | 技术讨论区 | 新时代的我们 | 达盖尔的旗帜 | 成人文学交流 | | ---------- | ------------ | ------------ | ------------ | - | 7 | 8 | 16 | 20 |`, + | 7 | 8 | 16 | 20 | + + **主题过滤** + + > 因为该类型无法搭配子类型使用,所以使用时 \`type\` 子类型需使用 \`-999\` 占位 + + | 今日主题 | 热门主题 | 精华主题 | 原创主题 | 今日新作 | + | ------- | ------- | ------- | ------- | ------ | + | today | hot | digest | 1 | 2 |`, }; -async function handler(ctx) { - const { id, type } = ctx.req.param(); +const SEARCH_NAMES = { + today: '今日主题', + hot: '热门主题', + digest: '精华主题', + 1: '原创主题', + 2: '今日新作', +}; - const url = new URL(`thread0806.php?fid=${id}&search=today`, baseUrl); - type && url.searchParams.set('type', type); +const DEFAULT_SEARCH_TYPE = 'today'; + +async function handler(ctx) { + const id = ctx.req.param('id'); + const type = (Number.parseInt(ctx.req.param('type')) || -999).toString(); + const isValidType = type !== '-999'; + const search = isValidType ? DEFAULT_SEARCH_TYPE : (ctx.req.param('search') ?? DEFAULT_SEARCH_TYPE); + + const url = new URL(`thread0806.php?fid=${id}&search=${search}`, baseUrl); + isValidType && url.searchParams.set('type', type); const { data: res } = await got(url); const $ = cheerio.load(res); @@ -80,8 +101,9 @@ async function handler(ctx) { ); return { - title: (type ? `[${$('.t .fn b').text()}]` : '') + $('head title').text(), + title: (isValidType ? `[${$('.t .fn b').text()}] ` : '') + (search ? `[${SEARCH_NAMES[search]}] ` : '') + $('head title').text(), link: url.href, item: out, + allowEmpty: true, }; }