From df4433789bc44f60f378e99b0f0fcc781de0dd3f Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 29 Feb 2024 02:15:07 +0800 Subject: [PATCH] feat: v3 migration - 11/n --- lib/utils/common-utils.ts | 7 +++++- lib/v2/141jav/index.js | 5 +++-- lib/v2/141jav/router.js | 2 +- lib/v2/141ppv/index.js | 5 +++-- lib/v2/141ppv/router.js | 2 +- lib/v2/36kr/index.js | 5 ++++- lib/v2/36kr/router.js | 2 +- lib/v2/78dm/index.js | 3 ++- lib/v2/78dm/router.js | 2 +- lib/v2/81/81rc/index.js | 3 ++- lib/v2/81/router.js | 2 +- lib/v2/8world/index.js | 3 ++- lib/v2/8world/router.js | 2 +- lib/v2/aljazeera/index.js | 3 ++- lib/v2/aljazeera/router.js | 2 +- lib/v2/aqara/post.js | 3 ++- lib/v2/aqara/router.js | 2 +- lib/v2/bad/index.js | 3 ++- lib/v2/bad/router.js | 2 +- lib/v2/bangumi/moe/index.js | 5 +++-- lib/v2/bangumi/router.js | 2 +- lib/v2/bast/index.js | 3 ++- lib/v2/bast/router.js | 2 +- lib/v2/biquge/index.js | 5 +++-- lib/v2/biquge/router.js | 2 +- lib/v2/cbaigui/index.js | 5 +++-- lib/v2/cbaigui/router.js | 2 +- lib/v2/cnblogs/common.js | 3 ++- lib/v2/cneb/router.js | 2 +- lib/v2/cneb/yjxx.js | 3 ++- lib/v2/dgjyw/index.js | 3 ++- lib/v2/dgjyw/router.js | 2 +- lib/v2/dlsite/router.js | 2 +- lib/v2/dlsite/utils.js | 6 ++--- lib/v2/dut/router.js | 2 +- lib/v2/gov/beijing/bphc/index.js | 3 ++- lib/v2/gov/ccdi/index.js | 3 ++- lib/v2/gov/cmse/index.js | 6 ++--- lib/v2/gov/cnnic/index.js | 5 +++-- lib/v2/gov/general/general.js | 5 ++++- lib/v2/gov/maoming/maoming.js | 5 ++++- lib/v2/gov/nopss/index.js | 3 ++- lib/v2/gov/nsfc/index.js | 3 ++- lib/v2/gov/router.js | 38 ++++++++++++++++---------------- lib/v2/gov/shanghai/yjj/index.js | 3 ++- lib/v2/gov/stats/index.js | 3 ++- lib/v2/ifeng/news.js | 3 ++- lib/v2/ifeng/router.js | 2 +- lib/v2/itch/index.js | 3 ++- lib/v2/itch/router.js | 2 +- lib/v2/javbus/index.js | 7 ++++-- lib/v2/javbus/router.js | 2 +- lib/v2/keylol/index.js | 3 ++- lib/v2/keylol/router.js | 2 +- lib/v2/logonews/index.js | 3 ++- lib/v2/logonews/router.js | 2 +- lib/v2/nber/index.js | 3 ++- lib/v2/nenu/router.js | 4 ++-- lib/v2/nenu/sohac.js | 3 ++- lib/v2/nenu/yjsy.js | 3 ++- lib/v2/nikkei/cn/index.js | 3 ++- lib/v2/nikkei/router.js | 2 +- lib/v2/npm/router.js | 2 +- lib/v2/nuist/router.js | 2 +- lib/v2/nuist/yjs.js | 3 ++- lib/v2/pts/index.js | 3 ++- lib/v2/pts/router.js | 3 +-- lib/v2/sinchew/index.js | 3 ++- lib/v2/sinchew/router.js | 3 +-- lib/v2/thenewslens/index.js | 3 ++- lib/v2/thenewslens/router.js | 2 +- lib/v2/web3caff/index.js | 3 ++- lib/v2/web3caff/router.js | 2 +- lib/v2/yangtzeu/dongke.js | 3 ++- lib/v2/yangtzeu/router.js | 2 +- lib/v2/zyshow/index.js | 3 ++- lib/v2/zyshow/router.js | 2 +- 77 files changed, 161 insertions(+), 109 deletions(-) diff --git a/lib/utils/common-utils.ts b/lib/utils/common-utils.ts index eec876109..123fa75ad 100644 --- a/lib/utils/common-utils.ts +++ b/lib/utils/common-utils.ts @@ -26,4 +26,9 @@ const convertDateToISO8601 = (date?: string | Date | number | null) => { return date.toISOString(); }; -export { toTitleCase, collapseWhitespace, convertDateToISO8601 }; +const getSubPath = (ctx) => { + const subPath = ctx.req.path.replace(/\/[^/]*/, '') || '/'; + return subPath; +}; + +export { toTitleCase, collapseWhitespace, convertDateToISO8601, getSubPath }; diff --git a/lib/v2/141jav/index.js b/lib/v2/141jav/index.js index b95e7a10d..48f2527d6 100644 --- a/lib/v2/141jav/index.js +++ b/lib/v2/141jav/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -6,7 +7,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://www.141jav.com'; - const currentUrl = `${rootUrl}${ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx)}`; const response = await got({ method: 'get', @@ -15,7 +16,7 @@ module.exports = async (ctx) => { const $ = load(response.data); - if (ctx.path === '/') { + if (getSubPath(ctx) === '/') { ctx.redirect(`/141jav${$('.overview').first().attr('href')}`); return; } diff --git a/lib/v2/141jav/router.js b/lib/v2/141jav/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/141jav/router.js +++ b/lib/v2/141jav/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/141ppv/index.js b/lib/v2/141ppv/index.js index a65ce12bd..04f0b2401 100644 --- a/lib/v2/141ppv/index.js +++ b/lib/v2/141ppv/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -6,7 +7,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://www.141ppv.com'; - const currentUrl = `${rootUrl}${ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx)}`; const response = await got({ method: 'get', @@ -15,7 +16,7 @@ module.exports = async (ctx) => { const $ = load(response.data); - if (ctx.path === '/') { + if (getSubPath(ctx) === '/') { ctx.redirect(`/141ppv${$('.overview').first().attr('href')}`); return; } diff --git a/lib/v2/141ppv/router.js b/lib/v2/141ppv/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/141ppv/router.js +++ b/lib/v2/141ppv/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/36kr/index.js b/lib/v2/36kr/index.js index cd397cebe..189ed3122 100644 --- a/lib/v2/36kr/index.js +++ b/lib/v2/36kr/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -15,7 +16,9 @@ const shortcuts = { }; module.exports = async (ctx) => { - const path = ctx.path.replace(/^\/news(?!flashes)/, '/information').replace(/\/search\/article/, '/search/articles'); + const path = getSubPath(ctx) + .replace(/^\/news(?!flashes)/, '/information') + .replace(/\/search\/article/, '/search/articles'); const currentUrl = `${rootUrl}${Object.hasOwn(shortcuts, path) ? shortcuts[path] : path}`; diff --git a/lib/v2/36kr/router.js b/lib/v2/36kr/router.js index ac9426e40..4703c7240 100644 --- a/lib/v2/36kr/router.js +++ b/lib/v2/36kr/router.js @@ -1,4 +1,4 @@ module.exports = (router) => { router.get('/hot-list/:category?', './hot-list'); - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/78dm/index.js b/lib/v2/78dm/index.js index 81cb8bf36..2e6259aa1 100644 --- a/lib/v2/78dm/index.js +++ b/lib/v2/78dm/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://www.78dm.net'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '/news' : /\/\d+$/.test(ctx.path) ? `${ctx.path}.html` : ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/' ? '/news' : /\/\d+$/.test(getSubPath(ctx)) ? `${getSubPath(ctx)}.html` : getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/78dm/router.js b/lib/v2/78dm/router.js index e039ea82a..91a6a8441 100644 --- a/lib/v2/78dm/router.js +++ b/lib/v2/78dm/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/81/81rc/index.js b/lib/v2/81/81rc/index.js index fa796f5f5..14297e7df 100644 --- a/lib/v2/81/81rc/index.js +++ b/lib/v2/81/81rc/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const thePath = ctx.path.replace(/^\/81rc/, ''); + const thePath = getSubPath(ctx).replace(/^\/81rc/, ''); const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; const rootUrl = 'https://81rc.81.cn'; diff --git a/lib/v2/81/router.js b/lib/v2/81/router.js index 47243f9c4..29085d755 100644 --- a/lib/v2/81/router.js +++ b/lib/v2/81/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/81rc(\/[\w-/]+)?/, './81rc'); + router.get('/81rc/*', './81rc'); }; diff --git a/lib/v2/8world/index.js b/lib/v2/8world/index.js index 773a29bb2..3e187442c 100644 --- a/lib/v2/8world/index.js +++ b/lib/v2/8world/index.js @@ -1,10 +1,11 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const path = ctx.path === '/' ? '/realtime' : ctx.path; + const path = getSubPath(ctx) === '/' ? '/realtime' : getSubPath(ctx); const rootUrl = 'https://www.8world.com'; const currentUrl = `${rootUrl}${path}`; diff --git a/lib/v2/8world/router.js b/lib/v2/8world/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/8world/router.js +++ b/lib/v2/8world/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/aljazeera/index.js b/lib/v2/aljazeera/index.js index f6542702a..a38cdf897 100644 --- a/lib/v2/aljazeera/index.js +++ b/lib/v2/aljazeera/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -21,7 +22,7 @@ const languages = { }; module.exports = async (ctx) => { - const params = ctx.path === '/' ? ['arabic'] : ctx.path.replace(/^\//, '').split('/'); + const params = getSubPath(ctx) === '/' ? ['arabic'] : getSubPath(ctx).replace(/^\//, '').split('/'); if (!Object.hasOwn(languages, params[0])) { params.unshift('arabic'); diff --git a/lib/v2/aljazeera/router.js b/lib/v2/aljazeera/router.js index e039ea82a..91a6a8441 100644 --- a/lib/v2/aljazeera/router.js +++ b/lib/v2/aljazeera/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/aqara/post.js b/lib/v2/aqara/post.js index 7cc6387ae..c1754a9d5 100644 --- a/lib/v2/aqara/post.js +++ b/lib/v2/aqara/post.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -15,7 +16,7 @@ module.exports = async (ctx) => { let currentUrl = rootUrl; let apiUrl = new URL(`${apiSlug}/posts?_embed=true&per_page=${limit}`, rootUrl).href; - const filterMatches = ctx.path.match(/^\/([^/]*)\/([^/]*)\/(.*)$/); + const filterMatches = getSubPath(ctx).match(/^\/([^/]*)\/([^/]*)\/(.*)$/); if (filterMatches) { const filterRegion = filterMatches[1]; diff --git a/lib/v2/aqara/router.js b/lib/v2/aqara/router.js index 73c94e5fa..c808fca5c 100644 --- a/lib/v2/aqara/router.js +++ b/lib/v2/aqara/router.js @@ -11,5 +11,5 @@ module.exports = function (router) { const redirectTo = `/aqara/${region}/category/${types[type]}`; ctx.redirect(redirectTo); }); - router.get(/([\w-/]+)?/, './post'); + router.get('*', './post'); }; diff --git a/lib/v2/bad/index.js b/lib/v2/bad/index.js index a9b0ab4dd..1fa1adef8 100644 --- a/lib/v2/bad/index.js +++ b/lib/v2/bad/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import timezone from '@/utils/timezone'; @@ -5,7 +6,7 @@ import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://bad.news'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '' : ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/' ? '' : getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/bad/router.js b/lib/v2/bad/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/bad/router.js +++ b/lib/v2/bad/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/bangumi/moe/index.js b/lib/v2/bangumi/moe/index.js index c8d7c445c..9de661b18 100644 --- a/lib/v2/bangumi/moe/index.js +++ b/lib/v2/bangumi/moe/index.js @@ -1,9 +1,10 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const isLatest = ctx.path === '/moe'; + const isLatest = getSubPath(ctx) === '/moe'; const rootUrl = 'https://bangumi.moe'; let response; @@ -20,7 +21,7 @@ module.exports = async (ctx) => { const tagUrl = `${rootUrl}/api/tag/search`; const torrentUrl = `${rootUrl}/api/torrent/search`; - const params = ctx.path.split('/').slice(2); + const params = getSubPath(ctx).split('/').slice(2); tag_id = await Promise.all( params.map((param) => diff --git a/lib/v2/bangumi/router.js b/lib/v2/bangumi/router.js index 2ad92b349..d82f11126 100644 --- a/lib/v2/bangumi/router.js +++ b/lib/v2/bangumi/router.js @@ -1,6 +1,6 @@ module.exports = function (router) { // bangumi.moe - router.get(/moe([\w-/]+)?/, './moe/index'); + router.get('/moe/*', './moe/index'); // bangumi.online router.get('/online', './online/online'); // bangumi.tv diff --git a/lib/v2/bast/index.js b/lib/v2/bast/index.js index 56166bb30..93b2e3e2b 100644 --- a/lib/v2/bast/index.js +++ b/lib/v2/bast/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const colPath = ctx.path.replace(/^\//, '') || '32942'; + const colPath = getSubPath(ctx).replace(/^\//, '') || '32942'; const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; const rootUrl = 'https://www.bast.net.cn'; diff --git a/lib/v2/bast/router.js b/lib/v2/bast/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/bast/router.js +++ b/lib/v2/bast/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/biquge/index.js b/lib/v2/biquge/index.js index 87b869b7b..96aba37e9 100644 --- a/lib/v2/biquge/index.js +++ b/lib/v2/biquge/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -24,8 +25,8 @@ const allowHost = new Set([ ]); module.exports = async (ctx) => { - const rootUrl = ctx.path.split('/').slice(1, 4).join('/'); - const currentUrl = ctx.path.slice(1); + const rootUrl = getSubPath(ctx).split('/').slice(1, 4).join('/'); + const currentUrl = getSubPath(ctx).slice(1); if (!config.feature.allow_user_supply_unsafe_domain && !allowHost.has(new URL(rootUrl).hostname)) { throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } diff --git a/lib/v2/biquge/router.js b/lib/v2/biquge/router.js index e039ea82a..91a6a8441 100644 --- a/lib/v2/biquge/router.js +++ b/lib/v2/biquge/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/cbaigui/index.js b/lib/v2/cbaigui/index.js index ab9989dab..c2cb4a092 100644 --- a/lib/v2/cbaigui/index.js +++ b/lib/v2/cbaigui/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -11,10 +12,10 @@ module.exports = async (ctx) => { let filterName; - const currentUrl = new URL(ctx.path.replace(/^\/cbaigui/, ''), rootUrl).href; + const currentUrl = new URL(getSubPath(ctx).replace(/^\/cbaigui/, ''), rootUrl).href; let apiUrl = new URL(`${apiSlug}/posts?_embed=true&per_page=${limit}`, rootUrl).href; - const filterMatches = ctx.path.match(/^\/post-(tag|category)\/(.*)$/); + const filterMatches = getSubPath(ctx).match(/^\/post-(tag|category)\/(.*)$/); if (filterMatches) { filterName = decodeURI(filterMatches[2].split('/').pop()); diff --git a/lib/v2/cbaigui/router.js b/lib/v2/cbaigui/router.js index 02bcb7192..6ea9e73a1 100644 --- a/lib/v2/cbaigui/router.js +++ b/lib/v2/cbaigui/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './'); + router.get('*', './'); }; diff --git a/lib/v2/cnblogs/common.js b/lib/v2/cnblogs/common.js index e3a0908c8..8a8e46b4d 100644 --- a/lib/v2/cnblogs/common.js +++ b/lib/v2/cnblogs/common.js @@ -1,10 +1,11 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const link = `https://www.cnblogs.com${ctx.path}`; + const link = `https://www.cnblogs.com${getSubPath(ctx)}`; const response = await got(link); const data = response.data; diff --git a/lib/v2/cneb/router.js b/lib/v2/cneb/router.js index 4ccfceead..7a2cc28f7 100644 --- a/lib/v2/cneb/router.js +++ b/lib/v2/cneb/router.js @@ -1,4 +1,4 @@ module.exports = function (router) { router.get('/yjxw/:category?', './yjxw'); - router.get(/\/yjxx([\w-/]+)?/, './yjxx'); + router.get('/yjxx/*', './yjxx'); }; diff --git a/lib/v2/cneb/yjxx.js b/lib/v2/cneb/yjxx.js index 75ce9ab48..d56df7088 100644 --- a/lib/v2/cneb/yjxx.js +++ b/lib/v2/cneb/yjxx.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; @@ -5,7 +6,7 @@ import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 200; - const options = decodeURI(ctx.path) + const options = decodeURI(getSubPath(ctx)) .replace(/\/yjxx/, '') .split('/'); diff --git a/lib/v2/dgjyw/index.js b/lib/v2/dgjyw/index.js index 9a8515f2d..1d8b198b6 100644 --- a/lib/v2/dgjyw/index.js +++ b/lib/v2/dgjyw/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const params = ctx.path; + const params = getSubPath(ctx); const rootUrl = 'https://www.dgjyw.com'; const currentUrl = `${rootUrl}${params === '/' ? '/tz' : params}.htm`; diff --git a/lib/v2/dgjyw/router.js b/lib/v2/dgjyw/router.js index e039ea82a..91a6a8441 100644 --- a/lib/v2/dgjyw/router.js +++ b/lib/v2/dgjyw/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/dlsite/router.js b/lib/v2/dlsite/router.js index 1c43d190e..3a80e677b 100644 --- a/lib/v2/dlsite/router.js +++ b/lib/v2/dlsite/router.js @@ -2,5 +2,5 @@ module.exports = function (router) { router.get('/campaign/:type/:free?', './campaign'); router.get('/ci-en/:id/article', './ci-en/article'); router.get('/new/:type', './new'); - router.get(/([\w-=/]+)?/, './'); + router.get('*', './'); }; diff --git a/lib/v2/dlsite/utils.js b/lib/v2/dlsite/utils.js index 5f8788fa3..c8e63ff1c 100644 --- a/lib/v2/dlsite/utils.js +++ b/lib/v2/dlsite/utils.js @@ -1,9 +1,9 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; import { art } from '@/utils/render'; -import * as path from 'node:path'; const dayjs = require('dayjs'); const rootUrl = 'https://www.dlsite.com'; @@ -45,11 +45,11 @@ const getDetails = async (works) => { const ProcessItems = async (ctx) => { art.defaults.imports.formatDate = formatDate; - ctx.path = ctx.path === '/' ? '/home/new' : ctx.path; + const path = getSubPath(ctx) === '/' ? '/home/new' : getSubPath(ctx); const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; - const currentUrl = `${rootUrl}${addFilters(ctx.path, defaultFilters)}`; + const currentUrl = `${rootUrl}${addFilters(path, defaultFilters)}`; const response = await got({ method: 'get', diff --git a/lib/v2/dut/router.js b/lib/v2/dut/router.js index 878fd906f..a840d2ce9 100644 --- a/lib/v2/dut/router.js +++ b/lib/v2/dut/router.js @@ -1,4 +1,4 @@ module.exports = function (router) { - router.get(/(\w+)\/([\w/]+)?/, './index'); + router.get('/*/*', './index'); router.get('/:0?', './index'); }; diff --git a/lib/v2/gov/beijing/bphc/index.js b/lib/v2/gov/beijing/bphc/index.js index 9863322ca..b5724daaa 100644 --- a/lib/v2/gov/beijing/bphc/index.js +++ b/lib/v2/gov/beijing/bphc/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; @@ -22,7 +23,7 @@ module.exports = async (ctx) => { const rootUrl = 'https://gycpt.bphc.com.cn'; const defaultPath = 'announcement'; - const pathname = ctx.path.replaceAll(/(^\/beijing\/bphc|\/$)/g, ''); + const pathname = getSubPath(ctx).replaceAll(/(^\/beijing\/bphc|\/$)/g, ''); const key = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname.slice(0, -1) : pathname; const obj = mapping[key]; const currentUrl = `${rootUrl}${obj.list}`; diff --git a/lib/v2/gov/ccdi/index.js b/lib/v2/gov/ccdi/index.js index bf74d4702..64bf4812a 100644 --- a/lib/v2/gov/ccdi/index.js +++ b/lib/v2/gov/ccdi/index.js @@ -1,9 +1,10 @@ +import { getSubPath } from '@/utils/common-utils'; const { rootUrl, parseNewsList, parseArticle } = require('./utils'); module.exports = async (ctx) => { const defaultPath = '/yaowenn/'; - let pathname = ctx.path.replaceAll(/(^\/ccdi|\/$)/g, ''); + let pathname = getSubPath(ctx).replaceAll(/(^\/ccdi|\/$)/g, ''); pathname = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname : pathname + '/'; const currentUrl = `${rootUrl}${pathname}`; diff --git a/lib/v2/gov/cmse/index.js b/lib/v2/gov/cmse/index.js index 1e09176b4..dff4caa3b 100644 --- a/lib/v2/gov/cmse/index.js +++ b/lib/v2/gov/cmse/index.js @@ -1,16 +1,16 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; import { art } from '@/utils/render'; -import * as path from 'node:path'; module.exports = async (ctx) => { - ctx.path = ctx.path.replaceAll(/(^\/cmse|\/$)/g, ''); + const path = getSubPath(ctx).replaceAll(/(^\/cmse|\/$)/g, ''); const rootUrl = 'http://www.cmse.gov.cn'; - const currentUrl = `${rootUrl}${ctx.path === '' ? '/xwzx/zhxw/' : `${ctx.path}/`}`; + const currentUrl = `${rootUrl}${path === '' ? '/xwzx/zhxw/' : `${path}/`}`; const response = await got({ method: 'get', diff --git a/lib/v2/gov/cnnic/index.js b/lib/v2/gov/cnnic/index.js index e0e63947a..3c1f7dff0 100644 --- a/lib/v2/gov/cnnic/index.js +++ b/lib/v2/gov/cnnic/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,10 +6,10 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - ctx.path = ctx.path.replaceAll(/^\/cnnic/g, ''); + const path = getSubPath(ctx).replaceAll(/^\/cnnic/g, ''); const rootUrl = 'http://www.cnnic.net.cn'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '/gywm/xwzx/rdxw/20172017_7086/' : `${ctx.path}/`}`; + const currentUrl = `${rootUrl}${path === '/' ? '/gywm/xwzx/rdxw/20172017_7086/' : `${path}/`}`; const response = await got({ method: 'get', diff --git a/lib/v2/gov/general/general.js b/lib/v2/gov/general/general.js index 78a67be1d..9513438b0 100644 --- a/lib/v2/gov/general/general.js +++ b/lib/v2/gov/general/general.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; // 来人拯救一下啊( >﹏<。) // 待做功能: @@ -44,7 +45,9 @@ import { art } from '@/utils/render'; import { finishArticleItem } from '@/utils/wechat-mp'; const gdgov = async (info, ctx) => { - const path = ctx.path.split('/').filter((item) => item !== ''); + const path = getSubPath(ctx) + .split('/') + .filter((item) => item !== ''); const [site, branch] = path; // 网站 diff --git a/lib/v2/gov/maoming/maoming.js b/lib/v2/gov/maoming/maoming.js index 5aa46ce94..d494e34dd 100644 --- a/lib/v2/gov/maoming/maoming.js +++ b/lib/v2/gov/maoming/maoming.js @@ -1,7 +1,10 @@ +import { getSubPath } from '@/utils/common-utils'; const { gdgov } = require('../general/general'); module.exports = async (ctx) => { - const path = ctx.path.split('/').filter((item) => item !== ''); + const path = getSubPath(ctx) + .split('/') + .filter((item) => item !== ''); let pathstartat = 0; let defaultPath = ''; let list_element = ''; diff --git a/lib/v2/gov/nopss/index.js b/lib/v2/gov/nopss/index.js index 8825c2907..a56d401c4 100644 --- a/lib/v2/gov/nopss/index.js +++ b/lib/v2/gov/nopss/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const params = ctx.path === '/nopss' ? '/GB/219469' : ctx.path.replace(/^\/nopss/, ''); + const params = getSubPath(ctx) === '/nopss' ? '/GB/219469' : getSubPath(ctx).replace(/^\/nopss/, ''); const rootUrl = 'http://www.nopss.gov.cn'; const currentUrl = `${rootUrl}${params}`; diff --git a/lib/v2/gov/nsfc/index.js b/lib/v2/gov/nsfc/index.js index a75bbd14f..5491ea066 100644 --- a/lib/v2/gov/nsfc/index.js +++ b/lib/v2/gov/nsfc/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import { parseDate } from '@/utils/parse-date'; const shortcuts = require('./shortcuts'); module.exports = async (ctx) => { - let thePath = ctx.path.replace(/^\/nsfc/, ''); + let thePath = getSubPath(ctx).replace(/^\/nsfc/, ''); const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index d82b2c40f..a945de715 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -1,14 +1,14 @@ module.exports = function (router) { // ministry - router.get(/cac(\/[\w/-]+)?/, './cac/index'); + router.get('/cac/*', './cac/index'); router.get('/caac/cjwt/:category?', './caac/cjwt'); - router.get(/ccdi(\/[\w/-]+)?/, './ccdi'); + router.get('/ccdi/*', './ccdi'); router.get('/chinamine-safety/zfxxgk/:category*', './chinamine-safety/zfxxgk'); router.get('/chinamine-safety/xw/:category*', './chinamine-safety/xw'); router.get('/chinatax/latest', './chinatax/latest'); router.get('/cmse/fxrw', './cmse/fxrw'); - router.get(/cmse(\/[\w/-]+)?/, './cmse'); - router.get(/cnnic(\/[\w/-]+)?/, './cnnic'); + router.get('/cmse/*', './cmse'); + router.get('/cnnic/*', './cnnic'); router.get('/csrc/auditstatus/:apply_id', './csrc/auditstatus'); router.get('/csrc/news/:suffix*', './csrc/news'); router.get('/customs/list/:gchannel?', './customs/list'); @@ -40,12 +40,12 @@ module.exports = function (router) { router.get('/nea/sjzz/ghs', './nea/ghs'); router.get('/news/:uid', './news'); router.get('/nifdc/:path*', './nifdc'); - router.get(/\/nmpa\/(\w[\w/]+)?/, './nmpa/generic'); - router.get(/nopss(\/[\w/-]+)?/, './nopss'); + router.get('/nmpa/*', './nmpa/generic'); + router.get('/nopss/*', './nopss'); router.get('/npc/:caty', './npc/index'); router.get('/nrta/news/:category?', './nrta/news'); router.get('/nrta/dsj/:category?', './nrta/dsj'); - router.get(/nsfc(\/[\w-/]+)?/, './nsfc'); + router.get('/nsfc/*', './nsfc'); router.get('/pbc/goutongjiaoliu', './pbc/goutongjiaoliu'); router.get('/pbc/gzlw', './pbc/gzlw'); router.get('/pbc/tradeAnnouncement', './pbc/trade-announcement'); @@ -54,40 +54,40 @@ module.exports = function (router) { router.get('/safe/complaint/:site?', './safe/complaint'); router.get('/samr/xgzlyhd/:category?/:department?', './samr/xgzlyhd'); router.get('/sasac/:path+', './sasac/generic'); - router.get(/stats(\/[\w/-]+)?/, './stats'); + router.get('/stats/*', './stats'); router.get('/zhengce/govall/:advance?', './zhengce/govall'); router.get('/zhengce/wenjian/:pcodeJiguan?', './zhengce/wenjian'); router.get('/zhengce/zhengceku/:department', './zhengce/zhengceku'); router.get('/zhengce/zuixin', './zhengce'); router.get('/zhengce/:category*', './zhengce'); // province - router.get(/anhui\/kjt\/([\w/-]+)?/, './anhui/kjt'); + router.get('/anhui/kjt/*', './anhui/kjt'); router.get('/beijing/bjedu/gh/:urlPath?', './beijing/bjedu/gh'); - router.get(/beijing\/bphc(\/[\w/-]+)?/, './beijing/bphc'); + router.get('/beijing/bphc/*', './beijing/bphc'); router.get('/beijing/jw/tzgg', './beijing/jw/tzgg'); router.get('/beijing/kw/:channel', './beijing/kw/index'); router.get('/chongqing/gzw/:category*', './chongqing/gzw'); router.get('/chongqing/rsks', './chongqing/rsks'); router.get('/chongqing/sydwgkzp', './chongqing/sydwgkzp'); - router.get(/dianbai(\/[\w/-]+)?/, './dianbai/dianbai'); - router.get(/gaozhou(\/[\w/-]+)?/, './gaozhou/gaozhou'); + router.get('/dianbai/*', './dianbai/dianbai'); + router.get('/gaozhou/*', './gaozhou/gaozhou'); router.get('/guangdong/tqyb/sncsyjxh', './guangdong/tqyb/sncsyjxh'); router.get('/guangdong/tqyb/tfxtq', './guangdong/tqyb/tfxtq'); router.get('/gz/:channel/:category', './gz/index'); router.get('/hebei/czt/xwdt/:category?', './hebei/czt'); - router.get(/huazhou(\/[\w/-]+)?/, './huazhou/huazhou'); + router.get('/huazhou/*', './huazhou/huazhou'); router.get('/huizhou/zwgk/:category?', './huizhou/zwgk/index'); router.get('/hunan/changsha/major-email', './hunan/changsha/major-email'); - router.get(/maoming(\/[\w/-]+)?/, './maoming/maoming'); + router.get('/maoming/*', './maoming/maoming'); router.get('/maonan/:category', './maonan/maonan'); - router.get(/mgs(\/[\w/-]+)?/, './mgs/mgs'); - router.get(/mmht(\/[\w/-]+)?/, './mmht/mmht'); - router.get(/sdb(\/[\w/-]+)?/, './sdb/sdb'); + router.get('/mgs/*', './mgs/mgs'); + router.get('/mmht/*', './mmht/mmht'); + router.get('/sdb/*', './sdb/sdb'); router.get('/shaanxi/kjt/:id?', './shaanxi/kjt'); router.get('/shanghai/rsj/ksxm', './shanghai/rsj/ksxm'); router.get('/shanghai/wsjkw/yqtb', './shanghai/wsjkw/yqtb'); router.get('/shanghai/wgj/:page?', './shanghai/wgj/wgj'); - router.get(/shanghai\/yjj\/([\w/-]+)?/, './shanghai/yjj'); + router.get('/shanghai/yjj/*', './shanghai/yjj'); router.get('/shenzhen/hrss/szksy/:caty/:page?', './shenzhen/hrss/szksy/index'); router.get('/shenzhen/xxgk/zfxxgj/:caty', './shenzhen/xxgk/zfxxgj'); router.get('/shenzhen/zjj/xxgk/:caty', './shenzhen/zjj/index'); @@ -99,7 +99,7 @@ module.exports = function (router) { router.get('/suzhou/news/:uid', './suzhou/news'); router.get('/taiyuan/rsj/:caty/:page?', './taiyuan/rsj'); router.get('/wuhan/sy/whyw', './wuhan/whyw'); - router.get(/xinyi(\/[\w/-]+)?/, './xinyi/xinyi'); + router.get('/xinyi/*', './xinyi/xinyi'); router.get('/xuzhou/hrss/:category?', './xuzhou/hrss'); router.get('/zhejiang/gwy/:category?/:column?', './zhejiang/gwy'); }; diff --git a/lib/v2/gov/shanghai/yjj/index.js b/lib/v2/gov/shanghai/yjj/index.js index ac09b5e68..60ac0a61c 100644 --- a/lib/v2/gov/shanghai/yjj/index.js +++ b/lib/v2/gov/shanghai/yjj/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const params = ctx.path === '/shanghai/yjj' ? '/shanghai/yjj/zx-ylqx' : ctx.path; + const params = getSubPath(ctx) === '/shanghai/yjj' ? '/shanghai/yjj/zx-ylqx' : getSubPath(ctx); const rootUrl = 'https://yjj.sh.gov.cn'; const currentUrl = `${rootUrl}${params.replace(/^\/shanghai\/yjj/, '')}/index.html`; diff --git a/lib/v2/gov/stats/index.js b/lib/v2/gov/stats/index.js index 7ae454381..55184c173 100644 --- a/lib/v2/gov/stats/index.js +++ b/lib/v2/gov/stats/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -12,7 +13,7 @@ module.exports = async (ctx) => { const defaultPath = '/sj/zxfb/'; const rootUrl = 'http://www.stats.gov.cn'; - const currentUrl = `${rootUrl}${ctx.path === '/stats' ? defaultPath : ctx.path.replace(/^\/stats(.*)/, '$1/')}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/stats' ? defaultPath : getSubPath(ctx).replace(/^\/stats(.*)/, '$1/')}`; let response = await got({ method: 'get', diff --git a/lib/v2/ifeng/news.js b/lib/v2/ifeng/news.js index e67235036..005e54c7c 100644 --- a/lib/v2/ifeng/news.js +++ b/lib/v2/ifeng/news.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -10,7 +11,7 @@ module.exports = async (ctx) => { const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://news.ifeng.com'; - const currentUrl = `${rootUrl}${ctx.path.replace(/^\/news/, '')}`; + const currentUrl = `${rootUrl}${getSubPath(ctx).replace(/^\/news/, '')}`; const response = await got({ method: 'get', diff --git a/lib/v2/ifeng/router.js b/lib/v2/ifeng/router.js index bfe712bc6..e4fcfeadb 100644 --- a/lib/v2/ifeng/router.js +++ b/lib/v2/ifeng/router.js @@ -1,4 +1,4 @@ module.exports = (router) => { router.get('/feng/:id/:type', './feng'); - router.get(/news([\w-/]+)?/, './news'); + router.get('/news/*', './news'); }; diff --git a/lib/v2/itch/index.js b/lib/v2/itch/index.js index 38963bcc1..df89ff1e7 100644 --- a/lib/v2/itch/index.js +++ b/lib/v2/itch/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://itch.io'; - const currentUrl = `${rootUrl}${ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/itch/router.js b/lib/v2/itch/router.js index dabea1bf3..2fb5aa865 100644 --- a/lib/v2/itch/router.js +++ b/lib/v2/itch/router.js @@ -1,5 +1,5 @@ module.exports = function (router) { router.get('/devlog/:user/:id', './devlog'); router.get('/posts/:topic/:id', './posts'); - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/javbus/index.js b/lib/v2/javbus/index.js index 8a602b785..bb615ead6 100644 --- a/lib/v2/javbus/index.js +++ b/lib/v2/javbus/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -14,7 +15,7 @@ const toSize = (raw) => { const allowDomain = new Set(['javbus.com', 'javbus.org', 'javsee.icu', 'javsee.one']); module.exports = async (ctx) => { - const isWestern = /^\/western/.test(ctx.path); + const isWestern = /^\/western/.test(getSubPath(ctx)); const domain = ctx.req.query('domain') ?? 'javbus.com'; const westernDomain = ctx.req.query('western_domain') ?? 'javbus.org'; @@ -25,7 +26,9 @@ module.exports = async (ctx) => { throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } - const currentUrl = `${isWestern ? westernUrl : rootUrl}${ctx.path.replace(/^\/western/, '').replace(/\/home/, '')}`; + const currentUrl = `${isWestern ? westernUrl : rootUrl}${getSubPath(ctx) + .replace(/^\/western/, '') + .replace(/\/home/, '')}`; const headers = { 'accept-language': 'zh-CN', diff --git a/lib/v2/javbus/router.js b/lib/v2/javbus/router.js index 4b24a7d56..f54c509e0 100644 --- a/lib/v2/javbus/router.js +++ b/lib/v2/javbus/router.js @@ -1,3 +1,3 @@ module.exports = (router) => { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/keylol/index.js b/lib/v2/keylol/index.js index c8a490dd0..463e70a23 100644 --- a/lib/v2/keylol/index.js +++ b/lib/v2/keylol/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - let thePath = ctx.path.replace(/^\//, ''); + let thePath = getSubPath(ctx).replace(/^\//, ''); if (/^f\d+-\d+/.test(thePath)) { thePath = `fid=${thePath.match(/^f(\d+)-\d+/)[1]}`; diff --git a/lib/v2/keylol/router.js b/lib/v2/keylol/router.js index 02bcb7192..6ea9e73a1 100644 --- a/lib/v2/keylol/router.js +++ b/lib/v2/keylol/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './'); + router.get('*', './'); }; diff --git a/lib/v2/logonews/index.js b/lib/v2/logonews/index.js index 9ac1eb90a..b6d9cd65a 100644 --- a/lib/v2/logonews/index.js +++ b/lib/v2/logonews/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import { art } from '@/utils/render'; import * as path from 'node:path'; module.exports = async (ctx) => { - const params = ctx.path; + const params = getSubPath(ctx); const isWork = params.indexOf('/work') === 0; const rootUrl = 'https://www.logonews.cn'; diff --git a/lib/v2/logonews/router.js b/lib/v2/logonews/router.js index 27a57c5cf..2f82924a3 100644 --- a/lib/v2/logonews/router.js +++ b/lib/v2/logonews/router.js @@ -1,5 +1,5 @@ module.exports = function (router) { router.get('/work/tags/:tag', './index'); router.get('/tag/:tag', './index'); - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/nber/index.js b/lib/v2/nber/index.js index 6bb64b474..e4de3045c 100644 --- a/lib/v2/nber/index.js +++ b/lib/v2/nber/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -17,7 +18,7 @@ module.exports = async (ctx) => { const data = await cache.tryGet(url, () => getData(url), config.cache.routeExpire, false); const items = await Promise.all( data - .filter((article) => ctx.path === '/papers' || article.newthisweek) + .filter((article) => getSubPath(ctx) === '/papers' || article.newthisweek) .map((article) => { const link = `${baseUrl}${article.url}`; return cache.tryGet(link, async () => { diff --git a/lib/v2/nenu/router.js b/lib/v2/nenu/router.js index 3af2953b9..808a6b124 100644 --- a/lib/v2/nenu/router.js +++ b/lib/v2/nenu/router.js @@ -1,4 +1,4 @@ module.exports = function (router) { - router.get(/\/sohac([\w-/]+)?/, './sohac'); - router.get(/\/yjsy([\w-/]+)?/, './yjsy'); + router.get('/sohac/*', './sohac'); + router.get('/yjsy/*', './yjsy'); }; diff --git a/lib/v2/nenu/sohac.js b/lib/v2/nenu/sohac.js index a233d0151..98d9256e0 100644 --- a/lib/v2/nenu/sohac.js +++ b/lib/v2/nenu/sohac.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10; - const path = ctx.path === '/sohac' ? '/index/tzgg' : ctx.path.replace(/^\/sohac/, ''); + const path = getSubPath(ctx) === '/sohac' ? '/index/tzgg' : getSubPath(ctx).replace(/^\/sohac/, ''); const rootUrl = 'https://sohac.nenu.edu.cn'; const currentUrl = `${rootUrl}${path}.htm`; diff --git a/lib/v2/nenu/yjsy.js b/lib/v2/nenu/yjsy.js index cfe90488d..d43890aa9 100644 --- a/lib/v2/nenu/yjsy.js +++ b/lib/v2/nenu/yjsy.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -6,7 +7,7 @@ import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10; - const path = ctx.path === '/yjsy' ? '/tzgg' : ctx.path.replace(/^\/yjsy/, ''); + const path = getSubPath(ctx) === '/yjsy' ? '/tzgg' : getSubPath(ctx).replace(/^\/yjsy/, ''); const rootUrl = 'https://yjsy.nenu.edu.cn'; const currentUrl = `${rootUrl}${path}.htm`; diff --git a/lib/v2/nikkei/cn/index.js b/lib/v2/nikkei/cn/index.js index dca357353..9596e9466 100644 --- a/lib/v2/nikkei/cn/index.js +++ b/lib/v2/nikkei/cn/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -7,7 +8,7 @@ import parser from '@/utils/rss-parser'; module.exports = async (ctx) => { let language = ''; - let path = ctx.path; + let path = getSubPath(ctx); if (/^\/cn\/(cn|zh)/.test(path)) { language = path.match(/^\/cn\/(cn|zh)/)[1]; diff --git a/lib/v2/nikkei/router.js b/lib/v2/nikkei/router.js index eea7eda4a..e3b7fb23c 100644 --- a/lib/v2/nikkei/router.js +++ b/lib/v2/nikkei/router.js @@ -1,7 +1,7 @@ module.exports = (router) => { router.get('/', './index'); router.get('/asia', './asia/index'); - router.get(/\/cn([\w-/]+)?/, './cn/index'); + router.get('/cn/*', './cn/index'); router.get('/index', './index'); router.get('/:category/:article_type?', './news'); }; diff --git a/lib/v2/npm/router.js b/lib/v2/npm/router.js index da8152f56..1a99dc9c3 100644 --- a/lib/v2/npm/router.js +++ b/lib/v2/npm/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/package[\w/-]+/, './package'); + router.get('package/*', './package'); }; diff --git a/lib/v2/nuist/router.js b/lib/v2/nuist/router.js index e0614ae34..d57531cb9 100644 --- a/lib/v2/nuist/router.js +++ b/lib/v2/nuist/router.js @@ -6,5 +6,5 @@ module.exports = function (router) { router.get('/scs/:category?', './scs'); router.get('/sese/:category?', './sese'); router.get('/xgc', './xgc'); - router.get(/yjs\/([\w/-]+)?/, './yjs'); + router.get('/yjs/*', './yjs'); }; diff --git a/lib/v2/nuist/yjs.js b/lib/v2/nuist/yjs.js index 12dbd9452..ab62fe1fe 100644 --- a/lib/v2/nuist/yjs.js +++ b/lib/v2/nuist/yjs.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -5,7 +6,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const path = ctx.path === '/yjs/' ? 'index/tzgg' : ctx.path.replace(/^\/yjs\//, ''); + const path = getSubPath(ctx) === '/yjs/' ? 'index/tzgg' : getSubPath(ctx).replace(/^\/yjs\//, ''); const rootUrl = 'https://yjs.nuist.edu.cn'; const currentUrl = `${rootUrl}/${path}.htm`; diff --git a/lib/v2/pts/index.js b/lib/v2/pts/index.js index d197d614b..bec172319 100644 --- a/lib/v2/pts/index.js +++ b/lib/v2/pts/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://news.pts.org.tw'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '/dailynews' : ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/' ? '/dailynews' : getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/pts/router.js b/lib/v2/pts/router.js index a9ac7f2ab..91d18f6af 100644 --- a/lib/v2/pts/router.js +++ b/lib/v2/pts/router.js @@ -2,6 +2,5 @@ module.exports = function (router) { router.get('/curations', './curations'); router.get('/live/:id', './live'); router.get('/projects', './projects'); - router.get(/([\w-/]+)?/, './index'); - router.get('', './index'); + router.get('*', './index'); }; diff --git a/lib/v2/sinchew/index.js b/lib/v2/sinchew/index.js index 2543bacef..5e5893e62 100644 --- a/lib/v2/sinchew/index.js +++ b/lib/v2/sinchew/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://www.sinchew.com.my'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '' : ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/' ? '' : getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/sinchew/router.js b/lib/v2/sinchew/router.js index 8c677962d..91a6a8441 100644 --- a/lib/v2/sinchew/router.js +++ b/lib/v2/sinchew/router.js @@ -1,4 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); - router.get('', './index'); + router.get('*', './index'); }; diff --git a/lib/v2/thenewslens/index.js b/lib/v2/thenewslens/index.js index b90cbafbf..760b92646 100644 --- a/lib/v2/thenewslens/index.js +++ b/lib/v2/thenewslens/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -7,7 +8,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'https://www.thenewslens.com'; - const currentUrl = `${rootUrl}${ctx.path === '/' ? '/latest-article' : ctx.path}`; + const currentUrl = `${rootUrl}${getSubPath(ctx) === '/' ? '/latest-article' : getSubPath(ctx)}`; const response = await got({ method: 'get', diff --git a/lib/v2/thenewslens/router.js b/lib/v2/thenewslens/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/thenewslens/router.js +++ b/lib/v2/thenewslens/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/web3caff/index.js b/lib/v2/web3caff/index.js index 58cb9e276..4ac05cf7d 100644 --- a/lib/v2/web3caff/index.js +++ b/lib/v2/web3caff/index.js @@ -1,10 +1,11 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const params = ctx.path === '/' ? '' : ctx.path; + const params = getSubPath(ctx) === '/' ? '' : getSubPath(ctx); const rootUrl = 'https://web3caff.com'; const currentUrl = `${rootUrl}${params}`; diff --git a/lib/v2/web3caff/router.js b/lib/v2/web3caff/router.js index fbceb7933..91a6a8441 100644 --- a/lib/v2/web3caff/router.js +++ b/lib/v2/web3caff/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w-/]+)?/, './index'); + router.get('*', './index'); }; diff --git a/lib/v2/yangtzeu/dongke.js b/lib/v2/yangtzeu/dongke.js index cd5d289c8..5002a7a95 100644 --- a/lib/v2/yangtzeu/dongke.js +++ b/lib/v2/yangtzeu/dongke.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ module.exports = async (ctx) => { const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10; const rootUrl = 'https://dongke.yangtzeu.edu.cn'; - const currentUrl = new URL(`${ctx.path.replace(/^\/dongke/, '') || '/yqzl/xyxw'}.htm`, rootUrl).href; + const currentUrl = new URL(`${getSubPath(ctx).replace(/^\/dongke/, '') || '/yqzl/xyxw'}.htm`, rootUrl).href; const { data: response } = await got(currentUrl); diff --git a/lib/v2/yangtzeu/router.js b/lib/v2/yangtzeu/router.js index dd4cc466b..a426379d1 100644 --- a/lib/v2/yangtzeu/router.js +++ b/lib/v2/yangtzeu/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/dongke([\w-/]+)?/, './dongke'); + router.get('/dongke/*', './dongke'); }; diff --git a/lib/v2/zyshow/index.js b/lib/v2/zyshow/index.js index 70401dcbd..39fb30d21 100644 --- a/lib/v2/zyshow/index.js +++ b/lib/v2/zyshow/index.js @@ -1,3 +1,4 @@ +import { getSubPath } from '@/utils/common-utils'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -6,7 +7,7 @@ import * as path from 'node:path'; module.exports = async (ctx) => { const rootUrl = 'http://www.zyshow.net'; - const currentUrl = `${rootUrl}${ctx.path.replace(/\/$/, '')}/`; + const currentUrl = `${rootUrl}${getSubPath(ctx).replace(/\/$/, '')}/`; const response = await got({ method: 'get', diff --git a/lib/v2/zyshow/router.js b/lib/v2/zyshow/router.js index e039ea82a..91a6a8441 100644 --- a/lib/v2/zyshow/router.js +++ b/lib/v2/zyshow/router.js @@ -1,3 +1,3 @@ module.exports = function (router) { - router.get(/([\w/-]+)?/, './index'); + router.get('*', './index'); };