
|
${item.description}
`, })); - ctx.state.data = { + ctx.set('data', { title: '快讯 - Odaily星球日报', link: `${rootUrl}/newsflash`, item: items, - }; + }); }; diff --git a/lib/v2/odaily/post.js b/lib/v2/odaily/post.js index 6155181ec7..0d049fba24 100644 --- a/lib/v2/odaily/post.js +++ b/lib/v2/odaily/post.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); const titles = { @@ -16,9 +16,9 @@ const titles = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? '280'; + const id = ctx.req.param('id') ?? '280'; - const currentUrl = `${rootUrl}/api/pp/api/app-front/feed-stream?feed_id=${id}&b_id=&per_page=${ctx.query.limit ?? 25}`; + const currentUrl = `${rootUrl}/api/pp/api/app-front/feed-stream?feed_id=${id}&b_id=&per_page=${ctx.req.query('limit') ?? 25}`; const response = await got(currentUrl); @@ -39,7 +39,7 @@ module.exports = async (ctx) => { const ssr = JSON.parse(`{${detailResponse.data.match(/window\.__INITIAL_STATE__ = {(.*)}/)[1]}}`); - const content = cheerio.load(ssr.post.detail.content, null, false); + const content = load(ssr.post.detail.content, null, false); content('img').each((_, img) => { img.attribs.src = img.attribs.src.split('?x-oss-process')[0]; img.attribs.src = img.attribs.src.split('!heading')[0]; @@ -55,9 +55,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${titles[id]} - Odaily星球日报`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/odaily/search-news.js b/lib/v2/odaily/search-news.js index 65dcae6466..d52c90968c 100644 --- a/lib/v2/odaily/search-news.js +++ b/lib/v2/odaily/search-news.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); module.exports = async (ctx) => { - const currentUrl = `${rootUrl}/api/pp/api/search/entity-search?per_page=${ctx.query.limit ?? 25}&keyword=${ctx.params.keyword}&entity_type=newsflash`; + const currentUrl = `${rootUrl}/api/pp/api/search/entity-search?per_page=${ctx.req.query('limit') ?? 25}&keyword=${ctx.req.param('keyword')}&entity_type=newsflash`; const response = await got({ method: 'get', @@ -18,9 +18,9 @@ module.exports = async (ctx) => { description: `${item.description}
`, })); - ctx.state.data = { + ctx.set('data', { title: '快讯 - Odaily星球日报', - link: `${rootUrl}/search/${ctx.params.keyword}`, + link: `${rootUrl}/search/${ctx.req.param('keyword')}`, item: items, - }; + }); }; diff --git a/lib/v2/odaily/user.js b/lib/v2/odaily/user.js index 89b3b76580..752e10dd7b 100644 --- a/lib/v2/odaily/user.js +++ b/lib/v2/odaily/user.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); - const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.query.limit ?? 25}`; + const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.req.query('limit') ?? 25}`; let author = ''; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); + const content = load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); content('img').each(function () { content(this).attr('src', content(this).attr('src').replaceAll('\\"', '')); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${author} - Odaily星球日报`, link: `${rootUrl}/user/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/app/channel.js b/lib/v2/oeeee/app/channel.js index 882791b5ea..deb6c06444 100644 --- a/lib/v2/oeeee/app/channel.js +++ b/lib/v2/oeeee/app/channel.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { parseArticle } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? 50; + const id = ctx.req.param('id') ?? 50; const currentUrl = `https://api-ndapp.oeeee.com/friends.php?m=Zone&a=SpaceDoclist&uid=${id}&type=doc`; const { data: response } = await got(currentUrl); @@ -28,9 +28,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报客户端 - ${channel}`, link: `https://m.mp.oeeee.com/u/${id}.html`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/app/reporter.js b/lib/v2/oeeee/app/reporter.js index f1d486c24e..729f75f041 100644 --- a/lib/v2/oeeee/app/reporter.js +++ b/lib/v2/oeeee/app/reporter.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseArticle } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? 0; + const id = ctx.req.param('id') ?? 0; const currentUrl = `https://m.mp.oeeee.com/show.php?m=Doc&a=getAuthorInfo&id=${id}`; const { data: response } = await got(currentUrl); @@ -22,9 +22,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报奥一网 - ${author}`, link: `https://m.mp.oeeee.com/w/${id}.html`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/utils.js b/lib/v2/oeeee/utils.js index 67e93378cd..3e4c9fc215 100644 --- a/lib/v2/oeeee/utils.js +++ b/lib/v2/oeeee/utils.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const parseArticle = (item, tryGet) => tryGet(item.link, async () => { @@ -10,7 +10,7 @@ const parseArticle = (item, tryGet) => url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); // nfapp page: if (content('.post-cont') && content('.post-cont').html()) { diff --git a/lib/v2/oeeee/web.js b/lib/v2/oeeee/web.js index 3bc8ecd616..d527be11ba 100644 --- a/lib/v2/oeeee/web.js +++ b/lib/v2/oeeee/web.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { parseArticle } = require('./utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const channel = ctx.params.channel ?? 0; + const channel = ctx.req.param('channel') ?? 0; const currentUrl = `https://www.oeeee.com/api/channel.php?m=Js4channelNews&a=newLatest&cid=${channel}`; const { data: response } = await got(currentUrl); @@ -28,9 +28,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报奥一网`, link: `https://www.oeeee.com/api/channel.php?s=/index/index/channel/${channelEname}`, item: items, - }; + }); }; diff --git a/lib/v2/oilchem/index.js b/lib/v2/oilchem/index.js index 4de1945c1d..f8710111ad 100644 --- a/lib/v2/oilchem/index.js +++ b/lib/v2/oilchem/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const routes = require('./routes'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const type = ctx.params.type ?? ''; - const category = ctx.params.category ?? ''; - const subCategory = ctx.params.subCategory ?? ''; + const type = ctx.req.param('type') ?? ''; + const category = ctx.req.param('category') ?? ''; + const subCategory = ctx.req.param('subCategory') ?? ''; const route = category === '' ? '' : `/${category}${subCategory === '' ? '' : `/${subCategory}`}`; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list ul ul li a') .map((_, item) => { @@ -39,7 +39,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#content').html(); item.pubDate = timezone( @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.hdbox h3').text()} - 隆众资讯`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/oncc/index.js b/lib/v2/oncc/index.js index 8214931ad1..9e00bb4aa5 100644 --- a/lib/v2/oncc/index.js +++ b/lib/v2/oncc/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const rootUrl = 'https://hk.on.cc'; @@ -35,12 +35,12 @@ const channelMap = { }; module.exports = async (ctx) => { - const language = ctx.params.language; - const channel = ctx.params.channel ?? 'news'; + const language = ctx.req.param('language'); + const channel = ctx.req.param('channel') ?? 'news'; const newsUrl = `${rootUrl}/hk/${channel}/index${languageMap[language]}.html`; const response = await got.get(newsUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#focusNews > div.focusItem[type=article]') .map((_, item) => { const title = $(item).find('div.focusTitle > span').text(); @@ -59,7 +59,7 @@ module.exports = async (ctx) => { list.map(async (item) => { const desc = await ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const imageUrl = rootUrl + $('img').eq(0).attr('src'); const content = $('div.breakingNewsContent').html(); const description = art(path.join(__dirname, 'templates/article.art'), { @@ -75,9 +75,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `東網 - ${channelMap[channel][language]}`, link: newsUrl, item: items, - }; + }); }; diff --git a/lib/v2/oncc/money18.js b/lib/v2/oncc/money18.js index edf14b54ec..dc77e3706e 100644 --- a/lib/v2/oncc/money18.js +++ b/lib/v2/oncc/money18.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const sections = { @@ -20,8 +20,8 @@ const sections = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'exp'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30; + const id = ctx.req.param('id') ?? 'exp'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30; const rootUrl = 'https://money18.on.cc'; const currentUrl = `${rootUrl}/finnews/news_${id === 'industry' ? 'industry.html' : `breaking.html?section=${id}`}`; @@ -92,7 +92,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = art(path.join(__dirname, 'templates/money18.art'), { images: content('.photo img') @@ -107,9 +107,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `東網產經 - ${sections[id]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/onehu/common.js b/lib/v2/onehu/common.js index 705184a3d9..0f4e260ad8 100644 --- a/lib/v2/onehu/common.js +++ b/lib/v2/onehu/common.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'https://onehu.xyz'; const response = await got(link); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#board article') .toArray() .map((item) => { @@ -20,9 +20,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link, item: list, - }; + }); }; diff --git a/lib/v2/onet/news.js b/lib/v2/onet/news.js index 225e146a73..bbe8c025ae 100644 --- a/lib/v2/onet/news.js +++ b/lib/v2/onet/news.js @@ -1,8 +1,8 @@ const parser = require('@/utils/rss-parser'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { parseArticleContent, parseMainImage } = require('./utils'); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const content = parseArticleContent($); const mainImage = parseMainImage($); @@ -45,12 +45,12 @@ module.exports = async (ctx) => { }; }) ); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.title, item: items, language: 'pl', image: 'https://ocdn.eu/wiadomosciucs/static/logo2017/onet2017big_dark.png', - }; + }); }; diff --git a/lib/v2/onet/utils.js b/lib/v2/onet/utils.js index af8a9a8145..061df7b39d 100644 --- a/lib/v2/onet/utils.js +++ b/lib/v2/onet/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const parseMainImage = ($) => { diff --git a/lib/v2/oo-software/changelog.js b/lib/v2/oo-software/changelog.js index 3a0fb7998c..2da0e7e613 100644 --- a/lib/v2/oo-software/changelog.js +++ b/lib/v2/oo-software/changelog.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'shutup10'; + const id = ctx.req.param('id') ?? 'shutup10'; const rootUrl = 'https://www.oo-software.com'; const currentUrl = `${rootUrl}/en/${id}/changelog`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.content h4') .toArray() @@ -32,9 +32,9 @@ module.exports = async (ctx) => { items[0].enclosure_url = $('.banner-inlay').find('a').attr('href'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/openai/blog.js b/lib/v2/openai/blog.js index 327005fabe..9d352abe2d 100644 --- a/lib/v2/openai/blog.js +++ b/lib/v2/openai/blog.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { toTitleCase } = require('@/utils/common-utils'); const { getApiUrl, parseArticle } = require('./common'); module.exports = async (ctx) => { - const tag = ctx.params.tag || ''; + const tag = ctx.req.param('tag') || ''; const rootUrl = 'https://openai.com'; const blogRootUrl = 'https://openai.com/blog'; @@ -36,9 +36,9 @@ module.exports = async (ctx) => { const title = `OpenAI Blog${tag ? ` - ${toTitleCase(tag)}` : ''}`; - ctx.state.data = { + ctx.set('data', { title, link: blogOriginUrl, item: items, - }; + }); }; diff --git a/lib/v2/openai/chatgpt.js b/lib/v2/openai/chatgpt.js index 717d249136..0a5daaef23 100644 --- a/lib/v2/openai/chatgpt.js +++ b/lib/v2/openai/chatgpt.js @@ -1,7 +1,7 @@ const dayjs = require('dayjs'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; dayjs.extend(require('dayjs/plugin/isSameOrBefore')); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: articleUrl, }); - const $ = cheerio.load(pageResponse.data); + const $ = load(pageResponse.data); const page = JSON.parse($('script#__NEXT_DATA__').text()); // 页面貌似是用 Next 渲染的,有现成的 JSON 数据可以直接 parse,而避免用 cheerio 去解析主体内容的 HTML const feedTitle = page.props.pageProps.articleContent.title; @@ -89,10 +89,10 @@ module.exports = async (ctx) => { false ); - ctx.state.data = { + ctx.set('data', { title: cache.feedTitle, description: cache.feedDesc, link: articleUrl, item: cache.items, - }; + }); }; diff --git a/lib/v2/openai/common.js b/lib/v2/openai/common.js index 6bf6c9ea01..5e6eeb8faa 100644 --- a/lib/v2/openai/common.js +++ b/lib/v2/openai/common.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); const getApiUrl = async () => { @@ -27,7 +27,7 @@ const parseArticle = (ctx, rootUrl, attributes) => method: 'get', url: textUrl, }); - let content = cheerio.load(detailResponse.data); + let content = load(detailResponse.data); const authors = content('[aria-labelledby="metaAuthorsHeading"] > li > a > span > span') .toArray() diff --git a/lib/v2/openai/research.js b/lib/v2/openai/research.js index 3af8174a3e..b4ef832b48 100644 --- a/lib/v2/openai/research.js +++ b/lib/v2/openai/research.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { getApiUrl, parseArticle } = require('./common'); module.exports = async (ctx) => { @@ -24,9 +24,9 @@ module.exports = async (ctx) => { const title = 'OpenAI Research'; - ctx.state.data = { + ctx.set('data', { title, link: researchRootUrl, item: items, - }; + }); }; diff --git a/lib/v2/openwrt/releases.js b/lib/v2/openwrt/releases.js index 7cb8b5e52e..9cbee47883 100644 --- a/lib/v2/openwrt/releases.js +++ b/lib/v2/openwrt/releases.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const brand = ctx.params.brand; - const model = ctx.params.model; + const brand = ctx.req.param('brand'); + const model = ctx.req.param('model'); const url = `https://openwrt.org/toh/${brand}/${model}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const table = $('#installation').next(); - ctx.state.data = { + ctx.set('data', { title: $('h1').text() + ' - OpenWrt Releases', link: url, description: $('.dw-content div.level1').text(), @@ -21,5 +21,5 @@ module.exports = async (ctx) => { description: `Firmware OpenWrt Install: ${table.find('.firmware_openwrt_install_url').html()}${$('.head-info-desc').text()}
`, - }; + }); }; diff --git a/lib/v2/qq/ac/rank.js b/lib/v2/qq/ac/rank.js index 9093d263e9..f9e9865f96 100644 --- a/lib/v2/qq/ac/rank.js +++ b/lib/v2/qq/ac/rank.js @@ -11,8 +11,8 @@ module.exports = async (ctx) => { female: '女生榜', }; - const type = ctx.params.type ?? 'mt'; - const time = ctx.params.time ?? 'cur'; + const type = ctx.req.param('type') ?? 'mt'; + const time = ctx.req.param('time') ?? 'cur'; const currentUrl = `${rootUrl}/Rank/comicRank/type/${type}`; diff --git a/lib/v2/qq/ac/utils.js b/lib/v2/qq/ac/utils.js index df3af92f2f..f8fa90dfa1 100644 --- a/lib/v2/qq/ac/utils.js +++ b/lib/v2/qq/ac/utils.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); const rootUrl = 'https://ac.qq.com'; @@ -15,10 +15,10 @@ module.exports = { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $(`${time ? `.${time}-month-data ` : ''}.text-overflow`) - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -38,7 +38,7 @@ module.exports = { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.link = item.guid; item.author = content('.author-wr') diff --git a/lib/v2/qq/fact/index.js b/lib/v2/qq/fact/index.js index 7b6b2a8bd7..45512d82f9 100644 --- a/lib/v2/qq/fact/index.js +++ b/lib/v2/qq/fact/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; const CryptoJS = require('crypto-js'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const getRequestToken = () => { @@ -38,7 +38,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const { initialState } = nextData.props.pageProps; @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '较真查证平台 - 腾讯新闻', link: `${baseUrl}/home`, item: items, - }; + }); }; diff --git a/lib/v2/qq/kg/cache.js b/lib/v2/qq/kg/cache.js index e3241eb489..4e6db07474 100644 --- a/lib/v2/qq/kg/cache.js +++ b/lib/v2/qq/kg/cache.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); module.exports = { diff --git a/lib/v2/qq/kg/reply.js b/lib/v2/qq/kg/reply.js index 35bffe0068..78909cb301 100644 --- a/lib/v2/qq/kg/reply.js +++ b/lib/v2/qq/kg/reply.js @@ -1,12 +1,12 @@ const cache = require('./cache'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const playId = ctx.params.playId; + const playId = ctx.req.param('playId'); const url = `https://node.kg.qq.com/play?s=${playId}`; const play_item = await cache.getPlayInfo(ctx, playId, ''); - ctx.state.data = { + ctx.set('data', { title: `${play_item.name} - ${play_item.author} 的评论`, link: url, image: play_item.itunes_item_image, @@ -17,5 +17,5 @@ module.exports = async (ctx) => { link: url, guid: `ksong:${play_item.ksong_mid}:${item.comment_id}`, })), - }; + }); }; diff --git a/lib/v2/qq/kg/user.js b/lib/v2/qq/kg/user.js index 8194507571..caac932c31 100644 --- a/lib/v2/qq/kg/user.js +++ b/lib/v2/qq/kg/user.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); const cache = require('./cache'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const userId = ctx.params.userId; + const userId = ctx.req.param('userId'); const url = `https://node.kg.qq.com/personal?uid=${userId}`; const response = await got(url); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${author} - 全民K歌`, link: url, description: data.share.content, @@ -46,5 +46,5 @@ module.exports = async (ctx) => { image: authorimg, itunes_author: author, itunes_category: '全民K歌', - }; + }); }; diff --git a/lib/v2/qq88/index.js b/lib/v2/qq88/index.js index 5bc35a9f3b..b478119157 100644 --- a/lib/v2/qq88/index.js +++ b/lib/v2/qq88/index.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; const rootUrl = 'https://qq88.info'; const currentUrl = category ? `${rootUrl}/?cat=${category}` : rootUrl; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.entry-title a') .slice(0, 15) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const links = content('.entry-content').find('a[download]'); @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.page-title').text() || '首页'} - 秋爸日字`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qqorw/index.js b/lib/v2/qqorw/index.js index efc7c13912..773a080518 100644 --- a/lib/v2/qqorw/index.js +++ b/lib/v2/qqorw/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category = '' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 10; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10; const rootUrl = 'https://qqorw.cn'; const currentUrl = new URL(category, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('article.excerpt') .slice(0, limit) @@ -40,7 +40,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('div.contenttxt').prev().nextAll().remove(); @@ -62,7 +62,7 @@ module.exports = async (ctx) => { const icon = new URL('favicon.ico', rootUrl).href; const title = $('header.archive-header h1 a').last().text(); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${title ? ` - ${title}` : ''}`, link: currentUrl, @@ -73,5 +73,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="keywords"]').prop('content'), author, - }; + }); }; diff --git a/lib/v2/questmobile/report.js b/lib/v2/questmobile/report.js index 6700b676f6..fb22b93f0d 100644 --- a/lib/v2/questmobile/report.js +++ b/lib/v2/questmobile/report.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); /** @@ -26,7 +26,7 @@ const parseTree = (tree, result = []) => { module.exports = async (ctx) => { const { industry, label } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://www.questmobile.com.cn'; const apiUrl = new URL('api/v2/report/article-list', rootUrl).href; @@ -80,7 +80,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('div.text div.daoyu').remove(); @@ -104,14 +104,14 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[property="og:title"]').prop('content').split(/-/)[0]; const categories = [industryObj?.value, labelObj?.value].filter(Boolean); const image = $(`img[alt="${author}"]`).prop('src'); const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${categories.length === 0 ? '' : ` - ${categories.join(' - ')}`}`, link: currentUrl, @@ -123,5 +123,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/qa.js b/lib/v2/quicker/qa.js index 28dc7d9e6b..98b732d97c 100644 --- a/lib/v2/quicker/qa.js +++ b/lib/v2/quicker/qa.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'all'; - const state = ctx.params.state ?? ''; + const category = ctx.req.param('category') ?? 'all'; + const state = ctx.req.param('state') ?? ''; const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/QA${category === 'all' ? '' : `?category=${category}`}${state ? `?state=${state}` : ''}`; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a.question-title') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('div[data-note="最后更新人信息"]').remove(); @@ -56,10 +56,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/share.js b/lib/v2/quicker/share.js index 8c16cb06d6..623bf86b36 100644 --- a/lib/v2/quicker/share.js +++ b/lib/v2/quicker/share.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'Recent'; + const category = ctx.req.param('category') ?? 'Recent'; const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/Share/${category}`; @@ -14,10 +14,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('table tbody tr') - .slice(1, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(1, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item).find('td a').first(); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('section').last().remove(); content('#app').children().slice(0, 2).remove(); @@ -52,10 +52,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/user.js b/lib/v2/quicker/user.js index cdbedcc0b1..8686e79805 100644 --- a/lib/v2/quicker/user.js +++ b/lib/v2/quicker/user.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category; - const id = ctx.params.id; + const category = ctx.req.param('category'); + const id = ctx.req.param('id'); const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/User/${category}/${id}`; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('table tbody tr') - .slice(1, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(1, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item).find('td a').first(); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('section').last().remove(); content('#app').children().slice(0, 2).remove(); @@ -53,10 +53,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/versions.js b/lib/v2/quicker/versions.js index ece5f7a0e3..1f4e4533d6 100644 --- a/lib/v2/quicker/versions.js +++ b/lib/v2/quicker/versions.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://getquicker.net'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.version') .toArray() @@ -28,9 +28,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qweather/3days.js b/lib/v2/qweather/3days.js index f3f7e8c03a..9f6cf76d74 100644 --- a/lib/v2/qweather/3days.js +++ b/lib/v2/qweather/3days.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; const WEATHER_API = 'https://devapi.qweather.com/v7/weather/3d'; const AIR_QUALITY_API = 'https://devapi.qweather.com/v7/air/5d'; @@ -12,12 +12,12 @@ module.exports = async (ctx) => { if (!config.hefeng.key) { throw new Error('QWeather RSS is disabled due to the lack of relevant config'); } - const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => { - const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.params.location}&key=${config.hefeng.key}`); + const id = await ctx.cache.tryGet(ctx.req.param('location') + '_id', async () => { + const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.req.param('location')}&key=${config.hefeng.key}`); return response.data.location[0].id; }); const weatherData = await ctx.cache.tryGet( - ctx.params.location, + ctx.req.param('location'), async () => { const response = await got(`${WEATHER_API}?key=${config.hefeng.key}&location=${id}`); return response.data; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { false ); const airQualityData = await ctx.cache.tryGet( - `qweather:air:${ctx.params.location}`, + `qweather:air:${ctx.req.param('location')}`, async () => { const airQualityResponse = await got(`${AIR_QUALITY_API}?location=${id}&key=${config.hefeng.key}`); return airQualityResponse.data; @@ -58,16 +58,16 @@ module.exports = async (ctx) => { item, }), pubDate: combined.updateTime, - guid: '位置:' + ctx.params.location + '--日期:' + item.fxDate, + guid: '位置:' + ctx.req.param('location') + '--日期:' + item.fxDate, link: combined.fxLink, author, })); - ctx.state.data = { - title: ctx.params.location + '未来三天天气', - description: ctx.params.location + '未来三天天气情况,使用和风彩云 API (包括空气质量)', + ctx.set('data', { + title: ctx.req.param('location') + '未来三天天气', + description: ctx.req.param('location') + '未来三天天气情况,使用和风彩云 API (包括空气质量)', item: items, link: combined.fxLink, author, - }; + }); }; diff --git a/lib/v2/qweather/now.js b/lib/v2/qweather/now.js index dabeb667b3..1455ea66ca 100644 --- a/lib/v2/qweather/now.js +++ b/lib/v2/qweather/now.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const rootUrl = 'https://devapi.qweather.com/v7/weather/now?'; module.exports = async (ctx) => { - const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => { - const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.params.location}&key=${config.hefeng.key}`); + const id = await ctx.cache.tryGet(ctx.req.param('location') + '_id', async () => { + const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.req.param('location')}&key=${config.hefeng.key}`); const data = []; for (const i in response.data.location) { data.push(response.data.location[i]); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { }); const requestUrl = rootUrl + 'key=' + config.hefeng.key + '&location=' + id; const responseData = await ctx.cache.tryGet( - ctx.params.location + '_now', + ctx.req.param('location') + '_now', async () => { const response = await got(requestUrl); return response.data; @@ -30,16 +30,16 @@ module.exports = async (ctx) => { const time_show = timeObj.toLocaleString(); - ctx.state.data = { - title: ctx.params.location + '实时天气', - description: ctx.params.location + '实时天气状况', + ctx.set('data', { + title: ctx.req.param('location') + '实时天气', + description: ctx.req.param('location') + '实时天气状况', item: data.map((item) => ({ title: '观测时间:' + time_show, description: art(path.join(__dirname, 'templates/now.art'), { item }), pubDate: timeObj, - guid: '位置:' + ctx.params.location + '--时间:' + time_show, + guid: '位置:' + ctx.req.param('location') + '--时间:' + time_show, link: responseData.fxLink, })), link: responseData.fxLink, - }; + }); }; diff --git a/lib/v2/radio-canada/latest.js b/lib/v2/radio-canada/latest.js index c5aa007c99..39ff5b5e1f 100644 --- a/lib/v2/radio-canada/latest.js +++ b/lib/v2/radio-canada/latest.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const language = ctx.params.language ?? 'en'; + const language = ctx.req.param('language') ?? 'en'; const rootUrl = 'https://ici.radio-canada.ca'; const apiRootUrl = 'https://services.radio-canada.ca'; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { url: item.link, }); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const rcState = $('script:contains("window._rcState_ = JSON.parse")') .text() .match(/JSON\.parse\((".*")\);/)[1]; @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: response.data.meta.title, link: response.data.metric.metrikContent.omniture.url, item: items, - }; + }); }; diff --git a/lib/v2/radio/album.js b/lib/v2/radio/album.js index 456e2e614a..be5984f98c 100644 --- a/lib/v2/radio/album.js +++ b/lib/v2/radio/album.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const CryptoJS = require('crypto-js'); module.exports = async (ctx) => { const KEY = 'f0fc4c668392f9f9a447e48584c214ee'; - const id = ctx.params.id; - const size = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; const rootUrl = 'https://www.radio.cn'; const apiRootUrl = 'https://ytmsout.radio.cn'; @@ -94,7 +94,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data.columnName}`, link: currentUrl, item: items, @@ -102,5 +102,5 @@ module.exports = async (ctx) => { itunes_author: data.anchorpersons, description: data.descriptions ?? data.descriptionSimple, itunes_category: data.atypeInfo.map((c) => c.categoryName).join(','), - }; + }); }; diff --git a/lib/v2/radio/index.js b/lib/v2/radio/index.js index 182c4c9eda..f14beb0186 100644 --- a/lib/v2/radio/index.js +++ b/lib/v2/radio/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id; - const size = ctx.query.limit ?? '100'; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ?? '100'; const rootUrl = 'https://www.radio.cn'; const apiRootUrl = 'http://tacc.radio.cn'; @@ -44,12 +44,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data.odchannel.name}`, link: currentUrl, item: items, image: data.odchannel.imageUrl[0].url, itunes_author: data.odchannel.commissioningEditorName || data.odchannel.editorName || data.odchannel.source || 'radio.cn', description: data.odchannel.description || data.odchannel.sub_title || '', - }; + }); }; diff --git a/lib/v2/radio/zhibo.js b/lib/v2/radio/zhibo.js index 3f52df1ffe..233b4529b7 100644 --- a/lib/v2/radio/zhibo.js +++ b/lib/v2/radio/zhibo.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const CryptoJS = require('crypto-js'); module.exports = async (ctx) => { const KEY = 'f0fc4c668392f9f9a447e48584c214ee'; - const id = ctx.params.id; - const size = ctx.query.limit ?? '100'; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ?? '100'; const params = `columnId=${id}&pageNo=0&pageSize=${size}`; @@ -62,12 +62,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data[0].name}`, link: currentUrl, item: items, image: iconUrl, itunes_author: 'radio.cn', description: data[0].des, - }; + }); }; diff --git a/lib/v2/rarehistoricalphotos/index.js b/lib/v2/rarehistoricalphotos/index.js index c95f91c569..7587a37e95 100644 --- a/lib/v2/rarehistoricalphotos/index.js +++ b/lib/v2/rarehistoricalphotos/index.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const baseUrl = 'https://rarehistoricalphotos.com'; module.exports = async (ctx) => { const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ? Number(ctx.query.limit) : undefined, + per_page: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : undefined, }, }); @@ -17,12 +17,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.date_gmt), })); - ctx.state.data = { + ctx.set('data', { title: 'Rare Historical Photos', description: 'And the story behind them...', link: baseUrl, image: 'https://rarehistoricalphotos.com/wp-content/uploads/2022/04/cropped-rarehistoricalphotos-32x32.png', language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/rattibha/user.js b/lib/v2/rattibha/user.js index 124c4a657a..31725908e0 100644 --- a/lib/v2/rattibha/user.js +++ b/lib/v2/rattibha/user.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://rattibha.com'; @@ -37,9 +37,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `سلاسل تغريدات ${twitterUser}`, link: `${baseUrl}/${twitterUser}`, item: items, - }; + }); }; diff --git a/lib/v2/rawkuma/manga.js b/lib/v2/rawkuma/manga.js index 191af83081..9c8bf55bba 100644 --- a/lib/v2/rawkuma/manga.js +++ b/lib/v2/rawkuma/manga.js @@ -1,19 +1,19 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://rawkuma.com'; const currentUrl = new URL(`/manga/${id}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const author = $('div.fmed span').eq(1).text().trim(); const category = $('div.wd-full span.mgen a[rel="tag"]') @@ -42,7 +42,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); const imageMatches = detailResponse.match(/"images":(\[.*?])}],"lazyload"/); @@ -67,7 +67,7 @@ module.exports = async (ctx) => { .prop('href') .replace(/-\d+x\d+/, ''); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -77,5 +77,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('div.wd-full span').text(), author, - }; + }); }; diff --git a/lib/v2/reactnewsletter/reactnewsletter.js b/lib/v2/reactnewsletter/reactnewsletter.js index 3c20d2f48b..2433949851 100644 --- a/lib/v2/reactnewsletter/reactnewsletter.js +++ b/lib/v2/reactnewsletter/reactnewsletter.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const currentURL = 'https://reactnewsletter.com/issues'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const resp = await got(currentURL); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const text = $('script#__NEXT_DATA__').text(); const json = JSON.parse(text); @@ -16,10 +16,10 @@ module.exports = async (ctx) => { link: `/issues/${item.slug}`, })); - ctx.state.data = { + ctx.set('data', { title: 'reactnewsletter.dev', description: 'Stay up to date on the latest React news, tutorials, resources, and more. Delivered every Tuesday, for free.', link: currentURL, item: items, - }; + }); }; diff --git a/lib/v2/readhub/daily.js b/lib/v2/readhub/daily.js index 9dfbfdb7f3..bbcd53047e 100644 --- a/lib/v2/readhub/daily.js +++ b/lib/v2/readhub/daily.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, processItems } = require('./util'); module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 11; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11; const currentUrl = new URL('daily', rootUrl).href; @@ -20,14 +20,14 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[name="application-name"]').prop('content'); const subtitle = $('meta[property="og:title"]').prop('content'); const image = 'https://readhub-oss.nocode.com/static/readhub.png'; const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -39,5 +39,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/readhub/index.js b/lib/v2/readhub/index.js index e64428a2f5..a71fe1aaa6 100644 --- a/lib/v2/readhub/index.js +++ b/lib/v2/readhub/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); const { rootUrl, apiTopicUrl, art, processItems } = require('./util'); module.exports = async (ctx) => { const { category = '' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; const currentUrl = new URL(category ?? '', rootUrl).href; @@ -39,14 +39,14 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[property="og:site_name"]').prop('content'); const subtitle = $(`a[data-path="/${category}"]`).text(); const image = $('link[rel="preload"][as="image"]').prop('href'); const icon = $('meta[property="og:image"]').prop('content'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -58,5 +58,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/readhub/util.js b/lib/v2/readhub/util.js index b6890d4a54..afb35e63d1 100644 --- a/lib/v2/readhub/util.js +++ b/lib/v2/readhub/util.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const dayjs = require('dayjs'); diff --git a/lib/v2/remnote/changelog.js b/lib/v2/remnote/changelog.js index 9b4c419f48..7090ca5290 100644 --- a/lib/v2/remnote/changelog.js +++ b/lib/v2/remnote/changelog.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const FQDN = 'feedback.remnote.com'; const apiGateway = 'https://gateway.hellonext.co'; @@ -21,12 +21,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.published_at.timestamp), })); - ctx.state.data = { + ctx.set('data', { title: 'Changelog | RemNote', description: 'Vote or request new RemNote features. Subscribe to get updates about new features from RemNote.', link: `https://${FQDN}/changelog`, image: 'https://vault.hnxt.dev/uploads/organization_customization/favicon/3970/88153ff13b4b03492ddfee6e675228c1.png', item: items, language: 'en-US', - }; + }); }; diff --git a/lib/v2/researchgate/publications.js b/lib/v2/researchgate/publications.js index 8451f6c672..af2914cf40 100644 --- a/lib/v2/researchgate/publications.js +++ b/lib/v2/researchgate/publications.js @@ -1,12 +1,13 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://www.researchgate.net'; const currentUrl = `${rootUrl}/profile/${id}`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -16,11 +17,11 @@ module.exports = async (ctx) => { const response = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const $ = cheerio.load(response); + const $ = load(response); const list = $('div[itemprop="headline"] a') .toArray() - .slice(0, ctx.query.limit ? Number(ctx.query.limit) : 15) + .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 15) .map((item) => { item = $(item); return { @@ -40,7 +41,7 @@ module.exports = async (ctx) => { await page.goto(item.link); const detailResponse = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.doi = content('meta[property="citation_doi"]').attr('content'); item.pubDate = parseDate(content('meta[property="citation_publication_date"]').attr('content')); @@ -62,9 +63,9 @@ module.exports = async (ctx) => { await browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${$('meta[property="profile:username"]').attr('content')}'s Publications - ResearchGate`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/reuters/common.js b/lib/v2/reuters/common.js index 5fa03002bc..c4a0641f0d 100644 --- a/lib/v2/reuters/common.js +++ b/lib/v2/reuters/common.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const MUST_FETCH_BY_TOPICS = new Set(['authors']); const CAN_USE_SOPHI = ['world']; - const category = ctx.params.category; - const topic = ctx.params.topic ?? (category === 'authors' ? 'reuters' : ''); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; - const useSophi = ctx.query.sophi === 'true' && 'topic' !== '' && CAN_USE_SOPHI.includes(category); + const category = ctx.req.param('category'); + const topic = ctx.req.param('topic') ?? (category === 'authors' ? 'reuters' : ''); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; + const useSophi = ctx.req.query('sophi') === 'true' && 'topic' !== '' && CAN_USE_SOPHI.includes(category); const section_id = `/${category}/${topic ? `${topic}/` : ''}`; const { title, description, rootUrl, response } = await (async () => { @@ -77,10 +77,10 @@ module.exports = async (ctx) => { const results = await Promise.allSettled( items.map((item) => - ctx.query.mode === 'fulltext' + ctx.req.query('mode') === 'fulltext' ? ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); if (detailResponse.url.startsWith('https://www.reuters.com/investigates/')) { const ldJson = JSON.parse(content('script[type="application/ld+json"]').text()); @@ -131,11 +131,11 @@ module.exports = async (ctx) => { ); items = results.filter((r) => r.status === 'fulfilled').map((r) => r.value); - ctx.state.data = { + ctx.set('data', { title, description, image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116', link: `https://www.reuters.com${section_id}`, item: items, - }; + }); }; diff --git a/lib/v2/reuters/investigates.js b/lib/v2/reuters/investigates.js index f61016eb8d..2c337bb2f4 100644 --- a/lib/v2/reuters/investigates.js +++ b/lib/v2/reuters/investigates.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.reuters.com'; const currentUrl = `${rootUrl}/investigates/`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('article.section-article-container.row') .map((_, item) => ({ @@ -19,7 +19,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('title').text(); item.description = content('article.special-report').html(); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('h1.series-subtitle').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/rfa/index.js b/lib/v2/rfa/index.js index e73e200d49..9f94cee2f3 100644 --- a/lib/v2/rfa/index.js +++ b/lib/v2/rfa/index.js @@ -1,19 +1,19 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - let url = 'https://www.rfa.org/' + (ctx.params.language ?? 'english'); + let url = 'https://www.rfa.org/' + (ctx.req.param('language') ?? 'english'); - if (ctx.params.channel) { - url += '/' + ctx.params.channel; + if (ctx.req.param('channel')) { + url += '/' + ctx.req.param('channel'); } - if (ctx.params.subChannel) { - url += '/' + ctx.params.subChannel; + if (ctx.req.param('subChannel')) { + url += '/' + ctx.req.param('subChannel'); } const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const selectors = ['div[id=topstorywidefull]', 'div.two_featured', 'div.three_featured', 'div.single_column_teaser', 'div.sectionteaser', 'div.specialwrap']; const list = []; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const content = await got(item.link); - const description = cheerio.load(content.data); + const description = load(content.data); item.description = description('#headerimg').html() + description('div[id=storytext]').html(); item.pubDate = parseDate(description('span[id=story_date]').text()); if (description('meta[property=og:audio]').attr('content') !== undefined) { @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'RFA', link: 'https://www.rfa.org/', item: result, - }; + }); }; diff --git a/lib/v2/rfi/news.js b/lib/v2/rfi/news.js index ceed07565b..698bcd0d15 100644 --- a/lib/v2/rfi/news.js +++ b/lib/v2/rfi/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.rfi.fr/'; - const path = ctx.params.path ?? 'en'; + const path = ctx.req.param('path') ?? 'en'; const currentUrl = `${rootUrl}${path.endsWith('/') ? path : `${path}/`}`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('aside[data-org-type="aside-content--highlighted"], aside[data-org-type="aside-content--sponsors"]').remove(); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.m-interstitial, .m-em-quote svg, .o-self-promo').remove(); @@ -56,7 +56,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), description: $('meta[name="description"]').attr('content'), link: currentUrl, @@ -65,5 +65,5 @@ module.exports = async (ctx) => { logo: new URL($('link[rel="apple-touch-icon"]').attr('href'), currentUrl).href, item: items, language: $('html').attr('lang'), - }; + }); }; diff --git a/lib/v2/right/forum.js b/lib/v2/right/forum.js index 94f2383ffe..e7a9d252f9 100644 --- a/lib/v2/right/forum.js +++ b/lib/v2/right/forum.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? '31'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const id = ctx.req.param('id') ?? '31'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://www.right.com.cn'; const currentUrl = `${rootUrl}/forum/forum-${id}-1.html`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('a[title="隐藏置顶帖"]').each(function () { $(this).parents('tbody').remove(); @@ -41,7 +41,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.pstatus').remove(); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.xs2 a').text()} - 恩山无线论坛`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/rodong/news.js b/lib/v2/rodong/news.js index 4ac45959ae..7aac6c2e0a 100644 --- a/lib/v2/rodong/news.js +++ b/lib/v2/rodong/news.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'http://www.rodong.rep.kp'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${host}/${language}/index.php?MkBAMkAxQA==`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.date_news_list .row') .toArray() .map((item) => { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.news_Title, .NewsDetail, .News_Detail, #moveNews').remove(); item.description = $('.col-sm-8').html(); @@ -36,10 +36,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/routledge/book-series.js b/lib/v2/routledge/book-series.js index 0ad430541b..1be90d983c 100644 --- a/lib/v2/routledge/book-series.js +++ b/lib/v2/routledge/book-series.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -21,7 +21,7 @@ module.exports = async (ctx) => { view: 'list', }, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.row.book') .toArray() @@ -46,7 +46,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const isbn = $('meta[property="books:isbn"]').attr('content'); const { data: image } = await got('https://productimages.routledge.com', { searchParams: { @@ -69,10 +69,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/rsc/journal.js b/lib/v2/rsc/journal.js index 5943bc79a6..6ba36a32cc 100644 --- a/lib/v2/rsc/journal.js +++ b/lib/v2/rsc/journal.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +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'; const path = require('path'); module.exports = async (ctx) => { const { id, category = 'allrecentarticles' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://pubs.rsc.org'; const currentUrl = new URL(`en/journals/journalissues/${id}#!recentarticles`, rootUrl).href; @@ -22,7 +22,7 @@ module.exports = async (ctx) => { }, }); - let $ = cheerio.load(response); + let $ = load(response); $('div.capsule__article-image').each(function () { $(this).replaceWith( @@ -66,7 +66,7 @@ module.exports = async (ctx) => { if (item.category.pop()) { const { data: detailResponse } = await got(item.link.replace(/\/articlelanding\//, '/articlehtml/')); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('#pnlArticleAccess, #pnlArticleContent').remove(); content('div.abstract, div.article-abstract__heading').prevAll().remove(); @@ -86,11 +86,11 @@ module.exports = async (ctx) => { const { data: detailResponse } = await got(currentUrl); - $ = cheerio.load(detailResponse); + $ = load(detailResponse); const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('meta[name="citation_title"]').prop('content'), link: currentUrl, @@ -102,5 +102,5 @@ module.exports = async (ctx) => { subtitle: $('title').text(), author: $('meta[name="citation_journal_abbrev"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/rsshub/routes.js b/lib/v2/rsshub/routes.js index 4e1e6389bd..6cff1e5483 100644 --- a/lib/v2/rsshub/routes.js +++ b/lib/v2/rsshub/routes.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const isEnglish = ctx.params.lang !== 'zh'; + const isEnglish = ctx.req.param('lang') !== 'zh'; const lang = isEnglish ? '' : 'zh/'; const types = [ @@ -36,7 +36,7 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const page = $('.page').toArray(); const item = $('.routeBlock').toArray(); return { page, item, type }; @@ -44,13 +44,13 @@ module.exports = async (ctx) => { ); const list = all.flatMap(({ page, item, type }) => item.map((item) => ({ page, item, type }))); - ctx.state.data = { + ctx.set('data', { title: isEnglish ? 'RSSHub has new routes' : 'RSSHub 有新路由啦', link: 'https://docs.rsshub.app', description: isEnglish ? 'Everything is RSSible' : '万物皆可 RSS', language: isEnglish ? 'en-us' : 'zh-cn', item: list.map(({ page, item, type }) => { - const $ = cheerio.load(page); + const $ = load(page); item = $(item); const h2Title = item.prevAll('h2').eq(0); const h3Title = item.prevAll('h3').eq(0); @@ -61,5 +61,5 @@ module.exports = async (ctx) => { guid: item.attr('id'), }; }), - }; + }); }; diff --git a/lib/v2/rsshub/transform/html.js b/lib/v2/rsshub/transform/html.js index 5f12adbd7c..93a94345de 100644 --- a/lib/v2/rsshub/transform/html.js +++ b/lib/v2/rsshub/transform/html.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -12,8 +12,8 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); - const $ = cheerio.load(response.data); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); + const $ = load(response.data); const rssTitle = routeParams.get('title') || $('title').text(); const item = routeParams.get('item') || 'html'; const items = $(item) @@ -56,10 +56,10 @@ module.exports = async (ctx) => { }) .filter(Boolean); - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/rsshub/transform/json.js b/lib/v2/rsshub/transform/json.js index 9c183c9509..ff567eb1fc 100644 --- a/lib/v2/rsshub/transform/json.js +++ b/lib/v2/rsshub/transform/json.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; function jsonGet(obj, attr) { if (typeof attr !== 'string') { @@ -16,7 +16,7 @@ function jsonGet(obj, attr) { module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -24,14 +24,14 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); let rssTitle = routeParams.get('title'); if (!rssTitle) { const resp = await got({ method: 'get', url: new URL(url).origin, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); rssTitle = $('title').text(); } @@ -49,10 +49,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/rsshub/transform/sitemap.js b/lib/v2/rsshub/transform/sitemap.js index 18de638f3e..2d901fe589 100644 --- a/lib/v2/rsshub/transform/sitemap.js +++ b/lib/v2/rsshub/transform/sitemap.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -12,8 +12,8 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); - const $ = cheerio.load(response.data, { xmlMode: true }); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); + const $ = load(response.data, { xmlMode: true }); const rssTitle = routeParams.get('title') || ($('urlset url').length && $('urlset url').first().find('loc').text() ? $('urlset url').first().find('loc').text() : 'Sitemap'); @@ -41,10 +41,10 @@ module.exports = async (ctx) => { .filter(Boolean) : []; - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/ruancan/category.js b/lib/v2/ruancan/category.js index a2a7edbeef..3239d9a094 100644 --- a/lib/v2/ruancan/category.js +++ b/lib/v2/ruancan/category.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category; + const category = ctx.req.param('category'); const currentUrl = `/cat/${category}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/search.js b/lib/v2/ruancan/search.js index ec3d7ff586..df17fd81c6 100644 --- a/lib/v2/ruancan/search.js +++ b/lib/v2/ruancan/search.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const currentUrl = `/?s=${keyword}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/user.js b/lib/v2/ruancan/user.js index 3117e0ee0f..4ea2ed6572 100644 --- a/lib/v2/ruancan/user.js +++ b/lib/v2/ruancan/user.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const currentUrl = `/i/${id}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/utils.js b/lib/v2/ruancan/utils.js index 4bc21001d2..b3b475b048 100644 --- a/lib/v2/ruancan/utils.js +++ b/lib/v2/ruancan/utils.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx, currentUrl) => { const rootUrl = 'https://www.ruancan.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx, currentUrl) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.item-title a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 15) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15) .toArray() .map((item) => { item = $(item); @@ -33,7 +33,7 @@ module.exports = async (ctx, currentUrl) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.entry-copyright').remove(); diff --git a/lib/v2/ruc/hr.js b/lib/v2/ruc/hr.js index 4dc05b387c..b2565e9b0e 100644 --- a/lib/v2/ruc/hr.js +++ b/lib/v2/ruc/hr.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const category = ctx.params.category?.replace(/-/g, '/') ?? 'tzgg'; + const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'tzgg'; const rootUrl = 'http://hr.ruc.edu.cn'; const currentUrl = `${rootUrl}/${category}/index.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a[title]') .toArray() @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.neirong').html(); item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]); @@ -50,9 +50,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/runtrail/posts.js b/lib/v2/runtrail/posts.js index 0ed141ec54..eb558dca1c 100644 --- a/lib/v2/runtrail/posts.js +++ b/lib/v2/runtrail/posts.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://runtrail.cn'; const { data: response } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { _embed: true, - per_page: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30, + per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30, }, }); @@ -26,9 +26,9 @@ module.exports = async (ctx) => { link: item.link, })); - ctx.state.data = { + ctx.set('data', { title: '最新文章 - 跑野大爆炸', link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/rustcc/jobs.js b/lib/v2/rustcc/jobs.js index e7f785fc39..607453aa1e 100644 --- a/lib/v2/rustcc/jobs.js +++ b/lib/v2/rustcc/jobs.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const base_url = 'https://rustcc.cn'; @@ -15,19 +15,19 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.article-list li').get(); - ctx.state.data = { + ctx.set('data', { title: 'Rust语言中文社区 | 招聘', link: jobs_url, description: `获取Rust语言中文社区的最新招聘`, item: await Promise.all(list.map((item) => getFeedItem(item))), - }; + }); }; function getFeedItem(item) { - const $ = cheerio.load(item); + const $ = load(item); const title = $('.title'); return { diff --git a/lib/v2/sakurazaka46/blog.js b/lib/v2/sakurazaka46/blog.js index a8ee1b7119..42a5a5deab 100644 --- a/lib/v2/sakurazaka46/blog.js +++ b/lib/v2/sakurazaka46/blog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'all'; - const page = ctx.params.page ?? '0'; + const id = ctx.req.param('id') ?? 'all'; + const page = ctx.req.param('page') ?? '0'; const rootUrl = 'https://sakurazaka46.com'; const params = id === 'all' ? `?page=${page}` : `?page=${page}&ct=${id}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.com-blog-part .box a') .toArray() @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.box-article').html(); item.pubDate = timezone(parseDate(content('.blog-foot .date').text()), +9); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()}${id ? ` - ${$('.name').first().text()}` : ''}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sakurazaka46/news.js b/lib/v2/sakurazaka46/news.js index 04edf4c1e7..6934da0e42 100644 --- a/lib/v2/sakurazaka46/news.js +++ b/lib/v2/sakurazaka46/news.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://sakurazaka46.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.com-news-part .box a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/samsung/research/blog.js b/lib/v2/samsung/research/blog.js index ab5c47f400..3d5237547b 100644 --- a/lib/v2/samsung/research/blog.js +++ b/lib/v2/samsung/research/blog.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://research.samsung.com'; @@ -32,7 +32,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.news-con').html(); @@ -41,9 +41,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'BLOG | Samsung Research', link: `${rootUrl}/blog`, item: items, - }; + }); }; diff --git a/lib/v2/saraba1st/digest.js b/lib/v2/saraba1st/digest.js index 89ee1182b1..628da33c3c 100644 --- a/lib/v2/saraba1st/digest.js +++ b/lib/v2/saraba1st/digest.js @@ -1,24 +1,24 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const tid = ctx.params.tid; + const tid = ctx.req.param('tid'); const cookieString = config.saraba1st.cookie ?? ''; const res = await got('https://bbs.saraba1st.com/2b/' + tid + '.html', { headers: { Cookie: cookieString, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const title = $('head title').text().replace(/-.*/, ''); const list = $('#threadlisttableid tbody[id^="normalthread_"] tr'); const count = list - .slice(0, ctx.query.limit ? Number(ctx.query.limit) : 20) + .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20) .toArray() .map((each) => { each = $(each); @@ -41,12 +41,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Stage1 论坛 - ${title}`, link: `https://bbs.saraba1st.com/2b/${tid}.html`, // item: await resultItems, item: resultItems, - }; + }); }; async function fetchContent(url) { @@ -57,7 +57,7 @@ async function fetchContent(url) { Cookie: cookieString, }, }); - const subind = cheerio.load(subres.data); + const subind = load(subres.data); const stubS = subind('链接: resolveRelativeUrl(data.content) + generateArticleLink(data.id); module.exports = async (ctx) => { - const categoryName = ctx.params.category || 'all'; + const categoryName = ctx.req.param('category') || 'all'; const categoryMeta = categoryMap[categoryName]; const qs = querystring.stringify({ @@ -113,9 +113,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学教务处学院通知 - ' + categoryMeta.title, link: listPageUrl, item: out, - }; + }); }; diff --git a/lib/v2/scut/scet/notice.js b/lib/v2/scut/scet/notice.js index 590461159d..4f9ed51e8a 100644 --- a/lib/v2/scut/scet/notice.js +++ b/lib/v2/scut/scet/notice.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const link = 'https://www2.scut.edu.cn/jtxs/24241/list.htm'; @@ -10,10 +10,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#wp_news_w5 li'); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学土木与交通学院 - 学工通知', link, item: @@ -27,5 +27,5 @@ module.exports = async (ctx) => { pubDate: item.find('.Article_PublishDate').text(), }; }), - }; + }); }; diff --git a/lib/v2/scut/seie/news-ccenter.js b/lib/v2/scut/seie/news-ccenter.js index f042d0000c..f59b5273ca 100644 --- a/lib/v2/scut/seie/news-ccenter.js +++ b/lib/v2/scut/seie/news-ccenter.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www2.scut.edu.cn'; const url = `${rootUrl}/ee/16285/list.htm`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news_ul li'); const articleList = list.toArray().map((item) => { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { articleList.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(`${rootUrl}${item.link}`); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.wp_articlecontent *').each((_, child) => { const childElem = content(child); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学电子与信息学院 - 新闻速递', link: url, item: items, - }; + }); }; diff --git a/lib/v2/scut/smae/notice.js b/lib/v2/scut/smae/notice.js index 4a15351807..b5c22d13f8 100644 --- a/lib/v2/scut/smae/notice.js +++ b/lib/v2/scut/smae/notice.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const categoryMap = { gwxx: { title: '公务信息', tag: '20616' }, @@ -16,12 +16,12 @@ const categoryMap = { module.exports = async (ctx) => { const baseUrl = 'http://www2.scut.edu.cn'; - const categoryName = ctx.params.category || 'yjsjw'; + const categoryName = ctx.req.param('category') || 'yjsjw'; const categoryMeta = categoryMap[categoryName]; const url = `${baseUrl}/smae/${categoryMeta.tag}/list.htm`; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#wp_news_w6 ul li.news') .toArray() .map((item) => { @@ -38,7 +38,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('div.wp_articlecontent').html(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: `华南理工大学机械与汽车工程学院 - ${categoryMeta.title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/scut/yjs.js b/lib/v2/scut/yjs.js index a1ac8457cb..77df9ff825 100644 --- a/lib/v2/scut/yjs.js +++ b/lib/v2/scut/yjs.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://www2.scut.edu.cn'; const link = `${baseUrl}/graduate/14562/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w4 a'); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学研究生院', link, description: '华南理工大学研究生院通知公告', @@ -26,5 +26,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('span').text()), }; }), - }; + }); }; diff --git a/lib/v2/scvtc/xygg.js b/lib/v2/scvtc/xygg.js index e316aaab38..f0b43b9ffd 100644 --- a/lib/v2/scvtc/xygg.js +++ b/lib/v2/scvtc/xygg.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const currentUrl = 'https://www.scvtc.edu.cn/ggfw1/xygg.htm'; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.text-list ul li') .toArray() .map((item) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#vsb_content').html(); @@ -31,10 +31,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), decription: $('meta[name=description]').attr('content'), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sdu/cmse.js b/lib/v2/sdu/cmse.js index 957b6afd68..74755f8402 100644 --- a/lib/v2/sdu/cmse.js +++ b/lib/v2/sdu/cmse.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'http://www.cmse.sdu.edu.cn/'; const typelist = ['通知公告', '学院新闻', '本科生教育', '研究生教育', '学术动态']; const urlList = ['zxzx/tzgg.htm', 'zxzx/xyxw.htm', 'zxzx/bksjy.htm', 'zxzx/yjsjy.htm', 'zxzx/xsdt.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.article_list li') .map((_, e) => { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { item.link = new URL(item.link.slice('3'), host).href; return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('.contentTitle').text(); item.author = @@ -50,10 +50,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学材料科学与工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/cs.js b/lib/v2/sdu/cs.js index 7b4386bee2..a4310e351d 100644 --- a/lib/v2/sdu/cs.js +++ b/lib/v2/sdu/cs.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); const host = 'https://www.cs.sdu.edu.cn/'; @@ -8,12 +8,12 @@ const typelist = ['学院公告', '学术报告', '科技简讯']; const urlList = ['xygg.htm', 'xsbg.htm', 'kjjx.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.dqlb ul li') .map((_, e) => { @@ -36,7 +36,7 @@ module.exports = async (ctx) => { return item; } const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('.xqnr_tit h2').text().trim(); item.author = $('.xqnr_tit span').eq(1).text().trim().replace('编辑:', '') || '山东大学计算机科学与技术学院'; @@ -48,10 +48,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学计算机科学与技术学院${typelist[type]}通知`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/epe.js b/lib/v2/sdu/epe.js index e71d375503..0467596b5d 100644 --- a/lib/v2/sdu/epe.js +++ b/lib/v2/sdu/epe.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const host = 'https://www.epe.sdu.edu.cn/'; const typelist = ['学院动态', '通知公告', '学术论坛']; const urlList = ['zxzx/xydt.htm', 'zxzx/tzgg.htm', 'zxzx/xslt.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('#page_right_main li a') .map((_, e) => { @@ -31,7 +31,7 @@ module.exports = async (ctx) => { item.link = new URL(item.link.slice('3'), host).href; return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const info = $('#show_info').text().split(/\s{4}/); const date = info[0].split(':')[1]; @@ -46,10 +46,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学能源与动力工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/extractor/sdrj.js b/lib/v2/sdu/extractor/sdrj.js index 42adf19cf3..1e43c125c7 100644 --- a/lib/v2/sdu/extractor/sdrj.js +++ b/lib/v2/sdu/extractor/sdrj.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#vsb_content').html(); author = $("form[name='_newscontent_fromname'] > h1").text(); const exactDateLine = $("form[name='_newscontent_fromname'] > p.info").text().trim(); diff --git a/lib/v2/sdu/extractor/view.js b/lib/v2/sdu/extractor/view.js index ff5e39b921..e9393ac469 100644 --- a/lib/v2/sdu/extractor/view.js +++ b/lib/v2/sdu/extractor/view.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#vsb_content').html(); author = $("form[name='_newscontent_fromname'] > div > p:last-of-type").text(); const exactDateLine = $('.news_tit > p:last-child').text(); diff --git a/lib/v2/sdu/extractor/wh/jwc.js b/lib/v2/sdu/extractor/wh/jwc.js index ede8c49ada..88083fb5dd 100644 --- a/lib/v2/sdu/extractor/wh/jwc.js +++ b/lib/v2/sdu/extractor/wh/jwc.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); const form = $("form[name='_newscontent_fromname']"); form.find('h2').remove(); const exactDateElement = form.find('#author'); diff --git a/lib/v2/sdu/extractor/wh/news.js b/lib/v2/sdu/extractor/wh/news.js index c5ff784a70..63a0135bea 100644 --- a/lib/v2/sdu/extractor/wh/news.js +++ b/lib/v2/sdu/extractor/wh/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#main-content').html(); author = $('#source').text(); const exactDateLine = $('.news_tit > p:last-child').text(); diff --git a/lib/v2/sdu/mech.js b/lib/v2/sdu/mech.js index 93c2cdf621..c332e39674 100644 --- a/lib/v2/sdu/mech.js +++ b/lib/v2/sdu/mech.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const typelist = ['通知公告', '院所新闻', '教学信息', '学术动态', '学院简报']; const urlList = ['xwdt/tzgg.htm', 'xwdt/ysxw.htm', 'xwdt/jxxx.htm', 'xwdt/xsdt.htm', 'xwdt/xyjb.htm']; const host = 'https://www.mech.sdu.edu.cn/'; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('#page_list li a') .slice(0, 1) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { } return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const info = $('#show_info').text().split(/\s{4}/); const date = info[0].split(':')[1]; @@ -51,10 +51,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学机械工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/sc.js b/lib/v2/sdu/sc.js index 9fe5c26df4..69fac7b3cf 100644 --- a/lib/v2/sdu/sc.js +++ b/lib/v2/sdu/sc.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'https://www.sc.sdu.edu.cn/'; const typelist = ['通知公告', '学术动态', '本科教育', '研究生教育']; const urlList = ['tzgg.htm', 'kxyj/xsyg.htm', 'rcpy/bkjy.htm', 'rcpy/yjsjy.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.newlist01 li') .map((_, e) => { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('h3').text(); item.author = @@ -52,10 +52,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学软件学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/wh/jwc.js b/lib/v2/sdu/wh/jwc.js index e664d38f07..e00c546ff1 100644 --- a/lib/v2/sdu/wh/jwc.js +++ b/lib/v2/sdu/wh/jwc.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const data = require('../data').wh.jwc; const extractor = require('../extractor'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const column = ctx.params.column ?? 'gztz'; + const column = ctx.req.param('column') ?? 'gztz'; const baseUrl = data.url; const response = await got(baseUrl + data.columns[column].url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.articleul li'); const out = await Promise.all( items.map(async (index, item) => { @@ -34,9 +34,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${data.name} ${data.columns[column].name}`, link: baseUrl + data.columns[column].url, item: out, - }; + }); }; diff --git a/lib/v2/sdu/wh/news.js b/lib/v2/sdu/wh/news.js index 1abd255945..93d8d64ee6 100644 --- a/lib/v2/sdu/wh/news.js +++ b/lib/v2/sdu/wh/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const data = require('../data').wh.news; const extractor = require('../extractor'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const column = ctx.params.column ?? 'xyyw'; + const column = ctx.req.param('column') ?? 'xyyw'; const baseUrl = data.url; const response = await got(baseUrl + data.columns[column].url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.n_newslist li'); const out = await Promise.all( items.map(async (index, item) => { @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${data.name} ${data.columns[column].name}`, link: baseUrl + data.columns[column].url, item: out, - }; + }); }; diff --git a/lib/v2/sdust/yjsy/zhaosheng.js b/lib/v2/sdust/yjsy/zhaosheng.js index 8cfc1144c3..1c52bb5b83 100644 --- a/lib/v2/sdust/yjsy/zhaosheng.js +++ b/lib/v2/sdust/yjsy/zhaosheng.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'tzgg'; + const id = ctx.req.param('id') ?? 'tzgg'; const rootUrl = 'https://yjsy.sdust.edu.cn'; const currentUrl = `${rootUrl}/zhaosheng/${id}.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.pageUl ul li a') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.txt, .v_news_content').html(); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sdzk/index.js b/lib/v2/sdzk/index.js index a6f7764d6b..eaa52c32e9 100644 --- a/lib/v2/sdzk/index.js +++ b/lib/v2/sdzk/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const bcid = ctx.params.bcid ?? '1'; - const cid = ctx.params.cid ?? '16'; + const bcid = ctx.req.param('bcid') ?? '1'; + const cid = ctx.req.param('cid') ?? '16'; const rootUrl = 'https://www.sdzk.cn'; const currentUrl = `${rootUrl}/NewsList.aspx?BCID=${bcid}${cid ? `&CID=${cid}` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a[title]') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const info = content('div.laylist-r em').text(); @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sec-in/index.js b/lib/v2/sec-in/index.js index d3e073d56d..43aabc0ed6 100644 --- a/lib/v2/sec-in/index.js +++ b/lib/v2/sec-in/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got('https://sec-in.com/api/v1/Common/getArticleList?tabs=newest'); @@ -11,9 +11,9 @@ module.exports = async (ctx) => { author: item.member_info.nickname, category: item.article_tag, })); - ctx.state.data = { + ctx.set('data', { title: 'SecIN信息安全技术社区', link: 'https://sec-in.com/', item: items, - }; + }); }; diff --git a/lib/v2/sec-wiki/weekly.js b/lib/v2/sec-wiki/weekly.js index adc0105390..315eebea9f 100644 --- a/lib/v2/sec-wiki/weekly.js +++ b/lib/v2/sec-wiki/weekly.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -// const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +// import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got('https://www.sec-wiki.com/weekly/index'); @@ -8,9 +8,9 @@ module.exports = async (ctx) => { link: `https://www.sec-wiki.com/weekly/${item[1]}`, description: item[3], })); - ctx.state.data = { + ctx.set('data', { title: 'SecWiki-安全维基', link: 'https://www.sec-wiki.com/', item: items, - }; + }); }; diff --git a/lib/v2/secrss/author.js b/lib/v2/secrss/author.js index ee221ff0c4..df9a8e95b8 100644 --- a/lib/v2/secrss/author.js +++ b/lib/v2/secrss/author.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles/group?author='; - const author = ctx.params.author; + const author = ctx.req.param('author'); const host = 'https://www.secrss.com'; const res = await got(`${api}${author}`); const dataArray = res.data.data.list; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const itemUrl = `${host}${item.url}`; return ctx.cache.tryGet(itemUrl, async () => { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('.article-body').html().trim(); return { title: item.title, @@ -27,9 +27,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `安全内参-${author}`, link: 'https://www.secrss.com', item: items, - }; + }); }; diff --git a/lib/v2/secrss/category.js b/lib/v2/secrss/category.js index 212c43268d..8e0982d576 100644 --- a/lib/v2/secrss/category.js +++ b/lib/v2/secrss/category.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles?tag='; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const itemUrl = `${host}/articles/${item.id}`; return ctx.cache.tryGet(itemUrl, async () => { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('.article-body').html().trim(); return { title: item.title, @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `安全内参-${category}`, link: 'https://www.secrss.com', item: items, - }; + }); }; diff --git a/lib/v2/seekingalpha/index.js b/lib/v2/seekingalpha/index.js index b7aea4dd8e..1e5ec817c5 100644 --- a/lib/v2/seekingalpha/index.js +++ b/lib/v2/seekingalpha/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); const baseUrl = 'https://seekingalpha.com'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { cacheBuster: category === 'news' ? dayjs().format('YYYY-MM-DD') : undefined, id: symbol.toLowerCase(), include: 'author,primaryTickers,secondaryTickers,sentiments', - 'page[size]': ctx.query.limit ? Number(ctx.query.limit) : category === 'news' ? 40 : 20, + 'page[size]': ctx.req.query('limit') ? Number(ctx.req.query('limit')) : category === 'news' ? 40 : 20, }, }); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const summary = $('[data-test-id=article-summary-title]').length ? $('[data-test-id=article-summary-title]').html() + $('[data-test-id=article-summary-title]').next().html() : ''; @@ -44,7 +44,7 @@ module.exports = async (ctx) => { ) : []; - ctx.state.data = { + ctx.set('data', { title: response.data.meta.page.title, description: response.data.meta.page.description, link: pageUrl, @@ -52,5 +52,5 @@ module.exports = async (ctx) => { item: items, allowEmpty: true, language: 'en-US', - }; + }); }; diff --git a/lib/v2/segmentfault/blogs.js b/lib/v2/segmentfault/blogs.js index 0ab77575c4..975b25119a 100644 --- a/lib/v2/segmentfault/blogs.js +++ b/lib/v2/segmentfault/blogs.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -13,9 +13,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault-Blogs-${tag}`, link: `${host}/t/${tag}/blogs`, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/channel.js b/lib/v2/segmentfault/channel.js index 00d5306043..21e67bc42a 100644 --- a/lib/v2/segmentfault/channel.js +++ b/lib/v2/segmentfault/channel.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -12,12 +12,12 @@ module.exports = async (ctx) => { query: 'channel', slug: name, offset: 0, - size: ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 20, + size: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20, mode: 'scrollLoad', }, }); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const channelName = $('#leftNav > a.active').text(); const list = parseList(apiResponse.rows); @@ -26,9 +26,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault - ${channelName}`, link, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/user.js b/lib/v2/segmentfault/user.js index 636d374981..f645e0cac0 100644 --- a/lib/v2/segmentfault/user.js +++ b/lib/v2/segmentfault/user.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -15,9 +15,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault - ${author}`, link: `${host}/u/${name}`, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/utils.js b/lib/v2/segmentfault/utils.js index bf19c3e8a1..582962e79b 100644 --- a/lib/v2/segmentfault/utils.js +++ b/lib/v2/segmentfault/utils.js @@ -1,8 +1,8 @@ const zlib = require('zlib'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const { getAcwScV2ByArg1 } = require('@/v2/5eplay/utils'); const host = 'https://segmentfault.com'; @@ -48,7 +48,7 @@ const parseItems = (cookie, item, tryGet) => cookie: `acw_sc__v2=${cookie};`, }, }); - const content = cheerio.load(response.data); + const content = load(response.data); item.description = content('article').html(); item.category = content('.badge-tag') diff --git a/lib/v2/sehuatang/index.js b/lib/v2/sehuatang/index.js index 5e298795db..b7dfdee722 100644 --- a/lib/v2/sehuatang/index.js +++ b/lib/v2/sehuatang/index.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { CookieJar } = require('tough-cookie'); const cookieJar = new CookieJar(); @@ -38,7 +38,7 @@ const forumIdMaps = { }; module.exports = async (ctx) => { - const subformName = ctx.params.subforumid ?? 'gqzwzm'; + const subformName = ctx.req.param('subforumid') ?? 'gqzwzm'; const subformId = subformName in forumIdMaps ? forumIdMaps[subformName] : subformName; const { type } = ctx.params; const typefilter = type ? `&filter=typeid&typeid=${type}` : ''; @@ -53,10 +53,10 @@ module.exports = async (ctx) => { cookieJar, headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#threadlisttableid tbody[id^=normalthread]') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -77,7 +77,7 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const postMessage = $("td[id^='postmessage']").slice(0, 1); const images = $(postMessage).find('img'); for (const image of images) { @@ -121,9 +121,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `色花堂 - ${$('#pt > div:nth-child(1) > a:last-child').text()}`, link, item: out, - }; + }); }; diff --git a/lib/v2/sehuatang/user.js b/lib/v2/sehuatang/user.js index fbcfbdff1c..5bd151d6dd 100644 --- a/lib/v2/sehuatang/user.js +++ b/lib/v2/sehuatang/user.js @@ -1,8 +1,8 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const baseUrl = 'https://sehuatang.org/'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { throw new Error('Sehuatang RSS is disabled due to the lack of relevant config'); } // 从Url参数中获取uid - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const link = `${baseUrl}home.php?mod=space&uid=${uid}&do=thread&view=me&from=space`; const response = await got(link, { @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#delform tr:not(.th)') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const postMessage = $("[id^='postmessage']").slice(0, 1); const images = $(postMessage).find('img'); for (const image of images) { @@ -103,10 +103,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: `${$('.mt').text()}的帖子-色花堂`, link, item: out, - }; + }); }; diff --git a/lib/v2/sensortower/blog.js b/lib/v2/sensortower/blog.js index 5cab8617e5..ddcb88b43b 100644 --- a/lib/v2/sensortower/blog.js +++ b/lib/v2/sensortower/blog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const language = ctx.params.language ?? ''; + const language = ctx.req.param('language') ?? ''; const rootUrl = 'https://sensortower.com'; const currentUrl = `${rootUrl}${language ? `/${language}` : ''}/blog`; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const detail = JSON.parse(`{${detailResponse.data.match(/("title":.*?),"body":/)[1]}}`); content('h1').remove(); @@ -60,10 +60,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Sensor Tower - Blog', link: currentUrl, item: items, language: language ?? 'en-US', - }; + }); }; diff --git a/lib/v2/setn/index.js b/lib/v2/setn/index.js index 8dfc38f3ae..13d7d4b049 100644 --- a/lib/v2/setn/index.js +++ b/lib/v2/setn/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const defaultRootUrl = 'https://www.setn.com'; @@ -42,8 +42,8 @@ const getCurrentUrl = (category) => { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? '即時'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 42; + const category = ctx.req.param('category') ?? '即時'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 42; const currentUrl = getCurrentUrl(category); @@ -52,7 +52,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('#NewsList, .newsList, .hotNewsList') .find('.newsItems, .st-news, .all_three_list, div.title-word') @@ -78,7 +78,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#gad_setn_innity_oop_1x1').remove(); @@ -92,9 +92,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `三立新聞網 - ${category}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/seu/cse/index.js b/lib/v2/seu/cse/index.js index bac2cb9c58..c66daf2fd3 100644 --- a/lib/v2/seu/cse/index.js +++ b/lib/v2/seu/cse/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://cse.seu.edu.cn'; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const link = new URL(`${id}/list.htm`, host).href; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.news_list .news') .toArray() @@ -45,7 +45,7 @@ module.exports = async (ctx) => { } throw error; } - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('div.wp_articlecontent').html(); @@ -54,10 +54,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { link, title: `${$('meta[name=keywords]').attr('content')}${$('meta[name=description]').attr('content')} -- ${$('head title').text()}`, description: '东南大学计算机技术与工程学院RSS', item: out, - }; + }); }; diff --git a/lib/v2/seu/radio/academic.js b/lib/v2/seu/radio/academic.js index e607decc1c..ccafeff0b7 100644 --- a/lib/v2/seu/radio/academic.js +++ b/lib/v2/seu/radio/academic.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://radio.seu.edu.cn'; const link = new URL('_s29/15986/list.psp', host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list_item') .toArray() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.author = $('.arti_publisher').text().replace('发布者:', ''); item.description = $('.wp_articlecontent').html(); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '东南大学信息科学与工程学院 -- 学术活动', link, item: out, - }; + }); }; diff --git a/lib/v2/seu/yjs.js b/lib/v2/seu/yjs.js index b0037a9612..1862e5b94c 100644 --- a/lib/v2/seu/yjs.js +++ b/lib/v2/seu/yjs.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = 'https://seugs.seu.edu.cn/26671/list.htm'; module.exports = async (ctx) => { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news') .toArray() .map((element) => { @@ -21,7 +21,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.wp_articlecontent').html(); item.pubDate = new Date(item.date).toUTCString(); return item; @@ -29,9 +29,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '东南大学研究生公告', link: url, item: items, - }; + }); }; diff --git a/lib/v2/seu/yzb/index.js b/lib/v2/seu/yzb/index.js index ab545a2c21..773243829d 100644 --- a/lib/v2/seu/yzb/index.js +++ b/lib/v2/seu/yzb/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://yzb.seu.edu.cn'; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const url = new URL(`${id}/list.htm`, host).href; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#wp_news_w3 td tbody tr') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('.Article_Content').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { link: url, title: `东南大学研究生招生网 -- ${$('head title').text()}`, item: items, - }; + }); }; diff --git a/lib/v2/shcstheatre/programs.js b/lib/v2/shcstheatre/programs.js index 5d3776644d..c33ad37966 100644 --- a/lib/v2/shcstheatre/programs.js +++ b/lib/v2/shcstheatre/programs.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; const path = require('path'); module.exports = async (ctx) => { const url = 'https://www.shcstheatre.com/Program/programList.aspx'; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = await Promise.all( $('#datarow .program-name a').map((_, elem) => { const link = new URL($(elem).attr('href'), url); @@ -30,10 +30,10 @@ module.exports = async (ctx) => { ); const image = $('.menu-logo img').attr('src'); - ctx.state.data = { + ctx.set('data', { title: '上海文化广场 - 节目列表', link: url, image, item: items, - }; + }); }; diff --git a/lib/v2/shiep/index.js b/lib/v2/shiep/index.js index 2c5ecd9001..9850146dac 100644 --- a/lib/v2/shiep/index.js +++ b/lib/v2/shiep/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const { config } = require('./config'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); if (!Object.keys(config).includes(type)) { throw new Error(`Invalid type: ${type}`); @@ -20,11 +20,11 @@ module.exports = async (ctx) => { } const host = `https://${type}.shiep.edu.cn`; - const id = ctx.params.id || config[type].id; + const id = ctx.req.param('id') || config[type].id; const link = type === 'career' ? `${host}/news/index/tag/${id}` : `${host}/${id}/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(listSelector) .toArray() @@ -48,7 +48,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $(descriptionSelector).length > 0 @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `上海电力大学-${title}`, link, item: items, - }; + }); }; diff --git a/lib/v2/shisu/news.js b/lib/v2/shisu/news.js index bc58b68c50..78da8b50a2 100644 --- a/lib/v2/shisu/news.js +++ b/lib/v2/shisu/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const url = 'https://news.shisu.edu.cn'; const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png'; @@ -9,7 +9,7 @@ const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316a module.exports = async (ctx) => { const { section = 'news' } = ctx.params; const { data: r } = await got(`${url}/${section}/index.html`); - const $ = cheerio.load(r); + const $ = load(r); let itemsoup; switch (section) { case 'news': @@ -42,7 +42,7 @@ module.exports = async (ctx) => { itemsoup.map((j) => ctx.cache.tryGet(j.link, async () => { const { data: r } = await got(j.link); - const $ = cheerio.load(r); + const $ = load(r); const img = $('.tempWrap > ul > li:nth-child(1)> img').attr('src'); j.description = $('.ot_main_r .content').html(); j.author = $('.math_time_l > span:nth-child(3)').text().trim(); @@ -55,10 +55,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `上外新闻|SISU TODAY -${section.charAt(0).toUpperCase() + section.slice(1)}`, image: 'https://bkimg.cdn.bcebos.com/pic/8d5494eef01f3a296b70affa9825bc315c607c4d?x-bce-process=image/resize,m_lfit,w_536,limit_1/quality,Q_70', link: `${url}/${section}/index.html`, item: items, - }; + }); }; diff --git a/lib/v2/shmeea/index.js b/lib/v2/shmeea/index.js index 6fc1c22f39..87aba2d6e2 100644 --- a/lib/v2/shmeea/index.js +++ b/lib/v2/shmeea/index.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? '08000'; + const id = ctx.req.param('id') ?? '08000'; const baseURL = 'https://www.shmeea.edu.cn'; const link = `${baseURL}/page/${id}/index.html`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = `上海市教育考试院-${$('#main .pageh4-tit').text().trim()}`; @@ -32,7 +32,7 @@ module.exports = async (ctx) => { } const result = await got(item.link); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('#ivs_content').html(); const pbTimeText = $('#ivs_title .PBtime').text().trim(); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link, item: items, - }; + }); };