From fdf3fcac574170a099a2018aa4b7d2c0a466e97e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 28 Feb 2024 16:33:13 +0800 Subject: [PATCH] feat: v3 migration - 3/n --- lib/v2/18comic/index.js | 2 +- lib/v2/18comic/search.js | 2 +- lib/v2/56kog/class.js | 2 +- lib/v2/56kog/top.js | 2 +- lib/v2/95mm/category.js | 2 +- lib/v2/95mm/tab.js | 2 +- lib/v2/95mm/tag.js | 2 +- lib/v2/bangumi/tv/subject/index.js | 2 +- lib/v2/bilibili/user-channel.js | 4 ++-- lib/v2/bilibili/user-collection.js | 2 +- lib/v2/cctv/category.js | 2 +- lib/v2/coomer/artist.js | 2 +- lib/v2/coomer/posts.js | 2 +- lib/v2/dapenti/subject.js | 2 +- lib/v2/dapenti/tugua.js | 2 +- lib/v2/discourse/posts.js | 2 +- lib/v2/dlsite/index.js | 2 +- lib/v2/dol/announce.js | 6 ++--- lib/v2/douban/other/latest-music.js | 2 +- lib/v2/dribbble/keyword.js | 2 +- lib/v2/dribbble/popular.js | 2 +- lib/v2/dribbble/user.js | 2 +- lib/v2/gov/safe/business.js | 2 +- lib/v2/gov/safe/complaint.js | 2 +- lib/v2/grubstreet/index.js | 2 +- lib/v2/hpoi/all.js | 2 +- lib/v2/hpoi/character.js | 2 +- lib/v2/hpoi/work.js | 2 +- lib/v2/iqiyi/video.js | 2 +- lib/v2/javdb/actors.js | 2 +- lib/v2/javdb/index.js | 2 +- lib/v2/javdb/lists.js | 2 +- lib/v2/javdb/makers.js | 2 +- lib/v2/javdb/rankings.js | 2 +- lib/v2/javdb/search.js | 2 +- lib/v2/javdb/series.js | 2 +- lib/v2/javdb/tags.js | 2 +- lib/v2/javlibrary/bestrated.js | 2 +- lib/v2/javlibrary/bestreviews.js | 2 +- lib/v2/javlibrary/genre.js | 2 +- lib/v2/javlibrary/maker.js | 2 +- lib/v2/javlibrary/mostwanted.js | 2 +- lib/v2/javlibrary/newentries.js | 2 +- lib/v2/javlibrary/newrelease.js | 2 +- lib/v2/javlibrary/star.js | 2 +- lib/v2/javlibrary/update.js | 2 +- lib/v2/javlibrary/user.js | 2 +- lib/v2/mihoyo/bbs/follow-list.js | 2 +- lib/v2/mihoyo/bbs/img-ranking.js | 2 +- lib/v2/mihoyo/bbs/official.js | 2 +- lib/v2/mihoyo/bbs/timeline.js | 2 +- lib/v2/mihoyo/bbs/user-post.js | 2 +- lib/v2/parliament/section77.js | 2 +- lib/v2/phoronix/index.js | 2 +- lib/v2/qq/ac/rank.js | 2 +- lib/v2/ruancan/category.js | 2 +- lib/v2/ruancan/index.js | 2 +- lib/v2/ruancan/search.js | 2 +- lib/v2/ruancan/user.js | 2 +- lib/v2/shmeea/self-study.js | 18 +++++++------- lib/v2/shmtu/jwc.js | 22 ++++++++--------- lib/v2/shmtu/portal.js | 18 +++++++------- lib/v2/shmtu/www.js | 20 ++++++++-------- lib/v2/shoac/recent-show.js | 10 ++++---- lib/v2/shopback/store.js | 12 +++++----- lib/v2/shoppingdesign/posts.js | 14 +++++------ lib/v2/showstart/artist.js | 6 ++--- lib/v2/showstart/brand.js | 6 ++--- lib/v2/showstart/event.js | 8 +++---- lib/v2/showstart/search.js | 4 ++-- lib/v2/showstart/utils.js | 4 ++-- lib/v2/shu/index.js | 16 ++++++------- lib/v2/shu/jwb.js | 16 ++++++------- lib/v2/shuiguopai/index.js | 18 +++++++------- lib/v2/sicau/dky.js | 18 +++++++------- lib/v2/sicau/yan.js | 18 +++++++------- lib/v2/sicau/zsjy.js | 16 ++++++------- lib/v2/sigsac/ccs.js | 14 +++++------ lib/v2/simpleinfo/index.js | 18 +++++++------- lib/v2/sina/chuangshiji.js | 4 ++-- lib/v2/sina/discovery.js | 6 ++--- lib/v2/sina/finance/china.js | 4 ++-- lib/v2/sina/finance/stock/usstock.js | 8 +++---- lib/v2/sina/rollnews.js | 4 ++-- lib/v2/sina/sports.js | 10 ++++---- lib/v2/sina/utils.js | 12 +++++----- lib/v2/sinchew/index.js | 20 ++++++++-------- lib/v2/sis001/forum.js | 16 ++++++------- lib/v2/sjtu/gs.js | 20 ++++++++-------- lib/v2/sjtu/jwc.js | 16 ++++++------- lib/v2/sjtu/seiee/bjwb.js | 2 +- lib/v2/sjtu/seiee/utils.js | 14 +++++------ lib/v2/sjtu/seiee/xsb.js | 2 +- lib/v2/sjtu/tongqu/activity.js | 10 ++++---- lib/v2/sjtu/yzb/zkxx.js | 14 +++++------ lib/v2/skysports/news.js | 16 ++++++------- lib/v2/slowmist/slowmist.js | 10 ++++---- lib/v2/smashingmagazine/category.js | 14 +++++------ lib/v2/smzdm/article.js | 18 +++++++------- lib/v2/smzdm/baoliao.js | 18 +++++++------- lib/v2/smzdm/haowen-fenlei.js | 20 ++++++++-------- lib/v2/smzdm/haowen.js | 18 +++++++------- lib/v2/smzdm/keyword.js | 16 ++++++------- lib/v2/smzdm/ranking.js | 8 +++---- lib/v2/snowpeak/us-new-arrivals.js | 12 +++++----- lib/v2/sobooks/date.js | 4 ++-- lib/v2/sobooks/index.js | 4 ++-- lib/v2/sobooks/tag.js | 4 ++-- lib/v2/sobooks/utils.js | 10 ++++---- lib/v2/sogou/doodles.js | 6 ++--- lib/v2/sogou/search.js | 16 ++++++------- lib/v2/sohu/mp.js | 14 +++++------ lib/v2/solidot/_article.js | 10 ++++---- lib/v2/solidot/main.js | 12 +++++----- lib/v2/sony/downloads.js | 10 ++++---- lib/v2/soundofhope/channel.js | 20 ++++++++-------- lib/v2/sourceforge/index.js | 14 +++++------ lib/v2/southcn/nfapp/column.js | 14 +++++------ lib/v2/southcn/nfapp/reporter.js | 14 +++++------ lib/v2/southcn/nfapp/utils.js | 6 ++--- lib/v2/spotify/artist.js | 8 +++---- lib/v2/spotify/playlist.js | 8 +++---- lib/v2/spotify/saved.js | 8 +++---- lib/v2/spotify/show.js | 8 +++---- lib/v2/spotify/top.js | 6 ++--- lib/v2/spotify/utils.js | 4 ++-- lib/v2/springer/journal.js | 18 +++++++------- lib/v2/sputniknews/index.js | 18 +++++++------- lib/v2/sqmc/www.js | 18 +++++++------- lib/v2/sse/convert.js | 10 ++++---- lib/v2/sse/disclosure.js | 10 ++++---- lib/v2/sse/inquire.js | 10 ++++---- lib/v2/sse/lawandrules.js | 16 ++++++------- lib/v2/sse/renewal.js | 10 ++++---- lib/v2/ssm/news.js | 14 +++++------ lib/v2/sspai/activity.js | 14 +++++------ lib/v2/sspai/author.js | 10 ++++---- lib/v2/sspai/bookmarks.js | 8 +++---- lib/v2/sspai/column.js | 10 ++++---- lib/v2/sspai/index.js | 8 +++---- lib/v2/sspai/matrix.js | 8 +++---- lib/v2/sspai/series-update.js | 10 ++++---- lib/v2/sspai/series.js | 10 ++++---- lib/v2/sspai/shortcuts-gallery.js | 8 +++---- lib/v2/sspai/tag.js | 10 ++++---- lib/v2/sspai/topic.js | 10 ++++---- lib/v2/sspai/topics.js | 8 +++---- lib/v2/sspu/jwc.js | 18 +++++++------- lib/v2/sspu/pe.js | 16 ++++++------- lib/v2/startuplatte/index.js | 16 ++++++------- lib/v2/stbu/jsjxy.js | 16 ++++++------- lib/v2/stbu/xyxw.js | 16 ++++++------- lib/v2/stcn/index.js | 18 +++++++------- lib/v2/stdaily/digitalpaper.js | 16 ++++++------- lib/v2/stheadline/std/realtime.js | 16 ++++++------- lib/v2/stockedge/daily-news.js | 4 ++-- lib/v2/stockedge/utils.js | 4 ++-- lib/v2/storm/index.js | 18 +++++++------- lib/v2/storyfm/episodes.js | 16 ++++++------- lib/v2/storyfm/index.js | 12 +++++----- lib/v2/studygolang/go.js | 2 +- lib/v2/studygolang/jobs.js | 4 +--- lib/v2/studygolang/utils.js | 18 +++++++------- lib/v2/studygolang/weekly.js | 4 +--- lib/v2/subhd/index.js | 20 ++++++++-------- lib/v2/supchina/index.js | 16 ++++++------- lib/v2/supchina/podcasts.js | 14 +++++------ lib/v2/surfshark/blog.js | 18 +++++++------- lib/v2/sustech/bidding.js | 12 +++++----- lib/v2/sustech/newshub-zh.js | 12 +++++----- lib/v2/sustech/yjs.js | 8 +++---- lib/v2/swissinfo/index.js | 22 ++++++++--------- lib/v2/swjtu/jtys/yjs.js | 14 +++++------ lib/v2/swjtu/jwc.js | 14 +++++------ lib/v2/swjtu/jyzpxx.js | 8 +++---- lib/v2/swjtu/utils.js | 6 ++--- lib/v2/swjtu/xg.js | 16 ++++++------- lib/v2/swpu/bgw.js | 18 +++++++------- lib/v2/swpu/cjxy.js | 18 +++++++------- lib/v2/swpu/dean.js | 18 +++++++------- lib/v2/swpu/dxy.js | 18 +++++++------- lib/v2/swpu/is.js | 18 +++++++------- lib/v2/swpu/scs.js | 18 +++++++------- lib/v2/syosetu/chapter.js | 20 ++++++++-------- lib/v2/sysu/cse.js | 10 ++++---- lib/v2/sysu/ygafz.js | 17 +++++++------- lib/v2/szse/inquire.js | 16 ++++++------- lib/v2/szse/notice.js | 12 +++++----- lib/v2/szse/projectdynamic.js | 18 +++++++------- lib/v2/szse/rule.js | 12 +++++----- lib/v2/szu/yz/index.js | 12 +++++----- lib/v2/szu/yz/utils.js | 14 +++++------ lib/v2/tableau/viz-of-the-day.js | 10 ++++---- lib/v2/taiwannews/hot.js | 16 ++++++------- lib/v2/tangshufang/index.js | 18 +++++++------- lib/v2/taobao/zhongchou.js | 8 +++---- lib/v2/taoguba/blog.js | 20 ++++++++-------- lib/v2/taoguba/index.js | 20 ++++++++-------- lib/v2/taptap/changelog.js | 12 +++++----- lib/v2/taptap/review.js | 18 +++++++------- lib/v2/taptap/topic.js | 20 ++++++++-------- lib/v2/taptap/utils.js | 8 +++---- lib/v2/tass/news.js | 14 +++++------ lib/v2/techcrunch/news.js | 10 ++++---- lib/v2/techflowpost/express.js | 14 +++++------ lib/v2/techflowpost/index.js | 14 +++++------ lib/v2/techpowerup/index.js | 14 +++++------ lib/v2/techpowerup/review.js | 14 +++++------ lib/v2/techpowerup/utils.js | 10 ++++---- lib/v2/telecompaper/news.js | 30 ++++++++++++------------ lib/v2/telecompaper/search.js | 22 ++++++++--------- lib/v2/telegram/blog.js | 8 +++---- lib/v2/telegram/channel.js | 22 ++++++++--------- lib/v2/telegram/stickerpack.js | 10 ++++---- lib/v2/tencent/news/author.js | 20 ++++++++-------- lib/v2/tencent/news/coronavirus/data.js | 12 +++++----- lib/v2/tencent/news/coronavirus/total.js | 8 +++---- lib/v2/tencent/news/coronavirus/utils.js | 2 +- lib/v2/tencent/pvp/newsindex.js | 10 ++++---- lib/v2/tencent/qq/sdk/changelog.js | 12 +++++----- lib/v2/tesla/cx.js | 16 ++++++------- lib/v2/tesla/price/get-price.js | 6 ++--- lib/v2/tesla/price/index.js | 4 ++-- lib/v2/tfc-taiwan/index.js | 12 +++++----- lib/v2/tfc-taiwan/utils.js | 10 ++++---- lib/v2/theatlantic/news.js | 12 +++++----- lib/v2/theatlantic/utils.js | 14 ++++++----- lib/v2/theblockbeats/index.js | 12 +++++----- lib/v2/thecatcity/index.js | 8 +++---- lib/v2/thecover/channel.js | 18 +++++++------- lib/v2/thehindu/topic.js | 16 ++++++------- lib/v2/theinitium/full.js | 22 ++++++++--------- lib/v2/themoviedb/collection.js | 6 ++--- lib/v2/themoviedb/episodes.js | 8 +++---- lib/v2/themoviedb/seasons.js | 8 +++---- lib/v2/themoviedb/sheet.js | 6 ++--- lib/v2/themoviedb/trending.js | 6 ++--- lib/v2/themoviedb/utils.js | 4 ++-- lib/v2/thenewslens/index.js | 18 +++++++------- lib/v2/thepaper/839studio/category.js | 12 +++++----- lib/v2/thepaper/839studio/studio.js | 10 ++++---- lib/v2/thepaper/channel.js | 10 ++++---- lib/v2/thepaper/factpaper.js | 14 +++++------ lib/v2/thepaper/featured.js | 10 ++++---- lib/v2/thepaper/list.js | 10 ++++---- lib/v2/thepaper/sidebar.js | 6 ++--- lib/v2/thepaper/utils.js | 14 +++++------ lib/v2/theverge/index.js | 12 +++++----- lib/v2/thoughtco/index.js | 18 +++++++------- lib/v2/threads/index.js | 8 +++---- lib/v2/threads/utils.js | 6 ++--- lib/v2/thwiki/index.js | 10 ++++---- lib/v2/tiktok/user.js | 13 +++++----- lib/v2/timednews/news.js | 22 ++++++++--------- lib/v2/tingshuitz/changsha.js | 14 +++++------ lib/v2/tingshuitz/dalian.js | 12 +++++----- lib/v2/tingshuitz/dongguan.js | 12 +++++----- lib/v2/tingshuitz/guangzhou.js | 6 ++--- lib/v2/tingshuitz/hangzhou.js | 12 +++++----- lib/v2/tingshuitz/nanjing.js | 12 +++++----- lib/v2/tingshuitz/shenzhen.js | 12 +++++----- lib/v2/tingshuitz/wuhan.js | 10 ++++---- lib/v2/tingshuitz/xian.js | 10 ++++---- lib/v2/tingshuitz/xiaoshan.js | 12 +++++----- lib/v2/tingshuitz/yangjiang.js | 12 +++++----- lib/v2/tingtingfm/program.js | 12 +++++----- lib/v2/tingtingfm/utils.js | 2 +- lib/v2/tisi/index.js | 14 +++++------ lib/v2/tju/cic/index.js | 14 +++++------ lib/v2/tju/news/index.js | 14 +++++------ lib/v2/tju/oaa/index.js | 14 +++++------ lib/v2/tju/yzb/index.js | 14 +++++------ lib/v2/tokeninsight/blog.js | 16 ++++++------- lib/v2/tokeninsight/bulletin.js | 14 +++++------ lib/v2/tokeninsight/report.js | 16 ++++++------- lib/v2/tongji/sse/_article.js | 6 ++--- lib/v2/tongji/sse/notice.js | 14 +++++------ lib/v2/tongji/yjs.js | 12 +++++----- lib/v2/toodaylab/index.js | 16 ++++++------- lib/v2/tophub/index.js | 14 +++++------ lib/v2/tophub/list.js | 16 ++++++------- lib/v2/topys/index.js | 16 ++++++------- lib/v2/tradingview/blog.js | 18 +++++++------- lib/v2/tradingview/desktop.js | 18 +++++++------- lib/v2/tradingview/pine.js | 14 +++++------ lib/v2/transcriptforest/index.js | 16 ++++++------- lib/v2/trending/all-trending.js | 19 ++++++++------- lib/v2/trendingpapers/papers.js | 8 +++---- lib/v2/tribalfootball/latest.js | 16 ++++++------- lib/v2/trow/portal.js | 14 +++++------ lib/v2/tvb/news.js | 16 ++++++------- lib/v2/twitch/live.js | 8 +++---- lib/v2/twitch/schedule.js | 6 ++--- lib/v2/twitch/video.js | 12 +++++----- lib/v2/twitter/api-fallback-common.js | 4 ++-- lib/v2/twitter/collection.js | 14 +++++------ lib/v2/twitter/developer-api/search.js | 8 +++---- lib/v2/twitter/developer-api/user.js | 8 +++---- lib/v2/twitter/followings.js | 10 ++++---- lib/v2/twitter/likes.js | 8 +++---- lib/v2/twitter/list.js | 6 ++--- lib/v2/twitter/trends.js | 8 +++---- lib/v2/twitter/utils.js | 6 ++--- lib/v2/twitter/web-api/login.js | 4 ++-- lib/v2/twitter/web-api/media.js | 10 ++++---- lib/v2/twitter/web-api/search.js | 6 ++--- lib/v2/twitter/web-api/token.js | 2 +- lib/v2/twitter/web-api/tweet.js | 14 +++++------ lib/v2/twitter/web-api/twitter-api.js | 4 ++-- lib/v2/twitter/web-api/user.js | 8 +++---- lib/v2/twreporter/fetch-article.js | 14 +++++------ lib/v2/twreporter/newest.js | 12 +++++----- lib/v2/txrjy/fornumtopic.js | 20 ++++++++-------- lib/v2/tynu/tynu.js | 14 +++++------ lib/v2/typora/changelog-dev.js | 10 ++++---- lib/v2/typora/changelog.js | 12 +++++----- lib/v2/u3c3/index.js | 12 +++++----- lib/v2/u9a9/index.js | 16 ++++++------- lib/v2/uber/blog.js | 10 ++++---- lib/v2/ucas/ai.js | 12 +++++----- lib/v2/ucas/index.js | 16 ++++++------- lib/v2/uchicago/current.js | 15 ++++++------ lib/v2/udn/breaking-news.js | 20 ++++++++-------- lib/v2/udn/global/index.js | 18 +++++++------- lib/v2/udn/global/tag.js | 14 +++++------ lib/v2/uestc/auto.js | 13 +++++----- lib/v2/uestc/cqe.js | 15 ++++++------ lib/v2/uestc/gr.js | 14 +++++------ lib/v2/uestc/jwc.js | 14 +++++------ lib/v2/uestc/news.js | 14 +++++------ lib/v2/uestc/scse.js | 13 +++++----- lib/v2/uestc/sice.js | 13 +++++----- lib/v2/uestc/sise.js | 15 ++++++------ lib/v2/uibe/hr.js | 18 +++++++------- lib/v2/ulapia/index.js | 14 +++++------ lib/v2/ulapia/research.js | 12 +++++----- lib/v2/uniqlo/new.js | 6 ++--- lib/v2/unraid/community-apps.js | 10 ++++---- lib/v2/unusualwhales/news.js | 8 +++---- lib/v2/upc/jsj.js | 18 +++++++------- lib/v2/upc/main.js | 18 +++++++------- lib/v2/upc/yjs.js | 12 +++++----- lib/v2/uptimerobot/rss.js | 8 +++---- lib/v2/uraaka-joshi/uraaka-joshi-user.js | 15 ++++++------ lib/v2/uraaka-joshi/uraaka-joshi.js | 13 +++++----- lib/v2/urbandictionary/random.js | 10 ++++---- lib/v2/usenix/usenix.js | 14 +++++------ lib/v2/usepanda/index.js | 12 +++++----- lib/v2/ustb/tj/news.js | 14 +++++------ lib/v2/ustb/yjsy/news.js | 14 +++++------ lib/v2/ustb/yzxc/tzgg.js | 14 +++++------ lib/v2/ustc/eeis.js | 18 +++++++------- lib/v2/ustc/gs.js | 18 +++++++------- lib/v2/ustc/index.js | 19 +++++++-------- lib/v2/ustc/job.js | 10 ++++---- lib/v2/ustc/jwc.js | 19 +++++++-------- lib/v2/ustc/sist.js | 18 +++++++------- lib/v2/usts/jwch.js | 18 +++++++------- lib/v2/utgd/category.js | 16 ++++++------- lib/v2/utgd/timeline.js | 14 +++++------ lib/v2/utgd/topic.js | 16 ++++++------- lib/v2/uw/gix/news.js | 14 +++++------ lib/v2/v1tx/index.js | 14 +++++------ lib/v2/v2ex/post.js | 8 +++---- lib/v2/v2ex/tab.js | 16 ++++++------- lib/v2/v2ex/topics.js | 8 +++---- lib/v2/v2rayshare/index.js | 8 +++---- lib/v2/vcb-s/category.js | 14 +++++------ lib/v2/vcb-s/index.js | 12 +++++----- lib/v2/verfghbw/press.js | 14 +++++------ lib/v2/vimeo/category.js | 14 +++++------ lib/v2/vimeo/channel.js | 18 +++++++------- lib/v2/vimeo/usr-videos.js | 10 ++++---- lib/v2/vocus/publication.js | 6 ++--- lib/v2/vocus/user.js | 6 ++--- lib/v2/vocus/utils.js | 8 +++---- lib/v2/vom/featured.js | 14 +++++------ lib/v2/wallhaven/index.js | 20 ++++++++-------- lib/v2/wallpaperhub/index.js | 10 ++++---- lib/v2/wallstreetcn/hot.js | 10 ++++---- lib/v2/wallstreetcn/live.js | 16 ++++++------- lib/v2/wallstreetcn/news.js | 12 +++++----- lib/v2/wanqu/news.js | 12 +++++----- lib/v2/warthunder/news.js | 16 ++++++------- lib/v2/wdc/download.js | 14 +++++------ lib/v2/web3caff/index.js | 16 ++++++------- lib/v2/wechat/announce.js | 12 +++++----- lib/v2/wechat/ce.js | 12 +++++----- lib/v2/wechat/data258.js | 22 ++++++++--------- lib/v2/wechat/ershcimi.js | 16 ++++++------- lib/v2/wechat/feeddd.js | 14 +++++------ lib/v2/wechat/feeds.js | 4 ++-- lib/v2/wechat/mp.js | 10 ++++---- lib/v2/wechat/msgalbum.js | 10 ++++---- lib/v2/wechat/sogou.js | 14 +++++------ lib/v2/wechat/tgchannel.js | 16 ++++++------- lib/v2/wechat/uread.js | 12 +++++----- lib/v2/wechat/wechat2rss.js | 6 ++--- lib/v2/wechat/wxnmh.js | 16 ++++++------- lib/v2/weekendhk/posts.js | 10 ++++---- lib/v2/weibo/friends.js | 12 +++++----- lib/v2/weibo/group.js | 16 ++++++------- lib/v2/weibo/keyword.js | 10 ++++---- lib/v2/weibo/oasis/user.js | 2 +- lib/v2/weibo/search/hot.js | 24 +++++++++---------- lib/v2/weibo/super-index.js | 8 +++---- lib/v2/weibo/timeline.js | 18 +++++++------- lib/v2/weibo/user.js | 18 +++++++------- lib/v2/weibo/utils.js | 8 +++---- lib/v2/wenku8/chapter.js | 12 +++++----- lib/v2/wenku8/index.js | 14 +++++------ lib/v2/wenku8/volume.js | 12 +++++----- lib/v2/wfdf/news.js | 10 ++++---- lib/v2/wfu/jwc.js | 12 +++++----- lib/v2/wfu/news.js | 24 +++++++++---------- lib/v2/whitehouse/briefing-room.js | 16 ++++++------- lib/v2/whitehouse/ostp.js | 14 +++++------ lib/v2/who/news-room.js | 18 +++++++------- lib/v2/who/news.js | 10 ++++---- lib/v2/who/speeches.js | 14 +++++------ lib/v2/whu/cs.js | 18 +++++++------- lib/v2/whu/gs/index.js | 16 ++++++------- lib/v2/whu/hyxt.js | 14 +++++------ lib/v2/whu/news.js | 16 ++++++------- lib/v2/whu/util.js | 12 +++++----- lib/v2/wikinews/index.js | 14 +++++------ lib/v2/winstall/update.js | 14 +++++------ lib/v2/wise/pair.js | 16 ++++++------- lib/v2/wizfile/index.js | 12 +++++----- lib/v2/wmc-bj/publish.js | 16 ++++++------- lib/v2/wnacg/index.js | 18 +++++++------- lib/v2/worldjournal/index.js | 16 ++++++------- lib/v2/woshipm/popular.js | 8 +++---- lib/v2/woshipm/user-article.js | 14 +++++------ lib/v2/woshipm/utils.js | 6 ++--- lib/v2/woshipm/wen.js | 14 +++++------ lib/v2/wsj/news.js | 14 +++++------ lib/v2/wsj/utils.js | 14 ++++++----- lib/v2/wsyu/news.js | 14 +++++------ lib/v2/wtu/index.js | 12 +++++----- lib/v2/wtu/job.js | 14 +++++------ lib/v2/wyzxwk/article.js | 16 ++++++------- lib/v2/wzu/news.js | 22 ++++++++--------- lib/v2/x-mol/news.js | 20 ++++++++-------- lib/v2/x-mol/paper.js | 18 +++++++------- lib/v2/x6d/index.js | 20 ++++++++-------- lib/v2/xaufe/jiaowu.js | 16 ++++++------- lib/v2/xaut/index.js | 16 ++++++------- lib/v2/xaut/jwc.js | 16 ++++++------- lib/v2/xaut/rsc.js | 16 ++++++------- lib/v2/xboxfan/news.js | 14 +++++------ lib/v2/xiaohongshu/board.js | 10 ++++---- lib/v2/xiaohongshu/notes.js | 6 ++--- lib/v2/xiaohongshu/user.js | 10 ++++---- lib/v2/xiaohongshu/util.js | 11 +++++---- lib/v2/xiaomiyoupin/crowdfunding.js | 8 +++---- lib/v2/xiaomiyoupin/latest.js | 6 ++--- lib/v2/xiaomiyoupin/utils.js | 2 +- lib/v2/xiaote/index.js | 8 +++---- lib/v2/xiaoyuzhou/pickup.js | 8 +++---- lib/v2/xiaoyuzhou/podcast.js | 14 +++++------ lib/v2/xiaozhuanlan/column.js | 14 +++++------ lib/v2/xidian/jwc.js | 14 +++++------ lib/v2/ximalaya/album.js | 22 ++++++++--------- lib/v2/xinpianchang/index.js | 6 ++--- lib/v2/xinpianchang/rank.js | 8 +++---- lib/v2/xinpianchang/util.js | 10 ++++---- lib/v2/xjtu/2yuan/news.js | 18 +++++++------- lib/v2/xjtu/dean.js | 18 +++++++------- lib/v2/xjtu/dyyy/index.js | 14 +++++------ lib/v2/xjtu/ee.js | 18 +++++++------- lib/v2/xjtu/gs/tzgg.js | 14 +++++------ lib/v2/xjtu/international.js | 16 ++++++------- lib/v2/xjtu/job.js | 14 +++++------ lib/v2/xjtu/std.js | 20 ++++++++-------- lib/v2/xkb/index.js | 14 +++++------ lib/v2/xmanhua/index.js | 14 +++++------ lib/v2/xmnn/epaper.js | 22 ++++++++--------- lib/v2/xmnn/news.js | 18 +++++++------- lib/v2/xmut/jwc/bkjw.js | 14 +++++------ lib/v2/xmut/jwc/yjs.js | 14 +++++------ lib/v2/xsijishe/forum.js | 16 ++++++------- lib/v2/xsijishe/rank.js | 14 +++++------ lib/v2/xueqiu/column.js | 8 +++---- lib/v2/xueqiu/favorite.js | 10 ++++---- lib/v2/xueqiu/fund.js | 12 +++++----- lib/v2/xueqiu/hots.js | 8 +++---- lib/v2/xueqiu/snb.js | 14 ++++++----- lib/v2/xueqiu/stock-comments.js | 16 ++++++------- lib/v2/xueqiu/stock-info.js | 16 ++++++------- lib/v2/xueqiu/today.js | 14 +++++------ lib/v2/xueqiu/user-stock.js | 10 ++++---- lib/v2/xueqiu/user.js | 12 +++++----- lib/v2/xys/new.js | 18 +++++++------- lib/v2/xyzrank/index.js | 18 +++++++------- lib/v2/yahoo/news/tw/index.js | 6 ++--- lib/v2/yahoo/news/tw/provider-helper.js | 4 ++-- lib/v2/yahoo/news/tw/provider.js | 6 ++--- lib/v2/yahoo/news/tw/utils.js | 12 +++++----- lib/v2/yahoo/news/us/index.js | 14 +++++------ lib/v2/yangtzeu/dongke.js | 18 +++++++------- lib/v2/ycwb/index.js | 18 +++++++------- lib/v2/yicai/author.js | 14 +++++------ lib/v2/yicai/brief.js | 12 +++++----- lib/v2/yicai/dt.js | 18 +++++++------- lib/v2/yicai/feed.js | 14 +++++------ lib/v2/yicai/headline.js | 6 ++--- lib/v2/yicai/latest.js | 6 ++--- lib/v2/yicai/news.js | 10 ++++---- lib/v2/yicai/utils.js | 12 +++++----- lib/v2/yicai/video.js | 10 ++++---- lib/v2/yicai/vip.js | 14 +++++------ lib/v2/ymgal/article.js | 16 ++++++------- lib/v2/ymgal/game.js | 12 +++++----- lib/v2/yoasobi-music/info.js | 12 +++++----- lib/v2/yoasobi-music/live.js | 8 +++---- lib/v2/yoasobi-music/media.js | 8 +++---- lib/v2/yomiuri/news.js | 16 ++++++------- lib/v2/yomujp/level.js | 18 +++++++------- lib/v2/youku/channel.js | 18 +++++++------- lib/v2/youtube/channel.js | 12 +++++----- lib/v2/youtube/charts.js | 10 ++++---- lib/v2/youtube/community.js | 14 +++++------ lib/v2/youtube/custom.js | 16 ++++++------- lib/v2/youtube/live.js | 18 +++++++------- lib/v2/youtube/playlist.js | 12 +++++----- lib/v2/youtube/subscriptions.js | 14 +++++------ lib/v2/youtube/user.js | 18 +++++++------- lib/v2/youtube/utils.js | 4 ++-- lib/v2/youzhiyouxing/materials.js | 16 ++++++------- lib/v2/yuque/book.js | 14 +++++------ lib/v2/yxdown/news.js | 18 +++++++------- lib/v2/yxdown/recommend.js | 16 ++++++------- lib/v2/yxdown/utils.js | 2 +- lib/v2/yxdzqb/index.js | 14 +++++------ lib/v2/yxrb/home.js | 16 ++++++------- lib/v2/yyets/article.js | 18 +++++++------- lib/v2/yyets/today.js | 10 ++++---- lib/v2/yystv/category.js | 10 ++++---- lib/v2/yystv/docs.js | 12 +++++----- lib/v2/zagg/new-arrivals.js | 14 +++++------ lib/v2/zaker/index.js | 20 ++++++++-------- lib/v2/zaobao/index.js | 8 +++---- lib/v2/zaobao/interactive.js | 4 ++-- lib/v2/zaobao/realtime.js | 6 ++--- lib/v2/zaobao/util.js | 14 +++++------ lib/v2/zaobao/znews.js | 6 ++--- lib/v2/zaozao/article.js | 8 +++---- lib/v2/zcmu/jwc/index.js | 14 +++++------ lib/v2/zcmu/yxy/index.js | 14 +++++------ lib/v2/zcool/discover.js | 30 ++++++++++++------------ lib/v2/zcool/top.js | 14 +++++------ lib/v2/zcool/user.js | 14 +++++------ lib/v2/zcool/utils.js | 2 +- lib/v2/zhangyoubao/index.js | 12 +++++----- lib/v2/zhibo8/forum.js | 18 +++++++------- lib/v2/zhibo8/luxiang.js | 14 +++++------ lib/v2/zhibo8/more.js | 20 ++++++++-------- lib/v2/zhibo8/post.js | 16 ++++++------- lib/v2/zhihu/activities.js | 12 +++++----- lib/v2/zhihu/answers.js | 10 ++++---- lib/v2/zhihu/bookstore/newest.js | 6 ++--- lib/v2/zhihu/collection.js | 16 ++++++------- lib/v2/zhihu/daily-section.js | 8 +++---- lib/v2/zhihu/daily.js | 8 +++---- lib/v2/zhihu/hot.js | 10 ++++---- lib/v2/zhihu/hotlist.js | 8 +++---- lib/v2/zhihu/pin/daily.js | 6 ++--- lib/v2/zhihu/pin/hotlist.js | 6 ++--- lib/v2/zhihu/pin/people.js | 6 ++--- lib/v2/zhihu/pin/utils.js | 2 +- lib/v2/zhihu/posts.js | 18 +++++++------- lib/v2/zhihu/question.js | 10 ++++---- lib/v2/zhihu/timeline.js | 10 ++++---- lib/v2/zhihu/topic.js | 10 ++++---- lib/v2/zhihu/utils.js | 4 ++-- lib/v2/zhihu/weekly.js | 10 ++++---- lib/v2/zhihu/xhu/activities.js | 8 +++---- lib/v2/zhihu/xhu/answers.js | 8 +++---- lib/v2/zhihu/xhu/auth.js | 2 +- lib/v2/zhihu/xhu/collection.js | 10 ++++---- lib/v2/zhihu/xhu/posts.js | 8 +++---- lib/v2/zhihu/xhu/question.js | 8 +++---- lib/v2/zhihu/xhu/topic.js | 8 +++---- lib/v2/zhihu/xhu/zhuanlan.js | 14 +++++------ lib/v2/zhihu/zhuanlan.js | 16 ++++++------- lib/v2/zhitongcaijing/index.js | 20 ++++++++-------- lib/v2/zhiy/letter.js | 10 ++++---- lib/v2/zhiy/post.js | 12 +++++----- lib/v2/zhiy/utils.js | 2 +- lib/v2/zhubai/index.js | 10 ++++---- lib/v2/zhubai/top20.js | 14 +++++------ lib/v2/zimuxia/index.js | 12 +++++----- lib/v2/zimuxia/portfolio.js | 14 +++++------ lib/v2/zjgtjy/index.js | 8 +++---- lib/v2/zjol/paper.js | 20 ++++++++-------- lib/v2/zju/career/index.js | 14 +++++------ lib/v2/zju/cst/custom.js | 14 +++++------ lib/v2/zju/cst/index.js | 16 ++++++------- lib/v2/zju/grs/index.js | 16 ++++++------- lib/v2/zju/list.js | 16 ++++++------- lib/v2/zju/physics/index.js | 14 +++++------ lib/v2/zjuvag/blog.js | 14 +++++------ lib/v2/zodgame/forum.js | 14 +++++------ lib/v2/zotero/versions.js | 10 ++++---- lib/v2/zuel/notice.js | 14 +++++------ lib/v2/zuvio/boards.js | 4 ++-- lib/v2/zuvio/student5.js | 10 ++++---- lib/v2/zuvio/utils.js | 4 ++-- lib/v2/zyshow/index.js | 14 +++++------ lib/v2/zyw/hot.js | 8 +++---- 611 files changed, 3540 insertions(+), 3528 deletions(-) diff --git a/lib/v2/18comic/index.js b/lib/v2/18comic/index.js index 878b5166f..46e498a30 100644 --- a/lib/v2/18comic/index.js +++ b/lib/v2/18comic/index.js @@ -10,5 +10,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/albums${category === 'all' ? '' : `/${category}`}${keyword ? `?screen=${keyword}` : '?'}${time === 'a' ? '' : `&t=${time}`}${order === 'mr' ? '' : `&o=${order}`}`; - ctx.state.data = await ProcessItems(ctx, currentUrl, rootUrl); + ctx.set('data', await ProcessItems(ctx, currentUrl, rootUrl)); }; diff --git a/lib/v2/18comic/search.js b/lib/v2/18comic/search.js index 594704563..5e8552572 100644 --- a/lib/v2/18comic/search.js +++ b/lib/v2/18comic/search.js @@ -11,5 +11,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/search/${option}${category === 'all' ? '' : `/${category}`}${keyword ? `?search_query=${keyword}` : '?'}${time === 'a' ? '' : `&t=${time}`}${order === 'mr' ? '' : `&o=${order}`}`; - ctx.state.data = await ProcessItems(ctx, currentUrl, rootUrl); + ctx.set('data', await ProcessItems(ctx, currentUrl, rootUrl)); }; diff --git a/lib/v2/56kog/class.js b/lib/v2/56kog/class.js index 49d3ade66..15525ecba 100644 --- a/lib/v2/56kog/class.js +++ b/lib/v2/56kog/class.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const currentUrl = new URL(`class/${category}.html`, rootUrl).href; - ctx.state.data = await fetchItems(limit, currentUrl, ctx.cache.tryGet); + ctx.set('data', await fetchItems(limit, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/56kog/top.js b/lib/v2/56kog/top.js index c8840d210..d83e1049d 100644 --- a/lib/v2/56kog/top.js +++ b/lib/v2/56kog/top.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const currentUrl = new URL(`top/${category.split(/_/)[0]}_1.html`, rootUrl).href; - ctx.state.data = await fetchItems(limit, currentUrl, ctx.cache.tryGet); + ctx.set('data', await fetchItems(limit, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/95mm/category.js b/lib/v2/95mm/category.js index c8c4913aa..ad402868e 100644 --- a/lib/v2/95mm/category.js +++ b/lib/v2/95mm/category.js @@ -16,5 +16,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/category-${category}/list-1/index.html?page=1`; - ctx.state.data = await ProcessItems(ctx, categories[category], currentUrl); + ctx.set('data', await ProcessItems(ctx, categories[category], currentUrl)); }; diff --git a/lib/v2/95mm/tab.js b/lib/v2/95mm/tab.js index bb58519e0..1b3722011 100644 --- a/lib/v2/95mm/tab.js +++ b/lib/v2/95mm/tab.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/home-ajax/index.html?tabcid=${tab}&page=1`; - ctx.state.data = await ProcessItems(ctx, tab, currentUrl); + ctx.set('data', await ProcessItems(ctx, tab, currentUrl)); }; diff --git a/lib/v2/95mm/tag.js b/lib/v2/95mm/tag.js index bccb9c2e9..50ef64c14 100644 --- a/lib/v2/95mm/tag.js +++ b/lib/v2/95mm/tag.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/tag-${tag}/page-1/index.html`; - ctx.state.data = await ProcessItems(ctx, tag, currentUrl); + ctx.set('data', await ProcessItems(ctx, tag, currentUrl)); }; diff --git a/lib/v2/bangumi/tv/subject/index.js b/lib/v2/bangumi/tv/subject/index.js index 1285a01e3..f2d155efc 100644 --- a/lib/v2/bangumi/tv/subject/index.js +++ b/lib/v2/bangumi/tv/subject/index.js @@ -24,5 +24,5 @@ module.exports = async (ctx) => { default: throw new Error(`暂不支持对${type}的订阅`); } - ctx.state.data = response; + ctx.set('data', response); }; diff --git a/lib/v2/bilibili/user-channel.js b/lib/v2/bilibili/user-channel.js index 02c91dc36..a03dee57c 100644 --- a/lib/v2/bilibili/user-channel.js +++ b/lib/v2/bilibili/user-channel.js @@ -28,7 +28,7 @@ module.exports = async (ctx) => { }); if (!channelInfo) { - ctx.state.data = notFoundData; + ctx.set('data', notFoundData); return; } const [userName, face] = await cache.getUsernameAndFaceFromUID(ctx, uid); @@ -42,7 +42,7 @@ module.exports = async (ctx) => { const data = response.data.data; if (!data.archives) { - ctx.state.data = notFoundData; + ctx.set('data', notFoundData); return; } diff --git a/lib/v2/bilibili/user-collection.js b/lib/v2/bilibili/user-collection.js index 857b9ea10..f004d0b43 100644 --- a/lib/v2/bilibili/user-collection.js +++ b/lib/v2/bilibili/user-collection.js @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const data = response.data.data; if (!data.archives) { - ctx.state.data = notFoundData; + ctx.set('data', notFoundData); return; } diff --git a/lib/v2/cctv/category.js b/lib/v2/cctv/category.js index ffdd24d97..7429cebd2 100644 --- a/lib/v2/cctv/category.js +++ b/lib/v2/cctv/category.js @@ -16,5 +16,5 @@ module.exports = async (ctx) => { responseData = await getNews(category, ctx); } - ctx.state.data = responseData; + ctx.set('data', responseData); }; diff --git a/lib/v2/coomer/artist.js b/lib/v2/coomer/artist.js index c39a69182..0e3d64a08 100644 --- a/lib/v2/coomer/artist.js +++ b/lib/v2/coomer/artist.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const currentUrl = `onlyfans/user/${id}`; - ctx.state.data = await fetchItems(ctx, currentUrl); + ctx.set('data', await fetchItems(ctx, currentUrl)); }; diff --git a/lib/v2/coomer/posts.js b/lib/v2/coomer/posts.js index 26d56a0d2..52e12d77e 100644 --- a/lib/v2/coomer/posts.js +++ b/lib/v2/coomer/posts.js @@ -3,5 +3,5 @@ const fetchItems = require('./utils'); module.exports = async (ctx) => { const currentUrl = 'posts'; - ctx.state.data = await fetchItems(ctx, currentUrl); + ctx.set('data', await fetchItems(ctx, currentUrl)); }; diff --git a/lib/v2/dapenti/subject.js b/lib/v2/dapenti/subject.js index 52041ff91..89021bc38 100644 --- a/lib/v2/dapenti/subject.js +++ b/lib/v2/dapenti/subject.js @@ -1,5 +1,5 @@ const utils = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await utils.parseFeed({ subjectid: ctx.req.param('id') }, ctx); + ctx.set('data', await utils.parseFeed({ subjectid: ctx.req.param('id') }, ctx)); }; diff --git a/lib/v2/dapenti/tugua.js b/lib/v2/dapenti/tugua.js index b6f4047fe..6c7730ae3 100644 --- a/lib/v2/dapenti/tugua.js +++ b/lib/v2/dapenti/tugua.js @@ -1,5 +1,5 @@ const utils = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await utils.parseFeed({ subjectid: 70 }, ctx); + ctx.set('data', await utils.parseFeed({ subjectid: 70 }, ctx)); }; diff --git a/lib/v2/discourse/posts.js b/lib/v2/discourse/posts.js index 6234994c1..6f21fe699 100644 --- a/lib/v2/discourse/posts.js +++ b/lib/v2/discourse/posts.js @@ -21,5 +21,5 @@ module.exports = async (ctx) => { ...e, })); - ctx.state.data = { item: feed.items, ...feed }; + ctx.set('data', { item: feed.items, ...feed }); }; diff --git a/lib/v2/dlsite/index.js b/lib/v2/dlsite/index.js index 4d3486993..77ff0f7ab 100644 --- a/lib/v2/dlsite/index.js +++ b/lib/v2/dlsite/index.js @@ -1,5 +1,5 @@ const { ProcessItems } = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await ProcessItems(ctx); + ctx.set('data', await ProcessItems(ctx)); }; diff --git a/lib/v2/dol/announce.js b/lib/v2/dol/announce.js index 9b77cf5f7..31a35b72c 100644 --- a/lib/v2/dol/announce.js +++ b/lib/v2/dol/announce.js @@ -27,7 +27,7 @@ module.exports = async (ctx) => { const slcProvince = $(`select#searchprovince option:contains('${province}')`); if (!slcProvince.length) { - ctx.state.data = result; + ctx.set('data', result); return; } @@ -38,7 +38,7 @@ module.exports = async (ctx) => { const slcOffice = $(`select#searchoffice option:contains('${office}')`); if (!slcOffice.length) { - ctx.state.data = result; + ctx.set('data', result); return; } @@ -88,5 +88,5 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = result; + ctx.set('data', result); }; diff --git a/lib/v2/douban/other/latest-music.js b/lib/v2/douban/other/latest-music.js index 63bf65426..65f55fc9a 100644 --- a/lib/v2/douban/other/latest-music.js +++ b/lib/v2/douban/other/latest-music.js @@ -70,5 +70,5 @@ module.exports = async (ctx) => { }; } - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/dribbble/keyword.js b/lib/v2/dribbble/keyword.js index 938c5678c..5dc871fae 100644 --- a/lib/v2/dribbble/keyword.js +++ b/lib/v2/dribbble/keyword.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const title = `Dribbble - keyword ${keyword}`; - ctx.state.data = await utils.getData(ctx, url, title); + ctx.set('data', await utils.getData(ctx, url, title)); }; diff --git a/lib/v2/dribbble/popular.js b/lib/v2/dribbble/popular.js index 92fe9df9f..a1de87d7b 100644 --- a/lib/v2/dribbble/popular.js +++ b/lib/v2/dribbble/popular.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const title = 'Dribbble - Popular Shots'; - ctx.state.data = await utils.getData(ctx, url, title); + ctx.set('data', await utils.getData(ctx, url, title)); }; diff --git a/lib/v2/dribbble/user.js b/lib/v2/dribbble/user.js index a427a3ffd..1ced515b8 100644 --- a/lib/v2/dribbble/user.js +++ b/lib/v2/dribbble/user.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const title = `Dribbble - user ${name}`; - ctx.state.data = await utils.getData(ctx, url, title); + ctx.set('data', await utils.getData(ctx, url, title)); }; diff --git a/lib/v2/gov/safe/business.js b/lib/v2/gov/safe/business.js index a4f82573a..d78459857 100644 --- a/lib/v2/gov/safe/business.js +++ b/lib/v2/gov/safe/business.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const { site = 'beijing' } = ctx.params; const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 3; - ctx.state.data = await processZxfkItems(site, 'ywzx', limit); + ctx.set('data', await processZxfkItems(site, 'ywzx', limit)); }; diff --git a/lib/v2/gov/safe/complaint.js b/lib/v2/gov/safe/complaint.js index c2eb9ffff..aee28ec7d 100644 --- a/lib/v2/gov/safe/complaint.js +++ b/lib/v2/gov/safe/complaint.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const { site = 'beijing' } = ctx.params; const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5; - ctx.state.data = await processZxfkItems(site, 'tsjy', limit); + ctx.set('data', await processZxfkItems(site, 'tsjy', limit)); }; diff --git a/lib/v2/grubstreet/index.js b/lib/v2/grubstreet/index.js index 38d5eda01..d0ac8a0ec 100644 --- a/lib/v2/grubstreet/index.js +++ b/lib/v2/grubstreet/index.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const title = `Grub Street`; const description = `New York Magazine's Food and Restaurant Blog`; - ctx.state.data = await utils.getData(ctx, url, title, description); + ctx.set('data', await utils.getData(ctx, url, title, description)); }; diff --git a/lib/v2/hpoi/all.js b/lib/v2/hpoi/all.js index 898049ac1..dada62194 100644 --- a/lib/v2/hpoi/all.js +++ b/lib/v2/hpoi/all.js @@ -1,3 +1,3 @@ const { ProcessFeed } = require('./utils'); -module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('all', 0, ctx.req.param('order'))); +module.exports = async (ctx) => ctx.set('data', await ProcessFeed('all', 0, ctx.req.param('order'))); diff --git a/lib/v2/hpoi/character.js b/lib/v2/hpoi/character.js index 9cdb6dbd8..4e2800962 100644 --- a/lib/v2/hpoi/character.js +++ b/lib/v2/hpoi/character.js @@ -1,3 +1,3 @@ const { ProcessFeed } = require('./utils'); -module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('character', ctx.req.param('id'), ctx.req.param('order'))); +module.exports = async (ctx) => ctx.set('data', await ProcessFeed('character', ctx.req.param('id'), ctx.req.param('order'))); diff --git a/lib/v2/hpoi/work.js b/lib/v2/hpoi/work.js index 59dd1c960..6f1573029 100644 --- a/lib/v2/hpoi/work.js +++ b/lib/v2/hpoi/work.js @@ -1,3 +1,3 @@ const { ProcessFeed } = require('./utils'); -module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('work', ctx.req.param('id'), ctx.req.param('order'))); +module.exports = async (ctx) => ctx.set('data', await ProcessFeed('work', ctx.req.param('id'), ctx.req.param('order'))); diff --git a/lib/v2/iqiyi/video.js b/lib/v2/iqiyi/video.js index cd58656fe..1f4dab1db 100644 --- a/lib/v2/iqiyi/video.js +++ b/lib/v2/iqiyi/video.js @@ -50,5 +50,5 @@ module.exports = async (ctx) => { ); browser.close(); - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/javdb/actors.js b/lib/v2/javdb/actors.js index 1eae14aea..766340e99 100644 --- a/lib/v2/javdb/actors.js +++ b/lib/v2/javdb/actors.js @@ -16,5 +16,5 @@ module.exports = async (ctx) => { const title = `JavDB${filters[filter] === '' ? '' : ` - ${filters[filter]}`} `; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/index.js b/lib/v2/javdb/index.js index b55da6837..7f38440e0 100644 --- a/lib/v2/javdb/index.js +++ b/lib/v2/javdb/index.js @@ -28,5 +28,5 @@ module.exports = async (ctx) => { const title = `${categories[category]} - JavDB - ${filters[filter] === '' ? '|' : `${filters[filter]} | `}${sorts[sort]}`; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/lists.js b/lib/v2/javdb/lists.js index 1507f35df..ac0ad4638 100644 --- a/lib/v2/javdb/lists.js +++ b/lib/v2/javdb/lists.js @@ -24,5 +24,5 @@ module.exports = async (ctx) => { const title = `JavDB${filters[filter] === '' ? '' : ` - ${filters[filter]}`} ${sortOptions[sort]}`; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/makers.js b/lib/v2/javdb/makers.js index 7fb0d91f0..43285a042 100644 --- a/lib/v2/javdb/makers.js +++ b/lib/v2/javdb/makers.js @@ -17,5 +17,5 @@ module.exports = async (ctx) => { const title = `JavDB${filters[filter] === '' ? '' : ` - ${filters[filter]}`} `; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/rankings.js b/lib/v2/javdb/rankings.js index aecd33e28..105f33a68 100644 --- a/lib/v2/javdb/rankings.js +++ b/lib/v2/javdb/rankings.js @@ -8,5 +8,5 @@ module.exports = async (ctx) => { const title = 'JavDB'; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/search.js b/lib/v2/javdb/search.js index 413401449..3821585a5 100644 --- a/lib/v2/javdb/search.js +++ b/lib/v2/javdb/search.js @@ -29,5 +29,5 @@ module.exports = async (ctx) => { const title = `關鍵字 ${keyword} ${filters[filter] === '' ? '' : `+ ${filters[filter]}`} ${sorts[sort]} 搜索結果 - JavDB`; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/series.js b/lib/v2/javdb/series.js index d1d0fc59b..768598ae2 100644 --- a/lib/v2/javdb/series.js +++ b/lib/v2/javdb/series.js @@ -17,5 +17,5 @@ module.exports = async (ctx) => { const title = `JavDB${filters[filter] === '' ? '' : ` - ${filter[filter]}`} `; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javdb/tags.js b/lib/v2/javdb/tags.js index 866732d60..03f7dc959 100644 --- a/lib/v2/javdb/tags.js +++ b/lib/v2/javdb/tags.js @@ -8,5 +8,5 @@ module.exports = async (ctx) => { const title = `JavDB${query === '' ? '' : ` - ${query}`} `; - ctx.state.data = await utils.ProcessItems(ctx, currentUrl, title); + ctx.set('data', await utils.ProcessItems(ctx, currentUrl, title)); }; diff --git a/lib/v2/javlibrary/bestrated.js b/lib/v2/javlibrary/bestrated.js index d419f05b9..245d3b479 100644 --- a/lib/v2/javlibrary/bestrated.js +++ b/lib/v2/javlibrary/bestrated.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_bestrated.php?list&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/bestreviews.js b/lib/v2/javlibrary/bestreviews.js index 51a313929..fc130d09a 100644 --- a/lib/v2/javlibrary/bestreviews.js +++ b/lib/v2/javlibrary/bestreviews.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/tl_bestreviews.php?list&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/genre.js b/lib/v2/javlibrary/genre.js index 32ce76136..bca115761 100644 --- a/lib/v2/javlibrary/genre.js +++ b/lib/v2/javlibrary/genre.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_genre.php?list&g=${genre}&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/maker.js b/lib/v2/javlibrary/maker.js index 6b5d24cbe..3dd6cd86a 100644 --- a/lib/v2/javlibrary/maker.js +++ b/lib/v2/javlibrary/maker.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_maker.php?list&m=${maker}&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/mostwanted.js b/lib/v2/javlibrary/mostwanted.js index 546a9f250..0a8f24dde 100644 --- a/lib/v2/javlibrary/mostwanted.js +++ b/lib/v2/javlibrary/mostwanted.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_mostwanted.php?list&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/newentries.js b/lib/v2/javlibrary/newentries.js index ca935979a..07306df14 100644 --- a/lib/v2/javlibrary/newentries.js +++ b/lib/v2/javlibrary/newentries.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_newentries.php?list`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/newrelease.js b/lib/v2/javlibrary/newrelease.js index 0db9df82b..639e0f55d 100644 --- a/lib/v2/javlibrary/newrelease.js +++ b/lib/v2/javlibrary/newrelease.js @@ -5,5 +5,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_newrelease.php?list&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/star.js b/lib/v2/javlibrary/star.js index 12e850f3f..0b415f258 100644 --- a/lib/v2/javlibrary/star.js +++ b/lib/v2/javlibrary/star.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_star.php?list&s=${id}&mode=${mode}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/update.js b/lib/v2/javlibrary/update.js index efcf3b30d..1c59b37c0 100644 --- a/lib/v2/javlibrary/update.js +++ b/lib/v2/javlibrary/update.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/vl_update.php?list`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/javlibrary/user.js b/lib/v2/javlibrary/user.js index b241d3709..b8d27b464 100644 --- a/lib/v2/javlibrary/user.js +++ b/lib/v2/javlibrary/user.js @@ -6,5 +6,5 @@ module.exports = async (ctx) => { const language = ctx.req.param('language') ?? defaultLanguage; const currentUrl = `${rootUrl}/${language}/${type}.php?list&u=${id}`; - ctx.state.data = await ProcessItems(language, currentUrl, ctx.cache.tryGet); + ctx.set('data', await ProcessItems(language, currentUrl, ctx.cache.tryGet)); }; diff --git a/lib/v2/mihoyo/bbs/follow-list.js b/lib/v2/mihoyo/bbs/follow-list.js index a314fc2b9..7e5123849 100644 --- a/lib/v2/mihoyo/bbs/follow-list.js +++ b/lib/v2/mihoyo/bbs/follow-list.js @@ -46,5 +46,5 @@ module.exports = async (ctx) => { link, item: items, }; - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/mihoyo/bbs/img-ranking.js b/lib/v2/mihoyo/bbs/img-ranking.js index 1e2c1b64e..0570235d8 100644 --- a/lib/v2/mihoyo/bbs/img-ranking.js +++ b/lib/v2/mihoyo/bbs/img-ranking.js @@ -77,5 +77,5 @@ module.exports = async (ctx) => { link: url, item: items, }; - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/mihoyo/bbs/official.js b/lib/v2/mihoyo/bbs/official.js index 2131b8c47..feaab1267 100644 --- a/lib/v2/mihoyo/bbs/official.js +++ b/lib/v2/mihoyo/bbs/official.js @@ -42,5 +42,5 @@ module.exports = async (ctx) => { item: items, }; - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/mihoyo/bbs/timeline.js b/lib/v2/mihoyo/bbs/timeline.js index e9c64acbc..abea838cb 100644 --- a/lib/v2/mihoyo/bbs/timeline.js +++ b/lib/v2/mihoyo/bbs/timeline.js @@ -37,5 +37,5 @@ module.exports = async (ctx) => { link, item: items, }; - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/mihoyo/bbs/user-post.js b/lib/v2/mihoyo/bbs/user-post.js index b9adf4d76..2b148733e 100644 --- a/lib/v2/mihoyo/bbs/user-post.js +++ b/lib/v2/mihoyo/bbs/user-post.js @@ -28,5 +28,5 @@ module.exports = async (ctx) => { link, item: items, }; - ctx.state.data = data; + ctx.set('data', data); }; diff --git a/lib/v2/parliament/section77.js b/lib/v2/parliament/section77.js index 93de26699..c82913713 100644 --- a/lib/v2/parliament/section77.js +++ b/lib/v2/parliament/section77.js @@ -157,5 +157,5 @@ module.exports = async (ctx) => { result.item = actListFull; - ctx.state.data = result; + ctx.set('data', result); }; diff --git a/lib/v2/phoronix/index.js b/lib/v2/phoronix/index.js index ffab2b236..fe2af0e46 100644 --- a/lib/v2/phoronix/index.js +++ b/lib/v2/phoronix/index.js @@ -230,5 +230,5 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = feed; + ctx.set('data', feed); }; diff --git a/lib/v2/qq/ac/rank.js b/lib/v2/qq/ac/rank.js index f9e9865f9..b1bfb61ff 100644 --- a/lib/v2/qq/ac/rank.js +++ b/lib/v2/qq/ac/rank.js @@ -16,5 +16,5 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/Rank/comicRank/type/${type}`; - ctx.state.data = await ProcessItems(ctx, currentUrl, time, titles[type]); + ctx.set('data', await ProcessItems(ctx, currentUrl, time, titles[type])); }; diff --git a/lib/v2/ruancan/category.js b/lib/v2/ruancan/category.js index 3239d9a09..d4143c472 100644 --- a/lib/v2/ruancan/category.js +++ b/lib/v2/ruancan/category.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const category = ctx.req.param('category'); const currentUrl = `/cat/${category}`; - ctx.state.data = await fetchFeed(ctx, currentUrl); + ctx.set('data', await fetchFeed(ctx, currentUrl)); }; diff --git a/lib/v2/ruancan/index.js b/lib/v2/ruancan/index.js index e6897946b..77998f6e3 100644 --- a/lib/v2/ruancan/index.js +++ b/lib/v2/ruancan/index.js @@ -3,5 +3,5 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { const currentUrl = ''; - ctx.state.data = await fetchFeed(ctx, currentUrl); + ctx.set('data', await fetchFeed(ctx, currentUrl)); }; diff --git a/lib/v2/ruancan/search.js b/lib/v2/ruancan/search.js index df17fd81c..87f1ecef7 100644 --- a/lib/v2/ruancan/search.js +++ b/lib/v2/ruancan/search.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const keyword = ctx.req.param('keyword'); const currentUrl = `/?s=${keyword}`; - ctx.state.data = await fetchFeed(ctx, currentUrl); + ctx.set('data', await fetchFeed(ctx, currentUrl)); }; diff --git a/lib/v2/ruancan/user.js b/lib/v2/ruancan/user.js index 4ea2ed657..49d8a6c78 100644 --- a/lib/v2/ruancan/user.js +++ b/lib/v2/ruancan/user.js @@ -4,5 +4,5 @@ module.exports = async (ctx) => { const id = ctx.req.param('id'); const currentUrl = `/i/${id}`; - ctx.state.data = await fetchFeed(ctx, currentUrl); + ctx.set('data', await fetchFeed(ctx, currentUrl)); }; diff --git a/lib/v2/shmeea/self-study.js b/lib/v2/shmeea/self-study.js index ffb76eaed..f1417f4ab 100644 --- a/lib/v2/shmeea/self-study.js +++ b/lib/v2/shmeea/self-study.js @@ -1,12 +1,12 @@ -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'; function load_detail(list, cache) { return Promise.all( list.map((item) => { - const notice_item = cheerio.load(item); + const notice_item = load(item); const href = notice_item('a').attr('href'); const url = 'http://www.shmeea.edu.cn' + href; if (href[0] !== '/') { @@ -25,7 +25,7 @@ function load_detail(list, cache) { Host: 'www.shmeea.edu.cn', }, }); - const detail = cheerio.load(detail_response.data); + const detail = load(detail_response.data); return { title: notice_item('a').attr('title'), description: detail('.Article_content').html(), @@ -48,14 +48,14 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#main > div.container > div > div.span9 > div.page-he > div > ul > li').get(); const detail = await load_detail(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '上海自学考试 - 通知公告', link: 'http://www.shmeea.edu.cn/page/04000/index.html', item: detail, - }; + }); }; diff --git a/lib/v2/shmtu/jwc.js b/lib/v2/shmtu/jwc.js index f49f43db0..7a9d33a48 100644 --- a/lib/v2/shmtu/jwc.js +++ b/lib/v2/shmtu/jwc.js @@ -1,12 +1,12 @@ -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://jwc.shmtu.edu.cn'; -async function load(link) { +async function loadContent(link) { const response = await got(link, { https: { rejectUnauthorized: false } }); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('.wp_articlecontent').html(); } @@ -15,14 +15,14 @@ const ProcessFeed = (list, caches) => Promise.all( list.map((item) => caches.tryGet(item.link, async () => { - item.description = await load(item.link); + item.description = await loadContent(item.link); return item; }) ) ); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const info = type === 'jwgg' ? '教务公告' : '教务新闻'; const response = await got(`${host}/${type}/list.htm`, { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { https: { rejectUnauthorized: false }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('tbody tr') .toArray() .map((item) => { @@ -48,10 +48,10 @@ module.exports = async (ctx) => { const result = await ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `上海海事大学 ${info}`, link: `${host}/${type}`, description: '上海海事大学 教务信息', item: result, - }; + }); }; diff --git a/lib/v2/shmtu/portal.js b/lib/v2/shmtu/portal.js index 871dd95e6..e3c0d5000 100644 --- a/lib/v2/shmtu/portal.js +++ b/lib/v2/shmtu/portal.js @@ -1,9 +1,9 @@ -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 path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const bootstrapHost = 'https://weixin.shmtu.edu.cn/dynamic/shmtuHttps'; const host = 'https://portal.shmtu.edu.cn/api'; @@ -38,7 +38,7 @@ const processFeed = (list, caches) => ); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let info; switch (type) { case 'bmtzgg': @@ -63,7 +63,7 @@ module.exports = async (ctx) => { }); const list = JSON.parse(response.data).map((item) => ({ - title: cheerio.load(item.title).text(), + title: load(item.title).text(), link: `${host}/node/${item.nid}.json`, pubDate: timezone(parseDate(item.created), 8), category: item.field_department[0], @@ -72,10 +72,10 @@ module.exports = async (ctx) => { const result = await processFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `上海海事大学 ${info}`, link: 'https://portal.shmtu.edu.cn/bumentongzhigonggao', description: '上海海事大学 数字平台', item: result, - }; + }); }; diff --git a/lib/v2/shmtu/www.js b/lib/v2/shmtu/www.js index 6040dea87..7072373ff 100644 --- a/lib/v2/shmtu/www.js +++ b/lib/v2/shmtu/www.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'; const host = 'https://www.shmtu.edu.cn'; -async function load(link) { +async function loadContent(link) { const response = await got.get(link, { https: { rejectUnauthorized: false } }); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('article').html(); } @@ -14,7 +14,7 @@ const ProcessFeed = (list, caches) => Promise.all( list.map((item) => caches.tryGet(item.link, async () => { - item.description = await load(item.link); + item.description = await loadContent(item.link); return item; }) @@ -22,7 +22,7 @@ const ProcessFeed = (list, caches) => ); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const info = type === 'notes' ? '通知公告' : '学术讲座'; const response = await got(`${host}/${type}`, { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { https: { rejectUnauthorized: false }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('tbody tr') .toArray() .map((item) => { @@ -49,10 +49,10 @@ module.exports = async (ctx) => { const result = await ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `上海海事大学 ${info}`, link: `${host}/${type}`, description: '上海海事大学 官网信息', item: result, - }; + }); }; diff --git a/lib/v2/shoac/recent-show.js b/lib/v2/shoac/recent-show.js index 0c7551d1b..1e6893786 100644 --- a/lib/v2/shoac/recent-show.js +++ b/lib/v2/shoac/recent-show.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const path = require('path'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://www.shoac.com.cn'; @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '演出月历 - 上海东方艺术中心管理有限公司', link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/shopback/store.js b/lib/v2/shopback/store.js index 126692f5e..fb1a4d2fd 100644 --- a/lib/v2/shopback/store.js +++ b/lib/v2/shopback/store.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 store = ctx.params.store; + const store = ctx.req.param('store'); const rootUrl = 'https://www.shopback.com.tw'; const currentUrl = `${rootUrl}/${store}`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('table').remove(); @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `${$('h1').text()} - ShopBack`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/shoppingdesign/posts.js b/lib/v2/shoppingdesign/posts.js index c1a691624..cd977c4d1 100644 --- a/lib/v2/shoppingdesign/posts.js +++ b/lib/v2/shoppingdesign/posts.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 asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { // sn_f parameter is required to prevent redirection const currentUrl = 'https://www.shoppingdesign.com.tw/post?sn_f=1'; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = []; // maximum parallel requests on the target website are limited to 11. for await (const data of asyncPool(10, $('article-item'), (item) => { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const link = item.attr('url'); return ctx.cache.tryGet(link, async () => { const response = await got(`${link}?sn_f=1`); - const $ = cheerio.load(response.data); + const $ = load(response.data); const article = $('.left article .htmlview'); article.find('d-image').each(function () { $(this).replaceWith(``); @@ -34,10 +34,10 @@ module.exports = async (ctx) => { items.push(data); } - ctx.state.data = { + ctx.set('data', { title: $('meta[property="og:title"]').attr('content'), link: currentUrl, description: $('meta[property="og:description"]').attr('content'), item: items, - }; + }); }; diff --git a/lib/v2/showstart/artist.js b/lib/v2/showstart/artist.js index bb2e0d5d4..124fb3df7 100644 --- a/lib/v2/showstart/artist.js +++ b/lib/v2/showstart/artist.js @@ -2,14 +2,14 @@ const { TITLE, HOST } = require('./const'); const { fetchPerformerInfo } = require('./service'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const artist = await fetchPerformerInfo({ performerId: id, }); - ctx.state.data = { + ctx.set('data', { title: `${TITLE} - ${artist.name}`, description: artist.content, link: `${HOST}/artist/${artist.id}`, item: artist.activityList, - }; + }); }; diff --git a/lib/v2/showstart/brand.js b/lib/v2/showstart/brand.js index 0b7fc4d8c..56623e598 100644 --- a/lib/v2/showstart/brand.js +++ b/lib/v2/showstart/brand.js @@ -2,14 +2,14 @@ const { TITLE, HOST } = require('./const'); const { fetchBrandInfo } = require('./service'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const brand = await fetchBrandInfo({ brandId: id, }); - ctx.state.data = { + ctx.set('data', { title: `${TITLE} - ${brand.name}`, description: brand.content, link: `${HOST}/host/${brand.id}`, item: brand.activityList, - }; + }); }; diff --git a/lib/v2/showstart/event.js b/lib/v2/showstart/event.js index 3406952b6..9b01cecba 100644 --- a/lib/v2/showstart/event.js +++ b/lib/v2/showstart/event.js @@ -2,17 +2,17 @@ const { TITLE, HOST } = require('./const'); const { fetchActivityList, fetchDictionary } = require('./service'); module.exports = async (ctx) => { - const cityCode = Number.parseInt(ctx.params.cityCode); - const showStyle = Number.parseInt(ctx.params.showStyle); + const cityCode = Number.parseInt(ctx.req.param('cityCode')); + const showStyle = Number.parseInt(ctx.req.param('showStyle')); const items = await fetchActivityList({ cityCode, showStyle, }); const { cityName, showName } = await fetchDictionary(cityCode, showStyle); const tags = [cityName, showName].filter(Boolean).join(' - '); - ctx.state.data = { + ctx.set('data', { title: `${TITLE} - ${tags}`, link: HOST, item: items, - }; + }); }; diff --git a/lib/v2/showstart/search.js b/lib/v2/showstart/search.js index cc222c1a2..3fd4d1489 100644 --- a/lib/v2/showstart/search.js +++ b/lib/v2/showstart/search.js @@ -2,8 +2,8 @@ const { TITLE, HOST } = require('./const'); const { fetchActivityList, fetchPerformerList, fetchBrandList, fetchCityList, fetchStyleList } = require('./service'); module.exports = async (ctx) => { - const type = ctx.params.type || ''; - const keyword = ctx.params.keyword || ''; + const type = ctx.req.param('type') || ''; + const keyword = ctx.req.param('keyword') || ''; switch (type) { case 'event': diff --git a/lib/v2/showstart/utils.js b/lib/v2/showstart/utils.js index 025a8be8f..a9634a23b 100644 --- a/lib/v2/showstart/utils.js +++ b/lib/v2/showstart/utils.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const md5 = require('@/utils/md5'); +import got from '@/utils/got'; +import md5 from '@/utils/md5'; const uuid = (length = 20) => { const e = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' + Date.now(); diff --git a/lib/v2/shu/index.js b/lib/v2/shu/index.js index bef5e95ec..1dd264a36 100644 --- a/lib/v2/shu/index.js +++ b/lib/v2/shu/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 host = 'https://www.shu.edu.cn/'; const alias = new Map([ @@ -12,10 +12,10 @@ const alias = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type || 'news'; + const type = ctx.req.param('type') || 'news'; const link = `https://www.shu.edu.cn/${alias.get(type) || type}.htm`; const respond = await got.get(link); - const $ = cheerio.load(respond.data); + const $ = load(respond.data); const title = $('title').text(); const list = $('.ej_main .list') .find('li') @@ -31,7 +31,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got.get(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.author = $('.xx>:nth-child(2)').text().trim().slice(3); // 投稿:xxx item.pubDate = parseDate(item.date, 'YYYY.MM.DD'); item.description = $('.v_news_content').html() || item.title; @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link, item: all, - }; + }); }; diff --git a/lib/v2/shu/jwb.js b/lib/v2/shu/jwb.js index 803cada7e..56ce30e0e 100644 --- a/lib/v2/shu/jwb.js +++ b/lib/v2/shu/jwb.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 = 'https://jwb.shu.edu.cn/'; const alias = new Map([ @@ -10,10 +10,10 @@ const alias = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type || 'notice'; + const type = ctx.req.param('type') || 'notice'; const link = `https://jwb.shu.edu.cn/index/${alias.get(type) || type}.htm`; const respond = await got.get(link); - const $ = cheerio.load(respond.data); + const $ = load(respond.data); const title = $('title').text(); const list = $('.only-list') .find('li') @@ -29,7 +29,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got.get(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.author = $('[id$=_lblUser]').text().trim(); item.pubDate = parseDate(item.date, 'YYYY年MM月DD日'); item.description = $('.v_news_content').html() || item.title; @@ -37,9 +37,9 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title, link, item: all, - }; + }); }; diff --git a/lib/v2/shuiguopai/index.js b/lib/v2/shuiguopai/index.js index bac250651..fd8a236ef 100644 --- a/lib/v2/shuiguopai/index.js +++ b/lib/v2/shuiguopai/index.js @@ -1,8 +1,8 @@ -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) => { @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const listUrl = `${apiRootUrl}/v1_2/homePage`; const filmUrl = `${apiRootUrl}/v1_2/filmInfo`; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; const response = await got({ method: 'post', @@ -43,7 +43,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('iframe').remove(); let videos; @@ -78,9 +78,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '水果派', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/sicau/dky.js b/lib/v2/sicau/dky.js index 23a4377f4..226fd6452 100644 --- a/lib/v2/sicau/dky.js +++ b/lib/v2/sicau/dky.js @@ -1,10 +1,10 @@ -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 = async (ctx) => { - const category = ctx.params.category ?? 'tzgg'; + const category = ctx.req.param('category') ?? 'tzgg'; const rootUrl = 'https://dky.sicau.edu.cn'; const currentUrl = `${rootUrl}/${category}.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a.tit') .slice(0, 10) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.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/sicau/yan.js b/lib/v2/sicau/yan.js index 138626906..ab0d4449e 100644 --- a/lib/v2/sicau/yan.js +++ b/lib/v2/sicau/yan.js @@ -1,10 +1,10 @@ -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 = async (ctx) => { - const category = ctx.params.category ?? 'xwgg'; + const category = ctx.req.param('category') ?? 'xwgg'; const rootUrl = 'https://yan.sicau.edu.cn'; const currentUrl = `${rootUrl}/index/${category}.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list-4 a[title]') .slice(0, 10) @@ -34,7 +34,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.v_news_content').html(); item.pubDate = timezone(parseDate(detailResponse.data.match(/发布时间: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm:ss'), +8); @@ -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/sicau/zsjy.js b/lib/v2/sicau/zsjy.js index e45fb42ab..d0c0ea335 100644 --- a/lib/v2/sicau/zsjy.js +++ b/lib/v2/sicau/zsjy.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 ?? 'bkszs'; + const category = ctx.req.param('category') ?? 'bkszs'; const rootUrl = 'https://dky.sicau.edu.cn'; const currentUrl = `${rootUrl}/zsjy/${category}.htm`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a.tit') .map((_, item) => { @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.v_news_content p').slice(0, 2).remove(); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sigsac/ccs.js b/lib/v2/sigsac/ccs.js index cb2cca561..7f14f14b8 100644 --- a/lib/v2/sigsac/ccs.js +++ b/lib/v2/sigsac/ccs.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = 'https://www.sigsac.org/'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // https://www.sigsac.org/ccs/CCS2022/program/accepted-papers.html module.exports = async (ctx) => { @@ -10,14 +10,14 @@ module.exports = async (ctx) => { const yearResponses = await got.all(yearList.map((url) => got(url))); const urlList = yearResponses.map((response) => { - const $ = cheerio.load(response.data); + const $ = load(response.data); return new URL($('a:contains("Accepted Papers")').attr('href'), response.url).href; }); const responses = await got.all(urlList.map((url) => got(url))); const items = responses.map((response) => { - const $ = cheerio.load(response.data); + const $ = load(response.data); const link = response.url; const paperSection = $('div.papers-item') .toArray() @@ -47,11 +47,11 @@ module.exports = async (ctx) => { return paperSection.length ? paperSection : paperTable; }); - ctx.state.data = { + ctx.set('data', { title: 'ACM CCS', link: url, description: 'The ACM Conference on Computer and Communications Security (CCS) Accepted Papers', allowEmpty: true, item: items.flat(), - }; + }); }; diff --git a/lib/v2/simpleinfo/index.js b/lib/v2/simpleinfo/index.js index 72fdf5c86..b129527b5 100644 --- a/lib/v2/simpleinfo/index.js +++ b/lib/v2/simpleinfo/index.js @@ -1,16 +1,16 @@ -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 path = require('path'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category } = ctx.params; const rootUrl = 'https://blog.simpleinfo.cc'; const link = `${rootUrl}${category ? (category === 'work' || category === 'talk' ? `/blog/${category}` : `/shasha77?category=${category}`) : '/shasha77'}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = `${$('.-active').text()} - 簡訊設計`; $('.-ad').remove(); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const result = await got(item.link); - const content = cheerio.load(result.data); + const content = load(result.data); item.author = content('meta[property="article:author"]').attr('content'); item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8); item.description = art(path.join(__dirname, 'templates/description.art'), { @@ -41,10 +41,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link, language: 'zh-tw', item: items, - }; + }); }; diff --git a/lib/v2/sina/chuangshiji.js b/lib/v2/sina/chuangshiji.js index d82d2b0bd..d15ab4aa7 100644 --- a/lib/v2/sina/chuangshiji.js +++ b/lib/v2/sina/chuangshiji.js @@ -9,9 +9,9 @@ module.exports = async (ctx) => { const out = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: '新浪专栏-创事记', link: 'https://tech.sina.com.cn/chuangshiji', item: out, - }; + }); }; diff --git a/lib/v2/sina/discovery.js b/lib/v2/sina/discovery.js index 857813e6b..2c5066d5d 100644 --- a/lib/v2/sina/discovery.js +++ b/lib/v2/sina/discovery.js @@ -13,7 +13,7 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const lid = map.get(type).id; const title = map.get(type).title; const pageid = '207'; @@ -24,9 +24,9 @@ module.exports = async (ctx) => { const out = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `${title}-新浪科技科学探索`, link, item: out, - }; + }); }; diff --git a/lib/v2/sina/finance/china.js b/lib/v2/sina/finance/china.js index d171c1f98..906bf0bfb 100644 --- a/lib/v2/sina/finance/china.js +++ b/lib/v2/sina/finance/china.js @@ -17,9 +17,9 @@ module.exports = async (ctx) => { const out = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `新浪财经-${map[lid]}`, link: 'http://finance.sina.com.cn/china/', item: out, - }; + }); }; diff --git a/lib/v2/sina/finance/stock/usstock.js b/lib/v2/sina/finance/stock/usstock.js index 1d42f729b..86f34207c 100644 --- a/lib/v2/sina/finance/stock/usstock.js +++ b/lib/v2/sina/finance/stock/usstock.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 { parseArticle } = require('../../utils'); module.exports = async (ctx) => { @@ -29,9 +29,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://finance.sina.com.cn/stock/usstock/', item: items, - }; + }); }; diff --git a/lib/v2/sina/rollnews.js b/lib/v2/sina/rollnews.js index 9a24a1d8d..ac8b81f47 100644 --- a/lib/v2/sina/rollnews.js +++ b/lib/v2/sina/rollnews.js @@ -23,9 +23,9 @@ module.exports = async (ctx) => { const out = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `新浪${map[lid]}滚动新闻`, link: `https://news.sina.com.cn/roll/#pageid=${pageid}&lid=${lid}&k=&num=${limit}&page=1`, item: out, - }; + }); }; diff --git a/lib/v2/sina/sports.js b/lib/v2/sina/sports.js index 86def3ddf..a4237e10c 100644 --- a/lib/v2/sina/sports.js +++ b/lib/v2/sina/sports.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { parseArticle } = require('./utils'); module.exports = async (ctx) => { @@ -21,7 +21,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(query) .toArray() .map((item) => { @@ -34,10 +34,10 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text().split('_')[0]} - 新浪体育`, description: $('meta[name="description"]').attr('content'), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sina/utils.js b/lib/v2/sina/utils.js index 8037643ea..dc95adac6 100644 --- a/lib/v2/sina/utils.js +++ b/lib/v2/sina/utils.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -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 { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); const getRollNewsList = (pageid, lid, limit) => @@ -34,7 +34,7 @@ const parseRollNewsList = (data) => const parseArticle = (item, tryGet) => tryGet(item.link, async () => { const detailResponse = await got(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); $('#left_hzh_ad, .appendQr_wrap, .app-kaihu-qr, .tech-quotation').remove(); const metaPublishTime = $('meta[property="article:published_time"]'); diff --git a/lib/v2/sinchew/index.js b/lib/v2/sinchew/index.js index 4583b2ef1..2869b09f6 100644 --- a/lib/v2/sinchew/index.js +++ b/lib/v2/sinchew/index.js @@ -1,8 +1,8 @@ -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) => { @@ -14,10 +14,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.title .internalLink') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20) .toArray() .map((item) => { item = $(item); @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.ads-frame, .read-more-msg').remove(); @@ -60,9 +60,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sis001/forum.js b/lib/v2/sis001/forum.js index 4b7a2046f..5be80938c 100644 --- a/lib/v2/sis001/forum.js +++ b/lib/v2/sis001/forum.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 baseUrl = 'https://www.sis001.com'; module.exports = async (ctx) => { @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('form table') .last() @@ -31,7 +31,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.category = $('.posttags a') .toArray() @@ -53,10 +53,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[name=description]').attr('content'), link: url, item: items, - }; + }); }; diff --git a/lib/v2/sjtu/gs.js b/lib/v2/sjtu/gs.js index 59592043f..74fabccae 100644 --- a/lib/v2/sjtu/gs.js +++ b/lib/v2/sjtu/gs.js @@ -1,12 +1,12 @@ -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 { fetchArticle } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - const type = ctx.params.type; - const num = ctx.params.num ?? ''; + const type = ctx.req.param('type'); + const num = ctx.req.param('num') ?? ''; const rootUrl = 'https://www.gs.sjtu.edu.cn'; const currentUrl = `${rootUrl}/announcement/${type}/${num}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a.announcement-item') .map((_, item) => { @@ -42,7 +42,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.page-content').html(); } @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${num === '' ? '' : `${$('.category-nav-block .active').text().trim()} - `}${$('div.inner-banner-text .title').text().trim()} - ${$('title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sjtu/jwc.js b/lib/v2/sjtu/jwc.js index d4650af9f..3861d12e6 100644 --- a/lib/v2/sjtu/jwc.js +++ b/lib/v2/sjtu/jwc.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'; const urlRoot = 'https://jwc.sjtu.edu.cn/xwtg'; async function getFullArticle(link) { const response = await got(link); - const $ = cheerio.load(response.body); + const $ = load(response.body); const content = $('.content-con'); if (content.length === 0) { return null; @@ -26,7 +26,7 @@ async function getFullArticle(link) { } module.exports = async (ctx) => { - const type = ctx.params.type ?? 'notice'; + const type = ctx.req.param('type') ?? 'notice'; const config = { all: { section: '通知通告', @@ -81,7 +81,7 @@ module.exports = async (ctx) => { url: sectionLink, }); - const $ = cheerio.load(response.body); + const $ = load(response.body); const out = await Promise.all( $('body > div.list-box > div.container > div > div.ny_right > div > div.ny_right_con > div > ul') @@ -108,9 +108,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '上海交通大学教务处 ' + config[type].section, link: sectionLink, item: out, - }; + }); }; diff --git a/lib/v2/sjtu/seiee/bjwb.js b/lib/v2/sjtu/seiee/bjwb.js index 0a61185f3..894e013b8 100644 --- a/lib/v2/sjtu/seiee/bjwb.js +++ b/lib/v2/sjtu/seiee/bjwb.js @@ -25,7 +25,7 @@ module.exports = workerFactory( }, }; - const type = ctx.params.type; + const type = ctx.req.param('type'); return { title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title, diff --git a/lib/v2/sjtu/seiee/utils.js b/lib/v2/sjtu/seiee/utils.js index 97caa7bf7..35808c52a 100644 --- a/lib/v2/sjtu/seiee/utils.js +++ b/lib/v2/sjtu/seiee/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'; const host = 'https://bjwb.seiee.sjtu.edu.cn'; @@ -11,14 +11,14 @@ module.exports = function (meta, extract) { const link = new URL(local, host).href; const response = await got(link); - const list = extract(cheerio.load(response.data)); + const list = extract(load(response.data)); const out = await Promise.all( list.map((item) => { const itemUrl = new URL(item.link, host).href; return ctx.cache.tryGet(itemUrl, async () => { const response = await got(itemUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); return { title: item.title, @@ -31,10 +31,10 @@ module.exports = function (meta, extract) { }) ); - ctx.state.data = { + ctx.set('data', { title, link, item: out, - }; + }); }; }; diff --git a/lib/v2/sjtu/seiee/xsb.js b/lib/v2/sjtu/seiee/xsb.js index 801d5aee8..f0114c3c8 100644 --- a/lib/v2/sjtu/seiee/xsb.js +++ b/lib/v2/sjtu/seiee/xsb.js @@ -33,7 +33,7 @@ module.exports = workerFactory( }, }; - const type = ctx.params.type || 'all'; + const type = ctx.req.param('type') || 'all'; return { title: '上海交通大学电子信息与电气工程学院学生办 -- ' + config[type].title, diff --git a/lib/v2/sjtu/tongqu/activity.js b/lib/v2/sjtu/tongqu/activity.js index 756abbd03..31ffe5445 100644 --- a/lib/v2/sjtu/tongqu/activity.js +++ b/lib/v2/sjtu/tongqu/activity.js @@ -1,11 +1,11 @@ -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 urlRoot = 'https://tongqu.sjtu.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type || 'all'; + const type = ctx.req.param('type') || 'all'; const config = { all: 0, newest: -1, @@ -36,9 +36,9 @@ module.exports = async (ctx) => { description: art(path.join(__dirname, '../templates/activity.art'), { e }), })); - ctx.state.data = { + ctx.set('data', { title: '同去网活动', link, item: feeds, - }; + }); }; diff --git a/lib/v2/sjtu/yzb/zkxx.js b/lib/v2/sjtu/yzb/zkxx.js index 9266d3e91..d6626d8b7 100644 --- a/lib/v2/sjtu/yzb/zkxx.js +++ b/lib/v2/sjtu/yzb/zkxx.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'; const baseTitle = '上海交通大学研究生招生网招考信息'; const baseUrl = 'https://yzb.sjtu.edu.cn/index/zkxx/'; module.exports = async (ctx) => { - const pageUrl = `${baseUrl}${ctx.params.type}.htm`; + const pageUrl = `${baseUrl}${ctx.req.param('type')}.htm`; const response = await got({ method: 'get', @@ -16,9 +16,9 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); - ctx.state.data = { + ctx.set('data', { link: pageUrl, title: `${baseTitle} -- ${$('title').text().split('-')[0]}`, item: $('li[id^="line"] a') @@ -28,5 +28,5 @@ module.exports = async (ctx) => { title: elem.attribs.title, pubDate: parseDate($(elem.next).text().trim()), })), - }; + }); }; diff --git a/lib/v2/skysports/news.js b/lib/v2/skysports/news.js index ded970e47..93a32ae0a 100644 --- a/lib/v2/skysports/news.js +++ b/lib/v2/skysports/news.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 team = ctx.params.team; + const team = ctx.req.param('team'); const rootUrl = 'https://www.skysports.com'; const currentUrl = `${rootUrl}/${team}-news`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.news-list__headline-link') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.roadblock').remove(); content('.sdc-article-widget, .sdc-site-layout-sticky-region').remove(); @@ -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/slowmist/slowmist.js b/lib/v2/slowmist/slowmist.js index 2a72f102c..c7fe29174 100644 --- a/lib/v2/slowmist/slowmist.js +++ b/lib/v2/slowmist/slowmist.js @@ -1,10 +1,10 @@ -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://www.slowmist.com'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - let type = ctx.params.type; + let type = ctx.req.param('type'); let title = '慢雾科技 - '; switch (type) { @@ -41,9 +41,9 @@ module.exports = async (ctx) => { items = await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title, link: url, item: items, - }; + }); }; diff --git a/lib/v2/smashingmagazine/category.js b/lib/v2/smashingmagazine/category.js index 2a1a6ec7f..260af7b5d 100644 --- a/lib/v2/smashingmagazine/category.js +++ b/lib/v2/smashingmagazine/category.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 { category } = ctx.params; const baseUrl = 'https://www.smashingmagazine.com'; const route = category ? `/category/${category}` : '/articles'; const { data: response } = await got(`${baseUrl}${route}`); - const $ = cheerio.load(response); + const $ = load(response); const listItems = $('article.article--post') .toArray() @@ -31,7 +31,7 @@ module.exports = async (ctx) => { listItems.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.category = $('li.meta-box--tags a') .toArray() .map((item) => $(item).text()); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Smashing Magazine Articles', link: `${baseUrl}${route}`, item: items, @@ -59,5 +59,5 @@ module.exports = async (ctx) => { logo: 'https://www.smashingmagazine.com/images/favicon/apple-touch-icon.png', icon: 'https://www.smashingmagazine.com/images/favicon/favicon.svg', language: 'en-us', - }; + }); }; diff --git a/lib/v2/smzdm/article.js b/lib/v2/smzdm/article.js index 64c90a450..ce3e72e50 100644 --- a/lib/v2/smzdm/article.js +++ b/lib/v2/smzdm/article.js @@ -1,13 +1,13 @@ -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 = async (ctx) => { - const link = `https://zhiyou.smzdm.com/member/${ctx.params.uid}/article/`; + const link = `https://zhiyou.smzdm.com/member/${ctx.req.param('uid')}/article/`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('.info-stuff-nickname').text(); const list = $('.pandect-content-stuff') @@ -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.description = $('.m-contant article').html(); item.pubDate = timezone(parseDate($('meta[property="og:release_date"]').attr('content'), 'YYYY-MM-DD HH:mm:ss'), 8); item.author = $('meta[property="og:author"]').attr('content'); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${title}-什么值得买`, link, item: out, - }; + }); }; diff --git a/lib/v2/smzdm/baoliao.js b/lib/v2/smzdm/baoliao.js index 75a008090..0b11579f5 100644 --- a/lib/v2/smzdm/baoliao.js +++ b/lib/v2/smzdm/baoliao.js @@ -1,13 +1,13 @@ -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 = async (ctx) => { - const link = `https://zhiyou.smzdm.com/member/${ctx.params.uid}/baoliao/`; + const link = `https://zhiyou.smzdm.com/member/${ctx.req.param('uid')}/baoliao/`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('.info-stuff-nickname').text(); const list = $('.pandect-content-stuff') @@ -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.description = $('article.txt-detail').html(); item.pubDate = timezone(parseDate($('.time').first().text().trim().replace('更新时间:', '')), 8); item.author = title; @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${title}的爆料 - 什么值得买`, link, item: out, - }; + }); }; diff --git a/lib/v2/smzdm/haowen-fenlei.js b/lib/v2/smzdm/haowen-fenlei.js index ecf4219c0..9e0176487 100644 --- a/lib/v2/smzdm/haowen-fenlei.js +++ b/lib/v2/smzdm/haowen-fenlei.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 name = ctx.params.name; - const sort = ctx.params.sort || '0'; + const name = ctx.req.param('name'); + const sort = ctx.req.param('sort') || '0'; const link = sort === '0' ? `https://post.smzdm.com/fenlei/${name}/` : `https://post.smzdm.com/fenlei/${name}/hot_${sort}/`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.crumbs.nav-crumbs').text().split('>').pop(); const list = $('div.list.post-list') @@ -30,7 +30,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 = $('article').html(); item.pubDate = timezone(parseDate($('meta[property="og:release_date"]').attr('content')), 8); item.author = $('meta[property="og:author"]').attr('content'); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${title}- 什么值得买好文分类`, link, item: out, - }; + }); }; diff --git a/lib/v2/smzdm/haowen.js b/lib/v2/smzdm/haowen.js index bb062cebb..83b9610da 100644 --- a/lib/v2/smzdm/haowen.js +++ b/lib/v2/smzdm/haowen.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 = async (ctx) => { - const day = ctx.params.day ?? 'all'; + const day = ctx.req.param('day') ?? 'all'; const link = `https://post.smzdm.com/hot_${day}/`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('li.filter-tab.active').text(); const list = $('li.feed-row-wide') @@ -26,7 +26,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 content = $('#articleId'); content.find('.item-name').remove(); content.find('.recommend-tab').remove(); @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${title}-什么值得买好文`, link, item: out, - }; + }); }; diff --git a/lib/v2/smzdm/keyword.js b/lib/v2/smzdm/keyword.js index c286a763b..1b931fd2d 100644 --- a/lib/v2/smzdm/keyword.js +++ b/lib/v2/smzdm/keyword.js @@ -1,10 +1,10 @@ -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 = async (ctx) => { - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const response = await got(`https://search.smzdm.com`, { headers: { @@ -21,10 +21,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.feed-row-wide'); - ctx.state.data = { + ctx.set('data', { title: `${keyword} - 什么值得买`, link: `https://search.smzdm.com/?c=home&s=${encodeURIComponent(keyword)}&order=time`, item: @@ -38,5 +38,5 @@ module.exports = async (ctx) => { link: item.find('.feed-block-title a').attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/smzdm/ranking.js b/lib/v2/smzdm/ranking.js index 7ec51e9bf..4a32b3e9c 100644 --- a/lib/v2/smzdm/ranking.js +++ b/lib/v2/smzdm/ranking.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; const getTrueHour = (rank_type, rank_id, hour) => { const rank_two_hour = ['11', '17', '28', '29']; @@ -42,7 +42,7 @@ module.exports = async (ctx) => { } const list = [...list1, ...list2]; - ctx.state.data = { + ctx.set('data', { title: `${rank_type}榜-${rank_id}-${hour}小时`, link: 'https://www.smzdm.com/top/', allowEmpty: true, @@ -52,5 +52,5 @@ module.exports = async (ctx) => { pubDate: timezone(item.article_pubdate, +8), link: item.article_url, })), - }; + }); }; diff --git a/lib/v2/snowpeak/us-new-arrivals.js b/lib/v2/snowpeak/us-new-arrivals.js index f461396a1..50e772085 100644 --- a/lib/v2/snowpeak/us-new-arrivals.js +++ b/lib/v2/snowpeak/us-new-arrivals.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 cheerio = require('cheerio'); +import { load } from 'cheerio'; const host = 'https://www.snowpeak.com'; module.exports = async (ctx) => { const url = `${host}/collections/new-arrivals`; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.element.product-tile') .map(function () { const data = {}; @@ -30,7 +30,7 @@ module.exports = async (ctx) => { return data; }) .get(); - ctx.state.data = { + ctx.set('data', { title: 'Snow Peak - New Arrivals', link: `${host}/new-arrivals`, description: 'Snow Peak - New Arrivals', @@ -41,5 +41,5 @@ module.exports = async (ctx) => { pubDate: item.pubDate, link: item.link, })), - }; + }); }; diff --git a/lib/v2/sobooks/date.js b/lib/v2/sobooks/date.js index 71a600f79..d1c453b56 100644 --- a/lib/v2/sobooks/date.js +++ b/lib/v2/sobooks/date.js @@ -1,7 +1,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const date = ctx.params.date ?? `${new Date().getFullYear()}/${new Date().getMonth()}`; + const date = ctx.req.param('date') ?? `${new Date().getFullYear()}/${new Date().getMonth()}`; - ctx.state.data = await utils(ctx, `books/date/${date.replace('-', '/')}`); + ctx.set('data', await utils(ctx, `books/date/${date.replace('-', '/')}`)); }; diff --git a/lib/v2/sobooks/index.js b/lib/v2/sobooks/index.js index d2bf4c2d0..78ce2497f 100644 --- a/lib/v2/sobooks/index.js +++ b/lib/v2/sobooks/index.js @@ -1,7 +1,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; - ctx.state.data = await utils(ctx, category); + ctx.set('data', await utils(ctx, category)); }; diff --git a/lib/v2/sobooks/tag.js b/lib/v2/sobooks/tag.js index 30ce8615a..1a30b5c35 100644 --- a/lib/v2/sobooks/tag.js +++ b/lib/v2/sobooks/tag.js @@ -1,7 +1,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '小说'; + const id = ctx.req.param('id') ?? '小说'; - ctx.state.data = await utils(ctx, `books/tag/${id}`); + ctx.set('data', await utils(ctx, `books/tag/${id}`)); }; diff --git a/lib/v2/sobooks/utils.js b/lib/v2/sobooks/utils.js index 719a242f1..04c8202e6 100644 --- a/lib/v2/sobooks/utils.js +++ b/lib/v2/sobooks/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.sobooks.net'; @@ -10,7 +10,7 @@ module.exports = async (ctx, currentUrl) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.card-item h3 a') .slice(0, 15) @@ -30,7 +30,7 @@ module.exports = async (ctx, currentUrl) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.e-secret, .article-social').remove(); diff --git a/lib/v2/sogou/doodles.js b/lib/v2/sogou/doodles.js index e7b592e41..69b3b79e6 100644 --- a/lib/v2/sogou/doodles.js +++ b/lib/v2/sogou/doodles.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const response = await got({ @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const data = response.data.split(/\r\n/).slice(1); - ctx.state.data = { + ctx.set('data', { title: '搜狗特色LOGO', link: 'http://help.sogou.com/logo/', item: data.map((item) => { @@ -22,5 +22,5 @@ module.exports = async (ctx) => { guid: item[4], }; }), - }; + }); }; diff --git a/lib/v2/sogou/search.js b/lib/v2/sogou/search.js index 9cdb63454..c38a81379 100644 --- a/lib/v2/sogou/search.js +++ b/lib/v2/sogou/search.js @@ -1,9 +1,9 @@ -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 { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const renderDescription = (description, images) => art(path.join(__dirname, './templates/description.art'), { description, images }); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { key, async () => { const response = (await got(url)).data; - const $ = cheerio.load(response); + const $ = load(response); const result = $('#main'); return result .find('.vrwrap') @@ -45,10 +45,10 @@ module.exports = async (ctx) => { false ); - ctx.state.data = { + ctx.set('data', { title: `${keyword} - 搜狗搜索`, description: `${keyword} - 搜狗搜索`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/sohu/mp.js b/lib/v2/sohu/mp.js index 1dc239ebf..58342fa01 100644 --- a/lib/v2/sohu/mp.js +++ b/lib/v2/sohu/mp.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'; module.exports = async (ctx) => { const { id } = ctx.params; @@ -20,7 +20,7 @@ module.exports = async (ctx) => { list.map((e) => ctx.cache.tryGet(e.link, async () => { const { data: response } = await got(e.link); - const $ = cheerio.load(response); + const $ = load(response); if (!author) { const meta = $('span[data-role="original-link"]'); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `搜狐号 - ${author}`, link, item: items, - }; + }); }; diff --git a/lib/v2/solidot/_article.js b/lib/v2/solidot/_article.js index 70fce0f03..b66655060 100644 --- a/lib/v2/solidot/_article.js +++ b/lib/v2/solidot/_article.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); // get web content -const cheerio = require('cheerio'); // html parser -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; // get web content +import { load } from 'cheerio'; // html parser +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async function get_article(url) { const domain = 'https://www.solidot.org'; @@ -14,7 +14,7 @@ module.exports = async function get_article(url) { url, }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const date_raw = $('div.talk_time').clone().children().remove().end().text(); const date_str_zh = date_raw.replaceAll(/^[^`]*发表于(.*分)[^`]*$/g, '$1'); // use [^`] to match \n diff --git a/lib/v2/solidot/main.js b/lib/v2/solidot/main.js index 7eac16573..bc6f9f259 100644 --- a/lib/v2/solidot/main.js +++ b/lib/v2/solidot/main.js @@ -3,13 +3,13 @@ // params: // type: subject type -const got = require('@/utils/got'); // get web content -const cheerio = require('cheerio'); // html parser +import got from '@/utils/got'; // get web content +import { load } from 'cheerio'; // html parser const get_article = require('./_article'); const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const type = ctx.params.type ?? 'www'; + const type = ctx.req.param('type') ?? 'www'; if (!isValidHost(type)) { throw new Error('Invalid type'); } @@ -20,7 +20,7 @@ module.exports = async (ctx) => { url: base_url, }); const data = response.data; // content is html format - const $ = cheerio.load(data); + const $ = load(data); // get urls const a = $('div.block_m').find('div.bg_htit > h2 > a'); @@ -33,9 +33,9 @@ module.exports = async (ctx) => { const msg_list = await Promise.all(urls.map((u) => ctx.cache.tryGet(u, () => get_article(u)))); // feed the data - ctx.state.data = { + ctx.set('data', { title: '奇客的资讯,重要的东西', link: base_url, item: msg_list, - }; + }); }; diff --git a/lib/v2/sony/downloads.js b/lib/v2/sony/downloads.js index 9f470fcce..a6bbc1bed 100644 --- a/lib/v2/sony/downloads.js +++ b/lib/v2/sony/downloads.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 = 'https://www.sony.com'; module.exports = async (ctx) => { const { productType, productId } = ctx.params; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const contents = $('script:contains("window.__PRELOADED_STATE__.downloads")').text(); const regex = /window\.__PRELOADED_STATE__\.downloads\s*=\s*({.*?});\s*window\.__PRELOADED_STATE__/s; @@ -34,7 +34,7 @@ module.exports = async (ctx) => { } return data; }); - ctx.state.data = { + ctx.set('data', { title: `Sony - ${productId.toUpperCase()}`, link: url, description: `Sony - ${productId.toUpperCase()}`, @@ -44,5 +44,5 @@ module.exports = async (ctx) => { link: item.url, pubDate: item.pubDate, })), - }; + }); }; diff --git a/lib/v2/soundofhope/channel.js b/lib/v2/soundofhope/channel.js index 41ee34aa8..61b05771a 100644 --- a/lib/v2/soundofhope/channel.js +++ b/lib/v2/soundofhope/channel.js @@ -1,17 +1,17 @@ -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.soundofhope.org'; module.exports = async (ctx) => { - const channel = ctx.params.channel; - const id = ctx.params.id; + const channel = ctx.req.param('channel'); + const id = ctx.req.param('id'); const url = `${host}/${channel}/${id}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.left > nav').text().split('/').slice(1).join(''); const list = $('div.item') .map((_, item) => ({ @@ -24,7 +24,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('div.Content__Wrapper-sc-1bvya0-0').html(); item.pubDate = timezone(parseDate(content('div.date').text(), 'YYYY.M.D HH:mm'), -8); @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `希望之声 - ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/sourceforge/index.js b/lib/v2/sourceforge/index.js index af4daf59b..676a095a7 100644 --- a/lib/v2/sourceforge/index.js +++ b/lib/v2/sourceforge/index.js @@ -1,18 +1,18 @@ -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 routeParams = ctx.params.routeParams; + const routeParams = ctx.req.param('routeParams'); const baseURL = 'https://sourceforge.net'; const link = `https://sourceforge.net/directory/?${routeParams.toString()}`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const itemList = $('ul.projects li[itemprop=itemListElement]'); - ctx.state.data = { + ctx.set('data', { title: $('.content h1').text().trim(), link, item: itemList.toArray().map((element) => { @@ -29,5 +29,5 @@ module.exports = async (ctx) => { pubDate, }; }), - }; + }); }; diff --git a/lib/v2/southcn/nfapp/column.js b/lib/v2/southcn/nfapp/column.js index 51d69762a..a5f8c2351 100644 --- a/lib/v2/southcn/nfapp/column.js +++ b/lib/v2/southcn/nfapp/column.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { parseArticle } = require('./utils'); module.exports = async (ctx) => { - const columnId = ctx.params.column ?? 38; + const columnId = ctx.req.param('column') ?? 38; const getColumnDetail = `https://api.nfapp.southcn.com/nanfang_if/getColumn?columnId=${columnId}`; const { data: responseColumn } = await got(getColumnDetail); @@ -37,9 +37,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: columnName, link: columnLink, item: items, - }; + }); }; diff --git a/lib/v2/southcn/nfapp/reporter.js b/lib/v2/southcn/nfapp/reporter.js index 34e5a7741..5e8b91e96 100644 --- a/lib/v2/southcn/nfapp/reporter.js +++ b/lib/v2/southcn/nfapp/reporter.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const { parseArticle } = require('./utils'); const path = require('path'); module.exports = async (ctx) => { - const reporterId = ctx.params.reporter; + const reporterId = ctx.req.param('reporter'); const currentUrl = `https://api.nfapp.southcn.com/nanfang_if/reporter/list?reporterUuid=${reporterId}&pageSize=20&pageNo=1&origin=0`; const { data: response } = await got(currentUrl); @@ -25,9 +25,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: `南方+ - ${response.data.reportInfo.reporterName}`, link: `https://static.nfapp.southcn.com/apptpl/reporterWorksList/index.html?reporterUuid=${reporterId}`, item: items, - }; + }); }; diff --git a/lib/v2/southcn/nfapp/utils.js b/lib/v2/southcn/nfapp/utils.js index d92543215..bdc1dd98c 100644 --- a/lib/v2/southcn/nfapp/utils.js +++ b/lib/v2/southcn/nfapp/utils.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const parseArticle = (item, tryGet) => tryGet(item.link, async () => { @@ -8,7 +8,7 @@ const parseArticle = (item, tryGet) => url: item.link, }); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); $('.article-nfh-icon, .article-crumb, .article-share, .article-copyright').remove(); diff --git a/lib/v2/spotify/artist.js b/lib/v2/spotify/artist.js index 5fa03c037..f42ee937c 100644 --- a/lib/v2/spotify/artist.js +++ b/lib/v2/spotify/artist.js @@ -1,6 +1,6 @@ const utils = require('./utils'); -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 token = await utils.getPublicToken(); @@ -22,7 +22,7 @@ module.exports = async (ctx) => { .json(); const albums = itemsResponse.items; - ctx.state.data = { + ctx.set('data', { title: `Albums of ${meta.name}`, link: meta.external_urls.spotify, allowEmpty: true, @@ -33,7 +33,7 @@ module.exports = async (ctx) => { pubDate: parseDate(x.release_date), link: x.external_urls.spotify, })), - }; + }); if (meta.images.length) { ctx.state.data.image = meta.images[0].url; diff --git a/lib/v2/spotify/playlist.js b/lib/v2/spotify/playlist.js index cfd806487..d79436189 100644 --- a/lib/v2/spotify/playlist.js +++ b/lib/v2/spotify/playlist.js @@ -1,6 +1,6 @@ const utils = require('./utils'); -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 token = await utils.getPublicToken(); @@ -14,7 +14,7 @@ module.exports = async (ctx) => { .json(); const tracks = meta.tracks.items; - ctx.state.data = { + ctx.set('data', { title: meta.name, link: meta.external_urls.spotify, description: meta.description, @@ -23,7 +23,7 @@ module.exports = async (ctx) => { ...utils.parseTrack(x.track), pubDate: parseDate(x.added_at), })), - }; + }); if (meta.images.length) { ctx.state.data.image = meta.images[0].url; diff --git a/lib/v2/spotify/saved.js b/lib/v2/spotify/saved.js index 6ab1e6700..5699b383f 100644 --- a/lib/v2/spotify/saved.js +++ b/lib/v2/spotify/saved.js @@ -1,6 +1,6 @@ const utils = require('./utils'); -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 token = await utils.getPrivateToken(); @@ -17,7 +17,7 @@ module.exports = async (ctx) => { .json(); const tracks = itemsResponse.items; - ctx.state.data = { + ctx.set('data', { title: 'Spotify: My Saved Tracks', link: 'https://open.spotify.com/collection/tracks', description: `Latest ${pageSize} saved tracks on Spotify.`, @@ -26,5 +26,5 @@ module.exports = async (ctx) => { ...utils.parseTrack(x.track), pubDate: parseDate(x.added_at), })), - }; + }); }; diff --git a/lib/v2/spotify/show.js b/lib/v2/spotify/show.js index 0fa76f148..dfef4ce8b 100644 --- a/lib/v2/spotify/show.js +++ b/lib/v2/spotify/show.js @@ -1,6 +1,6 @@ const utils = require('./utils'); -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 token = await utils.getPublicToken(); @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const episodes = meta.episodes.items; - ctx.state.data = { + ctx.set('data', { title: meta.name, description: meta.description, link: meta.external_urls.spotify, @@ -35,7 +35,7 @@ module.exports = async (ctx) => { enclosure_url: x.audio_preview_url, enclosure_type: 'audio/mpeg', })), - }; + }); if (meta.images.length) { ctx.state.data.image = meta.images[0].url; diff --git a/lib/v2/spotify/top.js b/lib/v2/spotify/top.js index 084dc2f25..ae58e27ec 100644 --- a/lib/v2/spotify/top.js +++ b/lib/v2/spotify/top.js @@ -1,5 +1,5 @@ const utils = require('./utils'); -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = (type) => async (ctx) => { if (type !== 'tracks' && type !== 'artists') { @@ -16,9 +16,9 @@ module.exports = (type) => async (ctx) => { .json(); const items = itemsResponse.items; - ctx.state.data = { + ctx.set('data', { title: `Spotify: My Top ${type[0].toUpperCase() + type.slice(1)}`, allowEmpty: true, item: type === 'tracks' ? items.map((element) => utils.parseTrack(element)) : items.map((element) => utils.parseArtist(element)), - }; + }); }; diff --git a/lib/v2/spotify/utils.js b/lib/v2/spotify/utils.js index 3492e8795..622ac55e0 100644 --- a/lib/v2/spotify/utils.js +++ b/lib/v2/spotify/utils.js @@ -1,5 +1,5 @@ -const config = require('@/config').value; -const got = require('@/utils/got'); +import { config } from '@/config'; +import got from '@/utils/got'; // Token used to retrieve public information. async function getPublicToken() { diff --git a/lib/v2/springer/journal.js b/lib/v2/springer/journal.js index 9e3565bf7..a3d9ea7d8 100644 --- a/lib/v2/springer/journal.js +++ b/lib/v2/springer/journal.js @@ -1,27 +1,27 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const { CookieJar } = require('tough-cookie'); const cookieJar = new CookieJar(); module.exports = async (ctx) => { const host = 'https://www.springer.com'; - const journal = ctx.params.journal; + const journal = ctx.req.param('journal'); const jrnlUrl = `${host}/journal/${journal}`; const response = await got(jrnlUrl, { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const jrnlName = $('h1#journalTitle').text().trim(); const issueUrl = $('p.c-card__title.u-mb-16.u-flex-grow').find('a').attr('href'); const response2 = await got(issueUrl, { cookieJar, }); - const $2 = cheerio.load(response2.data); + const $2 = load(response2.data); const issue = $2('.app-volumes-and-issues__info').find('h1').text(); const list = $2('article.c-card') .map((_, item) => { @@ -56,7 +56,7 @@ module.exports = async (ctx) => { const response3 = await got(item.link, { cookieJar, }); - const $3 = cheerio.load(response3.data); + const $3 = load(response3.data); $3('.c-article__sub-heading').remove(); item.abstract = $3('div#Abs1-content').text(); item.description = renderDesc(item); @@ -64,9 +64,9 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: jrnlName, link: jrnlUrl, item: items, - }; + }); }; diff --git a/lib/v2/sputniknews/index.js b/lib/v2/sputniknews/index.js index 1f1409afa..7356da49d 100644 --- a/lib/v2/sputniknews/index.js +++ b/lib/v2/sputniknews/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 languages = { english: 'https://sputniknews.com', @@ -36,8 +36,8 @@ const languages = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'news'; - const language = ctx.params.language ?? 'english'; + const category = ctx.req.param('category') ?? 'news'; + const language = ctx.req.param('language') ?? 'english'; const rootUrl = languages[language]; const currentUrl = `${rootUrl}/services/${category}/more.html`; @@ -47,7 +47,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list__title') .toArray() @@ -68,7 +68,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = parseDate(content('a[data-unixtime]').attr('data-unixtime') * 1000); @@ -86,9 +86,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${category} - Sputnik News`, link: `${rootUrl}/${category}`, item: items, - }; + }); }; diff --git a/lib/v2/sqmc/www.js b/lib/v2/sqmc/www.js index 3686eb446..026dcc895 100644 --- a/lib/v2/sqmc/www.js +++ b/lib/v2/sqmc/www.js @@ -1,10 +1,10 @@ -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.category || '3157'; + const category = ctx.req.param('category') || '3157'; const rootUrl = 'https://www.sqmc.edu.cn'; const currentUrl = `${rootUrl}/${category}/list.htm`; @@ -14,10 +14,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div#wp_news_w9 ul li').get(); - ctx.state.data = { + ctx.set('data', { title: `新乡医学院三全学院官网信息${$('title').text()}`, link: currentUrl, item: await Promise.all( @@ -32,7 +32,7 @@ module.exports = async (ctx) => { method: 'get', url: link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); return { title: item.find('dt a').text(), @@ -45,5 +45,5 @@ module.exports = async (ctx) => { return cache; }) ), - }; + }); }; diff --git a/lib/v2/sse/convert.js b/lib/v2/sse/convert.js index 827b200fd..0e75f93be 100644 --- a/lib/v2/sse/convert.js +++ b/lib/v2/sse/convert.js @@ -1,8 +1,8 @@ -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 query = ctx.params.query ?? ''; // beginDate=2018-08-18&endDate=2019-08-18&companyCode=603283&title=股份 + const query = ctx.req.param('query') ?? ''; // beginDate=2018-08-18&endDate=2019-08-18&companyCode=603283&title=股份 const pageUrl = 'https://bond.sse.com.cn/disclosure/announ/convertible/'; const host = 'https://www.sse.com.cn'; @@ -31,9 +31,9 @@ module.exports = async (ctx) => { author: item.security_Code, })); - ctx.state.data = { + ctx.set('data', { title: '上证债券信息网 - 可转换公司债券公告', link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/sse/disclosure.js b/lib/v2/sse/disclosure.js index 98c11791a..090f9af14 100644 --- a/lib/v2/sse/disclosure.js +++ b/lib/v2/sse/disclosure.js @@ -1,8 +1,8 @@ -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 query = ctx.params.query ?? ''; // beginDate=2018-08-18&endDate=2020-09-01&productId=600696 + const query = ctx.req.param('query') ?? ''; // beginDate=2018-08-18&endDate=2020-09-01&productId=600696 const queries = query.split('&').reduce((acc, cur) => { const [key, value] = cur.split('='); acc[key] = value; @@ -39,9 +39,9 @@ module.exports = async (ctx) => { author: item.SECURITY_NAME, })); - ctx.state.data = { + ctx.set('data', { title: `上海证券交易所 - 上市公司信息 - ${items[0].author}最新公告`, link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/sse/inquire.js b/lib/v2/sse/inquire.js index 420ded3dd..63c2375eb 100644 --- a/lib/v2/sse/inquire.js +++ b/lib/v2/sse/inquire.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'); module.exports = async (ctx) => { @@ -37,9 +37,9 @@ module.exports = async (ctx) => { author: item.extGSJC, })); - ctx.state.data = { + ctx.set('data', { title: '上海证券交易所 - 科创板股票审核', link: refererUrl, item: items, - }; + }); }; diff --git a/lib/v2/sse/lawandrules.js b/lib/v2/sse/lawandrules.js index d582f1f13..63ec096fe 100644 --- a/lib/v2/sse/lawandrules.js +++ b/lib/v2/sse/lawandrules.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 slug = ctx.params.slug ?? 'latest'; + const slug = ctx.req.param('slug') ?? 'latest'; const rootUrl = 'https://www.sse.com.cn'; const currentUrl = `${rootUrl}/lawandrules/guide/${slug.replaceAll('-', '/')}`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.sse_list_1 dl dd') .toArray() @@ -26,7 +26,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('.allZoom').html(); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sse/renewal.js b/lib/v2/sse/renewal.js index 3558a93e6..4f309a522 100644 --- a/lib/v2/sse/renewal.js +++ b/lib/v2/sse/renewal.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'); const localizedFormat = require('dayjs/plugin/localizedFormat'); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { author: item.stockAuditName, })); - ctx.state.data = { + ctx.set('data', { title: '上海证券交易所 - 科创板项目动态', link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/ssm/news.js b/lib/v2/ssm/news.js index f3a0091c1..df9fb953d 100644 --- a/lib/v2/ssm/news.js +++ b/lib/v2/ssm/news.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'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const rootUrl = `https://www.ssm.gov.mo`; const newsUrl = `${rootUrl}/apps1/content/ch/973/itemlist.aspx?defaultcss=false&dlimit=20&showdate=true&dorder=cridate%20desc,displaydate%20desc&withattach=true`; module.exports = async (ctx) => { const response = await got.get(newsUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > div > div > ul > li'); const item = list @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '澳门卫生局-最新消息', link: rootUrl, item, - }; + }); }; diff --git a/lib/v2/sspai/activity.js b/lib/v2/sspai/activity.js index 628ff0efc..76be341ee 100644 --- a/lib/v2/sspai/activity.js +++ b/lib/v2/sspai/activity.js @@ -1,8 +1,8 @@ -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 slug = ctx.params.slug; + const slug = ctx.req.param('slug'); const link = `https://sspai.com/u/${slug}/updates`; const response = await got({ @@ -29,15 +29,15 @@ module.exports = async (ctx) => { let item_desc = ''; let item_url = ''; - ctx.state.data = { + ctx.set('data', { title: `少数派用户「${user_nickname}」动态更新`, link, description: `少数派用户「${user_nickname}」的动态更新`, item: data.map((item) => { const content_data = item.data; - const nicknames = new Array(); - const slugs = new Array(); + const nicknames = []; + const slugs = []; // 根据用户action,选择输出 switch (item.key) { case 'follow_user': @@ -79,5 +79,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.created_at * 1000), }; }), - }; + }); }; diff --git a/lib/v2/sspai/author.js b/lib/v2/sspai/author.js index 75b137992..2ec642847 100644 --- a/lib/v2/sspai/author.js +++ b/lib/v2/sspai/author.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'; async function getUserId(slug) { const response = await got({ @@ -18,7 +18,7 @@ async function getUserId(slug) { } module.exports = async (ctx) => { - const id = /^\d+$/.test(ctx.params.id) ? ctx.params.id : await getUserId(ctx.params.id); + const id = /^\d+$/.test(ctx.req.param('id')) ? ctx.req.param('id') : await getUserId(ctx.req.param('id')); const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=20&author_ids=${id}&include_total=false`; const resp = await got({ method: 'get', @@ -48,10 +48,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${author_nickname} - 少数派作者`, link: `https://sspai.com/u/${author_slug}/posts`, description: `${author_nickname} 更新推送 `, item: items, - }; + }); }; diff --git a/lib/v2/sspai/bookmarks.js b/lib/v2/sspai/bookmarks.js index c99bcdd22..1e8c058cd 100644 --- a/lib/v2/sspai/bookmarks.js +++ b/lib/v2/sspai/bookmarks.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 { slug } = ctx.params; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { ).data.data; const { nickname } = user; - ctx.state.data = { + ctx.set('data', { title: `${nickname} 的全部收藏 - 少数派`, link, description: `少数派用户「${nickname}」的全部收藏`, @@ -37,5 +37,5 @@ module.exports = async (ctx) => { pubDate: parseDate(article.released_time * 1000), author: article.author.nickname, })), - }; + }); }; diff --git a/lib/v2/sspai/column.js b/lib/v2/sspai/column.js index 0f0246a53..33920acf7 100644 --- a/lib/v2/sspai/column.js +++ b/lib/v2/sspai/column.js @@ -1,8 +1,8 @@ -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 id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://sspai.com/column/${id}`; const desApi = `https://sspai.com/api/v1/special_columns/${id}`; @@ -53,10 +53,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `少数派专栏-${title}`, link, description, item: out, - }; + }); }; diff --git a/lib/v2/sspai/index.js b/lib/v2/sspai/index.js index f1e738263..dac106627 100644 --- a/lib/v2/sspai/index.js +++ b/lib/v2/sspai/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 api_url = 'https://sspai.com/api/v1/article/index/page/get?limit=10&offset=0&created_at=0'; @@ -28,10 +28,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '少数派 -- 首页', link: 'https://sspai.com', description: '少数派 -- 首页', item: items, - }; + }); }; diff --git a/lib/v2/sspai/matrix.js b/lib/v2/sspai/matrix.js index 335205cfb..e0a376eeb 100644 --- a/lib/v2/sspai/matrix.js +++ b/lib/v2/sspai/matrix.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 api_url = 'https://sspai.com/api/v1/articles?offset=0&limit=20&is_matrix=1&sort=matrix_at&include_total=false'; @@ -29,10 +29,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '少数派 -- Matrix', link: 'https://sspai.com/matrix', description: '少数派 -- Matrix', item: items, - }; + }); }; diff --git a/lib/v2/sspai/series-update.js b/lib/v2/sspai/series-update.js index 55e5ce633..9c747191b 100644 --- a/lib/v2/sspai/series-update.js +++ b/lib/v2/sspai/series-update.js @@ -1,11 +1,11 @@ -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 { id } = ctx.params; const seriesInfo = await got.get(`https://sspai.com/api/v1/series/info/get?id=${id}&view=second`); - const response = await got(`https://sspai.com/api/v1/series/article/search/page/get?series_id=${id}&weight=0&sort=desc&title=&limit=${ctx.query.limit ? Number(ctx.query.limit) : 40}&offset=0`); + const response = await got(`https://sspai.com/api/v1/series/article/search/page/get?series_id=${id}&weight=0&sort=desc&title=&limit=${ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 40}&offset=0`); const items = await Promise.all( response.data.data.map(async (item) => { @@ -27,10 +27,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${seriesInfo.data.data.title} - 少数派`, description: `${seriesInfo.data.data.description} - 少数派`, link: `https://sspai.com/series/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/sspai/series.js b/lib/v2/sspai/series.js index b31bb5108..c6db68c5a 100644 --- a/lib/v2/sspai/series.js +++ b/lib/v2/sspai/series.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 response = await got('https://sspai.com/api/v1/series/tag/all/get'); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { const res = await got(`https://sspai.com/api/v1/series/info/get?id=${item.id}&view=second`); const banner = ``; const description = banner + res.data.data.intro; - const $ = cheerio.load(description); + const $ = load(description); $('img').css('max-width', '100%'); item.description = $.html(); return item; @@ -37,10 +37,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '少数派 -- 最新上架付费专栏', link: 'https://sspai.com/series', description: '少数派 -- 最新上架付费专栏', item, - }; + }); }; diff --git a/lib/v2/sspai/shortcuts-gallery.js b/lib/v2/sspai/shortcuts-gallery.js index 8f079436e..128df48d4 100644 --- a/lib/v2/sspai/shortcuts-gallery.js +++ b/lib/v2/sspai/shortcuts-gallery.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 { @@ -20,10 +20,10 @@ module.exports = async (ctx) => { } } - ctx.state.data = { + ctx.set('data', { title: 'Shortcuts Gallery - 少数派', link: 'https://shortcuts.sspai.com/#/main/workflow', description: 'Shortcuts Gallery - 少数派', item: items, - }; + }); }; diff --git a/lib/v2/sspai/tag.js b/lib/v2/sspai/tag.js index b1db17408..b7188aaa7 100644 --- a/lib/v2/sspai/tag.js +++ b/lib/v2/sspai/tag.js @@ -1,8 +1,8 @@ -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 keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const keyword_encode = encodeURIComponent(decodeURIComponent(keyword)); const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=50&has_tag=1&tag=${keyword_encode}&include_total=false`; const host = `https://beta.sspai.com/tag/${keyword_encode}`; @@ -33,10 +33,10 @@ module.exports = async (ctx) => { }); }) ); - ctx.state.data = { + ctx.set('data', { title: `#${keyword} - 少数派`, link: host, description: `${keyword} 更新推送 `, item: items, - }; + }); }; diff --git a/lib/v2/sspai/topic.js b/lib/v2/sspai/topic.js index 3a828a6a0..81b10fda7 100644 --- a/lib/v2/sspai/topic.js +++ b/lib/v2/sspai/topic.js @@ -1,8 +1,8 @@ -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 id = ctx.params.id; + const id = ctx.req.param('id'); const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=20&topic_id=${id}&sort=created_at&include_total=false`; const response = await got({ method: 'get', @@ -41,10 +41,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `少数派专题-${topic_title}`, link: topic_link, description: topic_des, item: out, - }; + }); }; diff --git a/lib/v2/sspai/topics.js b/lib/v2/sspai/topics.js index 358150182..d2436e4f1 100644 --- a/lib/v2/sspai/topics.js +++ b/lib/v2/sspai/topics.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 api_url = `https://sspai.com/api/v1/topics?offset=0&limit=20&include_total=false`; @@ -28,10 +28,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `少数派专题广场更新推送`, link: `https://sspai.com/topics`, description: `仅仅推送新的专题(集合型而非具体文章) `, item: items, - }; + }); }; diff --git a/lib/v2/sspu/jwc.js b/lib/v2/sspu/jwc.js index 661b55dd9..2593e18f9 100644 --- a/lib/v2/sspu/jwc.js +++ b/lib/v2/sspu/jwc.js @@ -1,17 +1,17 @@ -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 = async (ctx) => { const { listId } = ctx.params; const baseUrl = 'https://jwc.sspu.edu.cn'; const { data: response, url: link } = await got(`${baseUrl}/${listId}/list.htm`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.news_list .news') - .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); @@ -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); item.description = $('.wp_articlecontent').html(); item.pubDate = timezone(parseDate($('.arti_update').text(), 'YYYY-MM-DD HH:mm:ss'), +8); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/sspu/pe.js b/lib/v2/sspu/pe.js index 214d069f9..79ca12cc0 100644 --- a/lib/v2/sspu/pe.js +++ b/lib/v2/sspu/pe.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'; module.exports = async (ctx) => { const { id = '342' } = 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 rootUrl = 'https://pe2016.sspu.edu.cn'; const currentUrl = new URL(`${id}/list.htm`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('table.wp_article_list_table a[title]') .slice(0, limit) @@ -32,7 +32,7 @@ module.exports = async (ctx) => { if (item.link.endsWith('htm')) { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); const info = content('div.time').text(); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { const subtitle = $('title').text(); const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -61,5 +61,5 @@ module.exports = async (ctx) => { logo: icon, subtitle, author, - }; + }); }; diff --git a/lib/v2/startuplatte/index.js b/lib/v2/startuplatte/index.js index 8d1d02039..8b74954ec 100644 --- a/lib/v2/startuplatte/index.js +++ b/lib/v2/startuplatte/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://startuplatte.com'; const currentUrl = `${rootUrl}${category ? `/category/${category}` : ''}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.post-header h2 a') .map((_, item) => { @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.wp-post-navigation').remove(); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/stbu/jsjxy.js b/lib/v2/stbu/jsjxy.js index 42884c705..17c209d50 100644 --- a/lib/v2/stbu/jsjxy.js +++ b/lib/v2/stbu/jsjxy.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const gbk2utf8 = (s) => iconv.decode(s, 'gbk'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(gbk2utf8(response)); + const $ = load(gbk2utf8(response)); const list = $('.content dl h4') .toArray() .map((item) => { @@ -34,7 +34,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(gbk2utf8(response)); + const $ = load(gbk2utf8(response)); item.description = $('.content14').first().html().trim(); item.pubDate = timezone(parseDate($('.article .source').text().split('日期:')[1].replace('\n', '').trim()), +8); return item; @@ -42,10 +42,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '四川工商学院计算机学院 - 新闻动态', link: baseUrl, description: '四川工商学院计算机学院 - 新闻动态', item: items, - }; + }); }; diff --git a/lib/v2/stbu/xyxw.js b/lib/v2/stbu/xyxw.js index 83c13966d..4f98c0d35 100644 --- a/lib/v2/stbu/xyxw.js +++ b/lib/v2/stbu/xyxw.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const gbk2utf8 = (s) => iconv.decode(s, 'gbk'); module.exports = async (ctx) => { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(gbk2utf8(response)); + const $ = load(gbk2utf8(response)); const list = $('.style_2 .Simple_title') .toArray() .map((item) => { @@ -35,7 +35,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(gbk2utf8(response)); + const $ = load(gbk2utf8(response)); item.description = $('.artmainl .articlemain').first().html(); item.pubDate = timezone(parseDate($('.artmainl .info').text().split('|')[2].split(':')[1].trim()), +8); return item; @@ -43,10 +43,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '四川工商学院 - 学院新闻', link: requestUrl, description: '四川工商学院 - 学院新闻', item: items, - }; + }); }; diff --git a/lib/v2/stcn/index.js b/lib/v2/stcn/index.js index 545ae1afd..a695a9987 100644 --- a/lib/v2/stcn/index.js +++ b/lib/v2/stcn/index.js @@ -1,10 +1,10 @@ -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 ?? 'yw'; + const id = ctx.req.param('id') ?? 'yw'; const rootUrl = 'https://www.stcn.com'; const currentUrl = `${rootUrl}/article/list/${id}.html`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: apiUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.t, .tt, .title') .find('a') @@ -40,7 +40,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('.detail-title').text(); item.author = content('.detail-info span').first().text().split(':').pop(); @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `证券时报网 - ${$('.breadcrumb a').last().text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/stdaily/digitalpaper.js b/lib/v2/stdaily/digitalpaper.js index 16a4bcc58..f2fc25c39 100644 --- a/lib/v2/stdaily/digitalpaper.js +++ b/lib/v2/stdaily/digitalpaper.js @@ -1,7 +1,7 @@ const path = require('path'); -const { art } = require('@/utils/render'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { art } from '@/utils/render'; +import got from '@/utils/got'; +import { load } from 'cheerio'; const renderDescription = ({ subtitle, quotation, pics, article }) => art(path.join(__dirname, 'templates/description.art'), { @@ -17,7 +17,7 @@ const getPageLength = async (url) => { url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const pageLength = $('.right1 .bmname').children().length; return { pageLength, $ }; }; @@ -46,7 +46,7 @@ const createGetPageArticleList = (paperUrl, page = 1) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); return getArticleList($, paperUrl); }; @@ -58,7 +58,7 @@ const getListArticles = async (list, cache) => { list.map((item) => cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const quotation = $('.right-meat .yinti').text(); const subtitle = $('.right-meat .futi').text(); @@ -117,9 +117,9 @@ module.exports = async (ctx) => { // get all articles const items = await getListArticles(allPageArticleLists, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `科技日报`, link: 'http://digitalpaper.stdaily.com', item: items, - }; + }); }; diff --git a/lib/v2/stheadline/std/realtime.js b/lib/v2/stheadline/std/realtime.js index bfca3488a..b856b6d98 100644 --- a/lib/v2/stheadline/std/realtime.js +++ b/lib/v2/stheadline/std/realtime.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 baseUrl = 'https://std.stheadline.com'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const { category = '即時' } = ctx.params; const url = `${baseUrl}/realtime/${category}`; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); let items = $(`${category === '即時' ? '.moreNews > .col-md-4' : ''} .media-body > .my-2 > a`) .toArray() @@ -26,7 +26,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); return { ...item, @@ -38,11 +38,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[name=description]').attr('content'), image: 'https://std.stheadline.com/dist/images/favicon/icon-512.png', link: url, item: items, - }; + }); }; diff --git a/lib/v2/stockedge/daily-news.js b/lib/v2/stockedge/daily-news.js index 1d8564085..d8aa6ddc0 100644 --- a/lib/v2/stockedge/daily-news.js +++ b/lib/v2/stockedge/daily-news.js @@ -17,7 +17,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Stock Edge', link: baseUrl, item: items, @@ -25,5 +25,5 @@ module.exports = async (ctx) => { logo: 'https://web.stockedge.com/assets/icon/favicon.png', icon: 'https://web.stockedge.com/assets/img/light/icon.png', language: 'en-us', - }; + }); }; diff --git a/lib/v2/stockedge/utils.js b/lib/v2/stockedge/utils.js index 023c3d251..c615cbe83 100644 --- a/lib/v2/stockedge/utils.js +++ b/lib/v2/stockedge/utils.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 baseUrl = 'https://web.stockedge.com/share/'; const getData = (url) => diff --git a/lib/v2/storm/index.js b/lib/v2/storm/index.js index b1242f242..fce165bf0 100644 --- a/lib/v2/storm/index.js +++ b/lib/v2/storm/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 category = ctx.params.category ?? 'articles'; - const id = ctx.params.id ?? ''; + const category = ctx.req.param('category') ?? 'articles'; + const id = ctx.req.param('id') ?? ''; const rootUrl = 'https://www.storm.mg'; const currentUrl = `${rootUrl}/${category}${id ? `/${id}` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.link_title') .map((_, item) => { @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.notify_wordings').remove(); content('#premium_block').remove(); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/storyfm/episodes.js b/lib/v2/storyfm/episodes.js index 4ac593158..d8e31b7de 100644 --- a/lib/v2/storyfm/episodes.js +++ b/lib/v2/storyfm/episodes.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) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.e-ep') .toArray() @@ -40,7 +40,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('.rs-post__author').text().replace(/By/, '').trim(); item.description = art(path.join(__dirname, 'templates/description.art'), { @@ -53,11 +53,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '故事FM', link: currentUrl, item: items, itunes_author: '故事FM', image: $('.custom-logo-link img').attr('src'), - }; + }); }; diff --git a/lib/v2/storyfm/index.js b/lib/v2/storyfm/index.js index af98998d6..d99d6c6e8 100644 --- a/lib/v2/storyfm/index.js +++ b/lib/v2/storyfm/index.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const url = 'http://storyfm.cn'; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const cnMonth = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二']; const items = $('.isotope > .isotope-item') .map((_, ele) => { - const $item = cheerio.load(ele); + const $item = load(ele); const img = $item('.isotope-img-container img').attr('src'); const infoNode = $item('.isotope-index-text').first(); const title = infoNode.find('.soundbyte-podcast-progression-title'); @@ -35,10 +35,10 @@ module.exports = async (ctx) => { }; }) .get(); - ctx.state.data = { + ctx.set('data', { title: '故事说FM', description: '故事说FM', link: url, item: items, - }; + }); }; diff --git a/lib/v2/studygolang/go.js b/lib/v2/studygolang/go.js index 090aba0a3..a87becc00 100644 --- a/lib/v2/studygolang/go.js +++ b/lib/v2/studygolang/go.js @@ -1,5 +1,5 @@ const { FetchGoItems } = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await FetchGoItems(ctx); + ctx.set('data', await FetchGoItems(ctx)); }; diff --git a/lib/v2/studygolang/jobs.js b/lib/v2/studygolang/jobs.js index 3e163f94c..eac05c9c6 100644 --- a/lib/v2/studygolang/jobs.js +++ b/lib/v2/studygolang/jobs.js @@ -1,7 +1,5 @@ const { FetchGoItems } = require('./utils'); module.exports = async (ctx) => { - ctx.params.id = 'jobs'; - - ctx.state.data = await FetchGoItems(ctx); + ctx.set('data', await FetchGoItems(ctx, 'jobs')); }; diff --git a/lib/v2/studygolang/utils.js b/lib/v2/studygolang/utils.js index 3036ded29..ba47d8fc1 100644 --- a/lib/v2/studygolang/utils.js +++ b/lib/v2/studygolang/utils.js @@ -1,16 +1,16 @@ -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 md = require('markdown-it')({ html: true, linkify: true, }); module.exports = { - FetchGoItems: async (ctx) => { - const id = ctx.params.id ?? 'weekly'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50; + FetchGoItems: async (ctx, rewriteId) => { + const id = rewriteId || (ctx.req.param('id') ?? 'weekly'); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; const rootUrl = 'https://studygolang.com'; const currentUrl = `${rootUrl}/go/${id}`; @@ -20,7 +20,7 @@ module.exports = { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.right-info .title') .slice(0, limit) @@ -50,7 +50,7 @@ module.exports = { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = timezone(parseDate(content('.timeago').first().attr('title')), +8); diff --git a/lib/v2/studygolang/weekly.js b/lib/v2/studygolang/weekly.js index 6a3ceb06b..4e5c71235 100644 --- a/lib/v2/studygolang/weekly.js +++ b/lib/v2/studygolang/weekly.js @@ -1,7 +1,5 @@ const { FetchGoItems } = require('./utils'); module.exports = async (ctx) => { - ctx.params.id = 'weekly'; - - ctx.state.data = await FetchGoItems(ctx); + ctx.set('data', await FetchGoItems(ctx, 'weekly')); }; diff --git a/lib/v2/subhd/index.js b/lib/v2/subhd/index.js index e7e8cba97..b4adab465 100644 --- a/lib/v2/subhd/index.js +++ b/lib/v2/subhd/index.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 config = { sub: { @@ -18,8 +18,8 @@ const config = { }; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'sub'; - const category = ctx.params.category ?? config[type].category; + const type = ctx.req.param('type') ?? 'sub'; + const category = ctx.req.param('category') ?? config[type].category; const rootUrl = 'https://subhd.tv'; const currentUrl = `${rootUrl}/${type === 'newest' ? 'sub/new' : `${type}/${category}${type === 'zu' ? '/l' : ''}`}`; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.align-middle').each(function () { $(this).removeClass('link-dark'); @@ -59,7 +59,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.rounded-circle').remove(); content('.view-text').last().remove(); @@ -71,9 +71,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/supchina/index.js b/lib/v2/supchina/index.js index 778cc23c4..8eb0dfc9f 100644 --- a/lib/v2/supchina/index.js +++ b/lib/v2/supchina/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 rootUrl = 'https://supchina.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('item') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50) .toArray() .map((item) => { item = $(item); @@ -48,7 +48,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.aspect-spacer, .post-recs, .author-bio').remove(); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/supchina/podcasts.js b/lib/v2/supchina/podcasts.js index de26b2e6a..5fb8b7698 100644 --- a/lib/v2/supchina/podcasts.js +++ b/lib/v2/supchina/podcasts.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://supchina.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('item') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50) .toArray() .map((item) => { item = $(item); @@ -56,11 +56,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'SupChina - Podcasts', link: `${rootUrl}/podcasts`, itunes_author: $('channel itunes\\:author').first().text(), image: $('itunes\\:image').attr('href'), item: items, - }; + }); }; diff --git a/lib/v2/surfshark/blog.js b/lib/v2/surfshark/blog.js index 26297e85c..92d478718 100644 --- a/lib/v2/surfshark/blog.js +++ b/lib/v2/surfshark/blog.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 { category } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 15; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15; const rootUrl = 'https://surfshark.com'; const currentUrl = new URL(`blog${category ? `/${category}` : ''}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.article-info') .slice(0, limit) @@ -41,7 +41,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.post-main-img').each(function () { const image = content(this).find('img'); @@ -76,7 +76,7 @@ module.exports = async (ctx) => { const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -87,5 +87,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[property="og:title"]').prop('content'), author: $('meta[property="og:site_name"]').prop('content'), - }; + }); }; diff --git a/lib/v2/sustech/bidding.js b/lib/v2/sustech/bidding.js index e88e17d1d..5c19999a5 100644 --- a/lib/v2/sustech/bidding.js +++ b/lib/v2/sustech/bidding.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 link = 'http://biddingoffice.sustech.edu.cn'; @@ -11,11 +11,11 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.index-wrap.index-2 ul li'); - ctx.state.data = { + ctx.set('data', { title: '南方科技大学采购与招标管理部', link, item: @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: a.attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/sustech/newshub-zh.js b/lib/v2/sustech/newshub-zh.js index c80c26bf6..830f63982 100644 --- a/lib/v2/sustech/newshub-zh.js +++ b/lib/v2/sustech/newshub-zh.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 baseUrl = 'https://newshub.sustech.edu.cn'; @@ -12,11 +12,11 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.m-newslist ul li'); - ctx.state.data = { + ctx.set('data', { title: '南方科技大学新闻网-中文', link, item: @@ -35,5 +35,5 @@ module.exports = async (ctx) => { link: `${baseUrl}${item.find('a').attr('href')}`, }; }), - }; + }); }; diff --git a/lib/v2/sustech/yjs.js b/lib/v2/sustech/yjs.js index bc232796b..ad3f2964f 100644 --- a/lib/v2/sustech/yjs.js +++ b/lib/v2/sustech/yjs.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://gs.sustech.edu.cn'; @@ -20,10 +20,10 @@ module.exports = async (ctx) => { pubDate: parseDate(item.published_at, 'YYYY-MM-DD'), })); - ctx.state.data = { + ctx.set('data', { title: '南方科技大学研究生院', link, description: '南方科技大学研招网通知公告', item: list, - }; + }); }; diff --git a/lib/v2/swissinfo/index.js b/lib/v2/swissinfo/index.js index 429f793eb..f0a04b8d2 100644 --- a/lib/v2/swissinfo/index.js +++ b/lib/v2/swissinfo/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 language = ctx.params.language ?? 'eng'; - const category = ctx.params.category ?? 'latest-news'; + const language = ctx.req.param('language') ?? 'eng'; + const category = ctx.req.param('category') ?? 'latest-news'; const rootUrl = 'https://www.swissinfo.ch'; const currentUrl = `${rootUrl}/${language}/${category}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - let $ = cheerio.load(response.data); + let $ = load(response.data); const title = $('title').text(); @@ -23,10 +23,10 @@ module.exports = async (ctx) => { url: `${rootUrl}${$('main div[data-fragment-placeholder]').attr('data-fragment-placeholder')}`, }); - $ = cheerio.load(fragmentResponse.data); + $ = load(fragmentResponse.data); let items = $('.si-teaser__link') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20) .toArray() .map((item) => { item = $(item); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.si-detail__content .si-grid').remove(); content('.si-detail__content .si-teaser').remove(); @@ -65,9 +65,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/swjtu/jtys/yjs.js b/lib/v2/swjtu/jtys/yjs.js index 2727225ec..df712c722 100644 --- a/lib/v2/swjtu/jtys/yjs.js +++ b/lib/v2/swjtu/jtys/yjs.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 rootURL = 'https://ctt.swjtu.edu.cn'; const url_addr = `${rootURL}/yethan/WebIndexAction?setAction=newsList&bigTypeId=0E4BF4D36E232918`; @@ -18,7 +18,7 @@ const getItem = (item, cache) => { method: 'get', url: link, }); - const $$ = cheerio.load(resp.data); + const $$ = load(resp.data); const info_text = $$('.news-left').html(); return { @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: url_addr, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const list = $("[class='news-list flex']"); const items = await Promise.all( @@ -46,10 +46,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '西南交大交运学院-研究生通知', link: url_addr, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/swjtu/jwc.js b/lib/v2/swjtu/jwc.js index e29d90bdf..69da6d970 100644 --- a/lib/v2/swjtu/jwc.js +++ b/lib/v2/swjtu/jwc.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 rootURL = 'http://jwc.swjtu.edu.cn'; const pageURL = `${rootURL}/vatuu/WebAction?setAction=newsList`; @@ -16,7 +16,7 @@ const getItem = (item, cache) => { method: 'get', url: link, }); - const $$ = cheerio.load(resp.data); + const $$ = load(resp.data); let newsText = $$('.content-main').html(); if (!newsText) { newsText = '转发通知'; @@ -48,7 +48,7 @@ module.exports = async (ctx) => { url: pageURL, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const list = $("[class='littleResultDiv']"); const items = await Promise.all( @@ -58,10 +58,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '西南交大-教务网通知', link: pageURL, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/swjtu/jyzpxx.js b/lib/v2/swjtu/jyzpxx.js index 96a534746..3fd68261a 100644 --- a/lib/v2/swjtu/jyzpxx.js +++ b/lib/v2/swjtu/jyzpxx.js @@ -1,10 +1,10 @@ const utils = require('./utils'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const rootURL = 'https://jiuye.swjtu.edu.cn/career'; module.exports = async (ctx) => { - const limit = Math.min(ctx.query.limit ?? 10, 50); + const limit = Math.min(ctx.req.query('limit') ?? 10, 50); const resp = await got({ method: 'post', url: `${rootURL}/zpxx/search/zpxx/1/${limit}`, @@ -19,10 +19,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '西南交大-就业招聘信息', link: `${rootURL}/zpxx/zpxx`, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/swjtu/utils.js b/lib/v2/swjtu/utils.js index 7667cd750..82b69eab9 100644 --- a/lib/v2/swjtu/utils.js +++ b/lib/v2/swjtu/utils.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); const renderDetail = (jobs) => art(path.join(__dirname, 'templates/job_detail.art'), { jobs }); diff --git a/lib/v2/swjtu/xg.js b/lib/v2/swjtu/xg.js index 1c755d82c..049beac84 100644 --- a/lib/v2/swjtu/xg.js +++ b/lib/v2/swjtu/xg.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 rootURL = 'http://xg.swjtu.edu.cn'; const listURL = { @@ -21,7 +21,7 @@ const getItem = (item, cache) => { method: 'get', url: link, }); - const $$ = cheerio.load(resp.data); + const $$ = load(resp.data); let newsText = $$('.detail-content-text').html(); if (!newsText) { newsText = '转发通知'; @@ -48,7 +48,7 @@ const getItem = (item, cache) => { }; module.exports = async (ctx) => { - const code = ctx.params.code ?? 'tzgg'; + const code = ctx.req.param('code') ?? 'tzgg'; const pageURL = listURL[code]; if (!pageURL) { @@ -60,7 +60,7 @@ module.exports = async (ctx) => { url: pageURL, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const list = $('div.right-side ul.block-ctxlist li'); const items = await Promise.all( @@ -70,10 +70,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '西南交大-扬华素质网', link: pageURL, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/swpu/bgw.js b/lib/v2/swpu/bgw.js index fcf8876d8..86c16d822 100644 --- a/lib/v2/swpu/bgw.js +++ b/lib/v2/swpu/bgw.js @@ -1,14 +1,14 @@ const { joinUrl } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const url = `https://www.swpu.edu.cn/bgw2/${ctx.params.code}.htm`; + const url = `https://www.swpu.edu.cn/bgw2/${ctx.req.param('code')}.htm`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const title = $('.title').text(); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { items.map(async (item) => { const $ = await ctx.cache.tryGet(item.link, async () => { const res = await got.get(item.link); - return cheerio.load(res.data); + return load(res.data); }); if ($('title').text().startsWith('系统提示')) { @@ -48,11 +48,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学办公网 ${title}`, link: url, description: `西南石油大学办公网 ${title} 列表`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/swpu/cjxy.js b/lib/v2/swpu/cjxy.js index 33ef336e0..afe1a75f2 100644 --- a/lib/v2/swpu/cjxy.js +++ b/lib/v2/swpu/cjxy.js @@ -1,13 +1,13 @@ -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const url = `https://www.swpu.edu.cn/nccjxy/xydt/${ctx.params.code}.htm`; + const url = `https://www.swpu.edu.cn/nccjxy/xydt/${ctx.req.param('code')}.htm`; const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); let title = $('title').text(); title = title.substring(0, title.indexOf('-')); @@ -24,7 +24,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got(item.link); - const $ = cheerio.load(res.data); + const $ = load(res.data); if ($('title').text().startsWith('系统提示')) { item.author = '系统'; item.description = '无权访问'; @@ -43,11 +43,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学财经学院 ${title}`, link: url, description: `西南石油大学财经学院 ${title}`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/swpu/dean.js b/lib/v2/swpu/dean.js index 11b03f38e..56de26c3c 100644 --- a/lib/v2/swpu/dean.js +++ b/lib/v2/swpu/dean.js @@ -1,14 +1,14 @@ const { joinUrl } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const url = `https://www.swpu.edu.cn/dean/${ctx.params.code}.htm`; + const url = `https://www.swpu.edu.cn/dean/${ctx.req.param('code')}.htm`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); let title = $('.r_list > h3').text(); title = title.substring(title.indexOf(':') + 1); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { items.map(async (item) => { const $ = await ctx.cache.tryGet(item.link, async () => { const res = await got.get(item.link); - return cheerio.load(res.data); + return load(res.data); }); if ($('title').text().startsWith('系统提示')) { @@ -49,11 +49,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学教务处 ${title}`, link: url, description: `西南石油大学教务处 ${title}`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/swpu/dxy.js b/lib/v2/swpu/dxy.js index f95fe7709..20b72e739 100644 --- a/lib/v2/swpu/dxy.js +++ b/lib/v2/swpu/dxy.js @@ -1,16 +1,16 @@ const { joinUrl } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { // 移除 urltype=tree.TreeTempUrl 虽然也能顺利访问页面, // 但标题会缺失,而且在其他地方定位提取标题也比较麻烦。 - const url = `https://www.swpu.edu.cn/dxy/list1.jsp?urltype=tree.TreeTempUrl&wbtreeid=${ctx.params.code}`; + const url = `https://www.swpu.edu.cn/dxy/list1.jsp?urltype=tree.TreeTempUrl&wbtreeid=${ctx.req.param('code')}`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); let title = $('title').text(); title = title.substring(0, title.indexOf('-')); @@ -30,7 +30,7 @@ module.exports = async (ctx) => { items.map(async (item) => { const $ = await ctx.cache.tryGet(item.link, async () => { const res = await got.get(item.link); - return cheerio.load(res.data); + return load(res.data); }); if ($('title').text().startsWith('系统提示')) { @@ -51,11 +51,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学电气信息学院 ${title}`, link: url, description: `西南石油大学电气信息学院 ${title}`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/swpu/is.js b/lib/v2/swpu/is.js index cde903df9..219b22edb 100644 --- a/lib/v2/swpu/is.js +++ b/lib/v2/swpu/is.js @@ -1,13 +1,13 @@ -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const url = `https://www.swpu.edu.cn/is/xydt/${ctx.params.code}.htm`; + const url = `https://www.swpu.edu.cn/is/xydt/${ctx.req.param('code')}.htm`; const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); let title = $('title').text(); title = title.substring(0, title.indexOf('-')); @@ -24,7 +24,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got(item.link); - const $ = cheerio.load(res.data); + const $ = load(res.data); if ($('title').text().startsWith('系统提示')) { item.author = '系统'; item.description = '无权访问'; @@ -43,11 +43,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学信息学院 ${title}`, link: url, description: `西南石油大学信息学院 ${title}`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/swpu/scs.js b/lib/v2/swpu/scs.js index c16fb2df7..41643a4fb 100644 --- a/lib/v2/swpu/scs.js +++ b/lib/v2/swpu/scs.js @@ -1,14 +1,14 @@ const { joinUrl } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const url = `https://www.swpu.edu.cn/scs/index/${ctx.params.code}.htm`; + const url = `https://www.swpu.edu.cn/scs/index/${ctx.req.param('code')}.htm`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const title = $('.r_list > h3').text(); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { items.map(async (item) => { const $ = await ctx.cache.tryGet(item.link, async () => { const res = await got.get(item.link); - return cheerio.load(res.data); + return load(res.data); }); if ($('title').text().startsWith('系统提示')) { @@ -48,11 +48,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `西南石油大学计算机科学学院 ${title}`, link: url, description: `西南石油大学计算机科学学院 ${title}`, language: 'zh-CN', item: out, - }; + }); }; diff --git a/lib/v2/syosetu/chapter.js b/lib/v2/syosetu/chapter.js index 408bd8078..4e45d8142 100644 --- a/lib/v2/syosetu/chapter.js +++ b/lib/v2/syosetu/chapter.js @@ -1,17 +1,17 @@ -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 { CookieJar } = require('tough-cookie'); const cookieJar = new CookieJar(); cookieJar.setCookieSync('over18=yes', 'https://novel18.syosetu.com/'); module.exports = async (ctx) => { - const id = ctx.params.id; - const limit = Number.parseInt(ctx.query.limit) || 5; + const id = ctx.req.param('id'); + const limit = Number.parseInt(ctx.req.query('limit')) || 5; const link = `https://ncode.syosetu.com/${id}`; - const $ = cheerio.load(await get(link)); + const $ = load(await get(link)); const title = $('p.novel_title').text(); const description = $('#novel_ex').html(); @@ -34,20 +34,20 @@ module.exports = async (ctx) => { chapter_list.map((chapter) => ctx.cache.tryGet(chapter.link, async () => { chapter.link = `https://ncode.syosetu.com${chapter.link}`; - const content = cheerio.load(await get(chapter.link)); + const content = load(await get(chapter.link)); chapter.description = content('#novel_honbun').html(); return chapter; }) ) ); - ctx.state.data = { + ctx.set('data', { title, description, link, language: 'ja', item: item_list, - }; + }); }; const get = async (url) => { diff --git a/lib/v2/sysu/cse.js b/lib/v2/sysu/cse.js index a0e6c3d26..9a562ee29 100644 --- a/lib/v2/sysu/cse.js +++ b/lib/v2/sysu/cse.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 response = await got({ @@ -9,7 +9,7 @@ module.exports = async (ctx) => { Referer: `http://cse.sysu.edu.cn/`, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 首页有多个板块,每个板块的css选择器不同,而且每个板块的信息分类也不一样 const block_index = [ @@ -93,11 +93,11 @@ module.exports = async (ctx) => { item_data.sort(compareLink); // console.log(item_data); - ctx.state.data = { + ctx.set('data', { title: `中山大学 - 数据科学与计算机学院`, link: `http://cse.sysu.edu.cn`, description: `中山大学 - 数据科学与计算机学院`, language: `zh-cn`, item: item_data, - }; + }); }; diff --git a/lib/v2/sysu/ygafz.js b/lib/v2/sysu/ygafz.js index 4dc258344..f158865f7 100644 --- a/lib/v2/sysu/ygafz.js +++ b/lib/v2/sysu/ygafz.js @@ -1,15 +1,16 @@ -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 logger = require('@/utils/logger'); const { CookieJar } = require('tough-cookie'); +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { type = 'notice' } = ctx.params; const baseUrl = 'https://ygafz.sysu.edu.cn'; const url = `${baseUrl}/${type}`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -32,7 +33,7 @@ module.exports = async (ctx) => { browser.close(); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.list-content a') .toArray() .map((item) => { @@ -50,7 +51,7 @@ module.exports = async (ctx) => { const { data } = await got(item.link, { cookieJar, }); - const $ = cheerio.load(data); + const $ = load(data); item.author = $('.article-submit') .text() @@ -61,9 +62,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/szse/inquire.js b/lib/v2/szse/inquire.js index 2aef59358..dccf72520 100644 --- a/lib/v2/szse/inquire.js +++ b/lib/v2/szse/inquire.js @@ -1,12 +1,12 @@ -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 category = ctx.params.category ?? '0'; - const select = ctx.params.select ?? '全部函件类别'; - const keyword = ctx.params.keyword ?? ''; + const category = ctx.req.param('category') ?? '0'; + const select = ctx.req.param('select') ?? '全部函件类别'; + const keyword = ctx.req.param('keyword') ?? ''; const rootUrl = 'https://www.szse.cn'; const currentUrl = `${rootUrl}/api/report/ShowReport/data?SHOWTYPE=JSON&CATALOGID=main_wxhj&TABKEY=tab${Number.parseInt(category) + 2}${select === '全部函件类别' ? '' : `&selecthjlb=${select}`}${keyword ? `&txtZqdm=${keyword}` : ''}`; @@ -32,10 +32,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `深圳证券交易所 - 问询函件 - ${data.metadata.name}`, link: `${rootUrl}/disclosure/supervision/inquire/index.html`, item: items, description: `函件类别:${select}${keyword ? `; 公司代码或简称:${keyword}` : ''}`, - }; + }); }; diff --git a/lib/v2/szse/notice.js b/lib/v2/szse/notice.js index f1d263572..547dd26b6 100644 --- a/lib/v2/szse/notice.js +++ b/lib/v2/szse/notice.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = require('url'); const host = 'http://www.szse.cn/'; module.exports = async (ctx) => { @@ -7,7 +7,7 @@ module.exports = async (ctx) => { const response = await got.get(link, { Referer: host, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 正则表达式匹配Script标签的url和title变量 function getData(jscontent, option) { const urlpattern = /(?<=curHref = ').*?(?=';)/; @@ -51,7 +51,7 @@ module.exports = async (ctx) => { const response = await got.get(itemUrl, { Referer: host, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('#desContent').html(); const single = { title, @@ -63,9 +63,9 @@ module.exports = async (ctx) => { return single; }) ); - ctx.state.data = { + ctx.set('data', { title: '深圳证券交易所——上市公告-可转换债券', link, item: out, - }; + }); }; diff --git a/lib/v2/szse/projectdynamic.js b/lib/v2/szse/projectdynamic.js index d38570e90..826bafa14 100644 --- a/lib/v2/szse/projectdynamic.js +++ b/lib/v2/szse/projectdynamic.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -39,9 +39,9 @@ module.exports = async (ctx) => { 95: '撤回', }; - const type = ctx.params.type ?? '1'; - const stage = ctx.params.stage ?? '0'; - const status = ctx.params.status ?? '0'; + const type = ctx.req.param('type') ?? '1'; + const stage = ctx.req.param('stage') ?? '0'; + const status = ctx.req.param('status') ?? '0'; const rootUrl = 'http://listing.szse.cn'; const apiUrl = `${rootUrl}/api/ras/projectrends/query?bizType=${type}${stage === '0' ? '' : `&stage=${stage}`}${status === '0' ? '' : `&status=${status}`}&pageIndex=0&pageSize=20`; @@ -82,9 +82,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${typeMap[type]}项目动态${status === '0' ? (stage === '0' ? '' : ` (${stageMap[stage]}) `) : ` (${statusMap[status]}) `} - 创业板发行上市审核信息公开网站 - 深圳证券交易所`, link: `${rootUrl}/projectdynamic/${type}/index.html`, item: items, - }; + }); }; diff --git a/lib/v2/szse/rule.js b/lib/v2/szse/rule.js index 73779a6eb..c9d92f12e 100644 --- a/lib/v2/szse/rule.js +++ b/lib/v2/szse/rule.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 = 'http://www.szse.cn'; @@ -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('#desContent').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '最新规则 - 深圳证券交易所', link: `${rootUrl}/lawrules/rule/new`, item: items, - }; + }); }; diff --git a/lib/v2/szu/yz/index.js b/lib/v2/szu/yz/index.js index 2982b8c8e..4734a1eda 100644 --- a/lib/v2/szu/yz/index.js +++ b/lib/v2/szu/yz/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const util = require('./utils'); const map = new Map([ @@ -8,7 +8,7 @@ const map = new Map([ ]); module.exports = async (ctx) => { - let type = Number.parseInt(ctx.params.type); + let type = Number.parseInt(ctx.req.param('type')); const struct = { 1: { selector: { @@ -36,16 +36,16 @@ module.exports = async (ctx) => { const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $(struct[type].selector.list).find(struct[type].selector.item).toArray(); const name = $('title').text(); const result = await util.ProcessFeed(list, ctx.cache, struct[type]); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: url, description: name, item: result, - }; + }); }; diff --git a/lib/v2/szu/yz/utils.js b/lib/v2/szu/yz/utils.js index 21618f248..3f9bee96f 100644 --- a/lib/v2/szu/yz/utils.js +++ b/lib/v2/szu/yz/utils.js @@ -1,28 +1,28 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const ProcessFeed = (list, cache, current) => Promise.all( list .filter((item) => { // 如果不包含链接说明不是新闻item,如表头的tr - const $ = cheerio.load(item, null, false); + const $ = load(item, null, false); return $('a').length; // return typeof ($('a').attr('href')) !== undefined; // return false; }) .map((item) => { - let $ = cheerio.load(item, null, false); + let $ = load(item, null, false); const $url = new URL($('a').attr('href'), current.url).href; return cache.tryGet($url, async () => { // 加载新闻内容页面 const response = await got($url); const data = response.data; - $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML + $ = load(data); // 使用 cheerio 加载返回的 HTML // 还原图片地址 $(`${current.selector.content} img`).each((index, elem) => { diff --git a/lib/v2/tableau/viz-of-the-day.js b/lib/v2/tableau/viz-of-the-day.js index 941cad7d4..03b671d38 100644 --- a/lib/v2/tableau/viz-of-the-day.js +++ b/lib/v2/tableau/viz-of-the-day.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) => { // Your logic here @@ -16,11 +16,11 @@ module.exports = async (ctx) => { itunes_item_image: item.screenshot, })); - ctx.state.data = { + ctx.set('data', { // Your RSS output here title: 'Tableau Viz of the Day', link: 'https://public.tableau.com/app/discover/viz-of-the-day', image: 'https://help.tableau.com/current/pro/desktop/en-us/Resources/tableau-logo.png', item: items, - }; + }); }; diff --git a/lib/v2/taiwannews/hot.js b/lib/v2/taiwannews/hot.js index dac02c329..c4f3c3893 100644 --- a/lib/v2/taiwannews/hot.js +++ b/lib/v2/taiwannews/hot.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 = async (ctx) => { const baseUrl = 'https://www.taiwannews.com.tw'; const { lang = 'en' } = ctx.params; const url = `${baseUrl}/${lang}/index`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.mod_group-columns .container-fluid .row') .toArray() @@ -27,7 +27,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 = $('.article-author').text(); item.category = $('.tagcloud a') @@ -43,11 +43,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.categories').eq(0).text()} - ${$('head title').text()}`, description: $('meta[name="description"]').attr('content'), link: url, item: items, language: lang, - }; + }); }; diff --git a/lib/v2/tangshufang/index.js b/lib/v2/tangshufang/index.js index b8847bba8..2d3125294 100644 --- a/lib/v2/tangshufang/index.js +++ b/lib/v2/tangshufang/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 category = ctx.params.category ?? ''; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10; + const category = ctx.req.param('category') ?? ''; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10; const rootUrl = 'https://www.tangshufang.com'; const currentUrl = `${rootUrl}${category ? `/${category}` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('article') .slice(0, limit) @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.wxsyncmain').html(); item.category = content('a[rel="category tag"]') @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/taobao/zhongchou.js b/lib/v2/taobao/zhongchou.js index 857cec8de..2c7398f1e 100644 --- a/lib/v2/taobao/zhongchou.js +++ b/lib/v2/taobao/zhongchou.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `淘宝众筹-${type}`, link: 'https://izhongchou.taobao.com/index.htm', item: items, - }; + }); }; diff --git a/lib/v2/taoguba/blog.js b/lib/v2/taoguba/blog.js index b0991606d..bfc7a70da 100644 --- a/lib/v2/taoguba/blog.js +++ b/lib/v2/taoguba/blog.js @@ -1,10 +1,10 @@ -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; + const id = ctx.req.param('id'); const rootUrl = 'https://www.taoguba.com.cn'; const currentUrl = `${rootUrl}/blog/${id}`; @@ -14,11 +14,11 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const author = $('meta[property="og:author"]').attr('content'); let items = $('.tittle_data') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50) .toArray() .map((item) => { item = $(item); @@ -44,7 +44,7 @@ module.exports = async (ctx) => { return item; } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#videoImg').remove(); content('img').each((_, img) => { @@ -74,11 +74,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `淘股吧 - ${author}`, description: $('meta[http-equiv="description"]').attr('content'), image: $('meta[property="og:image"]').attr('content'), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/taoguba/index.js b/lib/v2/taoguba/index.js index a22bd37cb..d824b4fe1 100644 --- a/lib/v2/taoguba/index.js +++ b/lib/v2/taoguba/index.js @@ -1,10 +1,10 @@ -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.category ?? 'zongban'; + const category = ctx.req.param('category') ?? 'zongban'; const rootUrl = 'https://www.taoguba.com.cn'; const currentUrl = `${rootUrl}/${category}/`; @@ -14,10 +14,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.items-comment-list') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 70) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 70) .toArray() .map((item) => { item = $(item); @@ -44,7 +44,7 @@ module.exports = async (ctx) => { return item; } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#videoImg').remove(); content('img').each((_, img) => { @@ -74,9 +74,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim().split('_')[0], link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/taptap/changelog.js b/lib/v2/taptap/changelog.js index 3e9318bf6..38d321325 100644 --- a/lib/v2/taptap/changelog.js +++ b/lib/v2/taptap/changelog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { getRootUrl, appDetail, X_UA } = require('./utils'); module.exports = async (ctx) => { const is_intl = ctx.request.url.indexOf('/intl/') === 0; - const id = ctx.params.id; - const lang = ctx.params.lang ?? (is_intl ? 'en_US' : 'zh_CN'); + const id = ctx.req.param('id'); + const lang = ctx.req.param('lang') ?? (is_intl ? 'en_US' : 'zh_CN'); const url = `${getRootUrl(is_intl)}/app/${id}`; @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const list = response.data.data.list; - ctx.state.data = { + ctx.set('data', { title: `TapTap 更新记录 ${app_name}`, description: app_description, link: url, @@ -37,5 +37,5 @@ module.exports = async (ctx) => { link: url, guid: item.version_label, })), - }; + }); }; diff --git a/lib/v2/taptap/review.js b/lib/v2/taptap/review.js index 5a50a8c32..3ab8ce533 100644 --- a/lib/v2/taptap/review.js +++ b/lib/v2/taptap/review.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 { getRootUrl, appDetail, X_UA } = require('./utils'); const sortMap = { @@ -105,9 +105,9 @@ const fetchIntlItems = async (params) => { module.exports = async (ctx) => { const is_intl = ctx.request.url.indexOf('/intl/') === 0; - const id = ctx.params.id; - const order = ctx.params.order ?? 'default'; - const lang = ctx.params.lang ?? (is_intl ? 'en_US' : 'zh_CN'); + const id = ctx.req.param('id'); + const order = ctx.req.param('order') ?? 'default'; + const lang = ctx.req.param('lang') ?? (is_intl ? 'en_US' : 'zh_CN'); const app_detail = await appDetail(id, lang, is_intl); const app_img = app_detail.app.icon.original_url; @@ -115,17 +115,17 @@ module.exports = async (ctx) => { const items = is_intl ? await fetchIntlItems(ctx.params) : await fetchMainlandItems(ctx.params); - ctx.state.data = { + ctx.set('data', { title: `TapTap 评价 ${app_name} - ${(is_intl ? intlSortMap : sortMap)[order][lang]}排序`, link: `${getRootUrl(is_intl)}/app/${id}/review?${makeSortParam(is_intl, order)}`, image: app_img, item: items, - }; + }); - ctx.state.json = { + ctx.set('json', { title: `TapTap 评价 ${app_name} - ${(is_intl ? intlSortMap : sortMap)[order][lang]}排序`, link: `${getRootUrl(is_intl)}/app/${id}/review?${makeSortParam(is_intl, order)}`, image: app_img, item: items, - }; + }); }; diff --git a/lib/v2/taptap/topic.js b/lib/v2/taptap/topic.js index c908bb865..e693266c3 100644 --- a/lib/v2/taptap/topic.js +++ b/lib/v2/taptap/topic.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 { getRootUrl, X_UA, appDetail, imagePost, topicPost, videoPost } = require('./utils'); const typeMap = { @@ -22,11 +22,11 @@ const typeMap = { }; module.exports = async (ctx) => { - const lang = ctx.params.lang ?? 'zh_CN'; - const appId = ctx.params.id; + const lang = ctx.req.param('lang') ?? 'zh_CN'; + const appId = ctx.req.param('id'); const appData = await appDetail(appId, lang); - const type = ctx.params.type ?? 'feed'; - const sort = ctx.params.sort ?? 'created'; + const type = ctx.req.param('type') ?? 'feed'; + const sort = ctx.req.param('sort') ?? 'created'; const groupId = appData.group.id; const app_img = appData.app.icon.original_url || appData.app.icon.url; const app_name = appData.app.title; @@ -66,14 +66,14 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${app_name} - ${typeMap[type][lang]} - TapTap 论坛`, link: `${getRootUrl(false)}/app/${appId}/topic?type=${type}&sort=${sort}`, image: app_img, item: out.filter((item) => item !== ''), - }; + }); - ctx.state.json = { + ctx.set('json', { title: `${app_name} - ${typeMap[type][lang]} - TapTap 论坛`, link: `${getRootUrl(false)}/app/${appId}/topic?type=${type}&sort=${sort}`, image: app_img, @@ -81,5 +81,5 @@ module.exports = async (ctx) => { appId, groupId, topics_list, - }; + }); }; diff --git a/lib/v2/taptap/utils.js b/lib/v2/taptap/utils.js index fcdc02f44..4c9e25bc9 100644 --- a/lib/v2/taptap/utils.js +++ b/lib/v2/taptap/utils.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; // Please do not change %26 to & const X_UA = (lang = 'zh_CN') => `X-UA=V=1%26PN=WebApp%26VN=0.1.0%26LANG=${lang}%26PLT=PC`; @@ -28,7 +28,7 @@ const topicPost = async (appId, topicId, lang = 'zh_CN') => { Referer: `${getRootUrl(false)}/app/${appId}`, }, }); - const $ = cheerio.load(res.data.data.first_post.contents.text, null, false); + const $ = load(res.data.data.first_post.contents.text, null, false); $('img').each((_, e) => { e = $(e); e.attr('src', e.attr('data-origin-url')); diff --git a/lib/v2/tass/news.js b/lib/v2/tass/news.js index 443ad117d..1a27a18c9 100644 --- a/lib/v2/tass/news.js +++ b/lib/v2/tass/news.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 { category = 'politics' } = ctx.params; const { data: categoryPage, url: link } = await got(`https://tass.com/${category}`); - const $ = cheerio.load(categoryPage); + const $ = load(categoryPage); const sectionId = $('.container .section-page') .attr('ng-init') @@ -31,7 +31,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-media img').each((_, ele) => { if (ele.attribs.src) { @@ -46,7 +46,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: 'en', @@ -54,5 +54,5 @@ module.exports = async (ctx) => { icon: $('head link[rel="apple-touch-icon"]').attr('href'), logo: $('head link[rel="apple-touch-icon"]').attr('href'), item: items, - }; + }); }; diff --git a/lib/v2/techcrunch/news.js b/lib/v2/techcrunch/news.js index f40ce73a7..2a37bcc3f 100644 --- a/lib/v2/techcrunch/news.js +++ b/lib/v2/techcrunch/news.js @@ -1,6 +1,6 @@ const parser = require('@/utils/rss-parser'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const host = 'https://techcrunch.com'; module.exports = async (ctx) => { const rssUrl = `${host}/feed/`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { method: 'get', }); const html = response.data; - const $ = cheerio.load(html); + const $ = load(html); const description = $('#root'); description.find('.article__title').remove(); description.find('.article__byline__meta').remove(); @@ -29,10 +29,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'TechCrunch', link: host, description: 'Reporting on the business of technology, startups, venture capital funding, and Silicon Valley.', item: items, - }; + }); }; diff --git a/lib/v2/techflowpost/express.js b/lib/v2/techflowpost/express.js index 91a0c7df3..fbf18a802 100644 --- a/lib/v2/techflowpost/express.js +++ b/lib/v2/techflowpost/express.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { unescapeAll } = require('markdown-it/lib/common/utils'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { unescapeAll } from 'markdown-it/lib/common/utils.mjs'; module.exports = async (ctx) => { const rootUrl = 'https://www.techflowpost.com'; const apiRootUrl = 'https://data.techflowpost.com'; const currentUrl = `${rootUrl}/express`; - const apiUrl = `${apiRootUrl}/api/pc/express/all?pageIndex=0&pageSize=${ctx.query.limit ?? 50}`; + const apiUrl = `${apiRootUrl}/api/pc/express/all?pageIndex=0&pageSize=${ctx.req.query('limit') ?? 50}`; const response = await got({ method: 'post', @@ -25,9 +25,9 @@ module.exports = async (ctx) => { description: unescapeAll(item.content), })); - ctx.state.data = { + ctx.set('data', { title: '深潮TechFlow - 快讯', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/techflowpost/index.js b/lib/v2/techflowpost/index.js index 853900ab0..7cdf32023 100644 --- a/lib/v2/techflowpost/index.js +++ b/lib/v2/techflowpost/index.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { unescapeAll } = require('markdown-it/lib/common/utils'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { unescapeAll } from 'markdown-it/lib/common/utils.mjs'; module.exports = async (ctx) => { const rootUrl = 'https://www.techflowpost.com'; const apiRootUrl = 'https://data.techflowpost.com'; - const apiUrl = `${apiRootUrl}/api/pc/home/more?pageIndex=0&pageSize=${ctx.query.limit ?? 50}`; + const apiUrl = `${apiRootUrl}/api/pc/home/more?pageIndex=0&pageSize=${ctx.req.query('limit') ?? 50}`; const response = await got({ method: 'get', @@ -22,9 +22,9 @@ module.exports = async (ctx) => { description: unescapeAll(item.content), })); - ctx.state.data = { + ctx.set('data', { title: '深潮TechFlow', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/techpowerup/index.js b/lib/v2/techpowerup/index.js index a40c4f278..d980723a8 100644 --- a/lib/v2/techpowerup/index.js +++ b/lib/v2/techpowerup/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 { baseUrl, headers, fixImages, parseReviews } = require('./utils'); module.exports = async (ctx) => { @@ -8,7 +8,7 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.newspost') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { const { data: response } = await got(item.link, { headers, }); - const $ = cheerio.load(response); + const $ = load(response); fixImages($); @@ -59,11 +59,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'TechPowerUp', link: baseUrl, language: 'en', image: 'https://tpucdn.com/apple-touch-icon-v1684568903519.png', item: items, - }; + }); }; diff --git a/lib/v2/techpowerup/review.js b/lib/v2/techpowerup/review.js index ff836a2c3..29394c73e 100644 --- a/lib/v2/techpowerup/review.js +++ b/lib/v2/techpowerup/review.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 { baseUrl, headers, fixImages, parseReviews } = require('./utils'); module.exports = async (ctx) => { @@ -16,7 +16,7 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.reviewlist-bit') .toArray() @@ -48,7 +48,7 @@ module.exports = async (ctx) => { const { data: response } = await got(item.link, { headers, }); - const $ = cheerio.load(response); + const $ = load(response); fixImages($); @@ -59,11 +59,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Reviews | TechPowerUp', link: url.href, language: 'en', image: 'https://tpucdn.com/apple-touch-icon-v1684568903519.png', item: items, - }; + }); }; diff --git a/lib/v2/techpowerup/utils.js b/lib/v2/techpowerup/utils.js index a0fca8d80..6a40d018a 100644 --- a/lib/v2/techpowerup/utils.js +++ b/lib/v2/techpowerup/utils.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const md5 = require('@/utils/md5'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import md5 from '@/utils/md5'; const baseUrl = 'https://www.techpowerup.com'; @@ -51,7 +51,7 @@ const parseReviews = async ($, item) => { const { data: response } = await got(url, { headers, }); - const $ = cheerio.load(response); + const $ = load(response); $('.text div.responsive-image-xx').each((_, d) => { removeResponsiveStyle(d); }); diff --git a/lib/v2/telecompaper/news.js b/lib/v2/telecompaper/news.js index f4d3a5634..7ef20c9c1 100644 --- a/lib/v2/telecompaper/news.js +++ b/lib/v2/telecompaper/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 tough = require('tough-cookie'); // eslint-disable-next-line n/no-extraneous-require const FormData = require('form-data'); module.exports = async (ctx) => { - const rootUrl = `https://www.telecompaper.com/${ctx.params.caty === 'industry-resources' ? ctx.params.caty : 'international/news/' + ctx.params.caty}`; - const year = ctx.params.year ?? 'all'; - const country = ctx.params.country ? ctx.params.country.split('-').join(' ') : 'all'; - const type = ctx.params.type ? ctx.params.type.split('-').join(' ') : 'all'; + const rootUrl = `https://www.telecompaper.com/${ctx.req.param('caty') === 'industry-resources' ? ctx.req.param('caty') : 'international/news/' + ctx.req.param('caty')}`; + const year = ctx.req.param('year') ?? 'all'; + const country = ctx.req.param('country') ? ctx.req.param('country').split('-').join(' ') : 'all'; + const type = ctx.req.param('type') ? ctx.req.param('type').split('-').join(' ') : 'all'; const cookieJar = new tough.CookieJar(); let response = await got({ @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: rootUrl, cookieJar, }), - $ = cheerio.load(response.data); + $ = load(response.data); const form = new FormData(); form.append('__EVENTTARGET', 'ctl00$MainPlaceHolder$ddlContentType'); @@ -24,14 +24,14 @@ module.exports = async (ctx) => { form.append('__LASTFOCUS', ''); form.append('__VIEWSTATE', $('#__VIEWSTATE').attr('value')); form.append('__VIEWSTATEGENERATOR', 'E4EF4CD1'); - form.append('ctl00$header$searchText', ctx.params.keyword || ''); - form.append('ctl00$header$searchTextMobile', ctx.params.keyword || ''); - if (ctx.params.caty !== 'industry-resources') { + form.append('ctl00$header$searchText', ctx.req.param('keyword') || ''); + form.append('ctl00$header$searchTextMobile', ctx.req.param('keyword') || ''); + if (ctx.req.param('caty') !== 'industry-resources') { form.append( 'ctl00$MainPlaceHolder$ddlYears', year && year !== 'all' ? $('select[name="ctl00$MainPlaceHolder$ddlYears"] option') - .filter((index, element) => $(element).text().split(' (')[0] === ctx.params.year) + .filter((index, element) => $(element).text().split(' (')[0] === ctx.req.param('year')) .attr('value') : '0' ); @@ -62,7 +62,7 @@ module.exports = async (ctx) => { }, body: form, }); - $ = cheerio.load(response.data); + $ = load(response.data); const list = $('table.details_rows tbody tr') .slice(0, 10) @@ -84,7 +84,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#pageContainer').html(); @@ -93,9 +93,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Telecompaper - ' + $('h1').text(), link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/telecompaper/search.js b/lib/v2/telecompaper/search.js index 98c54c3e5..62d612a04 100644 --- a/lib/v2/telecompaper/search.js +++ b/lib/v2/telecompaper/search.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const keyword = ctx.params.keyword || ''; - const company = ctx.params.company || ''; - const sort = ctx.params.sort || '2'; - const period = ctx.params.period || '12'; + const keyword = ctx.req.param('keyword') || ''; + const company = ctx.req.param('company') || ''; + const sort = ctx.req.param('sort') || '2'; + const period = ctx.req.param('period') || '12'; const rootUrl = `https://www.telecompaper.com/search/index.aspx?search=${keyword}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { method: 'get', url: rootUrl, }), - $ = cheerio.load(response.data); + $ = load(response.data); response = await got({ method: 'post', @@ -37,7 +37,7 @@ module.exports = async (ctx) => { ctl00$MainPlaceHolder$Submit: 'Search', }), }); - $ = cheerio.load(response.data); + $ = load(response.data); const list = $('table.details_rows tbody tr') .slice(0, 15) @@ -59,7 +59,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#pageContainer').html(); @@ -68,9 +68,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Telecompaper Search - ${keyword}`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/telegram/blog.js b/lib/v2/telegram/blog.js index bc6dc62e8..69e7efb73 100644 --- a/lib/v2/telegram/blog.js +++ b/lib/v2/telegram/blog.js @@ -1,6 +1,6 @@ const cherrio = require('cheerio'); -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 link = 'https://telegram.org/blog'; @@ -27,9 +27,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: $$('title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/telegram/channel.js b/lib/v2/telegram/channel.js index ee3909a83..ab9ed18a7 100644 --- a/lib/v2/telegram/channel.js +++ b/lib/v2/telegram/channel.js @@ -1,8 +1,8 @@ -const config = require('@/config').value; -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { config } from '@/config'; +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 querystring = require('querystring'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); @@ -50,8 +50,8 @@ const mediaTagDict = { }; module.exports = async (ctx) => { - const username = ctx.params.username; - let routeParams = ctx.params.routeParams; + const username = ctx.req.param('username'); + let routeParams = ctx.req.param('routeParams'); let showLinkPreview = true; let showViaBot = true; let showReplyTo = true; @@ -66,7 +66,7 @@ module.exports = async (ctx) => { let includeUnsupportedMsg = false; let searchQuery = routeParams; // for backward compatibility if (routeParams && routeParams.search(/(^|&)(show(LinkPreview|ViaBot|ReplyTo|FwdFrom(Author)?|InlineButtons|MediaTag(InTitle|AsEmoji))|include(Fwd|Reply|(Service|Unsupported)Msg)|searchQuery)=/) !== -1) { - routeParams = querystring.parse(ctx.params.routeParams); + routeParams = querystring.parse(ctx.req.param('routeParams')); showLinkPreview = !!fallback(undefined, queryToBoolean(routeParams.showLinkPreview), showLinkPreview); showViaBot = !!fallback(undefined, queryToBoolean(routeParams.showReplyTo), showViaBot); showReplyTo = !!fallback(undefined, queryToBoolean(routeParams.showViaBot), showReplyTo); @@ -94,7 +94,7 @@ module.exports = async (ctx) => { false ); - const $ = cheerio.load(data); + const $ = load(data); const list = includeServiceMsg ? $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.tme_no_messages_found))') // exclude 'no posts found' messages : $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.service_message,.tme_no_messages_found))'); // also exclude service messages @@ -106,7 +106,7 @@ module.exports = async (ctx) => { const channelName = $('.tgme_channel_info_header_title').text(); const feedTitle = (searchQuery ? `"${searchQuery}" - ` : '') + channelName + ' - Telegram Channel'; - ctx.state.data = { + ctx.set('data', { title: feedTitle, description: $('.tgme_channel_info_description').text(), link: resourceUrl, @@ -588,5 +588,5 @@ module.exports = async (ctx) => { .get() .filter(Boolean) .reverse(), - }; + }); }; diff --git a/lib/v2/telegram/stickerpack.js b/lib/v2/telegram/stickerpack.js index 42072b7ea..8671324d2 100644 --- a/lib/v2/telegram/stickerpack.js +++ b/lib/v2/telegram/stickerpack.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.telegram || !config.telegram.token) { throw new Error('Telegram Sticker Pack RSS is disabled due to the lack of relevant config'); } - const name = ctx.params.name; + const name = ctx.req.param('name'); const response = await got({ method: 'get', @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const data = response.data.result; - ctx.state.data = { + ctx.set('data', { title: `${data.title} - Telegram Sticker Pack`, link: `https://t.me/addstickers/${name}`, item: data.stickers.map((item) => ({ @@ -22,5 +22,5 @@ module.exports = async (ctx) => { description: item.file_id, guid: item.file_id, })), - }; + }); }; diff --git a/lib/v2/tencent/news/author.js b/lib/v2/tencent/news/author.js index 290fbf6a0..7ae74a2b8 100644 --- a/lib/v2/tencent/news/author.js +++ b/lib/v2/tencent/news/author.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const mid = ctx.params.mid; + const mid = ctx.req.param('mid'); const homePageInfoUrl = `https://i.news.qq.com/i/getUserHomepageInfo?chlid=${mid}`; const userInfo = await ctx.cache.tryGet(homePageInfoUrl, async () => (await got(homePageInfoUrl)).data.userinfo); const title = userInfo.nick; @@ -34,13 +34,13 @@ module.exports = async (ctx) => { } : ctx.cache.tryGet(itemUrl, async () => { const response = await got(itemUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const data = JSON.parse( $('script:contains("window.DATA")') .text() .match(/window\.DATA = ({.+});/)[1] ); - const $data = cheerio.load(data.originContent.text, null, false); + const $data = load(data.originContent.text, null, false); $data('*') .contents() @@ -63,10 +63,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title, description, link: `https://new.qq.com/omn/author/${mid}`, item: items, - }; + }); }; diff --git a/lib/v2/tencent/news/coronavirus/data.js b/lib/v2/tencent/news/coronavirus/data.js index c5c28777c..b91359b7c 100644 --- a/lib/v2/tencent/news/coronavirus/data.js +++ b/lib/v2/tencent/news/coronavirus/data.js @@ -1,11 +1,11 @@ const { getData } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const province = ctx.params.province || ''; - const city = ctx.params.city || ''; + const province = ctx.req.param('province') || ''; + const city = ctx.req.param('city') || ''; const link = 'https://news.qq.com/zt2020/page/feiyan.htm#/'; const item = []; @@ -63,9 +63,9 @@ module.exports = async (ctx) => { item.push(info); - ctx.state.data = { + ctx.set('data', { title, link, item, - }; + }); }; diff --git a/lib/v2/tencent/news/coronavirus/total.js b/lib/v2/tencent/news/coronavirus/total.js index 08c10f233..908ecd2fd 100644 --- a/lib/v2/tencent/news/coronavirus/total.js +++ b/lib/v2/tencent/news/coronavirus/total.js @@ -1,6 +1,6 @@ const { getData } = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -26,9 +26,9 @@ module.exports = async (ctx) => { }; item.push(info); - ctx.state.data = { + ctx.set('data', { title, link, item, - }; + }); }; diff --git a/lib/v2/tencent/news/coronavirus/utils.js b/lib/v2/tencent/news/coronavirus/utils.js index ccdd18d8f..dcb0837ee 100644 --- a/lib/v2/tencent/news/coronavirus/utils.js +++ b/lib/v2/tencent/news/coronavirus/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; /** * diff --git a/lib/v2/tencent/pvp/newsindex.js b/lib/v2/tencent/pvp/newsindex.js index 6f52505c6..6ba7c6b6b 100644 --- a/lib/v2/tencent/pvp/newsindex.js +++ b/lib/v2/tencent/pvp/newsindex.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 map = new Map([ ['rm', { name: '热门', channelid: 1760 }], ['xw', { name: '新闻', channelid: 1761 }], @@ -37,7 +37,7 @@ const getPage = async (id, typeName) => { }; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const OutName = map.get(type).name; const OutId = map.get(type).channelid; @@ -57,10 +57,10 @@ module.exports = async (ctx) => { item = await getPage(OutId, OutName); } - ctx.state.data = { + ctx.set('data', { title: `【${OutName}】 - 王者荣耀 - 新闻列表`, link, description: `《王者荣耀》是腾讯天美工作室历时3年推出的东方英雄即时对战手游大作,抗塔强杀、团灭超神,领略爽热血竞技的酣畅淋漓!1v1、3v3、闯关等丰富游戏模式,随时战,更自由!跨服匹配秒开局,好友组队战排位,不靠装备、没有等级,更公平、更爽快的无差异对战!`, item, - }; + }); }; diff --git a/lib/v2/tencent/qq/sdk/changelog.js b/lib/v2/tencent/qq/sdk/changelog.js index 88243e83d..b6d532180 100644 --- a/lib/v2/tencent/qq/sdk/changelog.js +++ b/lib/v2/tencent/qq/sdk/changelog.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 platform = ctx.params.platform; + const platform = ctx.req.param('platform'); let title = ''; let link = ''; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 获取主要文本,并且过滤空行 const contents = $('.wp-editor') @@ -48,9 +48,9 @@ module.exports = async (ctx) => { return changelog; }); - ctx.state.data = { + ctx.set('data', { title, link, item: changelogs, - }; + }); }; diff --git a/lib/v2/tesla/cx.js b/lib/v2/tesla/cx.js index ef8d4d3c7..ff9870133 100644 --- a/lib/v2/tesla/cx.js +++ b/lib/v2/tesla/cx.js @@ -1,12 +1,12 @@ -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 { category, city } = 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://cx.tesla.cn'; const rootApiUrl = 'https://community-api.tesla.cn'; @@ -97,13 +97,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('title').text(); const description = `${city ?? ''}${category ?? ''}`; const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}权益中心${description ? ` - ${description}` : ''}`, link: currentUrl, @@ -115,5 +115,5 @@ module.exports = async (ctx) => { subtitle: description, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/tesla/price/get-price.js b/lib/v2/tesla/price/get-price.js index 476bc8167..2ad1c2ab1 100644 --- a/lib/v2/tesla/price/get-price.js +++ b/lib/v2/tesla/price/get-price.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; async function getTeslaPrice(link) { const response = await got(link); - const $ = cheerio.load(response.body); + const $ = load(response.body); let price = ''; diff --git a/lib/v2/tesla/price/index.js b/lib/v2/tesla/price/index.js index a4e33d017..fad4a4606 100644 --- a/lib/v2/tesla/price/index.js +++ b/lib/v2/tesla/price/index.js @@ -27,7 +27,7 @@ module.exports = async (ctx) => { const promises = cars.map((car) => getTeslaPrice(car.link)); const prices = await Promise.all(promises); - ctx.state.data = { + ctx.set('data', { title: 'Tesla Model 系列价格更新', link: 'https://www.tesla.cn/model3/design#overview', description: 'Tesla Model 系列价格更新', @@ -37,5 +37,5 @@ module.exports = async (ctx) => { author: 'Tesla', guid: `https://www.tesla.cn/${cars[index].slug}/design#overview#${price}`, })), - }; + }); }; diff --git a/lib/v2/tfc-taiwan/index.js b/lib/v2/tfc-taiwan/index.js index 31bd0590e..186897746 100644 --- a/lib/v2/tfc-taiwan/index.js +++ b/lib/v2/tfc-taiwan/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { baseUrl, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -8,7 +8,7 @@ module.exports = async (ctx) => { let link = baseUrl; if (isTopic) { - link += `/topic/${ctx.params.id}`; + link += `/topic/${ctx.req.param('id')}`; } else if (requestPath === '/') { link += `/articles/report`; } else { @@ -16,7 +16,7 @@ module.exports = async (ctx) => { } const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $(`${isTopic ? '.view-grouping' : '.pane-clone-of-article'} .views-row-inner`) .toArray() @@ -24,7 +24,7 @@ module.exports = async (ctx) => { const items = await parseItems(list, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), image: $('head meta[property="og:image"]').attr('content'), @@ -32,5 +32,5 @@ module.exports = async (ctx) => { icon: $('head link[rel="shortcut icon"]').attr('href'), link, item: items, - }; + }); }; diff --git a/lib/v2/tfc-taiwan/utils.js b/lib/v2/tfc-taiwan/utils.js index cc38ea689..a30d7cfc1 100644 --- a/lib/v2/tfc-taiwan/utils.js +++ b/lib/v2/tfc-taiwan/utils.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const asyncPool = require('tiny-async-pool'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const asyncPoolAll = async (...args) => { const results = []; @@ -30,7 +30,7 @@ const parseItems = (list, tryGet) => asyncPoolAll(10, list, (item) => tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.field-name-field-addthis, #fb-root, .fb-comments, .likecoin-embed, style[type="text/css"]').remove(); diff --git a/lib/v2/theatlantic/news.js b/lib/v2/theatlantic/news.js index b91235e1c..e998e0f5c 100644 --- a/lib/v2/theatlantic/news.js +++ b/lib/v2/theatlantic/news.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { getArticleDetails } = require('./utils'); module.exports = async (ctx) => { const host = 'https://www.theatlantic.com'; - const category = ctx.params.category; + const category = ctx.req.param('category'); const url = `${host}/${category}/`; const response = await got({ method: 'get', url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const contents = JSON.parse($('script#__NEXT_DATA__').text()).props.pageProps.urqlState; const keyWithContent = Object.keys(contents).filter((key) => contents[key].data.includes(category)); const data = JSON.parse(contents[keyWithContent].data); @@ -23,10 +23,10 @@ module.exports = async (ctx) => { }); const items = await getArticleDetails(list, ctx); - ctx.state.data = { + ctx.set('data', { title: `The Atlantic - ${category.toUpperCase()}`, link: url, description: `The Atlantic - ${category.toUpperCase()}`, item: items, - }; + }); }; diff --git a/lib/v2/theatlantic/utils.js b/lib/v2/theatlantic/utils.js index a8d07fd33..dfdc9960a 100644 --- a/lib/v2/theatlantic/utils.js +++ b/lib/v2/theatlantic/utils.js @@ -1,9 +1,11 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); -const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' }); +import randUserAgent from '@/utils/rand-user-agent'; + +const UA = randUserAgent({ browser: 'chrome', os: 'android', device: 'mobile' }); const getArticleDetails = async (items, ctx) => { const list = await Promise.all( @@ -18,7 +20,7 @@ const getArticleDetails = async (items, ctx) => { }, }); const html = response.data; - const $ = cheerio.load(html); + const $ = load(html); let data = JSON.parse($('script#__NEXT_DATA__').text()); const list = data.props.pageProps.urqlState; diff --git a/lib/v2/theblockbeats/index.js b/lib/v2/theblockbeats/index.js index 371c9327f..f274549c8 100644 --- a/lib/v2/theblockbeats/index.js +++ b/lib/v2/theblockbeats/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 domain = 'theblockbeats.info'; const rootUrl = `https://www.${domain}`; @@ -37,7 +37,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.news-content').html(); return item; }) @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `TheBlockBeats - ${channelMap[channel].title}`, link: channelMap[channel].link, item: list, - }; + }); }; diff --git a/lib/v2/thecatcity/index.js b/lib/v2/thecatcity/index.js index ada3e831d..1e302cab3 100644 --- a/lib/v2/thecatcity/index.js +++ b/lib/v2/thecatcity/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'; const { termsMap } = require('./terms-map'); const baseUrl = 'https://thecatcity.com'; @@ -38,11 +38,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: termsMap[term] ? termsMap[term].title : termsMap[''].title, description: '提供貓咪日常照顧、新手準備、貓用品、貓咪醫療、貓飲食與行為等相關知識,以及療癒貓影片、貓趣聞、貓小物流行資訊,不論你是貓奴、還是貓控,一切所需都在貓奴日常找到', link: baseUrl, image: 'https://assets.presslogic.com/presslogic-hk-tc/static/favicon.ico', item: items, - }; + }); }; diff --git a/lib/v2/thecover/channel.js b/lib/v2/thecover/channel.js index 1e8bcd1a5..8dbff82d9 100644 --- a/lib/v2/thecover/channel.js +++ b/lib/v2/thecover/channel.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 rootUrl = 'https://www.thecover.cn'; const nodes = { @@ -23,13 +23,13 @@ const nodes = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? '3892'; + const id = ctx.req.param('id') ?? '3892'; const targetUrl = rootUrl.concat(`/channel_${id}`); const resp = await got({ method: 'get', url: targetUrl, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const list = $('a.link-to-article') .filter(function () { return $(this).attr('href').startsWith('/'); @@ -45,7 +45,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('h1', '.main-article').text(); item.description = content('section.article-content').html(); const info = content('span', '.props-of-title'); @@ -56,11 +56,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${nodes[id]}-封面新闻`, link: targetUrl, description: `封面新闻作为华西都市报深度融合转型和打造新型主流媒体的载体,牢固确立移动优先战略,创新移动新闻产品,打造移动传播矩阵,封面新闻的传播力、引导力、影响力和公信力不断得到各方肯定。封面新闻突破千万的用户下载量,呈现出以四川为主阵地的全国分布态势,用户年龄构成以20-35岁为主,“亿万年轻人的生活方式”的定位初步得到体现。`, language: 'zh-cn', item: items, - }; + }); }; diff --git a/lib/v2/thehindu/topic.js b/lib/v2/thehindu/topic.js index 07de003ba..3ef97f104 100644 --- a/lib/v2/thehindu/topic.js +++ b/lib/v2/thehindu/topic.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 baseUrl = 'https://www.thehindu.com'; @@ -11,9 +11,9 @@ module.exports = async (ctx) => { const { data: response } = await got(link); const { data: apiResponse } = await got(apiLink); - const $ = cheerio.load(response); + const $ = load(response); - const $api = cheerio.load(apiResponse); + const $api = load(apiResponse); const list = $('.element') .toArray() .map((item) => { @@ -30,7 +30,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); $('.position-relative, .articleblock-container, .article-ad, .comments-shares').remove(); item.description = $('.sub-title').prop('outerHTML') + $('div.article-picture').html() + $('div[itemprop="articleBody"]').html(); @@ -45,7 +45,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim(), link: `${baseUrl}/topic/${topic}/`, image: $('meta[property="og:image"]').attr('content'), @@ -53,5 +53,5 @@ module.exports = async (ctx) => { icon: $('link[rel="icon"]').attr('href'), language: 'en', item: items, - }; + }); }; diff --git a/lib/v2/theinitium/full.js b/lib/v2/theinitium/full.js index 7885a32d7..c4dd500c1 100644 --- a/lib/v2/theinitium/full.js +++ b/lib/v2/theinitium/full.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const TOKEN = 'Basic YW5vbnltb3VzOkdpQ2VMRWp4bnFCY1ZwbnA2Y0xzVXZKaWV2dlJRY0FYTHY='; module.exports = async (ctx) => { // model是channel/tag/etc.,而type是latest/feature/quest-academy这些一级栏目/标签/作者名的slug名。如果是追踪的话,那就是model是follow,type是articles。 - const model = ctx.params.model ?? 'channel'; - const type = ctx.params.type ?? 'latest'; - const language = ctx.params.language ?? 'zh-hans'; + const model = ctx.req.param('model') ?? 'channel'; + const type = ctx.req.param('type') ?? 'latest'; + const language = ctx.req.param('language') ?? 'zh-hans'; let listUrl; let listLink; switch (model) { @@ -115,7 +115,7 @@ module.exports = async (ctx) => { // 有时候文章并非普通html文章,而是带有互动内容等,表现为type为web,并且content里没有内容。我们也尽力抓点东西下来。 // 或许可能还有其他未知情况,等碰到了再说吧。先这样留空也不碍事。 const nonhtmlcontent = await got(data.web.url); - const webcontent = cheerio.load(nonhtmlcontent.body).html(); + const webcontent = load(nonhtmlcontent.body).html(); content += webcontent; } if (data.paywall_enabled) { @@ -128,7 +128,7 @@ module.exports = async (ctx) => { 'accept-language': accept_language, }, }); - const $ = cheerio.load(pay_part.body); + const $ = load(pay_part.body); const pay_content = $('div.paywall').html(); if (pay_content) { content += pay_content.replace('', ''); @@ -159,11 +159,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `端传媒 - ${name}`, link: listLink, icon: 'https://theinitium.com/misc/about/logo192.png', item: items, image, - }; + }); }; diff --git a/lib/v2/themoviedb/collection.js b/lib/v2/themoviedb/collection.js index 20ea2e61b..2178358d1 100644 --- a/lib/v2/themoviedb/collection.js +++ b/lib/v2/themoviedb/collection.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const apiKey = require('./api-key'); const { handleMovieItem } = require('./utils'); @@ -11,11 +11,11 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `${data.name} — TMDB`, description: data.overview.trim(), image: `https://image.tmdb.org/t/p/original${data.poster_path}`, link: `https://www.themoviedb.org/collection/${data.id}`, item: data.parts.map((item) => handleMovieItem(item, lang)), - }; + }); }; diff --git a/lib/v2/themoviedb/episodes.js b/lib/v2/themoviedb/episodes.js index 6a6eef26e..2d95d965b 100644 --- a/lib/v2/themoviedb/episodes.js +++ b/lib/v2/themoviedb/episodes.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 apiKey = require('./api-key'); const { handleDescription } = require('./utils'); @@ -12,7 +12,7 @@ module.exports = async (ctx) => { const { data: tvShowDetails } = await got(`https://api.themoviedb.org/3/tv/${id}`, { searchParams }); const { data: seasonDetails } = await got(`https://api.themoviedb.org/3/tv/${id}/season/${seasonNumber}`, { searchParams }); - ctx.state.data = { + ctx.set('data', { title: `${tvShowDetails.name} ${seasonDetails.name} — TMDB`, description: seasonDetails.overview.trim(), image: `https://image.tmdb.org/t/p/original${seasonDetails.poster_path}`, @@ -23,5 +23,5 @@ module.exports = async (ctx) => { description: handleDescription(item), pubDate: item.air_date ? parseDate(item.air_date) : undefined, })), - }; + }); }; diff --git a/lib/v2/themoviedb/seasons.js b/lib/v2/themoviedb/seasons.js index 68bbe05a0..93d288575 100644 --- a/lib/v2/themoviedb/seasons.js +++ b/lib/v2/themoviedb/seasons.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 apiKey = require('./api-key'); const { handleDescription } = require('./utils'); @@ -12,7 +12,7 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `${data.name} - Seasons — TMDB`, description: data.overview.trim(), image: `https://image.tmdb.org/t/p/original${data.poster_path}`, @@ -27,5 +27,5 @@ module.exports = async (ctx) => { pubDate: item.air_date ? parseDate(item.air_date) : undefined, }; }), - }; + }); }; diff --git a/lib/v2/themoviedb/sheet.js b/lib/v2/themoviedb/sheet.js index 66a93cda3..a15bbdc33 100644 --- a/lib/v2/themoviedb/sheet.js +++ b/lib/v2/themoviedb/sheet.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const apiKey = require('./api-key'); const { MEDIA_TYPE_TO_ITEM_HANDLE } = require('./utils'); @@ -37,9 +37,9 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `${TITLE[mediaType][sheet]} — TMDB`, link: `https://www.themoviedb.org/${mediaType}/${sheet}`, item: data.results.map((item) => MEDIA_TYPE_TO_ITEM_HANDLE[mediaType](item, lang)), - }; + }); }; diff --git a/lib/v2/themoviedb/trending.js b/lib/v2/themoviedb/trending.js index c5bed3780..4445aa010 100644 --- a/lib/v2/themoviedb/trending.js +++ b/lib/v2/themoviedb/trending.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const apiKey = require('./api-key'); const { MEDIA_TYPE_TO_ITEM_HANDLE } = require('./utils'); @@ -16,9 +16,9 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `Popular ${MEDIA_TYPE_TO_TITLE[mediaType]} — TMDB`, link: `https://www.themoviedb.org/${mediaType}`, item: data.results.map((item) => MEDIA_TYPE_TO_ITEM_HANDLE[mediaType](item, lang)), - }; + }); }; diff --git a/lib/v2/themoviedb/utils.js b/lib/v2/themoviedb/utils.js index bd93a0375..1604bcac2 100644 --- a/lib/v2/themoviedb/utils.js +++ b/lib/v2/themoviedb/utils.js @@ -1,6 +1,6 @@ const path = require('path'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; const handleDescription = (item) => { const poster_path = item.poster_path ?? item.still_path; diff --git a/lib/v2/thenewslens/index.js b/lib/v2/thenewslens/index.js index b58a991e4..dcb340d6e 100644 --- a/lib/v2/thenewslens/index.js +++ b/lib/v2/thenewslens/index.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) => { @@ -13,14 +13,14 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('h1.title').remove(); let items = $('.regular-article-list, #list-container, .list-container') .find('.article-title, .title') .find('a') - .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); @@ -41,7 +41,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#salon_comment_widget-anchor').remove(); content('ad2-recommender, footer, noscript').remove(); @@ -71,9 +71,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/thepaper/839studio/category.js b/lib/v2/thepaper/839studio/category.js index bc46ca169..19a1132c4 100644 --- a/lib/v2/thepaper/839studio/category.js +++ b/lib/v2/thepaper/839studio/category.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 id = ctx.params.id; + const id = ctx.req.param('id'); const link = `http://projects.thepaper.cn/thepaper-cases/839studio/?cat=${id}`; // 发起 HTTP GET 请求 @@ -14,13 +14,13 @@ module.exports = async (ctx) => { const data = response.data; // 使用 cheerio 加载返回的 HTML - const $ = cheerio.load(data); + const $ = load(data); const list = $('div[class=imgtext]'); const category = $('div[class=lefth]').find('h1').text(); const desc = $('div[class=leftc]').find('p').text(); - ctx.state.data = { + ctx.set('data', { title: `澎湃美数课作品集-${category}`, link, description: desc, @@ -36,5 +36,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/thepaper/839studio/studio.js b/lib/v2/thepaper/839studio/studio.js index 68235d327..0fbffeb70 100644 --- a/lib/v2/thepaper/839studio/studio.js +++ b/lib/v2/thepaper/839studio/studio.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) => { // 发起 HTTP GET 请求 @@ -11,10 +11,10 @@ module.exports = async (ctx) => { const data = response.data; // 使用 cheerio 加载返回的 HTML - const $ = cheerio.load(data); + const $ = load(data); const list = $('div[class=imgtext]'); - ctx.state.data = { + ctx.set('data', { title: '澎湃美数课作品集', link: 'http://projects.thepaper.cn/thepaper-cases/839studio/', item: @@ -29,5 +29,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/thepaper/channel.js b/lib/v2/thepaper/channel.js index 0772113bd..ddda0845f 100644 --- a/lib/v2/thepaper/channel.js +++ b/lib/v2/thepaper/channel.js @@ -1,12 +1,12 @@ const utils = require('./utils'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; module.exports = async (ctx) => { const { id } = ctx.params; const channel_url = `https://m.thepaper.cn/channel/${id}`; const channel_url_resp = await got(channel_url); - const channel_url_data = JSON.parse(cheerio.load(channel_url_resp.data)('#__NEXT_DATA__').html()); + const channel_url_data = JSON.parse(load(channel_url_resp.data)('#__NEXT_DATA__').html()); const resp = await got.post('https://api.thepaper.cn/contentapi/nodeCont/getByChannelId', { json: { @@ -16,11 +16,11 @@ module.exports = async (ctx) => { const list = resp.data.data.list; const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: `澎湃新闻频道 - ${utils.ChannelIdToName(id, channel_url_data)}`, link: channel_url, item: items, itunes_author: '澎湃新闻', image: utils.ExtractLogo(channel_url_resp), - }; + }); }; diff --git a/lib/v2/thepaper/factpaper.js b/lib/v2/thepaper/factpaper.js index 2a9a743d8..f35fface5 100644 --- a/lib/v2/thepaper/factpaper.js +++ b/lib/v2/thepaper/factpaper.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +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 status = Number.parseInt(ctx.params.status ?? '1'); + const status = Number.parseInt(ctx.req.param('status') ?? '1'); const rootUrl = 'https://www.factpaper.cn'; const apiRootUrl = 'https://api.factpaper.cn'; @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `澎湃明查 - ${status === 1 ? '有定论' : '核查中'}`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/thepaper/featured.js b/lib/v2/thepaper/featured.js index d7ec3d45f..861ccd998 100644 --- a/lib/v2/thepaper/featured.js +++ b/lib/v2/thepaper/featured.js @@ -1,18 +1,18 @@ const utils = require('./utils'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; module.exports = async (ctx) => { const response = await got('https://m.thepaper.cn'); - const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html()); + const data = JSON.parse(load(response.data)('#__NEXT_DATA__').html()); const list = [...data.props.pageProps.data.list, ...data.props.pageProps.topData.recommendImg]; const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: '澎湃新闻 - 首页头条', link: 'https://m.thepaper.cn', item: items, itunes_author: '澎湃新闻', image: utils.ExtractLogo(response), - }; + }); }; diff --git a/lib/v2/thepaper/list.js b/lib/v2/thepaper/list.js index 2198531dd..10374e0fd 100644 --- a/lib/v2/thepaper/list.js +++ b/lib/v2/thepaper/list.js @@ -1,12 +1,12 @@ const utils = require('./utils'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; module.exports = async (ctx) => { const { id } = ctx.params; const list_url = `https://m.thepaper.cn/list/${id}`; const list_url_resp = await got(list_url); - const list_url_data = JSON.parse(cheerio.load(list_url_resp.data)('#__NEXT_DATA__').html()); + const list_url_data = JSON.parse(load(list_url_resp.data)('#__NEXT_DATA__').html()); const resp = await got.post('https://api.thepaper.cn/contentapi/nodeCont/getByNodeIdPortal', { json: { @@ -17,11 +17,11 @@ module.exports = async (ctx) => { const list = pagePropsData.list; const items = await Promise.all(list.map((item) => utils.ProcessItem(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: `澎湃新闻栏目 - ${utils.ListIdToName(id, list_url_data)}`, link: list_url, item: items, itunes_author: '澎湃新闻', image: pagePropsData.nodeInfo?.pic ?? utils.ExtractLogo(list_url_resp), - }; + }); }; diff --git a/lib/v2/thepaper/sidebar.js b/lib/v2/thepaper/sidebar.js index 5c023d10b..8cbea421e 100644 --- a/lib/v2/thepaper/sidebar.js +++ b/lib/v2/thepaper/sidebar.js @@ -1,5 +1,5 @@ const utils = require('./utils'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const sections = { hotNews: '澎湃热榜', @@ -16,9 +16,9 @@ module.exports = async (ctx) => { const list = sidebar_url_data.data[sec]; const items = await Promise.all(list.filter((item) => item.contId).map((item) => utils.ProcessItem(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: `澎湃新闻 - ${sections[sec]}`, item: items, link: 'https://www.thepaper.cn', - }; + }); }; diff --git a/lib/v2/thepaper/utils.js b/lib/v2/thepaper/utils.js index aa9d48c76..91fa97374 100644 --- a/lib/v2/thepaper/utils.js +++ b/lib/v2/thepaper/utils.js @@ -1,7 +1,7 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); const defaultRssItem = (item) => ({ @@ -18,7 +18,7 @@ const defaultRssItem = (item) => ({ module.exports = { ProcessItem: (item, ctx) => { - const useOldMode = ctx.query.old === 'yes'; + const useOldMode = ctx.req.query('old') === 'yes'; if (item.link) { // external link return defaultRssItem(item); @@ -26,7 +26,7 @@ module.exports = { const itemUrl = `https://m.thepaper.cn/detail/${item.contId}`; return ctx.cache.tryGet(`${itemUrl}${useOldMode ? ':old' : ''}`, async () => { const res = await got(itemUrl); - const data = JSON.parse(cheerio.load(res.data)('#__NEXT_DATA__').html()); + const data = JSON.parse(load(res.data)('#__NEXT_DATA__').html()); const detailData = data.props.pageProps.detailData; const contentDetail = detailData.contentDetail || detailData.liveDetail || detailData.specialDetail?.specialInfo; if (!contentDetail) { @@ -80,5 +80,5 @@ module.exports = { }, ChannelIdToName: (nodeId, next_data) => next_data.props.appProps.menu.channelList.find((c) => c.nodeId.toString() === nodeId.toString()).name, ListIdToName: (listId, next_data) => next_data.props.appProps.menu.channelList.flatMap((c) => c.childNodeList || []).find((l) => l.nodeId.toString() === listId.toString())?.name, - ExtractLogo: (response) => 'https://m.thepaper.cn' + cheerio.load(response.data)('img.imageCover').attr('src'), + ExtractLogo: (response) => 'https://m.thepaper.cn' + load(response.data)('img.imageCover').attr('src'), }; diff --git a/lib/v2/theverge/index.js b/lib/v2/theverge/index.js index 2bb7659db..1b1bee3f8 100644 --- a/lib/v2/theverge/index.js +++ b/lib/v2/theverge/index.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const parser = require('@/utils/rss-parser'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; module.exports = async (ctx) => { - const link = ctx.params.hub ? `https://www.theverge.com/${ctx.params.hub}/rss/index.xml` : 'https://www.theverge.com/rss/index.xml'; + const link = ctx.req.param('hub') ? `https://www.theverge.com/${ctx.req.param('hub')}/rss/index.xml` : 'https://www.theverge.com/rss/index.xml'; const feed = await parser.parseURL(link); @@ -12,7 +12,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const content = $('#content'); const body = $('.duet--article--article-body-component-container'); @@ -83,10 +83,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.description, item: items, - }; + }); }; diff --git a/lib/v2/thoughtco/index.js b/lib/v2/thoughtco/index.js index 80c4abc02..64596d8cb 100644 --- a/lib/v2/thoughtco/index.js +++ b/lib/v2/thoughtco/index.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 { category = '' } = 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.thoughtco.com'; const currentUrl = new URL(category, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a[data-doc-id]') .slice(0, limit) @@ -32,7 +32,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.adslot').remove(); content('div.sources-and-citation, .mntl-figure-caption svg').remove(); @@ -80,7 +80,7 @@ module.exports = async (ctx) => { const title = $('meta[property="og:title"]').prop('content'); const icon = new URL($('link[rel="apple-touch-icon-precomposed"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${title.startsWith(author) ? '' : ` - ${title}`}`, link: currentUrl, @@ -91,5 +91,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[property="og:title"]').prop('content'), author, - }; + }); }; diff --git a/lib/v2/threads/index.js b/lib/v2/threads/index.js index f60e9f917..73e85b11f 100644 --- a/lib/v2/threads/index.js +++ b/lib/v2/threads/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'; const { PROFILE_QUERY, REPLIES_QUERY, THREADS_QUERY, apiUrl, threadUrl, profileUrl, extractTokens, makeHeader, buildContent } = require('./utils'); module.exports = async (ctx) => { @@ -63,11 +63,11 @@ module.exports = async (ctx) => { ctx.state.json.items = items; - ctx.state.data = { + ctx.set('data', { title: `${user} (@${user}) on Threads`, link: profileUrl(user), image: userData.hd_profile_pic_versions?.sort((a, b) => b.width - a.width)[0].url ?? userData.profile_pic_url, description: userData.biography, item: items, - }; + }); }; diff --git a/lib/v2/threads/utils.js b/lib/v2/threads/utils.js index 50ba8321c..bee5d4529 100644 --- a/lib/v2/threads/utils.js +++ b/lib/v2/threads/utils.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); const profileUrl = (user) => `https://www.threads.net/@${user}`; @@ -19,7 +19,7 @@ const extractTokens = async (user, ctx) => { 'X-IG-App-ID': appId, }, }); - const $ = cheerio.load(response); + const $ = load(response); const data = $('script:contains("LSD"):first').text(); diff --git a/lib/v2/thwiki/index.js b/lib/v2/thwiki/index.js index 3130178f6..653fc51cf 100644 --- a/lib/v2/thwiki/index.js +++ b/lib/v2/thwiki/index.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const dayjs = require('dayjs'); module.exports = async (ctx) => { - const beforeDays = ctx.params.before ? Number.parseInt(ctx.params.before) : 30; - const afterDays = ctx.params.after ? Number.parseInt(ctx.params.after) : 30; + const beforeDays = ctx.req.param('before') ? Number.parseInt(ctx.req.param('before')) : 30; + const afterDays = ctx.req.param('after') ? Number.parseInt(ctx.req.param('after')) : 30; const before = dayjs().subtract(beforeDays, 'day').format('YYYY-MM-DD'); const after = dayjs().add(afterDays, 'day').format('YYYY-MM-DD'); @@ -16,7 +16,7 @@ module.exports = async (ctx) => { }); const data = response.data.results; - ctx.state.data = { + ctx.set('data', { title: 'Touhou events calendar (THBWiki)', link: `https://calendar.thwiki.cc/`, description: 'A Touhou related events calendar api from THBWiki', @@ -28,5 +28,5 @@ module.exports = async (ctx) => { guid: item.id, link: item.url, })), - }; + }); }; diff --git a/lib/v2/tiktok/user.js b/lib/v2/tiktok/user.js index 151a98a2f..4f86674ea 100644 --- a/lib/v2/tiktok/user.js +++ b/lib/v2/tiktok/user.js @@ -1,8 +1,9 @@ -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { queryToBoolean } = require('@/utils/readable-social'); +import puppeteer from '@/utils/puppeteer'; const baseUrl = 'https://www.tiktok.com'; @@ -13,7 +14,7 @@ module.exports = async (ctx) => { const data = await ctx.cache.tryGet( `tiktok:user:${user}`, async () => { - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -49,12 +50,12 @@ module.exports = async (ctx) => { category: item.textExtra.map((t) => `#${t.hashtagName}`), })); - ctx.state.data = { + ctx.set('data', { title: data.SharingMetaState.value['og:title'], description: data.SharingMetaState.value['og:description'], image: data.SharingMetaState.value['og:image'], link: `${baseUrl}/${user}`, item: items, language: data.lang, - }; + }); }; diff --git a/lib/v2/timednews/news.js b/lib/v2/timednews/news.js index f751ebb25..509055f5a 100644 --- a/lib/v2/timednews/news.js +++ b/lib/v2/timednews/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 BASE = 'https://www.timednews.com/topic'; @@ -52,18 +52,18 @@ const PATH_LIST = { }; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'all'; + const type = ctx.req.param('type') ?? 'all'; const url = `${BASE}/${PATH_LIST[type].path}`; const res = await got({ method: 'get', url, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('#content li') .map((i, e) => { - const c = cheerio.load(e); + const c = load(e); return { title: c('a').text().trim(), link: c('a').attr('href'), @@ -79,7 +79,7 @@ module.exports = async (ctx) => { url: item.link, }); - const c = cheerio.load(detailResponse.data, { decodeEntities: false }); + const c = load(detailResponse.data, { decodeEntities: false }); c('.event .twitter').remove(); item.pubDate = parseDate(c('.datetime #publishdate').text(), 'YYYY-MM-DD'); item.author = c('.datetime #author').text(); @@ -90,17 +90,17 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '时刻新闻', link: url, description: `时刻新闻 ${PATH_LIST[type].name}`, item: items, - }; + }); - ctx.state.json = { + ctx.set('json', { title: '时刻新闻', link: url, description: `时刻新闻 ${PATH_LIST[type].name}`, item: items, - }; + }); }; diff --git a/lib/v2/tingshuitz/changsha.js b/lib/v2/tingshuitz/changsha.js index fc4d7a856..087c0f052 100644 --- a/lib/v2/tingshuitz/changsha.js +++ b/lib/v2/tingshuitz/changsha.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'; const baseUrl = 'http://www.supplywater.com'; module.exports = async (ctx) => { const { channelId = 78 } = ctx.params; const listPage = await got('http://www.supplywater.com/tstz-' + channelId + '.aspx'); - const $ = cheerio.load(listPage.data); + const $ = load(listPage.data); const pageName = $('.mainRightBox .news-title').text(); const list = $('.mainRightBox .announcements-title a') .map((_, item) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.map(async (item) => { const postPage = await got(item.link); - const $ = cheerio.load(postPage.data); + const $ = load(postPage.data); const data = { title: item.title, @@ -35,9 +35,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${pageName}通知 - 长沙水业集团`, link: `${baseUrl}/fuwuzhinan.aspx`, item: items, - }; + }); }; diff --git a/lib/v2/tingshuitz/dalian.js b/lib/v2/tingshuitz/dalian.js index f976ad07b..5c1938d44 100644 --- a/lib/v2/tingshuitz/dalian.js +++ b/lib/v2/tingshuitz/dalian.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 url = 'https://swj.dl.gov.cn/module/web/jpage/dataproxy.jsp?page=1&webid=28&path=https://swj.dl.gov.cn/&columnid=4296&unitid=31227&webname=%25E5%25A4%25A7%25E8%25BF%259E%25E5%25B8%2582%25E6%25B0%25B4%25E5%258A%25A1%25E5%25B1%2580&permissiontype=0'; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('recordset record') .toArray() .map((item) => { @@ -20,10 +20,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: '停水通知 - 大连市水务局', link: 'https://swj.dl.gov.cn/col/col4296/index.html', description: '停水通知 - 大连市水务局', item: items, - }; + }); }; diff --git a/lib/v2/tingshuitz/dongguan.js b/lib/v2/tingshuitz/dongguan.js index e77c6e96d..ac9f2ab04 100644 --- a/lib/v2/tingshuitz/dongguan.js +++ b/lib/v2/tingshuitz/dongguan.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 url = 'http://www.djsw.com.cn/news/tstz/index.html'; @@ -10,10 +10,10 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#cntR li'); - ctx.state.data = { + ctx.set('data', { title: $('title').text() || '停水通知 - 东莞市东江水务有限公司', link: 'http://www.djsw.com.cn/news/tstz/index.html', description: $('title').text() || '停水通知 - 东莞市东江水务有限公司', @@ -30,5 +30,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingshuitz/guangzhou.js b/lib/v2/tingshuitz/guangzhou.js index 95c8dc2d6..8f2ec3a74 100644 --- a/lib/v2/tingshuitz/guangzhou.js +++ b/lib/v2/tingshuitz/guangzhou.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const response = await got({ @@ -15,9 +15,9 @@ module.exports = async (ctx) => { description: `${title}
${digest}...`, })); - ctx.state.data = { + ctx.set('data', { title: '停水通知 - 广州市自来水96968', link: 'https://mp.weixin.qq.com/mp/homepage?__biz=MzA3MDE0NzAxMw%3D%3D&hid=15&sn=270abafdcf67ce4e2b52a049a0aa219a&scene=1&sharer_username=&clicktime=&devicetype=iOS12.2&version=1700042b&lang=zh_CN&nettype=WIFI&ascene=0&fontScale=100&wx_header=1', item: items, - }; + }); }; diff --git a/lib/v2/tingshuitz/hangzhou.js b/lib/v2/tingshuitz/hangzhou.js index 67e8e149d..16a1290ce 100644 --- a/lib/v2/tingshuitz/hangzhou.js +++ b/lib/v2/tingshuitz/hangzhou.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 area = ctx.params.area; + // const area = ctx.req.param('area'); const url = 'http://www.hzwgc.com/public/stop_the_water/'; const response = await got({ method: 'get', @@ -10,10 +10,10 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.datalist li'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: 'http://www.hzwgc.com/public/stop_the_water/', description: $('meta[name="description"]').attr('content') || $('title').text(), @@ -30,5 +30,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingshuitz/nanjing.js b/lib/v2/tingshuitz/nanjing.js index fbb1fb252..bf3cb14fd 100644 --- a/lib/v2/tingshuitz/nanjing.js +++ b/lib/v2/tingshuitz/nanjing.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 HOME_PAGE = 'http://www.jlwater.com/'; module.exports = async (ctx) => { @@ -8,10 +8,10 @@ module.exports = async (ctx) => { const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.list-content ul li'); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, item: list @@ -29,5 +29,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingshuitz/shenzhen.js b/lib/v2/tingshuitz/shenzhen.js index 86ab356cb..03561f688 100644 --- a/lib/v2/tingshuitz/shenzhen.js +++ b/lib/v2/tingshuitz/shenzhen.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: '停水通知 - 深圳水务', link: 'https://www.sz-water.com.cn/', item: data.map((item) => ({ @@ -25,5 +25,5 @@ module.exports = async (ctx) => { link: 'https://szgk.sz-water.com.cn/wechat_web/Water_stop.html', guid: `${item.position}${item.stopStartTime}`, })), - }; + }); }; diff --git a/lib/v2/tingshuitz/wuhan.js b/lib/v2/tingshuitz/wuhan.js index e12809cf5..9c0f72170 100644 --- a/lib/v2/tingshuitz/wuhan.js +++ b/lib/v2/tingshuitz/wuhan.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 baseUrl = 'https://www.whwater.com'; module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { topStatus: 0, recommendStatus: 0, page: 1, - size: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30, + size: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30, }, }); @@ -24,9 +24,9 @@ module.exports = async (ctx) => { link: `https://${baseUrl}/IPolicyDetails.shtml?id=31&sid=${channelId}${item.articleLink}`, })); - ctx.state.data = { + ctx.set('data', { title: `${data.channelName}通知 - 武汉市水务集团有限公司`, link: `${baseUrl}/IWater.shtml?id=31&sid=48`, item: items, - }; + }); }; diff --git a/lib/v2/tingshuitz/xian.js b/lib/v2/tingshuitz/xian.js index 47bdc3c9b..0d2dc4e45 100644 --- a/lib/v2/tingshuitz/xian.js +++ b/lib/v2/tingshuitz/xian.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); module.exports = async (ctx) => { @@ -9,10 +9,10 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(iconv.decode(data, 'gb2312')); + const $ = load(iconv.decode(data, 'gb2312')); const list = $('#body > div.M > div.AboutUsDetail > ul > li'); - ctx.state.data = { + ctx.set('data', { title: $('title').text() || '停水通知 - 西安市自来水有限公司', link: 'http://www.xazls.com/tsgg/index.htm', item: list @@ -27,5 +27,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingshuitz/xiaoshan.js b/lib/v2/tingshuitz/xiaoshan.js index c98c9f2ce..251d23ba3 100644 --- a/lib/v2/tingshuitz/xiaoshan.js +++ b/lib/v2/tingshuitz/xiaoshan.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 area = ctx.params.area; + // const area = ctx.req.param('area'); const url = 'https://www.xswater.com/gongshui/channels/227.html'; const response = await got({ method: 'get', @@ -10,10 +10,10 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.ul-list li'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: 'https://www.xswater.com/gongshui/channels/227.html', description: $('meta[name="description"]').attr('content') || $('title').text(), @@ -30,5 +30,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingshuitz/yangjiang.js b/lib/v2/tingshuitz/yangjiang.js index 5f406e602..ecf6b1059 100644 --- a/lib/v2/tingshuitz/yangjiang.js +++ b/lib/v2/tingshuitz/yangjiang.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 url = 'https://www.yjsswjt.com/zxdt_list.jsp?flbz=7'; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.list_ul_div > ul > li'); - ctx.state.data = { + ctx.set('data', { title: '停水通知 - 阳江市水务集团有限公司', link: 'https://www.yjsswjt.com/zxdt_list.jsp?flbz=7', item: list @@ -25,5 +25,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tingtingfm/program.js b/lib/v2/tingtingfm/program.js index 5f8e83e44..c1b2a1025 100644 --- a/lib/v2/tingtingfm/program.js +++ b/lib/v2/tingtingfm/program.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const { getClientVal, sign } = require('./utils'); module.exports = async (ctx) => { @@ -91,7 +91,7 @@ module.exports = async (ctx) => { enclosure_type: 'audio/x-m4a', })); - ctx.state.data = { + ctx.set('data', { title: `${radioInfo.title} - ${radioInfo.belong_radio}${radioInfo.belong_fm}`, description: radioInfo.description, link: `${mobileBaseUrl}/v3/program/${programId}`, @@ -100,5 +100,5 @@ module.exports = async (ctx) => { itunes_category: radioInfo.category, itunes_explicit: false, item: items, - }; + }); }; diff --git a/lib/v2/tingtingfm/utils.js b/lib/v2/tingtingfm/utils.js index 1ae43d431..0ee38d8dd 100644 --- a/lib/v2/tingtingfm/utils.js +++ b/lib/v2/tingtingfm/utils.js @@ -1,4 +1,4 @@ -const md5 = require('@/utils/md5'); +import md5 from '@/utils/md5'; const SALT = '1Ftjv0bfpVmqbE38'; diff --git a/lib/v2/tisi/index.js b/lib/v2/tisi/index.js index f00833fa9..6f84dc951 100644 --- a/lib/v2/tisi/index.js +++ b/lib/v2/tisi/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 rootUrl = 'https://www.tisi.org'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${rootUrl}/?page_id=11151`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.new-artice-list-box') .map((_, item) => ({ title: $(item).find('p.new-article-title > a').text(), @@ -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('div.article-content').html(); return item; @@ -30,9 +30,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '腾讯研究院 - 最近更新', link: url, item: items, - }; + }); }; diff --git a/lib/v2/tju/cic/index.js b/lib/v2/tju/cic/index.js index 1ec8b039a..027edf3c2 100644 --- a/lib/v2/tju/cic/index.js +++ b/lib/v2/tju/cic/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 cic_base_url = 'http://cic.tju.edu.cn/'; const repo_url = 'https://github.com/DIYgod/RSSHub/issues'; @@ -15,7 +15,7 @@ const pageType = (href) => { }; module.exports = async (ctx) => { - const type = ctx.params && ctx.params.type; + const type = ctx.params && ctx.req.param('type'); let path, subtitle; switch (type) { @@ -61,7 +61,7 @@ module.exports = async (ctx) => { ], }; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.wenzi_list_ul > li') .map((_index, item) => { const href = $('a', item).attr('href'); @@ -83,7 +83,7 @@ module.exports = async (ctx) => { let detailResponse = null; try { detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = timezone(parseDate(content('.news_info > span').first().text(), 'YYYY年MM月DD日 HH:mm'), +8); content('.news_tit').remove(); content('.news_info').remove(); diff --git a/lib/v2/tju/news/index.js b/lib/v2/tju/news/index.js index 387260eca..bccd9cd1b 100644 --- a/lib/v2/tju/news/index.js +++ b/lib/v2/tju/news/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 news_base_url = 'http://news.tju.edu.cn/'; const repo_url = 'https://github.com/DIYgod/RSSHub/issues'; @@ -17,7 +17,7 @@ const pageType = (href) => { }; module.exports = async (ctx) => { - const type = ctx.params && ctx.params.type; + const type = ctx.params && ctx.req.param('type'); let path, subtitle; switch (type) { @@ -71,7 +71,7 @@ module.exports = async (ctx) => { ], }; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); let list; list = type === 'picture' ? $('.picList > li').get() : $('.indexList > li').get(); @@ -96,7 +96,7 @@ module.exports = async (ctx) => { try { delete item.type; detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = timezone( parseDate( content('.contentTime') diff --git a/lib/v2/tju/oaa/index.js b/lib/v2/tju/oaa/index.js index b11af621d..723f51291 100644 --- a/lib/v2/tju/oaa/index.js +++ b/lib/v2/tju/oaa/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { finishArticleItem } = require('@/utils/wechat-mp'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const oaa_base_url = 'http://oaa.tju.edu.cn/'; const repo_url = 'https://github.com/DIYgod/RSSHub/issues'; @@ -22,7 +22,7 @@ const pageType = (href) => { }; module.exports = async (ctx) => { - const type = ctx.params && ctx.params.type; + const type = ctx.params && ctx.req.param('type'); let path, subtitle; switch (type) { @@ -64,7 +64,7 @@ module.exports = async (ctx) => { ], }; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.notice_l > ul > li > dl > dt') .map((_index, item) => { const href = $('a', item).attr('href'); @@ -89,7 +89,7 @@ module.exports = async (ctx) => { let detailResponse = null; try { detailResponse = await got(item.link, { https: { rejectUnauthorized: false } }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.v_news_content').html(); } catch { // ignore error handler diff --git a/lib/v2/tju/yzb/index.js b/lib/v2/tju/yzb/index.js index 287e5dcd3..466423bd9 100644 --- a/lib/v2/tju/yzb/index.js +++ b/lib/v2/tju/yzb/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const yzb_base_url = 'http://yzb.tju.edu.cn/'; const repo_url = 'https://github.com/DIYgod/RSSHub/issues'; @@ -18,7 +18,7 @@ const pageType = (href) => { }; module.exports = async (ctx) => { - const type = ctx.params && ctx.params.type; + const type = ctx.params && ctx.req.param('type'); let path, subtitle; switch (type) { @@ -69,7 +69,7 @@ module.exports = async (ctx) => { ], }; } else { - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); const list = $('body > table:nth-child(3) > tbody > tr > td.table_left_right > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(1) > td > table > tbody > tr') .slice(1, -1) .map((_index, item) => { @@ -93,7 +93,7 @@ module.exports = async (ctx) => { let detailResponse = null; try { detailResponse = await got(item.link, { responseType: 'buffer' }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + const content = load(iconv.decode(detailResponse.data, 'gbk')); content('.font_18_b').remove(); content('.font_grey_en').remove(); item.description = content('.nav_a10 > table > tbody').html(); diff --git a/lib/v2/tokeninsight/blog.js b/lib/v2/tokeninsight/blog.js index 6880ecce4..11509fded 100644 --- a/lib/v2/tokeninsight/blog.js +++ b/lib/v2/tokeninsight/blog.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'; const baseURL = 'https://www.tokeninsight.com/'; const title = 'TokenInsight'; const link = 'https://www.tokeninsight.com/'; module.exports = async (ctx) => { - const lang = ctx.params.lang ?? 'zh'; + const lang = ctx.req.param('lang') ?? 'zh'; const getBlogs = async () => { const url = `${baseURL}api/user/search/getAllList`; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { const blogUrl = `${baseURL}${lang}/blogs/${id}`; const description = await ctx.cache.tryGet(blogUrl, async () => { const res = await got(blogUrl); - const $ = cheerio.load(res.data); + const $ = load(res.data); const description = $('.detail_html_box').html(); return description; }); @@ -41,12 +41,12 @@ module.exports = async (ctx) => { link: blogUrl, }; }; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30; const blogs = (await getBlogs()).slice(0, limit); const list = await Promise.all(blogs.map((element) => getBlogInfomation(element))); - ctx.state.data = { + ctx.set('data', { title: `${lang === 'zh' ? '博客' : 'Blogs'} | ${title}`, link: `${link}${lang}/blogs`, item: list, - }; + }); }; diff --git a/lib/v2/tokeninsight/bulletin.js b/lib/v2/tokeninsight/bulletin.js index d6f6fcc35..891bcd219 100644 --- a/lib/v2/tokeninsight/bulletin.js +++ b/lib/v2/tokeninsight/bulletin.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 baseURL = 'https://www.tokeninsight.com/'; const title = 'TokenInsight'; const link = 'https://www.tokeninsight.com/'; @@ -12,14 +12,14 @@ const get_articles = async () => { }; module.exports = async (ctx) => { - const lang = ctx.params.lang ?? 'zh'; + const lang = ctx.req.param('lang') ?? 'zh'; const get_article_info = async (article) => { const { updateDate, titleEn, id, title } = article; const articleUrl = `${baseURL}${lang}/latest/${id}`; const description = await ctx.cache.tryGet(articleUrl, async () => { const res = await got(articleUrl); - const $ = cheerio.load(res.data); + const $ = load(res.data); return $('.detail_html_box').html(); }); return { @@ -36,9 +36,9 @@ module.exports = async (ctx) => { const articles = await get_articles(); const list = await Promise.all(articles.map((element) => get_article_info(element))); - ctx.state.data = { + ctx.set('data', { title: `${lang === 'zh' ? '快讯' : 'Latest'} | ${title}`, link: `${link}${lang}/latest`, item: list, - }; + }); }; diff --git a/lib/v2/tokeninsight/report.js b/lib/v2/tokeninsight/report.js index c44e1ed06..19b962d88 100644 --- a/lib/v2/tokeninsight/report.js +++ b/lib/v2/tokeninsight/report.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'; const baseURL = 'https://www.tokeninsight.com/'; const title = 'TokenInsight'; const link = 'https://www.tokeninsight.com/'; module.exports = async (ctx) => { - const lang = ctx.params.lang ?? 'zh'; + const lang = ctx.req.param('lang') ?? 'zh'; const getReports = async () => { const url = `${baseURL}api/user/search/getAllList`; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { const reportUrl = `${baseURL}${lang}/report/${id}`; const description = await ctx.cache.tryGet(reportUrl, async () => { const res = await got(reportUrl); - const $ = cheerio.load(res.data); + const $ = load(res.data); const description = $('.detail_html_box').html(); return description; }); @@ -41,12 +41,12 @@ module.exports = async (ctx) => { link: reportUrl, }; }; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30; const reports = (await getReports()).slice(0, limit); const list = await Promise.all(reports.map((element) => getReportInfomation(element))); - ctx.state.data = { + ctx.set('data', { title: `${lang === 'zh' ? '报告' : 'Research'} | ${title}`, link: `${link}${lang}/report`, item: list, - }; + }); }; diff --git a/lib/v2/tongji/sse/_article.js b/lib/v2/tongji/sse/_article.js index 7731ba514..722d95560 100644 --- a/lib/v2/tongji/sse/_article.js +++ b/lib/v2/tongji/sse/_article.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); // get web content -const cheerio = require('cheerio'); // html parser +import got from '@/utils/got'; // get web content +import { load } from 'cheerio'; // html parser module.exports = async function getArticle(item) { const response = await got({ @@ -8,7 +8,7 @@ module.exports = async function getArticle(item) { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const title = $('div.view-title').text(); const content = $('#vsb_content').html(); $('[name="_newscontent_fromname"] ul a').each((_, e) => { diff --git a/lib/v2/tongji/sse/notice.js b/lib/v2/tongji/sse/notice.js index 850c69969..8a279d1d5 100644 --- a/lib/v2/tongji/sse/notice.js +++ b/lib/v2/tongji/sse/notice.js @@ -3,14 +3,14 @@ // params: // type: notification type -const got = require('@/utils/got'); // get web content -const cheerio = require('cheerio'); // html parser +import got from '@/utils/got'; // get web content +import { load } from 'cheerio'; // html parser const getArticle = require('./_article'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://sse.tongji.edu.cn'; - const type = ctx.params.type || 'xytz'; + const type = ctx.req.param('type') || 'xytz'; const subType = ['bkstz', 'yjstz', 'jgtz', 'qttz']; const listUrl = `${baseUrl}/xxzx/${subType.includes(type) ? `xytz/${type}` : type}.htm`; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { url: listUrl, }); const data = response.data; // content is html format - const $ = cheerio.load(data); + const $ = load(data); // get urls const detailUrls = $('.data-list li') @@ -38,9 +38,9 @@ module.exports = async (ctx) => { const articleList = await Promise.all(detailUrls.map((item) => ctx.cache.tryGet(item.link, () => getArticle(item)))); // feed the data - ctx.state.data = { + ctx.set('data', { title: '同济大学软件学院', link: listUrl, item: articleList, - }; + }); }; diff --git a/lib/v2/tongji/yjs.js b/lib/v2/tongji/yjs.js index 40fc54f77..c7eca7b77 100644 --- a/lib/v2/tongji/yjs.js +++ b/lib/v2/tongji/yjs.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 link = 'https://yz.tongji.edu.cn/zsxw/ggtz.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list_main_content li'); - ctx.state.data = { + ctx.set('data', { title: '同济大学研究生院', link, description: '同济大学研究生院通知公告', @@ -23,5 +23,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('span').text(), 'YYYY-MM-DD'), }; }), - }; + }); }; diff --git a/lib/v2/toodaylab/index.js b/lib/v2/toodaylab/index.js index 9a383afcb..3e288abc6 100644 --- a/lib/v2/toodaylab/index.js +++ b/lib/v2/toodaylab/index.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 { params = 'posts' } = 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 isHot = params === 'hot'; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = isHot ? $('div.hot-list a') @@ -57,7 +57,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 pubDate = content('div.left-infos p') .text() @@ -84,7 +84,7 @@ module.exports = async (ctx) => { const title = $('title').text().split(/\s-/)[0]; const icon = $('link[rel="apple-touch-icon"]').last().prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: isHot ? title.replace(/[^|]+/, '最热 ') : title, link: currentUrl, @@ -95,5 +95,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="keywords"]').prop('content'), author: $('h3.logo a img').prop('alt'), - }; + }); }; diff --git a/lib/v2/tophub/index.js b/lib/v2/tophub/index.js index c00a3e7fc..b2f8c5a78 100644 --- a/lib/v2/tophub/index.js +++ b/lib/v2/tophub/index.js @@ -1,9 +1,9 @@ -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) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://tophub.today/n/${id}`; const response = await got.get(link, { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { Cookie: config.tophub.cookie, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.Xc-ec-L.b-L').text().trim(); @@ -26,9 +26,9 @@ module.exports = async (ctx) => { return info; }); - ctx.state.data = { + ctx.set('data', { title, link, item: out, - }; + }); }; diff --git a/lib/v2/tophub/list.js b/lib/v2/tophub/list.js index 7c56b40f2..39096af8f 100644 --- a/lib/v2/tophub/list.js +++ b/lib/v2/tophub/list.js @@ -1,11 +1,11 @@ -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'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://tophub.today/n/${id}`; const response = await got.get(link, { headers: { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { Cookie: config.tophub.cookie, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.Xc-ec-L.b-L').text().trim(); const items = $('div.Zd-p-Sc > div:nth-child(1) tr') .toArray() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const combinedTitles = items.map((item) => item.title).join(''); const renderRank = art(path.join(__dirname, 'templates/rank.art'), { items }); - ctx.state.data = { + ctx.set('data', { title, link, item: [ @@ -36,5 +36,5 @@ module.exports = async (ctx) => { guid: combinedTitles, }, ], - }; + }); }; diff --git a/lib/v2/topys/index.js b/lib/v2/topys/index.js index 756f25c3d..5dee1f1ce 100644 --- a/lib/v2/topys/index.js +++ b/lib/v2/topys/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 keyword = ctx.params.keyword ?? ''; + const keyword = ctx.req.param('keyword') ?? ''; const rootUrl = 'https://www.topys.cn'; const currentUrl = `${rootUrl}${keyword ? `/search/${keyword}` : '/api/web/article/get_article_list'}`; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: currentUrl, json: { istop_time: 0, - size: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 16, + size: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 16, }, }); @@ -48,7 +48,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article-content').html(); item.author = item.author ?? content('.author-name p').first().text(); @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${keyword ? `${keyword} - ` : ''}TOPYS`, link: keyword ? currentUrl : `${rootUrl}/pick`, item: items, - }; + }); }; diff --git a/lib/v2/tradingview/blog.js b/lib/v2/tradingview/blog.js index 2947eabf7..cb91c0716 100644 --- a/lib/v2/tradingview/blog.js +++ b/lib/v2/tradingview/blog.js @@ -1,20 +1,20 @@ -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 asyncPool = require('tiny-async-pool'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { category = 'en' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 22; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 22; const rootUrl = 'https://www.tradingview.com'; const currentUrl = new URL(`blog/${category.endsWith('/') ? category : `${category}/`}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('article[id]') .slice(0, limit) @@ -49,7 +49,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.entry-content') .find('img') @@ -90,7 +90,7 @@ module.exports = async (ctx) => { const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -99,5 +99,5 @@ module.exports = async (ctx) => { icon, logo: icon, subtitle: $('h1.site-title').text(), - }; + }); }; diff --git a/lib/v2/tradingview/desktop.js b/lib/v2/tradingview/desktop.js index 5a5bac268..ca80361bd 100644 --- a/lib/v2/tradingview/desktop.js +++ b/lib/v2/tradingview/desktop.js @@ -1,17 +1,17 @@ -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 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.tradingview.com'; const currentUrl = new URL('/support/solutions/43000673888-tradingview-desktop-releases-and-release-notes/', rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); $('h4[data-identifyelement]').each((_, el) => { el = $(el); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { const title = item.text(); const description = $.html(item.nextUntil('h4')); - const content = cheerio.load(description); + const content = load(description); return { title, @@ -47,7 +47,7 @@ module.exports = async (ctx) => { const titleSplits = title.split(/—/); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -57,5 +57,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: titleSplits[0], author: titleSplits.pop(), - }; + }); }; diff --git a/lib/v2/tradingview/pine.js b/lib/v2/tradingview/pine.js index 76cd4c1d7..e80c34534 100644 --- a/lib/v2/tradingview/pine.js +++ b/lib/v2/tradingview/pine.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'; module.exports = async (ctx) => { const { version = 'v5' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 100; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 100; const rootUrl = 'https://www.tradingview.com'; const currentUrl = new URL(`pine-script-docs/en/${version}/Release_notes.html`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('div.section') .toArray() @@ -41,7 +41,7 @@ module.exports = async (ctx) => { const image = new URL('_images/Pine_Script_logo.svg', currentUrl).href; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -50,5 +50,5 @@ module.exports = async (ctx) => { image, icon, logo: icon, - }; + }); }; diff --git a/lib/v2/transcriptforest/index.js b/lib/v2/transcriptforest/index.js index a83ce775e..228fdd4f6 100644 --- a/lib/v2/transcriptforest/index.js +++ b/lib/v2/transcriptforest/index.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'); const bakeTimestamp = (seconds) => { @@ -18,7 +18,7 @@ const bakeTimestamp = (seconds) => { module.exports = async (ctx) => { const { channel } = 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://www.transcriptforest.com'; @@ -93,14 +93,14 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const title = $('title').text(); const image = $('meta[property="og:image"]').prop('content'); const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; const author = title.split(/\|/)[0].trim(); - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -112,5 +112,5 @@ module.exports = async (ctx) => { author, itunes_author: author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/trending/all-trending.js b/lib/v2/trending/all-trending.js index c9556af13..639e6abd8 100644 --- a/lib/v2/trending/all-trending.js +++ b/lib/v2/trending/all-trending.js @@ -1,11 +1,11 @@ const dayjs = require('dayjs'); dayjs.extend(require('dayjs/plugin/utc')); dayjs.extend(require('dayjs/plugin/timezone')); -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; -const md5 = require('@/utils/md5'); +import { config } from '@/config'; +import md5 from '@/utils/md5'; // Constants const CACHE_KEY = 'trending-all-in-one'; @@ -156,10 +156,10 @@ const createItem = ({ dateTime, data, count, newItemCount }, keywords, isToday) // Main module.exports = async (ctx) => { // Prevent making over 100 requests per invocation - if (ctx.params.numberOfDays > 14) { + if (ctx.req.param('numberOfDays') > 14) { throw new Error('days must be less than 14'); } - const numberOfDays = ctx.params.numberOfDays || 3; + const numberOfDays = ctx.req.param('numberOfDays') || 3; const currentShanghaiDateTime = dayjs(toShanghaiTimezone(new Date())); const currentShanghaiDateStr = currentShanghaiDateTime.format(DATE_FORMAT); const dateList = []; @@ -168,7 +168,8 @@ module.exports = async (ctx) => { dateList.push(d); } - const keywordList = ctx.params.keywords + const keywordList = ctx.req + .param('keywords') .replace(',', ',') .split(',') .map((keyword) => keyword.trim()); @@ -187,10 +188,10 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: `${keywordStr} | 热点聚合`, description: `${keywordStr} | 今日头条热搜,知乎热门视频,知乎热搜榜,知乎热门话题,微博热搜榜聚合追踪`, language: 'zh-cn', item, - }; + }); }; diff --git a/lib/v2/trendingpapers/papers.js b/lib/v2/trendingpapers/papers.js index c3942673e..44be20f28 100644 --- a/lib/v2/trendingpapers/papers.js +++ b/lib/v2/trendingpapers/papers.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 { time = 'Since beginning', cited = 'Cited and uncited papers', category = 'All categories' } = ctx.params; @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Trending Papers on arXiv.org | ${category} | ${time} | ${cited} | `, link: currentUrl, item: papers, - }; + }); }; diff --git a/lib/v2/tribalfootball/latest.js b/lib/v2/tribalfootball/latest.js index 9758d93c4..1e4bbdb35 100644 --- a/lib/v2/tribalfootball/latest.js +++ b/lib/v2/tribalfootball/latest.js @@ -1,14 +1,14 @@ -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 cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const rssUrl = 'https://www.tribalfootball.com/rss/mediafed/general/rss.xml'; module.exports = async (ctx) => { const rss = await got(rssUrl); - const $ = cheerio.load(rss.data, { xmlMode: true }); + const $ = load(rss.data, { xmlMode: true }); const items = $('rss > channel > item') .map((_, item) => { const $item = $(item); @@ -32,7 +32,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('head > title').text().replace(' - Tribal Football', ''); @@ -58,11 +58,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Tribal Football - Latest', description: 'Tribal Football - Football News, Soccer News, Transfers & Rumours', link: 'https://www.tribalfootball.com/articles', image: 'https://www.tribalfootball.com/images/tribal-logo-rss.png', item: items, - }; + }); }; diff --git a/lib/v2/trow/portal.js b/lib/v2/trow/portal.js index b2cc303c6..105c84119 100644 --- a/lib/v2/trow/portal.js +++ b/lib/v2/trow/portal.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'; module.exports = async (ctx) => { let data; @@ -20,10 +20,10 @@ module.exports = async (ctx) => { data = response.data; } - const $ = cheerio.load(data); + const $ = load(data); const list = $('#portal_content .borderwrap[style="display:show"]'); - ctx.state.data = { + ctx.set('data', { title: `The Ring of Wonder - Portal`, link: `https://trow.cc`, description: `The Ring of Wonder 首页更新`, @@ -42,5 +42,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/tvb/news.js b/lib/v2/tvb/news.js index c515b99bb..4b8228cff 100644 --- a/lib/v2/tvb/news.js +++ b/lib/v2/tvb/news.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 titles = { @@ -43,8 +43,8 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'focus'; - const language = ctx.params.language ?? 'tc'; + const category = ctx.req.param('category') ?? 'focus'; + const language = ctx.req.param('language') ?? 'tc'; const rootUrl = 'https://inews-api.tvb.com'; const apiUrl = `${rootUrl}/news/entry/category`; @@ -57,7 +57,7 @@ module.exports = async (ctx) => { id: category, lang: language, page: 1, - limit: ctx.query.limit ?? 50, + limit: ctx.req.query('limit') ?? 50, }, }); @@ -72,9 +72,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: `${response.data.meta.title} - ${titles[category][language]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/twitch/live.js b/lib/v2/twitch/live.js index 815675d11..d447fd06d 100644 --- a/lib/v2/twitch/live.js +++ b/lib/v2/twitch/live.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'; // https://github.com/streamlink/streamlink/blob/master/src/streamlink/plugins/twitch.py#L286 const TWITCH_CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; @@ -79,10 +79,10 @@ module.exports = async (ctx) => { }); } - ctx.state.data = { + ctx.set('data', { title: `Twitch - ${displayName} - Live`, link: `https://www.twitch.tv/${login}`, item: liveItem, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/twitch/schedule.js b/lib/v2/twitch/schedule.js index fbb48b988..8bcc1c508 100644 --- a/lib/v2/twitch/schedule.js +++ b/lib/v2/twitch/schedule.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; // https://github.com/streamlink/streamlink/blob/master/src/streamlink/plugins/twitch.py#L286 const TWITCH_CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; @@ -67,10 +67,10 @@ module.exports = async (ctx) => { category: item.categories.map((item) => item.name), })); - ctx.state.data = { + ctx.set('data', { title: `Twitch - ${displayName} - Schedule`, link: `https://www.twitch.tv/${login}`, item: out, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/twitch/video.js b/lib/v2/twitch/video.js index 549e23b45..960a842b1 100644 --- a/lib/v2/twitch/video.js +++ b/lib/v2/twitch/video.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'; // https://github.com/streamlink/streamlink/blob/master/src/streamlink/plugins/twitch.py#L286 const TWITCH_CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; @@ -11,8 +11,8 @@ const FILTER_NODE_TYPE_MAP = { }; module.exports = async (ctx) => { - const login = ctx.params.login; - const filter = ctx.params.filter?.toLowerCase() || 'all'; + const login = ctx.req.param('login'); + const filter = ctx.req.param('filter')?.toLowerCase() || 'all'; if (!FILTER_NODE_TYPE_MAP[filter]) { throw new Error(`Unsupported filter type "${filter}", please choose from { ${Object.keys(FILTER_NODE_TYPE_MAP).join(', ')} }`); } @@ -63,9 +63,9 @@ module.exports = async (ctx) => { category: item.game && [item.game.displayName], // item.game may be null })); - ctx.state.data = { + ctx.set('data', { title: `Twitch - ${displayName} - ${videoShelvesEdge.node.title}`, link: `https://www.twitch.tv/${login}`, item: out, - }; + }); }; diff --git a/lib/v2/twitter/api-fallback-common.js b/lib/v2/twitter/api-fallback-common.js index b7e5e0976..dab4a50f5 100644 --- a/lib/v2/twitter/api-fallback-common.js +++ b/lib/v2/twitter/api-fallback-common.js @@ -1,9 +1,9 @@ -const config = require('@/config').value; +import { config } from '@/config'; const logger = require('@/utils/logger'); const utils = require('./utils'); module.exports = async (ctx, devApiImpl, webApiImpl) => { - const { force_web_api } = utils.parseRouteParams(ctx.params.routeParams); + const { force_web_api } = utils.parseRouteParams(ctx.req.param('routeParams')); if (!force_web_api && config.twitter && config.twitter.consumer_key && config.twitter.consumer_secret) { try { diff --git a/lib/v2/twitter/collection.js b/lib/v2/twitter/collection.js index 0368aec1f..cba32cb77 100644 --- a/lib/v2/twitter/collection.js +++ b/lib/v2/twitter/collection.js @@ -1,12 +1,12 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; const T = {}; const { TwitterApi } = require('twitter-api-v2'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); module.exports = async (ctx) => { - const uid = ctx.params.uid; - const collectionId = ctx.params.collectionId; + const uid = ctx.req.param('uid'); + const collectionId = ctx.req.param('collectionId'); const cookie = config.twitter.tokens[uid]; if (!cookie) { throw new Error(`lacking twitter token for user ${uid}`); @@ -24,10 +24,10 @@ module.exports = async (ctx) => { const data = await T[uid].v1.get('collections/entries.json', { id, - count: ctx.query.limit ? (Number(ctx.query.limit) > 200 ? 200 : Number(ctx.query.limit)) : 200, + count: ctx.req.query('limit') ? (Number(ctx.req.query('limit')) > 200 ? 200 : Number(ctx.req.query('limit'))) : 200, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); // fix user without screen_name for (const tweet of Object.values(data.objects.tweets)) { @@ -37,7 +37,7 @@ module.exports = async (ctx) => { } } - ctx.state.data = { + ctx.set('data', { title: data.objects.timelines[id].name, description: data.objects.timelines[id].description, link: data.objects.timelines[id].collection_url, @@ -51,5 +51,5 @@ module.exports = async (ctx) => { showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.get('showAuthorInDesc')), true), } ), - }; + }); }; diff --git a/lib/v2/twitter/developer-api/search.js b/lib/v2/twitter/developer-api/search.js index 25794fd47..5659fb251 100644 --- a/lib/v2/twitter/developer-api/search.js +++ b/lib/v2/twitter/developer-api/search.js @@ -1,8 +1,8 @@ const utils = require('../utils'); module.exports = async (ctx) => { - const keyword = ctx.params.keyword; - const limit = ctx.query.limit ?? 50; + const keyword = ctx.req.param('keyword'); + const limit = ctx.req.query('limit') ?? 50; const client = await utils.getAppClient(); const data = await client.v1.get('search/tweets.json', { q: keyword, @@ -11,12 +11,12 @@ module.exports = async (ctx) => { result_type: 'recent', }); - ctx.state.data = { + ctx.set('data', { title: `Twitter Keyword - ${keyword}`, link: `https://twitter.com/search?q=${encodeURIComponent(keyword)}`, item: utils.ProcessFeed(ctx, { data: data.statuses, }), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/twitter/developer-api/user.js b/lib/v2/twitter/developer-api/user.js index b7e0eb613..ff7742eef 100644 --- a/lib/v2/twitter/developer-api/user.js +++ b/lib/v2/twitter/developer-api/user.js @@ -1,9 +1,9 @@ const utils = require('../utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); // For compatibility - const { exclude_replies, include_rts, count } = utils.parseRouteParams(ctx.params.routeParams); + const { exclude_replies, include_rts, count } = utils.parseRouteParams(ctx.req.param('routeParams')); const client = await utils.getAppClient(); const user_timeline_query = { tweet_mode: 'extended', @@ -25,7 +25,7 @@ module.exports = async (ctx) => { } const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; - ctx.state.data = { + ctx.set('data', { title: `Twitter @${userInfo.name}`, link: `https://twitter.com/${screen_name}`, image: profileImageUrl, @@ -33,5 +33,5 @@ module.exports = async (ctx) => { item: utils.ProcessFeed(ctx, { data, }), - }; + }); }; diff --git a/lib/v2/twitter/followings.js b/lib/v2/twitter/followings.js index ca9fdd99c..0952c976f 100644 --- a/lib/v2/twitter/followings.js +++ b/lib/v2/twitter/followings.js @@ -1,11 +1,11 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; const T = {}; const { TwitterApi } = require('twitter-api-v2'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const cookie = config.twitter.tokens[id]; if (!cookie) { throw new Error(`lacking twitter token for user ${id}`); @@ -25,9 +25,9 @@ module.exports = async (ctx) => { }); // undefined and strings like "exclude_rts_replies" is also safely parsed, so no if branch is needed - const routeParams = new URLSearchParams(ctx.params.routeParams); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); - ctx.state.data = { + ctx.set('data', { title: `${id} 的 Twitter 关注时间线`, link: `https://twitter.com/${id}/`, item: utils.ProcessFeed( @@ -40,5 +40,5 @@ module.exports = async (ctx) => { showAuthorInDesc: fallback(undefined, queryToBoolean(routeParams.get('showAuthorInDesc')), true), } ), - }; + }); }; diff --git a/lib/v2/twitter/likes.js b/lib/v2/twitter/likes.js index e92246125..de5b1c510 100644 --- a/lib/v2/twitter/likes.js +++ b/lib/v2/twitter/likes.js @@ -1,22 +1,22 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) { throw new Error('Twitter RSS is disabled due to the lack of relevant config'); } - const id = ctx.params.id; + const id = ctx.req.param('id'); const client = await utils.getAppClient(); const data = await client.v1.get('favorites/list.json', { screen_name: id, tweet_mode: 'extended', }); - ctx.state.data = { + ctx.set('data', { title: `Twitter Likes - ${id}`, link: `https://twitter.com/${id}/likes`, item: utils.ProcessFeed(ctx, { data, }), - }; + }); }; diff --git a/lib/v2/twitter/list.js b/lib/v2/twitter/list.js index 928bb540d..42934f60d 100644 --- a/lib/v2/twitter/list.js +++ b/lib/v2/twitter/list.js @@ -1,5 +1,5 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) { @@ -28,11 +28,11 @@ module.exports = async (ctx) => { tweet_mode: 'extended', }); - ctx.state.data = { + ctx.set('data', { title: `Twitter List - ${id}/${name}`, link: `https://twitter.com/${id}/lists/${name}`, item: utils.ProcessFeed(ctx, { data, }), - }; + }); }; diff --git a/lib/v2/twitter/trends.js b/lib/v2/twitter/trends.js index de7746a53..6c92469c7 100644 --- a/lib/v2/twitter/trends.js +++ b/lib/v2/twitter/trends.js @@ -1,16 +1,16 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) { throw new Error('Twitter RSS is disabled due to the lack of relevant config'); } - const woeid = ctx.params.woeid ?? 1; // Global information is available by using 1 as the WOEID + const woeid = ctx.req.param('woeid') ?? 1; // Global information is available by using 1 as the WOEID const client = await utils.getAppClient(); const data = await client.v1.get('trends/place.json', { id: woeid }); const [{ trends }] = data; - ctx.state.data = { + ctx.set('data', { title: `Twitter Trends on ${data[0].locations[0].name}`, link: `https://twitter.com/i/trends`, item: trends @@ -20,5 +20,5 @@ module.exports = async (ctx) => { link: t.url, description: t.name + (t.tweet_volume ? ` (${t.tweet_volume})` : ''), })), - }; + }); }; diff --git a/lib/v2/twitter/utils.js b/lib/v2/twitter/utils.js index 36fb991df..e5037e5d3 100644 --- a/lib/v2/twitter/utils.js +++ b/lib/v2/twitter/utils.js @@ -1,8 +1,8 @@ const URL = require('url'); -const config = require('@/config').value; +import { config } from '@/config'; const { TwitterApi } = require('twitter-api-v2'); const { fallback, queryToBoolean, queryToInteger } = require('@/utils/readable-social'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const getQueryParams = (url) => URL.parse(url, true).query; const getOriginalImg = (url) => { @@ -46,7 +46,7 @@ const formatText = (item) => { const ProcessFeed = (ctx, { data = [] }, params = {}) => { // undefined and strings like "exclude_rts_replies" is also safely parsed, so no if branch is needed - const routeParams = new URLSearchParams(ctx.params.routeParams); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); const mergedParams = { readable: fallback(params.readable, queryToBoolean(routeParams.get('readable')), false), diff --git a/lib/v2/twitter/web-api/login.js b/lib/v2/twitter/web-api/login.js index 37c90992e..1fdf10d08 100644 --- a/lib/v2/twitter/web-api/login.js +++ b/lib/v2/twitter/web-api/login.js @@ -1,9 +1,9 @@ // https://github.com/BANKA2017/twitter-monitor/blob/node/apps/open_account/scripts/login.mjs const { bearerToken, guestActivateUrl } = require('./constants'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const crypto = require('crypto'); -const config = require('@/config').value; +import { config } from '@/config'; const { v5: uuidv5 } = require('uuid'); const { authenticator } = require('otplib'); const logger = require('@/utils/logger'); diff --git a/lib/v2/twitter/web-api/media.js b/lib/v2/twitter/web-api/media.js index df2999cf1..f41d24789 100644 --- a/lib/v2/twitter/web-api/media.js +++ b/lib/v2/twitter/web-api/media.js @@ -1,11 +1,11 @@ const utils = require('../utils'); -// const config = require('@/config').value; +// import { config } from '@/config'; const { getUser, getUserMedia } = require('./twitter-api'); const { initToken } = require('./token'); module.exports = async (ctx) => { - const id = ctx.params.id; - const { count } = utils.parseRouteParams(ctx.params.routeParams); + const id = ctx.req.param('id'); + const { count } = utils.parseRouteParams(ctx.req.param('routeParams')); const params = count ? { count } : {}; await initToken(ctx.cache.tryGet); @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const data = await getUserMedia(ctx.cache, id, params); const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; - ctx.state.data = { + ctx.set('data', { title: `Twitter @${userInfo.name}`, link: `https://twitter.com/${userInfo.screen_name}/media`, image: profileImageUrl.replace(/_normal.jpg$/, '.jpg'), @@ -21,5 +21,5 @@ module.exports = async (ctx) => { item: utils.ProcessFeed(ctx, { data, }), - }; + }); }; diff --git a/lib/v2/twitter/web-api/search.js b/lib/v2/twitter/web-api/search.js index 25e1939f5..8eda3c68a 100644 --- a/lib/v2/twitter/web-api/search.js +++ b/lib/v2/twitter/web-api/search.js @@ -3,16 +3,16 @@ const { getSearch } = require('./twitter-api'); const { initToken } = require('./token'); module.exports = async (ctx) => { - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); await initToken(ctx.cache.tryGet); const data = await getSearch(keyword); - ctx.state.data = { + ctx.set('data', { title: `Twitter Keyword - ${keyword}`, link: `https://twitter.com/search?q=${encodeURIComponent(keyword)}`, item: utils.ProcessFeed(ctx, { data, }), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/twitter/web-api/token.js b/lib/v2/twitter/web-api/token.js index ab1047db8..877c8b1c3 100644 --- a/lib/v2/twitter/web-api/token.js +++ b/lib/v2/twitter/web-api/token.js @@ -1,4 +1,4 @@ -const config = require('@/config').value; +import { config } from '@/config'; const login = require('./login'); let tokenIndex = 0; diff --git a/lib/v2/twitter/web-api/tweet.js b/lib/v2/twitter/web-api/tweet.js index 0b6ce37f7..9825fd2d8 100644 --- a/lib/v2/twitter/web-api/tweet.js +++ b/lib/v2/twitter/web-api/tweet.js @@ -1,14 +1,14 @@ -// const config = require('@/config').value; +// import { config } from '@/config'; const { getUser, getUserTweet } = require('./twitter-api'); const utils = require('../utils'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); -const config = require('@/config').value; +import { config } from '@/config'; const { initToken } = require('./token'); module.exports = async (ctx) => { - const id = ctx.params.id; - const status = ctx.params.status; - const routeParams = new URLSearchParams(ctx.params.original); + const id = ctx.req.param('id'); + const status = ctx.req.param('status'); + const routeParams = new URLSearchParams(ctx.req.param('original')); const original = fallback(undefined, queryToBoolean(routeParams.get('original')), false); const params = { focalTweetId: status }; await initToken(ctx.cache.tryGet); @@ -17,11 +17,11 @@ module.exports = async (ctx) => { const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; const item = original && config.isPackage ? data : utils.ProcessFeed(ctx, { data }); - ctx.state.data = { + ctx.set('data', { title: `Twitter @${userInfo.name}`, link: `https://twitter.com/${userInfo.screen_name}/status/${status}`, image: profileImageUrl.replace(/_normal.jpg$/, '.jpg'), description: userInfo.description, item, - }; + }); }; diff --git a/lib/v2/twitter/web-api/twitter-api.js b/lib/v2/twitter/web-api/twitter-api.js index 5ca8c0664..0ae93cab1 100644 --- a/lib/v2/twitter/web-api/twitter-api.js +++ b/lib/v2/twitter/web-api/twitter-api.js @@ -1,7 +1,7 @@ const { baseUrl, gqlMap, gqlFeatures, consumerKey, consumerSecret } = require('./constants'); -const config = require('@/config').value; +import { config } from '@/config'; const logger = require('@/utils/logger'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const OAuth = require('oauth-1.0a'); const CryptoJS = require('crypto-js'); const queryString = require('query-string'); diff --git a/lib/v2/twitter/web-api/user.js b/lib/v2/twitter/web-api/user.js index 745136e59..da1d8b397 100644 --- a/lib/v2/twitter/web-api/user.js +++ b/lib/v2/twitter/web-api/user.js @@ -3,10 +3,10 @@ const { getUser, getUserTweets, getUserTweetsAndReplies, excludeRetweet } = requ const { initToken } = require('./token'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); // For compatibility - const { count, exclude_replies, include_rts } = utils.parseRouteParams(ctx.params.routeParams); + const { count, exclude_replies, include_rts } = utils.parseRouteParams(ctx.req.param('routeParams')); const params = count ? { count } : {}; await initToken(ctx.cache.tryGet); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; - ctx.state.data = { + ctx.set('data', { title: `Twitter @${userInfo.name}`, link: `https://twitter.com/${userInfo.screen_name}`, image: profileImageUrl.replace(/_normal.jpg$/, '.jpg'), @@ -26,5 +26,5 @@ module.exports = async (ctx) => { item: utils.ProcessFeed(ctx, { data, }), - }; + }); }; diff --git a/lib/v2/twreporter/fetch-article.js b/lib/v2/twreporter/fetch-article.js index 628a210cc..0c303e17a 100644 --- a/lib/v2/twreporter/fetch-article.js +++ b/lib/v2/twreporter/fetch-article.js @@ -1,10 +1,10 @@ -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 function fetch(address) { const res = await got(address); - const capture = cheerio.load(res.data); + const capture = load(res.data); capture('.gIMvvS').remove(); let metaInfoBox = capture('.ffAPnj') @@ -18,7 +18,7 @@ module.exports = async function fetch(address) { .get(); } - const acquire = cheerio.load(metaInfoBox); + const acquire = load(metaInfoBox); let time = acquire('.gimsRe').text(); // For `photography` @@ -37,12 +37,12 @@ module.exports = async function fetch(address) { if (acquire('.loxoWO').text() === '') { for (const item of acquire('.flciyI').get()) { - const $ = cheerio.load(item); + const $ = load(item); const job = $('.hGsNtm').text(); // An article may have multiple authors const name = []; for (const item of $('.cidPTd > a').get()) { - const $ = cheerio.load(item); + const $ = load(item); name.push($('.fJSaZP').text()); } diff --git a/lib/v2/twreporter/newest.js b/lib/v2/twreporter/newest.js index 040b6b184..793f7f613 100644 --- a/lib/v2/twreporter/newest.js +++ b/lib/v2/twreporter/newest.js @@ -1,17 +1,17 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const fetch = require('./fetch-article'); module.exports = async (ctx) => { const url = 'https://www.twreporter.org'; const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.gKMjSz').get(); const out = await Promise.all( list.map((item) => { - const $ = cheerio.load(item); + const $ = load(item); const address = url + $('a').attr('href'); const title = $('.latest-section__Title-hzxpx3-6').text(); return ctx.cache.tryGet(address, async () => { @@ -21,9 +21,9 @@ module.exports = async (ctx) => { }); }) ); - ctx.state.data = { + ctx.set('data', { title: `報導者 | 最新`, link: url, item: out, - }; + }); }; diff --git a/lib/v2/txrjy/fornumtopic.js b/lib/v2/txrjy/fornumtopic.js index d29eaf1b6..fe86f662a 100644 --- a/lib/v2/txrjy/fornumtopic.js +++ b/lib/v2/txrjy/fornumtopic.js @@ -1,21 +1,21 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); const rootUrl = 'https://www.txrjy.com'; module.exports = async (ctx) => { - const channel = ctx.params.channel ?? '1'; + const channel = ctx.req.param('channel') ?? '1'; const url = `${rootUrl}/c114-listnewtopic.php?typeid=${channel}`; const response = await got(url, { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); const title = $('div.z > a').last().text(); const list = $('tbody > tr') .slice(0, 25) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { const detailResponse = await got(item.link, { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + const content = load(iconv.decode(detailResponse.data, 'gbk')); item.description = content('div.c_table') .map((_, item) => @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `通信人家园 - 论坛 ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/tynu/tynu.js b/lib/v2/tynu/tynu.js index 386f0c881..3fd4a24e0 100644 --- a/lib/v2/tynu/tynu.js +++ b/lib/v2/tynu/tynu.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 baseUrl = 'http://www.tynu.edu.cn'; module.exports = async (ctx) => { @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const response = await got(link); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.news_content_list') .toArray() .map((item) => { @@ -24,16 +24,16 @@ 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 = $('#vsb_content').html() + ($('.content ul').not('.btm-cate').html() || ''); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: '太原师范学院通知公告', link, item: list, - }; + }); }; diff --git a/lib/v2/typora/changelog-dev.js b/lib/v2/typora/changelog-dev.js index c7c366e3d..fb5fccb1a 100644 --- a/lib/v2/typora/changelog-dev.js +++ b/lib/v2/typora/changelog-dev.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const currentUrl = 'https://typora.io/releases/dev'; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('h2') .toArray() @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Typora Changelog - Dev`, link: currentUrl, description: 'Typora Changelog', item: items, - }; + }); }; diff --git a/lib/v2/typora/changelog.js b/lib/v2/typora/changelog.js index 9e6ad8ab8..5a920fbe4 100644 --- a/lib/v2/typora/changelog.js +++ b/lib/v2/typora/changelog.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://support.typora.io'; @@ -20,7 +20,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); item.pubDate = parseDate($('.post-meta time').text()); item.description = $('#post-content').html(); @@ -30,11 +30,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Typora Changelog', link: host, description: 'Typora Changelog', image: `${host}/assets/img/favicon-128.png`, item: items, - }; + }); }; diff --git a/lib/v2/u3c3/index.js b/lib/v2/u3c3/index.js index 428357d49..229d2d0fe 100644 --- a/lib/v2/u3c3/index.js +++ b/lib/v2/u3c3/index.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 { type, keywoard, preview } = ctx.params; @@ -27,7 +27,7 @@ module.exports = async (ctx) => { } const response = await got(currentURL); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > div.container > div.table-responsive > table > tbody > tr') .toArray() @@ -54,7 +54,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.panel-footer > img:first-child').parent().html(); @@ -64,10 +64,10 @@ module.exports = async (ctx) => { ) : list; - ctx.state.data = { + ctx.set('data', { title, description: title, link: currentURL, item: items, - }; + }); }; diff --git a/lib/v2/u9a9/index.js b/lib/v2/u9a9/index.js index b225c521d..8504e9d18 100644 --- a/lib/v2/u9a9/index.js +++ b/lib/v2/u9a9/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 baseUrl = 'https://u9a9.com'; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { } const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('table tr') .slice(1) // skip thead @@ -48,7 +48,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 = $('.panel-body').eq(1).html(); @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) : list; - ctx.state.data = { + ctx.set('data', { title, link, item: items, - }; + }); }; diff --git a/lib/v2/uber/blog.js b/lib/v2/uber/blog.js index 952a7d708..1f0170ca8 100644 --- a/lib/v2/uber/blog.js +++ b/lib/v2/uber/blog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const rootURL = 'https://www.uber.com'; const apiURL = 'https://blogapi.uber.com'; module.exports = async (ctx) => { - let maxPage = Number(ctx.params.maxPage); + let maxPage = Number(ctx.req.param('maxPage')); if (Number.isNaN(maxPage)) { maxPage = 1; } @@ -49,10 +49,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Uber Engineering Blog`, link: rootURL + '/blog/engineering', description: 'The technology behind Uber Engineering', item: result.flat(), - }; + }); }; diff --git a/lib/v2/ucas/ai.js b/lib/v2/ucas/ai.js index 9b816e4b0..4574117b6 100644 --- a/lib/v2/ucas/ai.js +++ b/lib/v2/ucas/ai.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://ai.ucas.ac.cn'; const link = `${baseUrl}/index.php/zh-cn/tzgg`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.b-list li'); - ctx.state.data = { + ctx.set('data', { title: '中科院人工智能所', link, description: '中科院人工智能通知公告', @@ -24,5 +24,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('.m-date').text(), 'YYYY-MM-DD'), }; }), - }; + }); }; diff --git a/lib/v2/ucas/index.js b/lib/v2/ucas/index.js index eb23b16c4..1cc53f309 100644 --- a/lib/v2/ucas/index.js +++ b/lib/v2/ucas/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 rootUrl = 'https://zhaopin.ucas.ac.cn'; @@ -19,11 +19,11 @@ const titleMap = { }; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'bsh'; + const type = ctx.req.param('type') ?? 'bsh'; const url = `${rootUrl}/gjob/login.do?method=contentList&t=zhaopin&c=${idMap[type]}`; const response = await got.get(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#col1_content > div.list > ul > li').get(); const items = await Promise.all( @@ -34,7 +34,7 @@ module.exports = async (ctx) => { const desc = await ctx.cache.tryGet(link, async () => { const response = await got.get(link); - const pageContent = cheerio.load(response.data); + const pageContent = load(response.data); const descDeadline = pageContent('#col1_content > div.content_head > div.top').html(); const descContent = pageContent('#col1_content > div.entry').html(); @@ -51,9 +51,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `中国科学院大学招聘 - ${titleMap[type]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/uchicago/current.js b/lib/v2/uchicago/current.js index f55c7ade6..3681f1c83 100644 --- a/lib/v2/uchicago/current.js +++ b/lib/v2/uchicago/current.js @@ -1,14 +1,15 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { getCookies, setCookies } = require('@/utils/puppeteer-utils'); const logger = require('@/utils/logger'); +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { journal } = ctx.params; const baseUrl = 'https://www.journals.uchicago.edu'; const link = `${baseUrl}/toc/${journal}/current`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -21,7 +22,7 @@ module.exports = async (ctx) => { const response = await page.evaluate(() => document.documentElement.innerHTML); const cookies = await getCookies(page); page.close(); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.issue-item__title') .toArray() @@ -44,7 +45,7 @@ module.exports = async (ctx) => { const response = await page.evaluate(() => document.documentElement.innerHTML); page.close(); - const $ = cheerio.load(response); + const $ = load(response); item.title = $('head title').text(); item.pubDate = parseDate($('head meta[name="dc.Date"]').attr('content')); @@ -70,11 +71,11 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('.jumbotron-journal-info').text(), link, image: $('head meta[property="og:image"]').attr('content'), item: items, - }; + }); }; diff --git a/lib/v2/udn/breaking-news.js b/lib/v2/udn/breaking-news.js index 10a8b1893..7e54fc050 100644 --- a/lib/v2/udn/breaking-news.js +++ b/lib/v2/udn/breaking-news.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `/news/breaknews/1/${id}#breaknews`; const name = await getLinkName(ctx, link); const rootUrl = 'https://udn.com'; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { result = await got(vip[1]); } - const $ = cheerio.load(result.data); + const $ = load(result.data); const metadata = $('script[type="application/ld+json"]') .eq(0) .text() @@ -66,19 +66,19 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `即時${name} - 聯合新聞網`, link: `${rootUrl}${link}`, description: 'udn.com 提供即時新聞以及豐富的政治、社會、地方、兩岸、國際、財經、數位、運動、NBA、娛樂、生活、健康、旅遊新聞,以最即時、多元的內容,滿足行動世代的需求', item: items, - }; + }); }; const getLinkName = async (ctx, link) => { const url = 'https://udn.com/news/breaknews'; const links = await ctx.cache.tryGet(url, async () => { const result = await got(url); - const $ = cheerio.load(result.data); + const $ = load(result.data); const data = $('.cate-list__subheader a') .get() .map((item) => { diff --git a/lib/v2/udn/global/index.js b/lib/v2/udn/global/index.js index aa943cabd..4dad7c543 100644 --- a/lib/v2/udn/global/index.js +++ b/lib/v2/udn/global/index.js @@ -1,10 +1,10 @@ -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.category ?? ''; + const category = ctx.req.param('category') ?? ''; const start = category === 'hot' ? 6 : 0; const end = category === 'new' ? 6 : 12; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.topic').remove(); @@ -40,7 +40,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#story_art_title, #story_bady_info, #story_also').remove(); content('.social_bar, .photo_pop, .only_mobile, .area').remove(); @@ -55,9 +55,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/udn/global/tag.js b/lib/v2/udn/global/tag.js index f14c07835..d3bb96271 100644 --- a/lib/v2/udn/global/tag.js +++ b/lib/v2/udn/global/tag.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 tag = ctx.params.tag ?? '過去24小時'; + const tag = ctx.req.param('tag') ?? '過去24小時'; const rootUrl = 'https://global.udn.com'; const currentUrl = `${rootUrl}/search/tagging/1020/${tag}`; @@ -30,7 +30,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#story_art_title, #story_bady_info, #story_also').remove(); content('.social_bar, .photo_pop, .only_mobile, .area').remove(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `轉角國際 udn Global - ${tag}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/uestc/auto.js b/lib/v2/uestc/auto.js index b14f99957..72c7f8bec 100644 --- a/lib/v2/uestc/auto.js +++ b/lib/v2/uestc/auto.js @@ -1,11 +1,12 @@ -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'; const baseIndexUrl = 'https://www.auto.uestc.edu.cn/index/tzgg1.htm'; const host = 'https://www.auto.uestc.edu.cn/'; module.exports = async (ctx) => { - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -17,7 +18,7 @@ module.exports = async (ctx) => { const content = await page.content(); await browser.close(); - const $ = cheerio.load(content); + const $ = load(content); const items = $('dl.clearfix'); @@ -36,10 +37,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '电子科技大学自动化学院通知', link: baseIndexUrl, description: '电子科技大学自动化工程学院通知', item: out, - }; + }); }; diff --git a/lib/v2/uestc/cqe.js b/lib/v2/uestc/cqe.js index aabe12c05..84aa8aa07 100644 --- a/lib/v2/uestc/cqe.js +++ b/lib/v2/uestc/cqe.js @@ -1,5 +1,6 @@ -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'; const baseUrl = 'https://cqe.uestc.edu.cn/'; @@ -14,13 +15,13 @@ const mapTitle = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 'tzgg'; + const type = ctx.req.param('type') || 'tzgg'; const pageUrl = mapUrl[type]; if (!pageUrl) { throw new Error('type not supported'); } - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -32,7 +33,7 @@ module.exports = async (ctx) => { const content = await page.content(); await browser.close(); - const $ = cheerio.load(content); + const $ = load(content); const items = $('div.Newslist li'); @@ -51,10 +52,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `大学生文化素质教育中心-${mapTitle[type]}`, link: baseUrl, description: '电子科技大学大学生文化素质教育中心通知', item: out, - }; + }); }; diff --git a/lib/v2/uestc/gr.js b/lib/v2/uestc/gr.js index a6b9951b0..d7e2c1d13 100644 --- a/lib/v2/uestc/gr.js +++ b/lib/v2/uestc/gr.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 baseUrl = 'https://gr.uestc.edu.cn/tongzhi/'; const baseIndexUrl = 'https://gr.uestc.edu.cn'; @@ -8,7 +8,7 @@ const baseIndexUrl = 'https://gr.uestc.edu.cn'; module.exports = async (ctx) => { const response = await got.get(baseIndexUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = []; $('[href^="/tongzhi/"]').each((_, item) => { @@ -20,7 +20,7 @@ module.exports = async (ctx) => { const newsDetail = await ctx.cache.tryGet(newsUrl, async () => { const result = await got.get(newsUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const title = '[' + $('.over').text() + '] ' + $('div.title').text(); const author = $('.info').text().split('|')[1].trim().substring(3); @@ -39,10 +39,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '研究生院通知', link: baseUrl, description: '电子科技大学研究生院通知公告', item: out, - }; + }); }; diff --git a/lib/v2/uestc/jwc.js b/lib/v2/uestc/jwc.js index f5f077550..44da04c32 100644 --- a/lib/v2/uestc/jwc.js +++ b/lib/v2/uestc/jwc.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 dateRegex = /(20\d{2})\/(\d{2})\/(\d{2})/; @@ -16,7 +16,7 @@ const map = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 'important'; + const type = ctx.req.param('type') || 'important'; const pageUrl = map[type]; if (!pageUrl) { throw new Error('type not supported'); @@ -24,7 +24,7 @@ module.exports = async (ctx) => { const response = await got.get(baseUrl + pageUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.textAreo.clearfix'); @@ -43,10 +43,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '教务处通知', link: baseUrl, description: '电子科技大学教务处通知', item: out, - }; + }); }; diff --git a/lib/v2/uestc/news.js b/lib/v2/uestc/news.js index 5b3abab1d..231e257ac 100644 --- a/lib/v2/uestc/news.js +++ b/lib/v2/uestc/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 dateRegex = /(20\d{2}).(\d{2})-(\d{2})/; @@ -13,7 +13,7 @@ const map = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 'announcement'; + const type = ctx.req.param('type') || 'announcement'; const pageUrl = map[type]; if (!pageUrl) { throw new Error('type not supported'); @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const response = await got.get(baseUrl + pageUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.notice-item.clearfix'); @@ -42,10 +42,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '新闻网通知', link: baseUrl, description: '电子科技大学新闻网信息公告', item: out, - }; + }); }; diff --git a/lib/v2/uestc/scse.js b/lib/v2/uestc/scse.js index a291c178e..d4a19fe41 100644 --- a/lib/v2/uestc/scse.js +++ b/lib/v2/uestc/scse.js @@ -1,6 +1,7 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); +import puppeteer from '@/utils/puppeteer'; const baseIndexUrl = 'https://www.scse.uestc.edu.cn/index.htm'; const host = 'https://www.scse.uestc.edu.cn/'; @@ -19,7 +20,7 @@ const prefixes = { }; module.exports = async (ctx) => { - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -31,7 +32,7 @@ module.exports = async (ctx) => { const content = await page.content(); await browser.close(); - const $ = cheerio.load(content); + const $ = load(content); const iList = $('.s2-lswitch .i-list'); let firstFlag = true; @@ -81,10 +82,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '计算机学院通知', link: baseIndexUrl, description: '电子科技大学计算机科学与工程学院通知', item: out, - }; + }); }; diff --git a/lib/v2/uestc/sice.js b/lib/v2/uestc/sice.js index 4a58c013c..fd70beff0 100644 --- a/lib/v2/uestc/sice.js +++ b/lib/v2/uestc/sice.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'; const dayjs = require('dayjs'); +import puppeteer from '@/utils/puppeteer'; const baseIndexUrl = 'https://www.sice.uestc.edu.cn/index.htm'; const host = 'https://www.sice.uestc.edu.cn/'; module.exports = async (ctx) => { - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -18,7 +19,7 @@ module.exports = async (ctx) => { const content = await page.content(); await browser.close(); - const $ = cheerio.load(content); + const $ = load(content); const out = $('.notice p') .map((_, item) => { @@ -37,10 +38,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '信通学院通知', link: baseIndexUrl, description: '电子科技大学信息与通信工程学院通知公告', item: out, - }; + }); }; diff --git a/lib/v2/uestc/sise.js b/lib/v2/uestc/sise.js index fe0c5a8bd..1f2f9a061 100644 --- a/lib/v2/uestc/sise.js +++ b/lib/v2/uestc/sise.js @@ -1,6 +1,7 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); +import puppeteer from '@/utils/puppeteer'; const baseUrl = 'https://sise.uestc.edu.cn/'; @@ -29,13 +30,13 @@ const mapTitle = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 1; + const type = ctx.req.param('type') || 1; const divId = mapId[type]; if (!divId) { throw new Error('type not supported'); } - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -47,7 +48,7 @@ module.exports = async (ctx) => { const content = await page.content(); await browser.close(); - const $ = cheerio.load(content); + const $ = load(content); const items = $(`div[id="${divId}"] p.news-item`); @@ -71,10 +72,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `信软学院通知-${mapTitle[type]}`, link: baseUrl, description: '电子科技大学信息与软件工程学院通知', item: out, - }; + }); }; diff --git a/lib/v2/uibe/hr.js b/lib/v2/uibe/hr.js index 4d91b6957..aa332fbe6 100644 --- a/lib/v2/uibe/hr.js +++ b/lib/v2/uibe/hr.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 category = ctx.params.category ?? 'tzgg'; - const type = ctx.params.type ?? ''; + const category = ctx.req.param('category') ?? 'tzgg'; + const type = ctx.req.param('type') ?? ''; const rootUrl = 'http://hr.uibe.edu.cn'; const currentUrl = `${rootUrl}/${category}${type ? `/${type}` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.lawul, .longul') .find('li a') @@ -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('.gp-article').html(); item.pubDate = parseDate(content('#shareTitle').next().text().replace('时间:', '')); @@ -50,9 +50,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.picTit').text()} - 对外经济贸易大学人力资源处`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/ulapia/index.js b/lib/v2/ulapia/index.js index 5d078f562..8aa37c420 100644 --- a/lib/v2/ulapia/index.js +++ b/lib/v2/ulapia/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 rootUrl = 'http://www.ulapia.com'; @@ -23,11 +23,11 @@ const selectorMap = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'brokerage_news'; + const category = ctx.req.param('category') ?? 'brokerage_news'; const url = `${rootUrl}/reports/${category}`; const response = await got.get(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $(String(selectorMap[category])) .filter((_, item) => $(item).find('img').attr('src')) .map((_, item) => ({ @@ -39,9 +39,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: ` ulapia - ${titleMap[category]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/ulapia/research.js b/lib/v2/ulapia/research.js index 32a631ec0..986807065 100644 --- a/lib/v2/ulapia/research.js +++ b/lib/v2/ulapia/research.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 rootUrl = 'http://www.ulapia.com'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(url, async () => { const response = await got.get(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.row > div.col-md-6') .slice(0, 6) .map((_, item) => ({ @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: 'Ulapia - 最新研报', link: rootUrl, item: items.flat(), - }; + }); }; diff --git a/lib/v2/uniqlo/new.js b/lib/v2/uniqlo/new.js index acd8e46b1..7485f9231 100644 --- a/lib/v2/uniqlo/new.js +++ b/lib/v2/uniqlo/new.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const { country, category } = ctx.params; @@ -54,9 +54,9 @@ module.exports = async (ctx) => { }${item.images.sub.map((image) => ``).join('')}`, })); - ctx.state.data = { + ctx.set('data', { title: `Uniqlo ${category} new arrivals in ${country}`, link: `https://www.uniqlo.com/${country}/${map[country].lang || 'en'}/feature/new/${category}`, item: items, - }; + }); }; diff --git a/lib/v2/unraid/community-apps.js b/lib/v2/unraid/community-apps.js index c19834469..c0e7b4b74 100644 --- a/lib/v2/unraid/community-apps.js +++ b/lib/v2/unraid/community-apps.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 appFeedUrl = 'https://raw.githubusercontent.com/Squidly271/AppFeed/master/applicationFeed.json'; const defaultLimit = 20; module.exports = async (ctx) => { const { data } = await got(appFeedUrl); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : defaultLimit; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : defaultLimit; let appList = data.applist; appList = appList.map((app) => { @@ -19,7 +19,7 @@ module.exports = async (ctx) => { appList.sort((a, b) => b._pubDate - a._pubDate); const returnedAppList = appList.slice(0, limit); - ctx.state.data = { + ctx.set('data', { title: 'Unraid Community Apps', link: 'https://unraid.net/community/apps', image: 'https://craftassets.unraid.net/static/favicon/favicon.ico?v=1.0', @@ -31,5 +31,5 @@ module.exports = async (ctx) => { category: app.CategoryList, upvotes: app.stars, })), - }; + }); }; diff --git a/lib/v2/unusualwhales/news.js b/lib/v2/unusualwhales/news.js index dc99da15b..a5446e36d 100644 --- a/lib/v2/unusualwhales/news.js +++ b/lib/v2/unusualwhales/news.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 apiBase = 'https://phx.unusualwhales.com'; @@ -13,12 +13,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.publish_date), })); - ctx.state.data = { + ctx.set('data', { title: 'Flow - News', description: 'Explore unusual options, options flow, dark pools, short activity, and stock activity on unusualwhales.com. Unusual whales has a full news service available!', link: 'https://unusualwhales.com/news-feed', image: 'https://unusualwhales.com/android-icon-192x192.png', language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/upc/jsj.js b/lib/v2/upc/jsj.js index 47fe2e31c..c44701f71 100644 --- a/lib/v2/upc/jsj.js +++ b/lib/v2/upc/jsj.js @@ -4,10 +4,10 @@ // - 学工动态:http://computer.upc.edu.cn/6279/list.htm // - 通知公告:http://computer.upc.edu.cn/6280/list.htm -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 MAP = { @@ -26,13 +26,13 @@ const HEAD = { module.exports = async (ctx) => { const baseUrl = 'https://computer.upc.edu.cn'; - const type = ctx.params.type; + const type = ctx.req.param('type'); const link = `${baseUrl}/${MAP[type]}/list.htm`; const response = await got({ method: 'get', url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // ## 获取列表 const list = $('.list tbody table tr') .toArray() @@ -56,7 +56,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const $ = cheerio.load(detail_response.data); + const $ = load(detail_response.data); const detailContent = $('.v_news_content, .wp_articlecontent').html(); // ### 设置 RSS feed item // author, @@ -68,10 +68,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: HEAD[type] + `-计算机科学与技术学院`, link, description: HEAD[type] + `-计算机科学与技术学院`, item: out, - }; + }); }; diff --git a/lib/v2/upc/main.js b/lib/v2/upc/main.js index aab8b9af7..e285be646 100644 --- a/lib/v2/upc/main.js +++ b/lib/v2/upc/main.js @@ -1,8 +1,8 @@ // 学校官网:http://www.upc.edu.cn/ -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 MAP = { @@ -17,13 +17,13 @@ const HEAD = { module.exports = async (ctx) => { const baseUrl = 'https://news.upc.edu.cn'; - const type = ctx.params.type; + const type = ctx.req.param('type'); const link = `${baseUrl}/${MAP[type]}.htm`; const response = await got({ method: 'get', url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // ## 获取列表 const list = $('.main-list-box-left li') .toArray() @@ -51,7 +51,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const $ = cheerio.load(detail_response.data); + const $ = load(detail_response.data); const detailContent = $('.v_news_content').html(); // ### 设置 RSS feed item // author, @@ -63,10 +63,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: HEAD[type] + `-中国石油大学(华东)`, link, description: HEAD[type] + `-中国石油大学(华东)`, item: out, - }; + }); }; diff --git a/lib/v2/upc/yjs.js b/lib/v2/upc/yjs.js index 4def72967..24b9c2281 100644 --- a/lib/v2/upc/yjs.js +++ b/lib/v2/upc/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 = 'http://zs.gs.upc.edu.cn'; const link = `${baseUrl}/sszs/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list tr'); - ctx.state.data = { + ctx.set('data', { title: '中国石油大学研究生院', link, description: '中国石油大学研究生院通知公告', @@ -24,5 +24,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('div[style]').text()), }; }), - }; + }); }; diff --git a/lib/v2/uptimerobot/rss.js b/lib/v2/uptimerobot/rss.js index eb08edb49..c9623f88e 100644 --- a/lib/v2/uptimerobot/rss.js +++ b/lib/v2/uptimerobot/rss.js @@ -1,5 +1,5 @@ const Parser = require('rss-parser'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const dayjs = require('dayjs'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); @@ -52,7 +52,7 @@ const rootURL = 'https://rss.uptimerobot.com'; module.exports = async (ctx) => { const { id } = ctx.params; - const routeParams = Object.fromEntries(new URLSearchParams(ctx.params.routeParams)); + const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams'))); const showID = fallback(undefined, queryToBoolean(routeParams.showID), true); const rssUrl = `${rootURL}/${id}`; @@ -116,11 +116,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'Uptime Robot - RSS (enhanced)', description: rss.description, link: rssUrl, item: items, image: 'https://uptimerobot.com/favicon.ico', - }; + }); }; diff --git a/lib/v2/uraaka-joshi/uraaka-joshi-user.js b/lib/v2/uraaka-joshi/uraaka-joshi-user.js index d4ab69157..2f73842d9 100644 --- a/lib/v2/uraaka-joshi/uraaka-joshi-user.js +++ b/lib/v2/uraaka-joshi/uraaka-joshi-user.js @@ -1,6 +1,7 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { id } = ctx.params; @@ -9,7 +10,7 @@ module.exports = async (ctx) => { const response = await ctx.cache.tryGet( link, async () => { - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -41,7 +42,7 @@ module.exports = async (ctx) => { false ); - const $ = cheerio.load(response); + const $ = load(response); const items = $('#main-block .grid .grid-cell') .toArray() .map((item) => { @@ -96,10 +97,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), description: $('meta[name="description"]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/uraaka-joshi/uraaka-joshi.js b/lib/v2/uraaka-joshi/uraaka-joshi.js index 543164354..bc81433b4 100644 --- a/lib/v2/uraaka-joshi/uraaka-joshi.js +++ b/lib/v2/uraaka-joshi/uraaka-joshi.js @@ -1,11 +1,12 @@ -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 link = `https://www.uraaka-joshi.com/`; const title = `裏垢女子まとめ`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); @@ -35,10 +36,10 @@ module.exports = async (ctx) => { } await browser.close(); - const $ = cheerio.load(html); + const $ = load(html); const list = $('.grid-cell'); - ctx.state.data = { + ctx.set('data', { title, link, item: @@ -85,5 +86,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/urbandictionary/random.js b/lib/v2/urbandictionary/random.js index 84a58964d..34ca8da93 100644 --- a/lib/v2/urbandictionary/random.js +++ b/lib/v2/urbandictionary/random.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'); module.exports = async (ctx) => { @@ -16,9 +16,9 @@ module.exports = async (ctx) => { author: item.author, })); - ctx.state.data = { + ctx.set('data', { title: 'Urban Dictionary: Random words', link: `${baseUrl}/random.php`, item: items, - }; + }); }; diff --git a/lib/v2/usenix/usenix.js b/lib/v2/usenix/usenix.js index a09d25161..da80eb8cc 100644 --- a/lib/v2/usenix/usenix.js +++ b/lib/v2/usenix/usenix.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = 'https://www.usenix.org'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const seasons = ['spring', 'summer', 'fall', 'winter']; @@ -21,7 +21,7 @@ module.exports = async (ctx) => { ); const list = responses.filter(Boolean).flatMap((response) => { - const $ = cheerio.load(response.data); + const $ = load(response.data); const pubDate = parseDate($('meta[property=article:modified_time]').attr('content')); return $('article.node-paper') .toArray() @@ -40,7 +40,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 = $('.content').html(); return item; @@ -48,11 +48,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'USENIX', link: url, description: 'USENIX Security Symposium Accpeted Papers', allowEmpty: true, item: items, - }; + }); }; diff --git a/lib/v2/usepanda/index.js b/lib/v2/usepanda/index.js index 3b117b864..0d107b8d8 100644 --- a/lib/v2/usepanda/index.js +++ b/lib/v2/usepanda/index.js @@ -1,9 +1,9 @@ -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 feedId = ctx.params.id; - const limit = ctx.query.limit ?? 30; // 默认30条 + const feedId = ctx.req.param('id'); + const limit = ctx.req.query('limit') ?? 30; // 默认30条 const rootUrl = 'https://api-panda.com/v4/'; const apiUrl = `${rootUrl}articles?feeds=${feedId}&limit=${limit}&page=1&sort=popular`; @@ -18,9 +18,9 @@ module.exports = async (ctx) => { description: item.description, })); - ctx.state.data = { + ctx.set('data', { title: 'Panda Feeds', link: 'https://usepanda.com/', item: items, - }; + }); }; diff --git a/lib/v2/ustb/tj/news.js b/lib/v2/ustb/tj/news.js index 745d2d101..5642f33e2 100644 --- a/lib/v2/ustb/tj/news.js +++ b/lib/v2/ustb/tj/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 baseUrl = 'http://tj.ustb.edu.cn'; const maps = { @@ -20,7 +20,7 @@ const maps = { }; function getNews(data) { - const $ = cheerio.load(data); + const $ = load(data); return $('div[class="classnews"] ul li a') .toArray() .map((elem) => ({ @@ -31,7 +31,7 @@ function getNews(data) { } module.exports = async (ctx) => { - let type = ctx.params.type || 'all'; + let type = ctx.req.param('type') || 'all'; if (!Object.keys(maps).includes(type)) { type = 'all'; } @@ -57,5 +57,5 @@ module.exports = async (ctx) => { responseData.item = news; } - ctx.state.data = responseData; + ctx.set('data', responseData); }; diff --git a/lib/v2/ustb/yjsy/news.js b/lib/v2/ustb/yjsy/news.js index b1b3bb708..a098a0933 100644 --- a/lib/v2/ustb/yjsy/news.js +++ b/lib/v2/ustb/yjsy/news.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // const logger = require('@/utils/logger'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const struct = { all: { selector: { @@ -393,7 +393,7 @@ module.exports = async (ctx) => { // 获取response const data = type === 'iet' ? iconv.decode(response.data, 'gb2312') : response.data; - const $ = cheerio.load(data); + const $ = load(data); // logger.info("data:" + data); // 获取响应中有用的部分 @@ -401,7 +401,7 @@ module.exports = async (ctx) => { // logger.info("list:" + list); // 处理返回 - ctx.state.data = { + ctx.set('data', { title: struct[type].name, link: struct[type].link, description: '北京科技大学研究生院', @@ -453,5 +453,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/ustb/yzxc/tzgg.js b/lib/v2/ustb/yzxc/tzgg.js index afd645851..3ab5e88ea 100644 --- a/lib/v2/ustb/yzxc/tzgg.js +++ b/lib/v2/ustb/yzxc/tzgg.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 host = 'https://yzxc.ustb.edu.cn'; const url = `${host}/tzgg/index.htm`; module.exports = async (ctx) => { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.page_content .ul-inline .box'); const items = await Promise.all( list.map((i, item) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(itemUrl, async () => { let description = titleText; const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); if ($('.article') && $('.article').html()) { description = $('.article').html().trim(); } @@ -40,10 +40,10 @@ module.exports = async (ctx) => { }); }) ); - ctx.state.data = { + ctx.set('data', { title: '北京科技大学研究生招生信息网 - 通知公告', link: url, description: '北京科技大学研究生招生信息网 - 通知公告', item: items, - }; + }); }; diff --git a/lib/v2/ustc/eeis.js b/lib/v2/ustc/eeis.js index c84288ef9..7b59151d3 100644 --- a/lib/v2/ustc/eeis.js +++ b/lib/v2/ustc/eeis.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 map = new Map([ ['tzgg', { title: '中国科学技术大学电子工程与信息科学系 - 通知公告', id: '2702' }], @@ -11,7 +11,7 @@ const map = new Map([ const host = 'https://eeis.ustc.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'tzgg'; + const type = ctx.req.param('type') ?? 'tzgg'; const info = map.get(type); if (!info) { throw new Error('invalid type'); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const id = info.id; const response = await got(`${host}/${id}/list.htm`); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div[portletmode=simpleList]') .find('article') .toArray() @@ -42,7 +42,7 @@ module.exports = async (ctx) => { let desc = ''; try { const response = await got(item.link); - desc = cheerio.load(response.data)('div.wp_articlecontent').html(); + desc = load(response.data)('div.wp_articlecontent').html(); item.description = desc; } catch { // intranet only contents @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: info.title, link: `${host}/${id}/list.htm`, item: items, - }; + }); }; diff --git a/lib/v2/ustc/gs.js b/lib/v2/ustc/gs.js index d0b556c4f..d3f4399ae 100644 --- a/lib/v2/ustc/gs.js +++ b/lib/v2/ustc/gs.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 map = new Map([ ['tzgg', { title: '中国科学技术大学研究生院 - 通知公告', id: '9' }], @@ -11,7 +11,7 @@ const map = new Map([ const host = 'https://gradschool.ustc.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'tzgg'; + const type = ctx.req.param('type') ?? 'tzgg'; const info = map.get(type); if (!info) { throw new Error('invalid type'); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const id = info.id; const response = await got(`${host}/column/${id}`); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('div.r-box > ul') .find('li') .toArray() @@ -41,7 +41,7 @@ module.exports = async (ctx) => { let desc = ''; try { const response = await got(item.link); - desc = cheerio.load(response.data)('article.article').html(); + desc = load(response.data)('article.article').html(); item.description = desc; } catch { // intranet only contents @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: info.title, link: `${host}/column/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/ustc/index.js b/lib/v2/ustc/index.js index adf04b1b5..d35b8b69d 100644 --- a/lib/v2/ustc/index.js +++ b/lib/v2/ustc/index.js @@ -1,8 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -// const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'windows', device: 'desktop' }); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const notice_type = { jx: { title: '中国科学技术大学 - 教学类通知', url: 'https://ustc.edu.cn/tzgg/jxltz.htm' }, @@ -27,7 +26,7 @@ const notice_type = { // } module.exports = async (ctx) => { - const type = ctx.params.type ?? 'gl'; + const type = ctx.req.param('type') ?? 'gl'; // 发起 HTTP GET 请求 const response = await got({ method: 'get', @@ -39,7 +38,7 @@ module.exports = async (ctx) => { url: notice_type[type].url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('table[portletmode=simpleList] > tbody > tr.light') .map(function () { const child = $(this).children(); @@ -59,7 +58,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 = $('div.v_news_content').html(); } catch { @@ -70,10 +69,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: notice_type[type].title, description: notice_type[type].title, link: notice_type[type].url, item: items, - }; + }); }; diff --git a/lib/v2/ustc/job.js b/lib/v2/ustc/job.js index d028623dc..ed01817bc 100644 --- a/lib/v2/ustc/job.js +++ b/lib/v2/ustc/job.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 titles = { RecruitList: '专场招聘会', @@ -9,7 +9,7 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'joblist2'; + const category = ctx.req.param('category') ?? 'joblist2'; const rand = 0.012_345_678_901_234_56; const apiRootUrl = 'http://ustc.ahbys.com'; @@ -185,9 +185,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${titles[category]} - 中国科学技术大学就业信息网`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/ustc/jwc.js b/lib/v2/ustc/jwc.js index 05632a506..7298e9515 100644 --- a/lib/v2/ustc/jwc.js +++ b/lib/v2/ustc/jwc.js @@ -1,13 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -// const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'windows', device: 'desktop' }); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const noticeUrl = 'https://www.teach.ustc.edu.cn/category/notice'; const noticeType = { teaching: '教学', info: '信息', exam: '考试', exchange: '交流' }; module.exports = async (ctx) => { - const type = ctx.params.type ?? ''; + const type = ctx.req.param('type') ?? ''; // 发起 HTTP GET 请求 const response = await got({ method: 'get', @@ -18,7 +17,7 @@ module.exports = async (ctx) => { url: `${noticeUrl}${type === '' ? '' : '-' + type}`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $(type === '' ? 'ul[class="article-list with-tag"] > li' : 'ul[class=article-list] > li') .map(function () { const child = $(this).children(); @@ -37,7 +36,7 @@ module.exports = async (ctx) => { .map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); // www.teach ?? pms.cmet ?? news item.description = $('main[class=single]').html() ?? $('.card-footer').html() ?? $('.v_news_content').html(); item.pubDate = $('li[class=meta-date]').text() ? timezone(parseDate($('li[class=meta-date]').text(), 'YYYY-MM-DD HH:mm'), +8) : item.pubDate; @@ -48,10 +47,10 @@ module.exports = async (ctx) => { const desc = type === '' ? '中国科学技术大学教务处 - 通知新闻' : `中国科学技术大学教务处 - ${noticeType[type]}类通知`; - ctx.state.data = { + ctx.set('data', { title: desc, description: desc, link: `${noticeUrl}${type === '' ? '' : '-' + type}`, item: items, - }; + }); }; diff --git a/lib/v2/ustc/sist.js b/lib/v2/ustc/sist.js index d0b013300..23ddcb12c 100644 --- a/lib/v2/ustc/sist.js +++ b/lib/v2/ustc/sist.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 map = new Map([ ['tzgg', { title: '中国科学技术大学信息科学技术学院 - 通知公告', id: '5142' }], @@ -11,7 +11,7 @@ const map = new Map([ const host = 'https://sist.ustc.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'tzgg'; + const type = ctx.req.param('type') ?? 'tzgg'; const info = map.get(type); if (!info) { throw new Error('invalid type'); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const id = info.id; const response = await got(`${host}/${id}/list.htm`); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('div[portletmode=simpleList]') .find('div.card') .toArray() @@ -42,7 +42,7 @@ module.exports = async (ctx) => { let desc = ''; try { const response = await got(item.link); - desc = cheerio.load(response.data)('div.wp_articlecontent').html(); + desc = load(response.data)('div.wp_articlecontent').html(); item.description = desc; } catch { // intranet only contents @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: info.title, link: `${host}/${id}/list.htm`, item: items, - }; + }); }; diff --git a/lib/v2/usts/jwch.js b/lib/v2/usts/jwch.js index 323bd6706..1e2f51ffe 100644 --- a/lib/v2/usts/jwch.js +++ b/lib/v2/usts/jwch.js @@ -1,16 +1,16 @@ -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 rootURL = 'http://jwch.usts.edu.cn/index'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'jwdt'; + const type = ctx.req.param('type') ?? 'jwdt'; const url = `${rootURL}/${type}.htm`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.mainWrap.cleafix > div > div.right.fr > div.local.fl > h3').text(); const list = $('div.list > ul > li') .map((_index, item) => ({ @@ -23,7 +23,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); let author = null; let pubDate = null; @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `苏州科技大学 教务处 - ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/utgd/category.js b/lib/v2/utgd/category.js index 2a9711951..8f4d4c7e1 100644 --- a/lib/v2/utgd/category.js +++ b/lib/v2/utgd/category.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const md = require('markdown-it')({ html: true, }); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'method'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const category = ctx.req.param('category') ?? 'method'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://utgd.net'; const apiUrl = `${rootUrl}/api/v2/pages/`; @@ -59,11 +59,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `UNTAG - ${data.category_name}`, link: currentUrl, item: items, image: data.category_image, description: data.category_description, - }; + }); }; diff --git a/lib/v2/utgd/timeline.js b/lib/v2/utgd/timeline.js index 1317efc90..3ffa413b3 100644 --- a/lib/v2/utgd/timeline.js +++ b/lib/v2/utgd/timeline.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const md = require('markdown-it')({ html: true, }); module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://utgd.net'; const apiUrl = `${rootUrl}/api/v2/timeline/?page=1&page_size=${limit}`; @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'UNTAG', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/utgd/topic.js b/lib/v2/utgd/topic.js index b625462b3..e416af791 100644 --- a/lib/v2/utgd/topic.js +++ b/lib/v2/utgd/topic.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const md = require('markdown-it')({ html: true, }); module.exports = async (ctx) => { - const topic = ctx.params.topic ?? '在线阅读专栏'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const topic = ctx.req.param('topic') ?? '在线阅读专栏'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://utgd.net'; const currentUrl = `${rootUrl}/topic`; @@ -62,10 +62,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `UNTAG - ${topicItem.title}`, link: currentUrl, item: items, description: topicItem.summary, - }; + }); }; diff --git a/lib/v2/uw/gix/news.js b/lib/v2/uw/gix/news.js index 8bec563bf..982b7b81e 100644 --- a/lib/v2/uw/gix/news.js +++ b/lib/v2/uw/gix/news.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const gixBaseURL = 'https://gixnetwork.org'; module.exports = async (ctx) => { - const category = ctx.params.category; + const category = ctx.req.param('category'); let newsURL = gixBaseURL + '/news'; let feedTitle = 'UW GIX News - '; @@ -27,7 +27,7 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $(listSelector) .map((index, item) => { @@ -48,7 +48,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const descriptionResponse = await got(item.link); - const content = cheerio.load(descriptionResponse.data); + const content = load(descriptionResponse.data); item.title = content('header.entry-header').find('h1').text(); item.description = content('div.entry-content').html(); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: feedTitle, link: newsURL, item: itemContent, - }; + }); }; diff --git a/lib/v2/v1tx/index.js b/lib/v2/v1tx/index.js index 6c31e7046..c8daababd 100644 --- a/lib/v2/v1tx/index.js +++ b/lib/v2/v1tx/index.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 baseUrl = 'https://www.v1tx.com'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = $('h2.entry-title a') .toArray() .map((item) => { @@ -21,7 +21,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); const data = JSON.parse($('script[type="application/ld+json"]').text()); @@ -45,11 +45,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link: baseUrl, image: `${baseUrl}/wp-content/uploads/2018/10/cropped-Favicon.webp`, item: items, - }; + }); }; diff --git a/lib/v2/v2ex/post.js b/lib/v2/v2ex/post.js index b933692cf..82079d6ce 100644 --- a/lib/v2/v2ex/post.js +++ b/lib/v2/v2ex/post.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 { postid } = ctx.params; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const topic = topicResponse[0]; - ctx.state.data = { + ctx.set('data', { title: `V2EX-${topic.title}`, link: pageUrl, description: topic.content, @@ -31,5 +31,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.created, 'X'), })), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/v2ex/tab.js b/lib/v2/v2ex/tab.js index 7371b288b..15c69d92d 100644 --- a/lib/v2/v2ex/tab.js +++ b/lib/v2/v2ex/tab.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 tabid = ctx.params.tabid; + const tabid = ctx.req.param('tabid'); const host = 'https://v2ex.com'; const pageUrl = `${host}/?tab=${tabid}`; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: pageUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const links = $('span.item_title > a') .toArray() - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10) .map((link) => `${host}${$(link).attr('href').replace(/#.*$/, '')}`); const items = await Promise.all( @@ -25,7 +25,7 @@ module.exports = async (ctx) => { url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('[id^="r_"]').toArray(); const replyContent = list .map((item) => { @@ -47,10 +47,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `V2EX-${tabid}`, link: pageUrl, description: `V2EX-tab-${tabid}`, item: items, - }; + }); }; diff --git a/lib/v2/v2ex/topics.js b/lib/v2/v2ex/topics.js index 28062030b..af06eadaa 100644 --- a/lib/v2/v2ex/topics.js +++ b/lib/v2/v2ex/topics.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 { type } = ctx.params; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { title = '最新主题'; } - ctx.state.data = { + ctx.set('data', { title: `V2EX-${title}`, link: 'https://www.v2ex.com/', description: `V2EX-${title}`, @@ -26,5 +26,5 @@ module.exports = async (ctx) => { author: item.member.username, comments: item.replies, })), - }; + }); }; diff --git a/lib/v2/v2rayshare/index.js b/lib/v2/v2rayshare/index.js index 305e15ba8..ab5e070d1 100644 --- a/lib/v2/v2rayshare/index.js +++ b/lib/v2/v2rayshare/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); // 自订的 got -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data: response } = await got('https://v2rayshare.com/wp-json/wp/v2/posts/?per_page=10'); @@ -13,10 +13,10 @@ module.exports = async (ctx) => { description: item.content.rendered, })); - ctx.state.data = { + ctx.set('data', { title: 'V2rayShare', link: 'https://v2rayshare.com/', description: '免费节点分享网站', item: items, - }; + }); }; diff --git a/lib/v2/vcb-s/category.js b/lib/v2/vcb-s/category.js index 9053cd9a3..78862e272 100644 --- a/lib/v2/vcb-s/category.js +++ b/lib/v2/vcb-s/category.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 rootUrl = 'https://vcb-s.com'; @@ -8,8 +8,8 @@ const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`; const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`; module.exports = async (ctx) => { - const cate = ctx.params.cate; - const limit = ctx.query.limit ?? 7; + const cate = ctx.req.param('cate'); + const limit = ctx.req.query('limit') ?? 7; const cateUrl = `${cateAPIUrl}?slug=${cate}`; const category = await ctx.cache.tryGet(cateUrl, async () => { @@ -43,9 +43,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${category.name} | VCB-Studio`, link: `${rootUrl}/archives/category/${category.slug}`, item: items, - }; + }); }; diff --git a/lib/v2/vcb-s/index.js b/lib/v2/vcb-s/index.js index 924b559d4..bc223b81b 100644 --- a/lib/v2/vcb-s/index.js +++ b/lib/v2/vcb-s/index.js @@ -1,13 +1,13 @@ -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 rootUrl = 'https://vcb-s.com'; const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`; module.exports = async (ctx) => { - const limit = ctx.query.limit ?? 7; + const limit = ctx.req.query('limit') ?? 7; const url = `${postsAPIUrl}?per_page=${limit}&_embed`; const response = await got.get(url); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'VCB-Studio - 大家一起实现的故事!', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/verfghbw/press.js b/lib/v2/verfghbw/press.js index 2453ec90e..929d9596c 100644 --- a/lib/v2/verfghbw/press.js +++ b/lib/v2/verfghbw/press.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 keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const rootUrl = 'https://verfgh.baden-wuerttemberg.de'; let request = { @@ -29,7 +29,7 @@ module.exports = async (ctx) => { const response = await got(request); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.pressListItem') .map((_, item) => { @@ -49,10 +49,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: 'Verfassungsgerichtshof Baden-Württemberg - Pressemitteilungen', link: request.url, description: 'Pressemitteilungen des Verfassungsgerichtshof für das Land Baden-Württemberg', item: list, - }; + }); }; diff --git a/lib/v2/vimeo/category.js b/lib/v2/vimeo/category.js index 37bc6f953..db78e6ffe 100644 --- a/lib/v2/vimeo/category.js +++ b/lib/v2/vimeo/category.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) => { @@ -42,11 +42,11 @@ module.exports = async (ctx) => { const response = await got({ url: feedlink + (staffpicks ? feedlinkstaffpicks : ''), }); - const description = cheerio.load(response.data); + const description = load(response.data); return description('meta[name="description"]').attr('content'); }); - ctx.state.data = { + ctx.set('data', { title: `${feedtitle} | Vimeo category`, link: feedlink + (staffpicks ? feedlinkstaffpicks : ''), description: feedDescription, @@ -60,5 +60,5 @@ module.exports = async (ctx) => { link: item.link, author: item.user.name, })), - }; + }); }; diff --git a/lib/v2/vimeo/channel.js b/lib/v2/vimeo/channel.js index 7a3332c0f..359a4ea70 100644 --- a/lib/v2/vimeo/channel.js +++ b/lib/v2/vimeo/channel.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 channel = ctx.params.channel; + const channel = ctx.req.param('channel'); const url = `https://vimeo.com/channels/${channel}/videos`; const page1 = await got({ method: 'get', @@ -25,7 +25,7 @@ module.exports = async (ctx) => { }) : ''; const pagedata = [...page1.data, ...page2.data]; - const $ = cheerio.load(pagedata); + const $ = load(pagedata); const list = $('ol li.clearfix'); const description = await Promise.all( @@ -42,13 +42,13 @@ module.exports = async (ctx) => { }, }); const articledata = response2.data; - const $2 = cheerio.load(articledata); + const $2 = load(articledata); $2('span').remove(); return $2.html(); }); }) ); - ctx.state.data = { + ctx.set('data', { title: `${channel} | Vimeo channel`, link: url, item: list @@ -68,5 +68,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/vimeo/usr-videos.js b/lib/v2/vimeo/usr-videos.js index 49449b6ee..c7d344205 100644 --- a/lib/v2/vimeo/usr-videos.js +++ b/lib/v2/vimeo/usr-videos.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'); module.exports = async (ctx) => { @@ -53,7 +53,7 @@ module.exports = async (ctx) => { }); const vimeojs = picked ? contentresponse.data.data[0].videos.data : contentresponse.data.data; - ctx.state.data = { + ctx.set('data', { title: `${profilesjs.name} ${catword ? cat.replace('|', '/') : ''} ${picked ? 'picks' : ''} | Vimeo `, link: profilesjs.link, description: profilesjs.bio, @@ -72,5 +72,5 @@ module.exports = async (ctx) => { author: profilesjs.name, }; }), - }; + }); }; diff --git a/lib/v2/vocus/publication.js b/lib/v2/vocus/publication.js index 603d5b110..46d67f497 100644 --- a/lib/v2/vocus/publication.js +++ b/lib/v2/vocus/publication.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { processList, ProcessFeed, baseUrl, apiUrl } = require('./utils'); module.exports = async (ctx) => { @@ -33,10 +33,10 @@ module.exports = async (ctx) => { const items = await ProcessFeed(list, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${publicationData.title} - 文章列表|方格子 vocus`, link, description: publicationData.abstract, item: items, - }; + }); }; diff --git a/lib/v2/vocus/user.js b/lib/v2/vocus/user.js index ddb82d9a5..f18fcf5e5 100644 --- a/lib/v2/vocus/user.js +++ b/lib/v2/vocus/user.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { processList, ProcessFeed, baseUrl, apiUrl } = require('./utils'); module.exports = async (ctx) => { @@ -33,11 +33,11 @@ module.exports = async (ctx) => { const items = await ProcessFeed(list, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${userData.fullname}|方格子 vocus`, link, description: userData.intro, image: userData.avatarUrl, item: items, - }; + }); }; diff --git a/lib/v2/vocus/utils.js b/lib/v2/vocus/utils.js index 4821a71e8..688b6e3eb 100644 --- a/lib/v2/vocus/utils.js +++ b/lib/v2/vocus/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'; const baseUrl = 'https://vocus.cc'; const apiUrl = 'https://api.vocus.cc'; @@ -27,7 +27,7 @@ const ProcessFeed = (list, tryGet) => }, }); - const $ = cheerio.load(article.content, null, false); + const $ = load(article.content, null, false); $('div.draft--imgNormal').each((_, elem) => (elem.name = 'figure')); $('.image-block-prerender').each((_, elem) => { diff --git a/lib/v2/vom/featured.js b/lib/v2/vom/featured.js index c1853dbe6..ccd8ca19a 100644 --- a/lib/v2/vom/featured.js +++ b/lib/v2/vom/featured.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 baseUrl = 'http://www.vom.mn'; module.exports = async (ctx) => { const { lang = 'mn' } = ctx.params; const { data: response } = await got(`${baseUrl}/${lang}`); - const $ = cheerio.load(response); + const $ = load(response); const items = [ ...new Set( @@ -26,7 +26,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.title = $('h2').text(); item.author = $('.uk-border-circle').next().text(); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('meta[name=description]').attr('content'), image: 'http://www.vom.mn/dist/images/vom-logo.png', item: items, - }; + }); }; diff --git a/lib/v2/wallhaven/index.js b/lib/v2/wallhaven/index.js index 4d0e68503..1c1edfd1b 100644 --- a/lib/v2/wallhaven/index.js +++ b/lib/v2/wallhaven/index.js @@ -1,19 +1,19 @@ -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 rootUrl = 'https://wallhaven.cc'; module.exports = async (ctx) => { - const filter = ctx.params.filter ?? 'latest'; - const needDetails = /t|y/i.test(ctx.params.needDetails ?? 'false'); + const filter = ctx.req.param('filter') ?? 'latest'; + const needDetails = /t|y/i.test(ctx.req.param('needDetails') ?? 'false'); const url = `${rootUrl}/${filter.indexOf('=') > 0 ? `search?${filter.replaceAll(/page=\d+/g, 'page=1')}` : filter}`; const response = await got.get(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('li > figure.thumb') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 24) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 24) .map((_, item) => ({ title: $(item).find('img.lazyload').attr('data-src').split('/').pop(), description: $(item) @@ -31,7 +31,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('meta[name="title"]').attr('content'); item.author = content('.username').text(); @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/wallpaperhub/index.js b/lib/v2/wallpaperhub/index.js index ea46a597a..ef32ac2e7 100644 --- a/lib/v2/wallpaperhub/index.js +++ b/lib/v2/wallpaperhub/index.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'); module.exports = async (ctx) => { @@ -20,9 +20,9 @@ module.exports = async (ctx) => { link: `https://wallpaperhub.app/wallpapers/${item.entity.id}`, })); - ctx.state.data = { + ctx.set('data', { title: 'WallpaperHub', link: 'https://wallpaperhub.app/wallpapers', item: list, - }; + }); }; diff --git a/lib/v2/wallstreetcn/hot.js b/lib/v2/wallstreetcn/hot.js index 20c8f06c9..1c2f2156f 100644 --- a/lib/v2/wallstreetcn/hot.js +++ b/lib/v2/wallstreetcn/hot.js @@ -1,8 +1,8 @@ -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 period = ctx.params.period ?? 'day'; + const period = ctx.req.param('period') ?? 'day'; const rootUrl = 'https://wallstreetcn.com'; const apiRootUrl = 'https://api-one-wscn.awtmt.com'; @@ -46,11 +46,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '华尔街见闻 - 最热文章', link: rootUrl, item: items, itunes_author: '华尔街见闻', image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg', - }; + }); }; diff --git a/lib/v2/wallstreetcn/live.js b/lib/v2/wallstreetcn/live.js index ee32c0c7a..31fdd5d09 100644 --- a/lib/v2/wallstreetcn/live.js +++ b/lib/v2/wallstreetcn/live.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 titles = { @@ -14,13 +14,13 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'global'; - const score = ctx.params.score ?? 1; + const category = ctx.req.param('category') ?? 'global'; + const score = ctx.req.param('score') ?? 1; const rootUrl = 'https://wallstreetcn.com'; const apiRootUrl = 'https://api-one.wallstcn.com'; const currentUrl = `${rootUrl}/live/${category}`; - const apiUrl = `${apiRootUrl}/apiv1/content/lives?channel=${category}-channel&limit=${ctx.query.limit ?? 100}`; + const apiUrl = `${apiRootUrl}/apiv1/content/lives?channel=${category}-channel&limit=${ctx.req.query('limit') ?? 100}`; const response = await got({ method: 'get', @@ -41,9 +41,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: `华尔街见闻 - 实时快讯 - ${titles[category]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/wallstreetcn/news.js b/lib/v2/wallstreetcn/news.js index e7f6e05ba..03491a642 100644 --- a/lib/v2/wallstreetcn/news.js +++ b/lib/v2/wallstreetcn/news.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 titles = { global: '最新', @@ -16,12 +16,12 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'global'; + const category = ctx.req.param('category') ?? 'global'; const rootUrl = 'https://wallstreetcn.com'; const apiRootUrl = 'https://api-one.wallstcn.com'; const currentUrl = `${rootUrl}/news/${category}`; - const apiUrl = `${apiRootUrl}/apiv1/content/information-flow?channel=${category}-channel&accept=article&limit=${ctx.query.limit ?? 25}`; + const apiUrl = `${apiRootUrl}/apiv1/content/information-flow?channel=${category}-channel&accept=article&limit=${ctx.req.query('limit') ?? 25}`; const response = await got({ method: 'get', @@ -66,11 +66,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `华尔街见闻 - 资讯 - ${titles[category]}`, link: currentUrl, item: items, itunes_author: '华尔街见闻', image: 'https://static-alpha-wscn.awtmt.com/wscn-static/qrcode.jpg', - }; + }); }; diff --git a/lib/v2/wanqu/news.js b/lib/v2/wanqu/news.js index a888970a3..759bd1762 100644 --- a/lib/v2/wanqu/news.js +++ b/lib/v2/wanqu/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://www.wanqu.co'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.mb-4') .toArray() @@ -19,9 +19,9 @@ module.exports = async (ctx) => { pubDate: parseDate($(item).find('i.text-helper-color.mr-4').text().trim()), })); - ctx.state.data = { + ctx.set('data', { title: '湾区日报 - 最新推荐', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/warthunder/news.js b/lib/v2/warthunder/news.js index c619c928d..64a16d881 100644 --- a/lib/v2/warthunder/news.js +++ b/lib/v2/warthunder/news.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const path = require('path'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const renderDescription = (desc) => art(path.join(__dirname, 'templates/description.art'), desc); module.exports = async (ctx) => { @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const response = await got(rootUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const pageFace = $('div.showcase__item.widget') .map((_, item) => { @@ -41,9 +41,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: 'War Thunder News', link: 'https://warthunder.com/en/news/', item: pageFace, - }; + }); }; diff --git a/lib/v2/wdc/download.js b/lib/v2/wdc/download.js index 109120451..61d30fcee 100644 --- a/lib/v2/wdc/download.js +++ b/lib/v2/wdc/download.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 ?? '279'; + const id = ctx.req.param('id') ?? '279'; const rootUrl = 'https://support.wdc.com'; const currentUrl = `${rootUrl}/downloads.aspx?p=${id}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const version = $('#WD_lblVersionSelected').text(); @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: `${$('#WD_lblSelectedName').text()} | WD Support`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/web3caff/index.js b/lib/v2/web3caff/index.js index df6603f9f..e1389e4aa 100644 --- a/lib/v2/web3caff/index.js +++ b/lib/v2/web3caff/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 params = ctx.path === '/' ? '' : ctx.path; @@ -13,12 +13,12 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list-grouped') .first() .find('.list-body') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10) .toArray() .map((item) => { item = $(item); @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.ss-inline-share-wrapper').remove(); @@ -55,9 +55,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/wechat/announce.js b/lib/v2/wechat/announce.js index eb9f6dedd..14c2ad43f 100644 --- a/lib/v2/wechat/announce.js +++ b/lib/v2/wechat/announce.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 { data: htmlString } = await got({ @@ -8,7 +8,7 @@ module.exports = async (ctx) => { url: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN', }); - const $ = cheerio.load(htmlString); + const $ = load(htmlString); const announceList = []; $('.mp_news_list > .mp_news_item').each(function () { @@ -25,9 +25,9 @@ module.exports = async (ctx) => { }); }); - ctx.state.data = { + ctx.set('data', { title: '微信公众平台-系统公告栏目', link: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN', item: announceList, - }; + }); }; diff --git a/lib/v2/wechat/ce.js b/lib/v2/wechat/ce.js index 0e2f5dbee..332b20047 100644 --- a/lib/v2/wechat/ce.js +++ b/lib/v2/wechat/ce.js @@ -1,8 +1,8 @@ const parser = require('@/utils/rss-parser'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { fixArticleContent } = require('@/utils/wechat-mp'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // any UA containing "RSS" can pass the check // mark the UA as a desktop UA with "(X11; Linux x86_64)" @@ -33,7 +33,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = fixArticleContent($('.post')); @@ -60,10 +60,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `微信公众号 - ${feed.title}`, link: `https://posts.careerengine.us/author/${id}/posts`, description: feed.description, item: items, - }; + }); }; diff --git a/lib/v2/wechat/data258.js b/lib/v2/wechat/data258.js index 74ba34e63..93c9cd754 100644 --- a/lib/v2/wechat/data258.js +++ b/lib/v2/wechat/data258.js @@ -1,10 +1,10 @@ -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 { finishArticleItem } = require('@/utils/wechat-mp'); const { RequestInProgressError } = require('@/errors'); -const wait = require('@/utils/wait'); +import wait from '@/utils/wait'; const parsePage = ($item, hyperlinkSelector, timeSelector) => { const hyperlink = $item.find(hyperlinkSelector); @@ -25,15 +25,15 @@ module.exports = async (ctx) => { } // !!! here no need to acquire the lock, because the MP/category page has no crawler detection !!! - const id = ctx.params.id; + const id = ctx.req.param('id'); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 5; const rootUrl = 'https://mp.data258.com'; const pageUrl = id ? `${rootUrl}/article/category/${id}` : rootUrl; const response = await got(pageUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('head title').text(); // title = title.endsWith('-微阅读') ? title.slice(0, title.length - 4) : title; @@ -88,7 +88,7 @@ module.exports = async (ctx) => { err = new got.RequestError(response.data, {}, response.request); return null; } - const $ = cheerio.load(response.data); + const $ = load(response.data); const jmpJS = $('script') .filter((_, e) => $(e).html().includes('location.href')) .html(); @@ -121,12 +121,12 @@ module.exports = async (ctx) => { await Promise.all(items.map((item) => finishArticleItem(item, !!categoryPage))); - ctx.state.data = { + ctx.set('data', { title, link: pageUrl, description, item: items, - }; + }); }; // TODO: login? the valid time for cookies seems to be short, and abusing account will probably get banned... diff --git a/lib/v2/wechat/ershcimi.js b/lib/v2/wechat/ershcimi.js index 0a48ad0b9..c556e872b 100644 --- a/lib/v2/wechat/ershcimi.js +++ b/lib/v2/wechat/ershcimi.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { finishArticleItem } = require('@/utils/wechat-mp'); -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 { id } = ctx.params; @@ -10,10 +10,10 @@ module.exports = async (ctx) => { const url = `${rootUrl}/a/${id}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.weui_media_box') .map((_, ele) => { - const $item = cheerio.load(ele); + const $item = load(ele); const link = $item('.weui_media_title a').attr('href'); return { title: $item('.weui_media_title a').text(), @@ -26,10 +26,10 @@ module.exports = async (ctx) => { await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title: `微信公众号 - ${$('span.name').text()}`, link: url, description: $('div.Profile-sideColumnItemValue').text(), item: items, - }; + }); }; diff --git a/lib/v2/wechat/feeddd.js b/lib/v2/wechat/feeddd.js index 1e7449a26..ffa7ec663 100644 --- a/lib/v2/wechat/feeddd.js +++ b/lib/v2/wechat/feeddd.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const baseUrl = 'https://feed.hamibot.com'; const apiUrl = `${baseUrl}/api/feeds/${id}/json`; @@ -29,19 +29,19 @@ module.exports = async (ctx) => { items = await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title: response.data.title, link: response.data.feed_url, description: response.data.title, item: items, allowEmpty: true, - }; + }); - ctx.state.json = { + ctx.set('json', { title: response.data.title, link: response.data.feed_url, image: 'https://mp.weixin.qq.com/favicon.ico', description: response.data.title, item: items, - }; + }); }; diff --git a/lib/v2/wechat/feeds.js b/lib/v2/wechat/feeds.js index 1b4f4572a..175d3d3cb 100644 --- a/lib/v2/wechat/feeds.js +++ b/lib/v2/wechat/feeds.js @@ -14,10 +14,10 @@ module.exports = async (ctx) => { })); await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title: feed.title, link, description: feed.description, item: items, - }; + }); }; diff --git a/lib/v2/wechat/mp.js b/lib/v2/wechat/mp.js index 02303ad92..50fa4cdbd 100755 --- a/lib/v2/wechat/mp.js +++ b/lib/v2/wechat/mp.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); const { finishArticleItem } = require('@/utils/wechat-mp'); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { url: `https://mp.weixin.qq.com/mp/homepage?__biz=${biz}${hidurl}${cidurl}`, }); const list = JSONresponse.data.appmsg_list; - const $ = cheerio.load(HTMLresponse.data); + const $ = load(HTMLresponse.data); // 标题,另外差一个菜单标题!求助 const mptitle = $('div.articles_header').find('a').text() + `|` + $('div.articles_header > h2.rich_media_title').text(); const articledata = await Promise.all( @@ -35,7 +35,7 @@ module.exports = async (ctx) => { return finishArticleItem(single); }) ); - ctx.state.data = { + ctx.set('data', { // 源标题,差一个cid相关的标题! title: mptitle, link: `https://mp.weixin.qq.com/mp/homepage?__biz=${biz}${hidurl}${cidurl}`, @@ -55,5 +55,5 @@ module.exports = async (ctx) => { author: articledata[index].author, pubDate: dayjs.unix(item.sendtime).format(), })), - }; + }); }; diff --git a/lib/v2/wechat/msgalbum.js b/lib/v2/wechat/msgalbum.js index a8df36819..4ddc5f23d 100644 --- a/lib/v2/wechat/msgalbum.js +++ b/lib/v2/wechat/msgalbum.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); const { finishArticleItem } = require('@/utils/wechat-mp'); @@ -11,7 +11,7 @@ module.exports = async (ctx) => { method: 'get', url: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`, }); - const $ = cheerio.load(HTMLresponse.data); + const $ = load(HTMLresponse.data); const list = $('li').get(); const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text(); const articledata = await Promise.all( @@ -26,7 +26,7 @@ module.exports = async (ctx) => { return finishArticleItem(single); }) ); - ctx.state.data = { + ctx.set('data', { title: mptitle, link: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`, item: list.map((item, index) => ({ @@ -37,5 +37,5 @@ module.exports = async (ctx) => { author: articledata[index].author, pubDate: dayjs.unix($(item).find('.js_article_create_time').text()).format(), })), - }; + }); }; diff --git a/lib/v2/wechat/sogou.js b/lib/v2/wechat/sogou.js index 582273a86..85d180f80 100644 --- a/lib/v2/wechat/sogou.js +++ b/lib/v2/wechat/sogou.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const host = 'https://weixin.sogou.com'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - const wechatId = ctx.params.id; + const wechatId = ctx.req.param('id'); let url = `${host}/weixin`; let response = await got({ method: 'get', @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }, }); - let $ = cheerio.load(response.data); + let $ = load(response.data); const href = $('a[uigs="account_article_0"]').attr('href'); const title = $('a[uigs="account_name_0"]').text(); url = `${host}${href}`; @@ -24,7 +24,7 @@ module.exports = async (ctx) => { Cookie: 'SNUID=78725B470A0EF2C3F97AA5EB0BBF95C1; ABTEST=0|1680917938|v1; SUID=8F7B1C682B83A20A000000006430C5B2; PHPSESSID=le2lak0vghad5c98ijd3t51ls4; IPLOC=USUS5', }, }); - $ = cheerio.load(response.data); + $ = load(response.data); const jsCode = $('script').text(); const regex = /url \+= '([^']+)';/g; const matches = []; @@ -49,10 +49,10 @@ module.exports = async (ctx) => { await finishArticleItem(item); - ctx.state.data = { + ctx.set('data', { title: `${title} 的微信公众号`, link: url, description: `${title} 的微信公众号`, item: [item], - }; + }); }; diff --git a/lib/v2/wechat/tgchannel.js b/lib/v2/wechat/tgchannel.js index 70b19b1f9..338add822 100644 --- a/lib/v2/wechat/tgchannel.js +++ b/lib/v2/wechat/tgchannel.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - const id = ctx.params.id; - const mpName = ctx.params.mpName ?? ''; - let searchQueryType = ctx.params.searchQueryType ?? '0'; + const id = ctx.req.param('id'); + const mpName = ctx.req.param('mpName') ?? ''; + let searchQueryType = ctx.req.param('searchQueryType') ?? '0'; if (searchQueryType !== '0' && searchQueryType !== '1' && searchQueryType !== '2') { searchQueryType = '0'; } @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const channelUrl = `https://t.me/s/${id}`; const searchQuery = mpName && searchQueryType ? (searchQueryType === 2 ? `?q=%23${mpName}` : `?q=${mpName}`) : ''; const { data } = await got.get(`${channelUrl}${searchQuery}`); - const $ = cheerio.load(data); + const $ = load(data); const list = $('.tgme_widget_message_wrap').slice(-20); const out = await Promise.all( @@ -137,10 +137,10 @@ module.exports = async (ctx) => { ); out.reverse(); - ctx.state.data = { + ctx.set('data', { title: mpName ?? $('.tgme_channel_info_header_title').text(), link: `https://t.me/s/${id}`, item: out.filter(Boolean), allowEmpty: !!mpName, - }; + }); }; diff --git a/lib/v2/wechat/uread.js b/lib/v2/wechat/uread.js index 7670bef3e..58c1a8d9d 100644 --- a/lib/v2/wechat/uread.js +++ b/lib/v2/wechat/uread.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 userid = ctx.params.userid; + const userid = ctx.req.param('userid'); const url = `http://119.29.146.143:8080/reading/subscription/account/recent?uid=${userid}`; const response = await got({ method: 'get', @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const data = response.data; const ProcessFeed = (data) => { - const $ = cheerio.load(data); + const $ = load(data); return $('.rich_media_content').html(); }; @@ -43,9 +43,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `优读 - ${userid}`, link: 'https://uread.ai/', item: items, - }; + }); }; diff --git a/lib/v2/wechat/wechat2rss.js b/lib/v2/wechat/wechat2rss.js index f81c3be54..81b27921e 100644 --- a/lib/v2/wechat/wechat2rss.js +++ b/lib/v2/wechat/wechat2rss.js @@ -1,5 +1,5 @@ const parser = require('@/utils/rss-parser'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { @@ -18,11 +18,11 @@ module.exports = async (ctx) => { items = await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title, link, description, image: image.url, item: items, - }; + }); }; diff --git a/lib/v2/wechat/wxnmh.js b/lib/v2/wechat/wxnmh.js index 0ceb9461b..79b519e63 100644 --- a/lib/v2/wechat/wxnmh.js +++ b/lib/v2/wechat/wxnmh.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const origin = 'https://www.wxnmh.com/'; - const response = await got.get(`${origin}user-${ctx.params.id}.htm`); - const $ = cheerio.load(response.data); + const response = await got.get(`${origin}user-${ctx.req.param('id')}.htm`); + const $ = load(response.data); const name = $('#body .col-lg-9 .card-block .col-md-9 h3').text().trim(); const description = $('#body .col-lg-9 .card-block .col-md-9 p').text().trim(); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const res = await got.get(item.link); - const $ = cheerio.load(res.data); + const $ = load(res.data); const desc = $('#js_content').html().replaceAll('data-src="http', 'src="http'); item.description = `
${desc}
`; item.pubDate = parseRelativeDate($('.date').text()); @@ -35,10 +35,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${name} - 微信公众号`, link: 'https://www.wxnmh.com/', description, item, - }; + }); }; diff --git a/lib/v2/weekendhk/posts.js b/lib/v2/weekendhk/posts.js index 3b9b9a5a5..5115efed4 100644 --- a/lib/v2/weekendhk/posts.js +++ b/lib/v2/weekendhk/posts.js @@ -1,11 +1,11 @@ -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://www.weekendhk.com'; const response = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ?? 100, + per_page: ctx.req.query('limit') ?? 100, }, }); @@ -18,12 +18,12 @@ module.exports = async (ctx) => { author: item.creator_editor, })); - ctx.state.data = { + ctx.set('data', { title: '新假期周刊', description: '新假期周刊網站為全港最強吃喝玩樂搵節目平台。網羅世界各地最詳盡旅遊潮流資訊;最新鮮熱辣本地飲食情報;最好玩周末玩樂節目,即時瞓身報導,全天候為你update。', link: baseUrl, language: 'zh-HK', image: `${baseUrl}/wp-content/themes/bucket/theme-content/images/196x196.png`, item: items, - }; + }); }; diff --git a/lib/v2/weibo/friends.js b/lib/v2/weibo/friends.js index 03d5a5794..e769a4c52 100644 --- a/lib/v2/weibo/friends.js +++ b/lib/v2/weibo/friends.js @@ -1,6 +1,6 @@ const querystring = require('querystring'); -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; const weiboUtils = require('./utils'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); @@ -12,11 +12,11 @@ module.exports = async (ctx) => { let displayVideo = '1'; let displayArticle = '0'; let displayComments = '0'; - if (ctx.params.routeParams) { - if (ctx.params.routeParams === '1' || ctx.params.routeParams === '0') { - displayVideo = ctx.params.routeParams; + if (ctx.req.param('routeParams')) { + if (ctx.req.param('routeParams') === '1' || ctx.req.param('routeParams') === '0') { + displayVideo = ctx.req.param('routeParams'); } else { - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0'; displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0'; displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0'; diff --git a/lib/v2/weibo/group.js b/lib/v2/weibo/group.js index 3a8e06907..bc33e3de5 100644 --- a/lib/v2/weibo/group.js +++ b/lib/v2/weibo/group.js @@ -1,6 +1,6 @@ const querystring = require('querystring'); -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; const weiboUtils = require('./utils'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); @@ -9,16 +9,16 @@ module.exports = async (ctx) => { throw new Error('Weibo Group Timeline is not available due to the absense of [Weibo Cookies]. Check relevant config tutorial'); } - const gid = ctx.params.gid; - const groupName = ctx.params.gname || '微博分组'; + const gid = ctx.req.param('gid'); + const groupName = ctx.req.param('gname') || '微博分组'; let displayVideo = '1'; let displayArticle = '0'; let displayComments = '0'; - if (ctx.params.routeParams) { - if (ctx.params.routeParams === '1' || ctx.params.routeParams === '0') { - displayVideo = ctx.params.routeParams; + if (ctx.req.param('routeParams')) { + if (ctx.req.param('routeParams') === '1' || ctx.req.param('routeParams') === '0') { + displayVideo = ctx.req.param('routeParams'); } else { - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0'; displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0'; displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0'; diff --git a/lib/v2/weibo/keyword.js b/lib/v2/weibo/keyword.js index 5ac90ce55..ba0ef5765 100644 --- a/lib/v2/weibo/keyword.js +++ b/lib/v2/weibo/keyword.js @@ -1,12 +1,12 @@ const querystring = require('querystring'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const weiboUtils = require('./utils'); -const timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; const { fallback, queryToBoolean } = require('@/utils/readable-social'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const data = await ctx.cache.tryGet( `weibo:keyword:${keyword}`, @@ -27,7 +27,7 @@ module.exports = async (ctx) => { false ); - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); ctx.state.data = weiboUtils.sinaimgTvax({ title: `又有人在微博提到${keyword}了`, link: `http://s.weibo.com/weibo/${encodeURIComponent(keyword)}&b=1&nodup=1`, diff --git a/lib/v2/weibo/oasis/user.js b/lib/v2/weibo/oasis/user.js index ede9373e4..476a63ba8 100644 --- a/lib/v2/weibo/oasis/user.js +++ b/lib/v2/weibo/oasis/user.js @@ -2,7 +2,7 @@ const buildData = require('@/utils/common-config'); const weiboUtils = require('../utils'); module.exports = async (ctx) => { - const userid = ctx.params.userid; + const userid = ctx.req.param('userid'); const link = `https://oasis.weibo.cn/v1/h5/share?uid=${userid}`; ctx.state.data = weiboUtils.sinaimgTvax( await buildData({ diff --git a/lib/v2/weibo/search/hot.js b/lib/v2/weibo/search/hot.js index f2c14be1d..521244741 100644 --- a/lib/v2/weibo/search/hot.js +++ b/lib/v2/weibo/search/hot.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { art } from '@/utils/render'; +import { load } from 'cheerio'; const path = require('path'); // const weiboUtils = require('../utils'); @@ -10,8 +10,8 @@ let wpic = 'false'; let fullpic = 'false'; module.exports = async (ctx) => { - wpic = ctx.query.pic ?? 'false'; - fullpic = ctx.query.fullpic ?? 'false'; + wpic = ctx.req.query('pic') ?? 'false'; + fullpic = ctx.req.query('fullpic') ?? 'false'; const { data: { data }, } = await got({ @@ -26,7 +26,7 @@ module.exports = async (ctx) => { }); let resultItems = null; - if (ctx.params.fulltext === 'fulltext') { + if (ctx.req.param('fulltext') === 'fulltext') { const cardslist = data.cards[0].card_group; // Topic List const tlist = cardslist.map((item) => { @@ -63,13 +63,13 @@ module.exports = async (ctx) => { } // Update ctx - ctx.state.data = { + ctx.set('data', { title: '微博热搜榜', link: 'https://s.weibo.com/top/summary?cate=realtimehot', description: '实时热点,每分钟更新一次', item: resultItems, - }; - // ctx.state.data = weiboUtils.sinaimgTvax(ctx.state.data); // no image in the route + }); + // ctx.set('data', weiboUtils.sinaimgTvax(ctx.state.data)); // no image in the route }; async function fetchContent(url) { @@ -97,7 +97,7 @@ async function fetchContent(url) { } function seekContent(clist) { - const $ = cheerio.load('
'); + const $ = load('
'); const stub = $('#wbcontent'); // To for..of per reviewers comment @@ -108,7 +108,7 @@ function seekContent(clist) { const index = tbpic.lastIndexOf('/'); const thumbfolder = tbpic.substring(0, index + 1); - const curcontent = cheerio.load(curitem.mblog.text); + const curcontent = load(curitem.mblog.text); if (wpic === 'true') { curcontent('img').attr('width', '1em').attr('height', '1em'); } else { diff --git a/lib/v2/weibo/super-index.js b/lib/v2/weibo/super-index.js index 98cb45977..6a8e2bff3 100644 --- a/lib/v2/weibo/super-index.js +++ b/lib/v2/weibo/super-index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const weiboUtils = require('./utils'); const queryString = require('query-string'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const id = ctx.params.id; - const type = ctx.params.type ?? 'feed'; + const id = ctx.req.param('id'); + const type = ctx.req.param('type') ?? 'feed'; const containerData = await ctx.cache.tryGet( `weibo:super_index:container:${id}:${type}`, diff --git a/lib/v2/weibo/timeline.js b/lib/v2/weibo/timeline.js index 8fca52340..7392b015a 100644 --- a/lib/v2/weibo/timeline.js +++ b/lib/v2/weibo/timeline.js @@ -1,14 +1,14 @@ const querystring = require('querystring'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const weiboUtils = require('./utils'); const { fallback, queryToBoolean } = require('@/utils/readable-social'); module.exports = async (ctx) => { - const uid = ctx.params.uid; - const feature = ctx.params.feature || 0; - const routeParams = ctx.params.routeParams || undefined; + const uid = ctx.req.param('uid'); + const feature = ctx.req.param('feature') || 0; + const routeParams = ctx.req.param('routeParams') || undefined; const token = await ctx.cache.get('weibotimelineuid' + uid, false); let displayVideo = '1'; let displayArticle = '0'; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { if (routeParams === '1' || routeParams === '0') { displayVideo = routeParams; } else { - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0'; displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0'; displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0'; @@ -127,8 +127,8 @@ module.exports = async (ctx) => { } else if (uid === '0' || ctx.querystring) { const { app_key = '', redirect_url = ctx.request.origin + '/weibo/timeline/0', app_secret = '' } = config.weibo; - const code = ctx.query.code; - const routeParams = ctx.query.state; + const code = ctx.req.query('code'); + const routeParams = ctx.req.query('state'); if (code) { const rep = await got.post(`https://api.weibo.com/oauth2/access_token?client_id=${app_key}&client_secret=${app_secret}&code=${code}&redirect_uri=${redirect_url}&grant_type=authorization_code`); const token = rep.data.access_token; diff --git a/lib/v2/weibo/user.js b/lib/v2/weibo/user.js index 2e4429b5c..9f5083fad 100644 --- a/lib/v2/weibo/user.js +++ b/lib/v2/weibo/user.js @@ -1,21 +1,21 @@ const querystring = require('query-string'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const weiboUtils = require('./utils'); -const config = require('@/config').value; -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import { config } from '@/config'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { fallback, queryToBoolean } = require('@/utils/readable-social'); module.exports = async (ctx) => { - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); let displayVideo = '1'; let displayArticle = '0'; let displayComments = '0'; - if (ctx.params.routeParams) { - if (ctx.params.routeParams === '1' || ctx.params.routeParams === '0') { - displayVideo = ctx.params.routeParams; + if (ctx.req.param('routeParams')) { + if (ctx.req.param('routeParams') === '1' || ctx.req.param('routeParams') === '0') { + displayVideo = ctx.req.param('routeParams'); } else { - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0'; displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0'; displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0'; diff --git a/lib/v2/weibo/utils.js b/lib/v2/weibo/utils.js index aa9c8fc50..022cabeec 100644 --- a/lib/v2/weibo/utils.js +++ b/lib/v2/weibo/utils.js @@ -1,6 +1,6 @@ const querystring = require('querystring'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { fallback, queryToBoolean, queryToInteger } = require('@/utils/readable-social'); const weiboUtils = { @@ -18,7 +18,7 @@ const weiboUtils = { // `uid = undefined` to explicitly mark it as optional, avoiding IDEs prompting warnings // undefined and strings like "1" is also safely parsed, so no if branch is needed - const routeParams = querystring.parse(ctx.params.routeParams); + const routeParams = querystring.parse(ctx.req.param('routeParams')); const mergedParams = { readable: fallback(params.readable, queryToBoolean(routeParams.readable), false), @@ -364,7 +364,7 @@ const weiboUtils = { html += '
'; // 分割线 // 正文处理,加入一些在微博文章页的 CSS 中定义的不可或缺的样式 - const $ = cheerio.load(content); + const $ = load(content); $('p').each((_, elem) => { elem = $(elem); let style = elem.attr('style') || ''; diff --git a/lib/v2/wenku8/chapter.js b/lib/v2/wenku8/chapter.js index 1d8f5d170..b86892304 100644 --- a/lib/v2/wenku8/chapter.js +++ b/lib/v2/wenku8/chapter.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const index = Number.parseInt(id / 1000); const response = await got({ @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const responseHtml = iconv.decode(response.data, 'gbk'); - const $ = cheerio.load(responseHtml); + const $ = load(responseHtml); const name = $('#title').text(); @@ -27,9 +27,9 @@ module.exports = async (ctx) => { }); }); - ctx.state.data = { + ctx.set('data', { title: `轻小说文库 ${name}`, link: `https://www.wenku8.net/book/${id}.htm`, item: chapter_item, - }; + }); }; diff --git a/lib/v2/wenku8/index.js b/lib/v2/wenku8/index.js index 572ecec76..16324a1de 100644 --- a/lib/v2/wenku8/index.js +++ b/lib/v2/wenku8/index.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const config = require('@/config').value; +import { config } from '@/config'; const cateUrlMap = { lastupdate: 'https://www.wenku8.net/modules/article/toplist.php?sort=lastupdate', @@ -22,7 +22,7 @@ const cateTitleMap = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'lastupdate'; + const category = ctx.req.param('category') ?? 'lastupdate'; const response = await got({ method: 'get', url: cateUrlMap[category], @@ -35,7 +35,7 @@ module.exports = async (ctx) => { const responseHtml = iconv.decode(response.data, 'gbk'); - const $ = cheerio.load(responseHtml); + const $ = load(responseHtml); const items = $('td > div') .map((_, item) => ({ title: $(item).find('b > a').text(), @@ -44,9 +44,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: `轻小说文库 - ${cateTitleMap[category]}`, link: cateUrlMap[category], item: items, - }; + }); }; diff --git a/lib/v2/wenku8/volume.js b/lib/v2/wenku8/volume.js index 2380b6b58..797050893 100644 --- a/lib/v2/wenku8/volume.js +++ b/lib/v2/wenku8/volume.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); module.exports = async (ctx) => { - const aid = ctx.params.id; + const aid = ctx.req.param('id'); const novel_url = `https://www.wenku8.net/novel/${Number.parseInt(aid / 1000)}/${aid}/index.htm`; - const $ = cheerio.load(await get(novel_url)); + const $ = load(await get(novel_url)); const novel_name = $('#title').text(); @@ -27,11 +27,11 @@ module.exports = async (ctx) => { })); }); - ctx.state.data = { + ctx.set('data', { title: `轻小说文库 ${novel_name} 最新卷`, link: novel_url, item: item_list, - }; + }); }; const get = async (url) => { diff --git a/lib/v2/wfdf/news.js b/lib/v2/wfdf/news.js index 44eeb328e..384fa84e3 100644 --- a/lib/v2/wfdf/news.js +++ b/lib/v2/wfdf/news.js @@ -1,11 +1,11 @@ -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://wfdf.sport'; const { data: response } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ?? 100, + per_page: ctx.req.query('limit') ?? 100, _embed: 1, }, }); @@ -19,11 +19,11 @@ module.exports = async (ctx) => { author: item._embedded.author[0].name, })); - ctx.state.data = { + ctx.set('data', { title: 'WFDF News', link: `${baseUrl}/news/`, image: `${baseUrl}/favicon.ico`, description: 'WFDF 新闻', item: items, - }; + }); }; diff --git a/lib/v2/wfu/jwc.js b/lib/v2/wfu/jwc.js index 26829bf29..d6740fb4a 100644 --- a/lib/v2/wfu/jwc.js +++ b/lib/v2/wfu/jwc.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; // 参考 whu/news 武汉大学页面写成 @@ -14,7 +14,7 @@ module.exports = async (ctx) => { Referer: 'https://jwc.wfu.edu.cn/', }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 获取当前页面的 list const list = $('ul.wp_article_list>li'); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { // 遍历每一篇文章 list .map((item) => { - const $ = cheerio.load(list[item]); // 将列表项加载成 html + const $ = load(list[item]); // 将列表项加载成 html const $article_title = $('div.pr_fields>span.Article_Title>a'); const $item_url = 'https://jwc.wfu.edu.cn/' + $article_title.attr('href'); // 获取 每一项的url const $title = $article_title.text(); // 获取每个的标题 @@ -45,10 +45,10 @@ module.exports = async (ctx) => { .get() ); - ctx.state.data = { + ctx.set('data', { title: sizeTitle, link: baseUrl, description: '潍坊学院教务处通知(通知为文件需下载)', item: result, - }; + }); }; diff --git a/lib/v2/wfu/news.js b/lib/v2/wfu/news.js index e650b03a1..5d4f0d7ac 100644 --- a/lib/v2/wfu/news.js +++ b/lib/v2/wfu/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'; // 参考 whu/news 武汉大学页面写成 @@ -15,7 +15,7 @@ const catrgoryMap = { }; // 专门定义一个function用于加载文章内容 -async function load(link) { +async function loadContent(link) { let description = ''; let response; @@ -36,7 +36,7 @@ async function load(link) { return { description }; } // 加载文章内容 - const $ = cheerio.load(response.data); + const $ = load(response.data); // 提取文章内容 description = $('div.wp_articlecontent').html(); @@ -46,7 +46,7 @@ async function load(link) { module.exports = async (ctx) => { // 默认 潍院要闻 然后获取列表页面 - const type = ctx.params.type ?? 'wyyw'; + const type = ctx.req.param('type') ?? 'wyyw'; const listPageUrl = baseUrl + catrgoryMap[type][0]; const response = await got({ method: 'get', @@ -55,7 +55,7 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 获取当前页面的 list const list = $('div[frag=窗口1]>ul>li'); @@ -64,7 +64,7 @@ module.exports = async (ctx) => { // 遍历每一篇文章 list .map(async (item) => { - const $ = cheerio.load(list[item]); // 将列表项加载成 html + const $ = load(list[item]); // 将列表项加载成 html const $item_url = 'https://www.wfu.edu.cn' + $('a').attr('href'); // 获取 每一项的url const $title = $('a>div.txt>h1').text(); // 获取每个的标题 const $pubdate = timezone(parseDate($('a>div.txt>span.date').text().split(':')[1]), +8); // 获取发布时间 @@ -80,17 +80,17 @@ module.exports = async (ctx) => { // 对于列表的每一项, 单独获取 时间与详细内容 // eslint-disable-next-line no-return-await - const other = await ctx.cache.tryGet($item_url, () => load($item_url)); + const other = await ctx.cache.tryGet($item_url, () => loadContent($item_url)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; }) .get() ); - ctx.state.data = { + ctx.set('data', { title: catrgoryMap[type][1] + sizeTitle, link: baseUrl, description: catrgoryMap[type][1] + sizeTitle, item: result, - }; + }); }; diff --git a/lib/v2/whitehouse/briefing-room.js b/lib/v2/whitehouse/briefing-room.js index 6239a6145..04e99a6bf 100644 --- a/lib/v2/whitehouse/briefing-room.js +++ b/lib/v2/whitehouse/briefing-room.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://www.whitehouse.gov'; const currentUrl = `${rootUrl}/briefing-room/${category}`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news-item__title') .slice(0, 10) @@ -32,7 +32,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.body-content').html(); item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content')); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/whitehouse/ostp.js b/lib/v2/whitehouse/ostp.js index b41d3b37a..0bcc77b71 100644 --- a/lib/v2/whitehouse/ostp.js +++ b/lib/v2/whitehouse/ostp.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://www.whitehouse.gov'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news-item__title') .slice(0, 10) @@ -30,7 +30,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.body-content').html(); item.pubDate = parseDate(content('time.published').attr('datetime')); @@ -41,10 +41,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Whitehouse OSTP', link: currentUrl, description: 'Whitehouse Office of Science and Technology Policy', item: items, - }; + }); }; diff --git a/lib/v2/who/news-room.js b/lib/v2/who/news-room.js index 2140003ee..c9b30136e 100644 --- a/lib/v2/who/news-room.js +++ b/lib/v2/who/news-room.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 category = ctx.params.category ?? 'feature-stories'; - const language = ctx.params.language ?? ''; + const category = ctx.req.param('category') ?? 'feature-stories'; + const language = ctx.req.param('language') ?? ''; const rootUrl = 'https://www.who.int'; const currentUrl = `${rootUrl}/${language ? `${language}/` : ''}news-room/${category}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let list = $('.list-view--item a'); @@ -57,7 +57,7 @@ module.exports = async (ctx) => { item.description = matches[2]; item.pubDate = parseDate(matches[3]); } else { - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.sf-content-block').html(); } @@ -67,9 +67,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('meta[property="og:title"]').attr('content')} - WHO`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/who/news.js b/lib/v2/who/news.js index 309a33cc9..740a1d374 100644 --- a/lib/v2/who/news.js +++ b/lib/v2/who/news.js @@ -1,8 +1,8 @@ -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 language = ctx.params.language ?? 'en'; + const language = ctx.req.param('language') ?? 'en'; const rootUrl = 'https://www.who.int'; const currentUrl = `${rootUrl}/${language === 'en' ? '' : `${language}/`}news`; @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'News - WHO', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/who/speeches.js b/lib/v2/who/speeches.js index 268ea9892..7a575fc54 100644 --- a/lib/v2/who/speeches.js +++ b/lib/v2/who/speeches.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 language = ctx.params.language || 'en'; + const language = ctx.req.param('language') || 'en'; const rootUrl = 'https://www.who.int'; const currentUrl = `${rootUrl}/${language === 'en' ? '' : `${language}/`}director-general/speeches`; @@ -28,7 +28,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.sf-detail-body-wrapper').html(); @@ -37,9 +37,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Speeches - WHO', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/whu/cs.js b/lib/v2/whu/cs.js index acd9d8a0f..ef5d4a4d4 100644 --- a/lib/v2/whu/cs.js +++ b/lib/v2/whu/cs.js @@ -1,12 +1,12 @@ -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'; const baseUrl = 'https://cs.whu.edu.cn'; module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); let link; switch (type) { @@ -35,7 +35,7 @@ module.exports = async (ctx) => { } const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.study ul li') .toArray() @@ -52,7 +52,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); if ($('.prompt').length) { item.description = $('.prompt').html(); @@ -78,9 +78,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), link, item: items, - }; + }); }; diff --git a/lib/v2/whu/gs/index.js b/lib/v2/whu/gs/index.js index 5680fd95a..eed0332e6 100644 --- a/lib/v2/whu/gs/index.js +++ b/lib/v2/whu/gs/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 gsIndexMap = new Map([ [0, 'xwdt.htm'], @@ -16,10 +16,10 @@ const gsIndexMap = new Map([ module.exports = async (ctx) => { const host = 'https://gs.whu.edu.cn/'; - const type = (ctx.params && Number.parseInt(ctx.params.type)) || 0; + const type = (ctx.params && Number.parseInt(ctx.req.param('type'))) || 0; const response = await got(host + gsIndexMap.get(type)); - const $ = cheerio.load(response.data); + const $ = load(response.data); const feed_title = $('div.location a') .slice(-2) .map((index, element) => $(element).text()) @@ -43,7 +43,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const detail = await got(item.link); - const content = cheerio.load(detail.data); + const content = load(detail.data); content('input').remove(); content('h1').remove(); @@ -76,10 +76,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `武汉大学研究生院 - ${feed_title}`, link: host + gsIndexMap.get(type), description: '武大研究生院', item: items, - }; + }); }; diff --git a/lib/v2/whu/hyxt.js b/lib/v2/whu/hyxt.js index a7992ce20..b37ef4fb1 100644 --- a/lib/v2/whu/hyxt.js +++ b/lib/v2/whu/hyxt.js @@ -1,19 +1,19 @@ -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 { domain, processMeta, getMeta, processItems } = require('./util'); module.exports = async (ctx) => { const { category = 'tzgg' } = 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 rootUrl = `https://hyxt.${domain}`; const currentUrl = new URL(`${category}.htm`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('tr.content-title') .slice(0, limit) @@ -36,7 +36,7 @@ module.exports = async (ctx) => { const siteName = getMeta(meta, 'SiteName'); const columnName = getMeta(meta, 'ColumnName'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${siteName} - ${columnName}`, link: currentUrl, @@ -46,5 +46,5 @@ module.exports = async (ctx) => { subtitle: columnName, author: siteName, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/whu/news.js b/lib/v2/whu/news.js index 45a0a9c8d..c428d08e1 100644 --- a/lib/v2/whu/news.js +++ b/lib/v2/whu/news.js @@ -1,21 +1,21 @@ -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 { domain, processMeta, getMeta, processItems } = require('./util'); module.exports = async (ctx) => { const { category = 'wdzx/wdyw' } = 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://news.${domain}`; const currentUrl = new URL(`${category}.htm`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); // The elements where the information is located vary with the category. // 武大资讯 https://news.whu.edu.cn/wdzx/wdyw.htm => ul.wdzxList li a[title] @@ -54,7 +54,7 @@ module.exports = async (ctx) => { const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${siteName} - ${columnName}`, link: currentUrl, @@ -66,5 +66,5 @@ module.exports = async (ctx) => { subtitle: columnName, author: siteName, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/whu/util.js b/lib/v2/whu/util.js index 573234268..64e66ff18 100644 --- a/lib/v2/whu/util.js +++ b/lib/v2/whu/util.js @@ -1,8 +1,8 @@ -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'); const domain = 'whu.edu.cn'; @@ -42,7 +42,7 @@ const getItemDetail = async (item, rootUrl) => { try { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); // Missing the `src` properties for the images. // The `src` property should be replaced with the value of `orisrc` to show the image. diff --git a/lib/v2/wikinews/index.js b/lib/v2/wikinews/index.js index 323c06c22..4e2914b4e 100644 --- a/lib/v2/wikinews/index.js +++ b/lib/v2/wikinews/index.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://zh.wikinews.org/wiki/Special:%E6%96%B0%E9%97%BB%E8%AE%A2%E9%98%85'; -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 urls = $('url') .toArray() .map((item) => { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { urls.map((item) => ctx.cache.tryGet(item.link, async () => { const resp = await got(item.link); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); item.description = $('#bodyContent').html(); return item; @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '最新新闻 - 维基新闻', link: currentURL, item: items, - }; + }); }; diff --git a/lib/v2/winstall/update.js b/lib/v2/winstall/update.js index da1247dcc..079c535e1 100644 --- a/lib/v2/winstall/update.js +++ b/lib/v2/winstall/update.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { 'winget:buildId', async () => { const { data } = await got(baseUrl); - const $ = cheerio.load(data); + const $ = load(data); return JSON.parse($('#__NEXT_DATA__').text()).buildId; }, @@ -32,12 +32,12 @@ module.exports = async (ctx) => { guid: `winstall:${appId}:${item.version}`, })); - ctx.state.data = { + ctx.set('data', { title: `${app.name} - winstall`, description: app.desc, link: `${baseUrl}/apps/${appId}`, image: `https://api.winstall.app/icons/next/${appId}.webp`, language: 'en', item: items, - }; + }); }; diff --git a/lib/v2/wise/pair.js b/lib/v2/wise/pair.js index d3a78c8f2..758f81249 100644 --- a/lib/v2/wise/pair.js +++ b/lib/v2/wise/pair.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); const customParseFormat = require('dayjs/plugin/customParseFormat'); dayjs.extend(customParseFormat); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const renderDesc = (content) => art(path.join(__dirname, 'templates/description.art'), content); @@ -12,11 +12,11 @@ module.exports = async (ctx) => { const dayBefore = yesterday.subtract(1, 'day').format('YYYY-MM-DD'); yesterday = yesterday.format('YYYY-MM-DD'); - const source = ctx.params.source.toUpperCase(); - const target = ctx.params.target.toUpperCase(); + const source = ctx.req.param('source').toUpperCase(); + const target = ctx.req.param('target').toUpperCase(); const link = 'https://wise.com/tools/exchange-rate-alerts/'; - const guid = `wise:rates:${ctx.params.source}-${ctx.params.target}-${yesterday}`; + const guid = `wise:rates:${ctx.req.param('source')}-${ctx.req.param('target')}-${yesterday}`; const single = await ctx.cache.tryGet(guid, async () => { const { data } = await got('https://wise.com/rates/history', { searchParams: { @@ -56,10 +56,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${source} to ${target} by Wise`, link, description: `Exchange Rate from Wise`, item: [single], - }; + }); }; diff --git a/lib/v2/wizfile/index.js b/lib/v2/wizfile/index.js index b653bcd32..d709e50e2 100644 --- a/lib/v2/wizfile/index.js +++ b/lib/v2/wizfile/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 rootUrl = 'https://antibody-software.com'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/wizfile/download`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('section.blog-section > div > div > div > h4') .map((_, item) => { @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `WziFile - 更新日志`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/wmc-bj/publish.js b/lib/v2/wmc-bj/publish.js index 29b0a2a5b..4ae2bc1ce 100644 --- a/lib/v2/wmc-bj/publish.js +++ b/lib/v2/wmc-bj/publish.js @@ -1,8 +1,8 @@ -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) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const title = $('title').text(); const author = 'World Meteorological Centre BeiJing'; @@ -43,7 +43,7 @@ module.exports = async (ctx) => { const image = 'http://image.nmc.cn/static/wmc/img/logo-cma.png'; const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -54,5 +54,5 @@ module.exports = async (ctx) => { subtitle: categories.join(' > '), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/wnacg/index.js b/lib/v2/wnacg/index.js index 3cc6cc058..d0b9f1c7c 100644 --- a/lib/v2/wnacg/index.js +++ b/lib/v2/wnacg/index.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'); const categories = { @@ -33,7 +33,7 @@ module.exports = async (ctx) => { const url = `${baseUrl}/albums${cid ? `-index-cate-${cid}` : ''}${tag ? `-index-tag-${tag}` : ''}.html`; const { data } = await got(url); - const $ = cheerio.load(data); + const $ = load(data); const list = $('.gallary_item') .toArray() @@ -63,7 +63,7 @@ module.exports = async (ctx) => { referer: encodeURI(url), }, }); - let $ = cheerio.load(descRes); + let $ = load(descRes); const author = $('.uwuinfo p').first().text(); const category = $('.tagshow') .toArray() @@ -76,7 +76,7 @@ module.exports = async (ctx) => { referer: `${baseUrl}/photos-slide-aid-${item.aid}.html`, }, }); - $ = cheerio.load(data); + $ = load(data); const imgListMatch = $('script') .text() @@ -96,9 +96,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/worldjournal/index.js b/lib/v2/worldjournal/index.js index ae1f68f63..711595088 100644 --- a/lib/v2/worldjournal/index.js +++ b/lib/v2/worldjournal/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 baseUrl = 'https://www.worldjournal.com'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const { path = 'cate/breaking' } = ctx.params; const { data: response } = await got(`${baseUrl}/wj/${path}`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.subcate-list__wrapper .subcate-list__link__text') .toArray() @@ -28,7 +28,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); $('[id^=div-gpt-ad], [class^=udn-ads-], .keywords, .next-page, .udn-ads, .article-content__ads--bd').remove(); @@ -50,11 +50,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), image: 'https://www.worldjournal.com/static/img/icons/icon-144x144.png', link: `${baseUrl}/wj/${path}`, item: items, - }; + }); }; diff --git a/lib/v2/woshipm/popular.js b/lib/v2/woshipm/popular.js index 229acdc33..79c48a04d 100644 --- a/lib/v2/woshipm/popular.js +++ b/lib/v2/woshipm/popular.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 { baseUrl, parseArticle } = require('./utils'); const rangeMap = { @@ -25,9 +25,9 @@ module.exports = async (ctx) => { const result = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `热门文章 - ${rangeMap[range]} - 人人都是产品经理`, link: baseUrl, item: result, - }; + }); }; diff --git a/lib/v2/woshipm/user-article.js b/lib/v2/woshipm/user-article.js index c20087763..a689ae2e4 100644 --- a/lib/v2/woshipm/user-article.js +++ b/lib/v2/woshipm/user-article.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'; const { baseUrl, parseArticle } = require('./utils'); module.exports = async (ctx) => { const { id } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 12; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 12; const link = `${baseUrl}/u/${id}`; const data = await got(link).then((res) => res.data); - const $ = cheerio.load(data); + const $ = load(data); const name = $('.author--meta .name').text(); const list = $('.post--card') @@ -27,11 +27,11 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `${name}的文章-人人都是产品经理`, description: $('.author--meta .description').text(), image: $('.author--meta .avatar').attr('src').split('!')[0], link, item: items, - }; + }); }; diff --git a/lib/v2/woshipm/utils.js b/lib/v2/woshipm/utils.js index 491c67885..b0234fb29 100644 --- a/lib/v2/woshipm/utils.js +++ b/lib/v2/woshipm/utils.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const baseUrl = 'https://www.woshipm.com'; @@ -7,7 +7,7 @@ const parseArticle = (item, tryGet) => tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.support-author').remove(); item.description = $('.article--content').html(); diff --git a/lib/v2/woshipm/wen.js b/lib/v2/woshipm/wen.js index 0b1347f51..0cf1f6a79 100644 --- a/lib/v2/woshipm/wen.js +++ b/lib/v2/woshipm/wen.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const baseUrl = 'https://wen.woshipm.com'; -const { parseRelativeDate } = require('@/utils/parse-date'); +import { parseRelativeDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const response = await got(`${baseUrl}/m/main/indexNewData.html`); - const $ = cheerio.load(response.data); + const $ = load(response.data); const postList = $('.article-list-item') .toArray() .map((item) => { @@ -21,16 +21,16 @@ module.exports = async (ctx) => { postList.map((item) => ctx.cache.tryGet(item.link, async () => { const temp = await got(item.link); - const $ = cheerio.load(temp.data); + const $ = load(temp.data); item.description = $('.wt-desc').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: '天天问 - 人人都是产品经理', link: baseUrl, item: result, - }; + }); }; diff --git a/lib/v2/wsj/news.js b/lib/v2/wsj/news.js index 6ec68335d..151fbbe2c 100644 --- a/lib/v2/wsj/news.js +++ b/lib/v2/wsj/news.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { asyncPoolAll, parseArticle } = require('./utils'); const hostMap = { 'en-us': 'https://www.wsj.com', @@ -7,8 +7,8 @@ const hostMap = { 'zh-tw': 'https://cn.wsj.com/zh-hant', }; module.exports = async (ctx) => { - const lang = ctx.params.lang; - const category = ctx.params.category || ''; + const lang = ctx.req.param('lang'); + const category = ctx.req.param('category') || ''; const host = hostMap[lang]; let subTitle = ` - ${lang.toUpperCase()}`; let url = host; @@ -21,7 +21,7 @@ module.exports = async (ctx) => { url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const contents = $('script:contains("window.__STATE__")').text(); const data = JSON.parse(contents.match(/{.*}/)[0]).data; const filteredKeys = Object.entries(data) @@ -42,10 +42,10 @@ module.exports = async (ctx) => { }); const items = await asyncPoolAll(10, list, (item) => parseArticle(item, ctx)); - ctx.state.data = { + ctx.set('data', { title: `WSJ${subTitle}`, link: url, description: `WSJ${subTitle}`, item: items, - }; + }); }; diff --git a/lib/v2/wsj/utils.js b/lib/v2/wsj/utils.js index b1220e5e8..fe4675d34 100644 --- a/lib/v2/wsj/utils.js +++ b/lib/v2/wsj/utils.js @@ -1,10 +1,12 @@ const asyncPool = require('tiny-async-pool'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); -const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' }); +import randUserAgent from '@/utils/rand-user-agent'; + +const UA = randUserAgent({ browser: 'chrome', os: 'android', device: 'mobile' }); // const chromeMobileUserAgent = 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 Mobile Safari/537.36'; const parseArticle = (item, ctx) => @@ -19,7 +21,7 @@ const parseArticle = (item, ctx) => }, }); const html = response.data; - const $ = cheerio.load(html); + const $ = load(html); // Summary const summary = $('head > meta[name="description"]').attr('content'); diff --git a/lib/v2/wsyu/news.js b/lib/v2/wsyu/news.js index 9f00c09e3..8e12aeaca 100644 --- a/lib/v2/wsyu/news.js +++ b/lib/v2/wsyu/news.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = require('url'); const baseUrl = 'http://www.wsyu.edu.cn'; @@ -20,7 +20,7 @@ const typeMap = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 'xxyw'; + const type = ctx.req.param('type') || 'xxyw'; const link = baseUrl + typeMap[type].url; const response = await got({ method: 'get', @@ -29,7 +29,7 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const urlList = $('.mainContent li') .slice(0, 10) @@ -55,7 +55,7 @@ module.exports = async (ctx) => { return JSON.parse(cache); } const response = await got.get(itemUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.content .photos').remove(); const single = { title: titleList[index], @@ -77,9 +77,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '武昌首义学院-' + typeMap[type].name, link, item: out, - }; + }); }; diff --git a/lib/v2/wtu/index.js b/lib/v2/wtu/index.js index f804df6f6..c974d68a0 100644 --- a/lib/v2/wtu/index.js +++ b/lib/v2/wtu/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { const apiUrl = 'https://ehall.wtu.edu.cn/wtu/api/queryBulletinListByConditional.do?pageNum=1&pageSize=20&columnId='; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { [3, { title: '科研动态', type: '7', id: '48e8abfb983b4e4486b69feacad1dc1b' }], ]); - const typeInt = Number.parseInt(ctx.params.type); + const typeInt = Number.parseInt(ctx.req.param('type')); const value = map.get(typeInt); const title = value.title; const columnId = value.id; @@ -23,7 +23,7 @@ module.exports = async (ctx) => { }); const resJson = res.data.bulletinList; - ctx.state.data = { + ctx.set('data', { title: `${title} - 武汉纺织大学信息门户`, link: `${listUrl}${type}`, description: `${title} - 武汉纺织大学信息门户`, @@ -33,5 +33,5 @@ module.exports = async (ctx) => { link: item.GOTO_URL ?? `${psgUrl}type=${type}?bulletinId=${item.WID}`, author: item.PUBLISH_USER_DEPT_NAME, })), - }; + }); }; diff --git a/lib/v2/wtu/job.js b/lib/v2/wtu/job.js index 90cd9b41c..1c30432c4 100644 --- a/lib/v2/wtu/job.js +++ b/lib/v2/wtu/job.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const zlib = require('zlib'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const baseUrl = 'https://wtu.91wllm.com/'; @@ -35,7 +35,7 @@ function decodeData(str) { module.exports = async (ctx) => { // 获取参数 type - const type = ctx.params.type; + const type = ctx.req.param('type'); const mapItem = typeMap.get(type); const msgTitle = `${mapItem.title} - 武汉纺织大学就业信息`; const link = mapItem.url; @@ -45,7 +45,7 @@ module.exports = async (ctx) => { // 解压缩列表数据 const listStr = decodeData(resp.data); // 解析列表数据 - const $ = cheerio.load(listStr); + const $ = load(listStr); const list = $('.newsList') .toArray() .map((item) => { @@ -71,10 +71,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: msgTitle, link, description: msgTitle, item: items, - }; + }); }; diff --git a/lib/v2/wyzxwk/article.js b/lib/v2/wyzxwk/article.js index bf65d38c8..856b7a4cc 100644 --- a/lib/v2/wyzxwk/article.js +++ b/lib/v2/wyzxwk/article.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 ?? 'shidai'; + const id = ctx.req.param('id') ?? 'shidai'; const rootUrl = 'http://www.wyzxwk.com'; const currentUrl = `${rootUrl}/Article/${id}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.g-sd').remove(); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.zs-modal-body').prev().nextAll().remove(); @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text().split(' - ')[0]} - 乌有之乡网刊`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/wzu/news.js b/lib/v2/wzu/news.js index e19a64dfe..ece94cb2f 100644 --- a/lib/v2/wzu/news.js +++ b/lib/v2/wzu/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { URL } = require('url'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; /* 新闻列表 温大新闻 http://www.wzu.edu.cn/index/wdxw.htm @@ -28,12 +28,12 @@ const newsType = { * @param {*} link * @return {*} description */ -async function load(link) { +async function loadContent(link) { let videoUrl = ''; // 请求文章页面 const newsResp = await got.get(link); // 加载文章内容 - const $ = cheerio.load(newsResp.data, { decodeEntities: false }); + const $ = load(newsResp.data, { decodeEntities: false }); // 图片相对链接处理 $('img').attr('src', (n, v) => new URL(v, baseUrl).href); // 视频相对链接处理,替换原有播放方法 showVsbVideo @@ -50,17 +50,17 @@ async function load(link) { module.exports = async (ctx) => { // 获取路由 Tag - const routeTag = Number.parseInt(ctx.params.type) || 0; + const routeTag = Number.parseInt(ctx.req.param('type')) || 0; // 设定新闻标题及 Url const newsArr = Object.entries(newsType); const [k1, newsTitle] = newsArr[routeTag]; const newsLink = new URL(k1 + '.htm', baseUrl).href; const response = await got.get(newsLink); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#News-sidebar-b-nav').find('li'); - ctx.state.data = { + ctx.set('data', { title: newsTitle, link: newsLink, description: '温州大学' + ' - ' + newsTitle, @@ -68,17 +68,17 @@ module.exports = async (ctx) => { list && list .map(async (item) => { - const $ = cheerio.load(list[item]); + const $ = load(list[item]); const $a1 = $('li>a'); const $originUrl = $a1.attr('href'); const $itemUrl = new URL($originUrl, baseUrl).href; return { title: $a1.attr('title'), - description: await ctx.cache.tryGet($itemUrl, () => load($itemUrl)), + description: await ctx.cache.tryGet($itemUrl, () => loadContent($itemUrl)), pubDate: parseDate($('li>samp').text(), 'YYYY-MM-DD'), link: $itemUrl, }; }) .get(), - }; + }); }; diff --git a/lib/v2/x-mol/news.js b/lib/v2/x-mol/news.js index bf8b3ea1f..62025db04 100644 --- a/lib/v2/x-mol/news.js +++ b/lib/v2/x-mol/news.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +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 tag = ctx.params.tag; + const tag = ctx.req.param('tag'); const urlPath = tag ? `news/tag/${tag}` : 'news/index'; const link = new URL(urlPath, utils.host).href; const response = await got(link); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const newsitem = $('.newsitem') .toArray() @@ -42,7 +42,7 @@ module.exports = async (ctx) => { } const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('.newscontent'); description.find('.detitemtit, .detposttiau').remove(); @@ -54,10 +54,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: response.url, description: $('meta[name="description"]').attr('content'), item, - }; + }); }; diff --git a/lib/v2/x-mol/paper.js b/lib/v2/x-mol/paper.js index 9c99c4596..2ee17ddd3 100644 --- a/lib/v2/x-mol/paper.js +++ b/lib/v2/x-mol/paper.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { @@ -15,11 +15,11 @@ module.exports = async (ctx) => { }, }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const newsItem = $('.magazine-model-content-new li') .toArray() - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 20) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20) .map((item) => { item = $(item); return { @@ -48,7 +48,7 @@ module.exports = async (ctx) => { const item = await asyncPoolAll(2, newsItem, (element) => ctx.cache.tryGet(element.link, async () => { const response = await got(element.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('.maga-content'); element.doi = description.find('.itsmblue').eq(1).text().trim(); @@ -64,10 +64,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: response.url, description: $('meta[name="description"]').attr('content'), item, - }; + }); }; diff --git a/lib/v2/x6d/index.js b/lib/v2/x6d/index.js index 9bea885a2..5f866a4b0 100644 --- a/lib/v2/x6d/index.js +++ b/lib/v2/x6d/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 baseUrl = 'https://xd.x6d.com'; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); $('i.rj').remove(); @@ -23,8 +23,8 @@ module.exports = async (ctx) => { .find('li') .not('.addd') .find('a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 22) - : $('a.soft-title').slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10); + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 22) + : $('a.soft-title').slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10); const list = query.toArray().map((item) => { item = $(item); @@ -38,7 +38,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description = content('div.article-content').html(); item.pubDate = timezone(parseDate(content('time').text()), 8); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `小刀娱乐网 - ${$('title').text().split('-')[0]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/xaufe/jiaowu.js b/lib/v2/xaufe/jiaowu.js index a843c1476..39d11f10c 100644 --- a/lib/v2/xaufe/jiaowu.js +++ b/lib/v2/xaufe/jiaowu.js @@ -1,6 +1,6 @@ -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'; // Yep http is bad, but I had no choice :( const rootMeta = { @@ -16,7 +16,7 @@ const categories = { }; module.exports = async (ctx) => { - const pCategory = ctx.params.category; + const pCategory = ctx.req.param('category'); const category = categories[pCategory] || categories.tzgg; const response = ( @@ -26,7 +26,7 @@ module.exports = async (ctx) => { }) ).body; - const $ = cheerio.load(response); + const $ = load(response); const data = $('.main_conRCb ul li') .slice(0, 16) @@ -43,7 +43,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${category.title}-${rootMeta.title}`, link: rootMeta.url + category.url, description: `${category.title}-${rootMeta.title}`, @@ -51,7 +51,7 @@ module.exports = async (ctx) => { item: await Promise.all( data.map((item) => ctx.cache.tryGet(item.link, async () => { - const $ = cheerio.load( + const $ = load( ( await got({ method: 'get', @@ -65,5 +65,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/xaut/index.js b/lib/v2/xaut/index.js index c7ca30f6f..5b4e2a2fe 100644 --- a/lib/v2/xaut/index.js +++ b/lib/v2/xaut/index.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) => { - let category = ctx.params.category; + let category = ctx.req.param('category'); const dic_html = { tzgg: 'tzgg.htm', xyyw: 'xyyw.htm', mtbd: 'mtbd1.htm', xshd: 'xshd.htm' }; const dic_title = { tzgg: '通知公告', xyyw: '校园要闻', mtbd: '媒体播报', xshd: '学术活动' }; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { url: 'http://www.xaut.edu.cn/index/' + dic_html[category], }); const data = response.body; - const $ = cheerio.load(data); + const $ = load(data); // 这个列表指通知公告详情列表 const list = $('.newslist_block ul a') @@ -43,7 +43,7 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { // 源标题 title: '西安理工大学官网-' + dic_title[category], // 源链接 @@ -59,7 +59,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(res.body); + const content = load(res.body); item.description = content('#vsb_content').html(); } else { item.description = '请在校内或校园VPN内查看内容'; @@ -68,5 +68,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/xaut/jwc.js b/lib/v2/xaut/jwc.js index 59e473871..54bf4706c 100644 --- a/lib/v2/xaut/jwc.js +++ b/lib/v2/xaut/jwc.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) => { - let category = ctx.params.category; + let category = ctx.req.param('category'); const rootUrl = 'http://jwc.xaut.edu.cn/'; const dic_html = { tzgg: 'tzgg.htm', xwdt: 'xwdt.htm', gzzd: 'gzzd.htm', jggs: 'xkjs/jggs.htm', jsjg: 'xkjs/jsjg.htm', jsxx: 'xkjs/jsxx.htm', gkgs: 'gkgs.htm' }; const dic_title = { tzgg: '通知公告', xwdt: '新闻动态', gzzd: '规章制度', jggs: '竞赛结果公示', jsjg: '竞赛获奖通知', jsxx: '竞赛信息', gkgs: '公开公示' }; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: rootUrl + dic_html[category], }); const data = response.body; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.main_conRCb a') .slice(0, 20) @@ -36,7 +36,7 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { // 源标题 title: '西安理工大学教务处-' + dic_title[category], // 源链接 @@ -52,7 +52,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(res.body); + const content = load(res.body); item.description = content('#vsb_content').html(); } else { item.description = '请在校内或校园VPN内查看内容'; @@ -61,5 +61,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/xaut/rsc.js b/lib/v2/xaut/rsc.js index 949335914..148e8d21d 100644 --- a/lib/v2/xaut/rsc.js +++ b/lib/v2/xaut/rsc.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) => { - let category = ctx.params.category; + let category = ctx.req.param('category'); // 这里的category是个形参 const dic_html = { tzgg: 'tzgg.htm', gzdt: 'gzdt.htm' }; const dic_title = { tzgg: '通知公告', gzdt: '工作动态' }; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: 'http://renshichu.xaut.edu.cn/' + dic_html[category], }); const data = response.body; - const $ = cheerio.load(data); + const $ = load(data); // 这个列表指通知公告详情列表 const list = $('.vsb-space.n_right .list .cleafix') @@ -35,7 +35,7 @@ module.exports = async (ctx) => { }; }) .get(); - ctx.state.data = { + ctx.set('data', { // 源标题 title: '西安理工大学人事处-' + dic_title[category], // 源链接 @@ -53,7 +53,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(res.body); + const content = load(res.body); item.description = content('.vsb-space form[name]').html(); item.pubDate = parseDate(content('.vsb-space form[name] h3 span:contains(时间)').text().slice(3)); } else { @@ -63,5 +63,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/xboxfan/news.js b/lib/v2/xboxfan/news.js index fab89af9d..97321e87e 100644 --- a/lib/v2/xboxfan/news.js +++ b/lib/v2/xboxfan/news.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const md5 = require('@/utils/md5'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; +import md5 from '@/utils/md5'; module.exports = async (ctx) => { const baseUrl = 'https://xboxfan.com/'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); $('div.homeCom').remove(); $('div.homeMore').remove(); @@ -37,9 +37,9 @@ module.exports = async (ctx) => { return data; }); - ctx.state.data = { + ctx.set('data', { title: '盒心光环·资讯', link: 'https://xboxfan.com/', item: items, - }; + }); }; diff --git a/lib/v2/xiaohongshu/board.js b/lib/v2/xiaohongshu/board.js index b25526fee..a00df7380 100644 --- a/lib/v2/xiaohongshu/board.js +++ b/lib/v2/xiaohongshu/board.js @@ -1,9 +1,9 @@ -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getBoard } = require('./util'); module.exports = async (ctx) => { - const url = `https://www.xiaohongshu.com/board/${ctx.params.board_id}`; + const url = `https://www.xiaohongshu.com/board/${ctx.req.param('board_id')}`; const main = await getBoard(url, ctx.cache); const albumInfo = main.albumInfo; @@ -20,11 +20,11 @@ module.exports = async (ctx) => { pubDate: timezone(parseDate(item.time), 8), })); - ctx.state.data = { + ctx.set('data', { title, link: url, image, item: resultItem, description, - }; + }); }; diff --git a/lib/v2/xiaohongshu/notes.js b/lib/v2/xiaohongshu/notes.js index 1ac7c8071..83b410d47 100644 --- a/lib/v2/xiaohongshu/notes.js +++ b/lib/v2/xiaohongshu/notes.js @@ -1,16 +1,16 @@ const { getNotes, formatText, formatNote } = require('./util'); module.exports = async (ctx) => { - const userId = ctx.params.user_id; + const userId = ctx.req.param('user_id'); const url = `https://www.xiaohongshu.com/user/profile/${userId}`; const { user, notes } = await getNotes(url, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `${user.nickname} - 笔记 • 小红书 / RED`, description: formatText(user.desc), image: user.imageb || user.images, link: url, item: notes.map((item) => formatNote(url, item)), - }; + }); }; diff --git a/lib/v2/xiaohongshu/user.js b/lib/v2/xiaohongshu/user.js index 6f3a4616e..398af977f 100644 --- a/lib/v2/xiaohongshu/user.js +++ b/lib/v2/xiaohongshu/user.js @@ -1,8 +1,8 @@ const { getUser } = require('./util'); module.exports = async (ctx) => { - const userId = ctx.params.user_id; - const category = ctx.params.category; + const userId = ctx.req.param('user_id'); + const category = ctx.req.param('category'); const url = `https://www.xiaohongshu.com/user/profile/${userId}`; const { @@ -33,7 +33,7 @@ module.exports = async (ctx) => { throw new Error(JSON.stringify(collect)); } if (!collect.data.notes.length) { - throw ctx.throw(403, '该用户已设置收藏内容不可见'); + throw new Error('该用户已设置收藏内容不可见'); } return collect.data.notes.map((item) => ({ title: item.display_title, @@ -44,11 +44,11 @@ module.exports = async (ctx) => { })); }; - ctx.state.data = { + ctx.set('data', { title, description, image, link: url, item: category === 'notes' ? renderNote(notes) : renderCollect(collect), - }; + }); }; diff --git a/lib/v2/xiaohongshu/util.js b/lib/v2/xiaohongshu/util.js index 0f7c21e26..f33b670cc 100644 --- a/lib/v2/xiaohongshu/util.js +++ b/lib/v2/xiaohongshu/util.js @@ -1,12 +1,13 @@ -const config = require('@/config').value; +import { config } from '@/config'; const logger = require('@/utils/logger'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; +import puppeteer from '@/utils/puppeteer'; const getUser = (url, cache) => cache.tryGet( url, async () => { - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); try { const page = await browser.newPage(); await page.setRequestInterception(true); @@ -55,7 +56,7 @@ const getBoard = (url, cache) => cache.tryGet( url, async () => { - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); try { const page = await browser.newPage(); await page.setRequestInterception(true); @@ -89,7 +90,7 @@ const getNotes = (url, cache) => let user = ''; let notes = []; - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); try { const page = await browser.newPage(); await setPageFilter(page); diff --git a/lib/v2/xiaomiyoupin/crowdfunding.js b/lib/v2/xiaomiyoupin/crowdfunding.js index 6f5db4dd3..da4ad24cc 100644 --- a/lib/v2/xiaomiyoupin/crowdfunding.js +++ b/lib/v2/xiaomiyoupin/crowdfunding.js @@ -1,5 +1,5 @@ -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 base_url = 'https://m.xiaomiyoupin.com'; @@ -34,10 +34,10 @@ module.exports = async (ctx) => { pubDate: new Date(goods.fist_release_time * 1000).toUTCString(), }; }); - ctx.state.data = { + ctx.set('data', { title: '小米有品众筹', link: site_url, description: '小米有品众筹', item: items, - }; + }); }; diff --git a/lib/v2/xiaomiyoupin/latest.js b/lib/v2/xiaomiyoupin/latest.js index b27dd27b6..79bfb44b4 100644 --- a/lib/v2/xiaomiyoupin/latest.js +++ b/lib/v2/xiaomiyoupin/latest.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseModule, parseFloorItem } = require('./utils'); module.exports = async (ctx) => { @@ -6,10 +6,10 @@ module.exports = async (ctx) => { const floors = parseModule(response.data.data.homepage.floors, 'product_hot'); const items = parseFloorItem(floors); - ctx.state.data = { + ctx.set('data', { title: '小米有品每日上新', link: 'https://m.xiaomiyoupin.com/w/newproduct?pageid=1605', description: '小米有品每日上新', item: items, - }; + }); }; diff --git a/lib/v2/xiaomiyoupin/utils.js b/lib/v2/xiaomiyoupin/utils.js index c0eb6bf2b..a7e517031 100644 --- a/lib/v2/xiaomiyoupin/utils.js +++ b/lib/v2/xiaomiyoupin/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const parseModule = (floors, module_key) => floors.find((floor) => floor.module_key === module_key); diff --git a/lib/v2/xiaote/index.js b/lib/v2/xiaote/index.js index 642ad8cac..eeb178d0a 100644 --- a/lib/v2/xiaote/index.js +++ b/lib/v2/xiaote/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); // 自订的 got -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got.post('https://lcen.xiaote.net//api/graphql/', { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: '小特社区', // 源链接 link: 'https://xiaote.com/', @@ -44,5 +44,5 @@ module.exports = async (ctx) => { author: item.user.nickname, }; }), - }; + }); }; diff --git a/lib/v2/xiaoyuzhou/pickup.js b/lib/v2/xiaoyuzhou/pickup.js index f31791e07..551b72bad 100644 --- a/lib/v2/xiaoyuzhou/pickup.js +++ b/lib/v2/xiaoyuzhou/pickup.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; const XIAOYUZHOU_ITEMS = 'xiaoyuzhou_items'; @@ -84,7 +84,7 @@ module.exports = async (ctx) => { resultItems = await ProcessFeed(ctx); ctx.cache.set(XIAOYUZHOU_ITEMS, resultItems); } - ctx.state.data = { + ctx.set('data', { title: '小宇宙 - 发现', link: 'https://www.xiaoyuzhoufm.com/', description: '小宇宙的编辑精选', @@ -92,5 +92,5 @@ module.exports = async (ctx) => { itunes_author: '小宇宙', itunes_category: 'Society & Culture', item: resultItems, - }; + }); }; diff --git a/lib/v2/xiaoyuzhou/podcast.js b/lib/v2/xiaoyuzhou/podcast.js index fb0bda331..3dfb02a13 100644 --- a/lib/v2/xiaoyuzhou/podcast.js +++ b/lib/v2/xiaoyuzhou/podcast.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 link = `https://www.xiaoyuzhoufm.com/podcast/${ctx.params.id}`; + const link = `https://www.xiaoyuzhoufm.com/podcast/${ctx.req.param('id')}`; const response = await got({ method: 'get', url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const page_data = JSON.parse($('#__NEXT_DATA__')[0].children[0].data); @@ -24,7 +24,7 @@ module.exports = async (ctx) => { itunes_item_image: (item.image || item.podcast?.image)?.smallPicUrl, })); - ctx.state.data = { + ctx.set('data', { title: page_data.props.pageProps.podcast.title, link: `https://www.xiaoyuzhoufm.com/podcast/${page_data.props.pageProps.podcast.pid}`, itunes_author: page_data.props.pageProps.podcast.author, @@ -32,5 +32,5 @@ module.exports = async (ctx) => { image: page_data.props.pageProps.podcast.image.smallPicUrl, item: episodes, description: page_data.props.pageProps.podcast.description, - }; + }); }; diff --git a/lib/v2/xiaozhuanlan/column.js b/lib/v2/xiaozhuanlan/column.js index e82f63fda..fa0dd4e9f 100644 --- a/lib/v2/xiaozhuanlan/column.js +++ b/lib/v2/xiaozhuanlan/column.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 md = require('markdown-it')({ linkify: true, }); @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const { id } = ctx.params; const response = await got(`${baseUrl}/${id}`); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.xzl-topic-item') .toArray() @@ -29,7 +29,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); item.description = md.render($('.hidden_markdown_body').attr('data-summary')); if ($('.topic-tags')) { @@ -43,10 +43,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim(), link: `${baseUrl}/${id}`, description: $('meta[name=description]').attr('content'), item: items, - }; + }); }; diff --git a/lib/v2/xidian/jwc.js b/lib/v2/xidian/jwc.js index 503c179a9..b37539be9 100644 --- a/lib/v2/xidian/jwc.js +++ b/lib/v2/xidian/jwc.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 baseUrl = 'https://jwc.xidian.edu.cn'; module.exports = async (ctx) => { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list ul li') .toArray() @@ -38,7 +38,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.tit, .zd, #div_vote_id').remove(); item.description = content('.con').html(); return item; @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/ximalaya/album.js b/lib/v2/ximalaya/album.js index cabfe4297..a20b20c74 100644 --- a/lib/v2/ximalaya/album.js +++ b/lib/v2/ximalaya/album.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { getUrl, getRandom16 } = require('./utils'); const baseUrl = 'https://www.ximalaya.com'; -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; // Find category from: https://help.apple.com/itc/podcasts_connect/?lang=en#/itc9267a2f12 const categoryDict = { @@ -50,7 +50,7 @@ async function parseAlbumData(category, album_id) { // https://www.ximalaya.com/{category}/{album_id} const response = await got(`${baseUrl}/${category}/${album_id}`); const data = response.body; - const $ = cheerio.load(data); + const $ = load(data); const stateElement = $('script') .toArray() .filter((element) => getTextFromElement(element).startsWith('window.__INITIAL_STATE__')); @@ -80,10 +80,10 @@ function judgeTrue(str, ...validStrings) { } module.exports = async (ctx) => { - const type = ctx.params.type; // 专辑分类 - const id = ctx.params.id; // 专辑id - const shouldAll = judgeTrue(ctx.params.all, 'all'); - const shouldShowNote = judgeTrue(ctx.params.shownote, 'shownote'); + const type = ctx.req.param('type'); // 专辑分类 + const id = ctx.req.param('id'); // 专辑id + const shouldAll = judgeTrue(ctx.req.param('all'), 'all'); + const shouldShowNote = judgeTrue(ctx.req.param('shownote'), 'shownote'); const pageSize = shouldAll ? 200 : 30; const albumData = await parseAlbumData(type, id); @@ -208,7 +208,7 @@ module.exports = async (ctx) => { return resultItem; }); - ctx.state.data = { + ctx.set('data', { title: albumTitle, link: baseUrl + albumUrl, description: albumIntro, @@ -216,5 +216,5 @@ module.exports = async (ctx) => { itunes_author: author, itunes_category: categoryDict[albumCategory] || albumCategory, item: resultItems, - }; + }); }; diff --git a/lib/v2/xinpianchang/index.js b/lib/v2/xinpianchang/index.js index 32848eded..b91d9caca 100644 --- a/lib/v2/xinpianchang/index.js +++ b/lib/v2/xinpianchang/index.js @@ -2,7 +2,7 @@ const { rootUrl, getData, processItems } = require('./util'); module.exports = async (ctx) => { const { params = 'article-0-0-all-all-0-0-score' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 60; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 60; const currentUrl = new URL(`discover/${params}`, rootUrl).href; @@ -12,8 +12,8 @@ module.exports = async (ctx) => { items = await processItems(items.slice(0, limit), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { ...data, item: items, - }; + }); }; diff --git a/lib/v2/xinpianchang/rank.js b/lib/v2/xinpianchang/rank.js index f4f93457c..d1cc93925 100644 --- a/lib/v2/xinpianchang/rank.js +++ b/lib/v2/xinpianchang/rank.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, getData, processItems } = require('./util'); module.exports = async (ctx) => { const { category = 'all' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 60; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 60; const apiRankUrl = new URL(`api/xpc/v2/rank/${category}`, rootUrl).href; @@ -26,8 +26,8 @@ module.exports = async (ctx) => { items = await processItems(items.slice(0, limit), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { ...data, item: items, - }; + }); }; diff --git a/lib/v2/xinpianchang/util.js b/lib/v2/xinpianchang/util.js index 5aa1f67ce..188c379f7 100644 --- a/lib/v2/xinpianchang/util.js +++ b/lib/v2/xinpianchang/util.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'); const appKey = '61a2f329348b3bf77'; @@ -21,7 +21,7 @@ const getData = (url, tryGet) => tryGet(url, async () => { const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const icon = new URL('favicon.ico', rootUrl).href; const author = $('meta[property="og:site_name"]').prop('content'); diff --git a/lib/v2/xjtu/2yuan/news.js b/lib/v2/xjtu/2yuan/news.js index 6c7484e47..91dc391be 100644 --- a/lib/v2/xjtu/2yuan/news.js +++ b/lib/v2/xjtu/2yuan/news.js @@ -1,10 +1,10 @@ -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 ?? '110'; + const id = ctx.req.param('id') ?? '110'; const rootUrl = 'http://2yuan.xjtu.edu.cn'; const currentUrl = `${rootUrl}/Html/News/Columns/${id}/Index.html`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.column_list h2') .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('#zoom').html(); item.pubDate = timezone( @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/xjtu/dean.js b/lib/v2/xjtu/dean.js index df21eb4a4..e3353b779 100644 --- a/lib/v2/xjtu/dean.js +++ b/lib/v2/xjtu/dean.js @@ -1,10 +1,10 @@ -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 parseContent = (htmlString) => { - const $ = cheerio.load(htmlString); + const $ = load(htmlString); const info = $('.detail_main_content > h1') .contents() @@ -29,13 +29,13 @@ const parseContent = (htmlString) => { }; module.exports = async (ctx) => { - const subpath = ctx.params.subpath; + const subpath = ctx.req.param('subpath'); const url = `http://dean.xjtu.edu.cn/${subpath.replaceAll('.htm', '')}.htm`; const base = url.split('/').slice(0, -1).join('/'); const list_response = await got(url); - const $ = cheerio.load(list_response.data); + const $ = load(list_response.data); const subname = $('em.ma-nav a') .slice(1) @@ -75,9 +75,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `西安交大教务处 - ${subname}`, link: url, item: out.filter((item) => item !== ''), - }; + }); }; diff --git a/lib/v2/xjtu/dyyy/index.js b/lib/v2/xjtu/dyyy/index.js index 629720d62..60ffd305a 100644 --- a/lib/v2/xjtu/dyyy/index.js +++ b/lib/v2/xjtu/dyyy/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 baseUrl = 'http://www.dyyy.xjtu.edu.cn'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const { path } = ctx.params; const response = await got(`${baseUrl}/${path}.htm`); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.list_right_con div li') .toArray() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.author = $('.content_source') .text() @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: `${baseUrl}/${path}.htm`, item: items, - }; + }); }; diff --git a/lib/v2/xjtu/ee.js b/lib/v2/xjtu/ee.js index 427518ea3..ced3cde79 100644 --- a/lib/v2/xjtu/ee.js +++ b/lib/v2/xjtu/ee.js @@ -1,15 +1,15 @@ -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 = async (ctx) => { - const id = ctx.params.id ?? '1124'; + const id = ctx.req.param('id') ?? '1124'; const rootUrl = `http://ee.xjtu.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=${id}`; const baseUrl = 'http://ee.xjtu.edu.cn'; const list_response = await got(rootUrl); - const $ = cheerio.load(list_response.data); + const $ = load(list_response.data); const feed_title = $('span.windowstyle67278', "div[class='list_right fr']").text().trim(); @@ -26,19 +26,19 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `西安交通大学电气学院 - ${feed_title}`, link: baseUrl, item: await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got(item.link); - const content = cheerio.load(res.data); + const content = load(res.data); item.title = content('tr td[class^=titlestyle]').text(); item.description = content('td.contentstyle67362', 'form').html(); return item; }) ) ), - }; + }); }; diff --git a/lib/v2/xjtu/gs/tzgg.js b/lib/v2/xjtu/gs/tzgg.js index d93ba06d3..85a40e820 100644 --- a/lib/v2/xjtu/gs/tzgg.js +++ b/lib/v2/xjtu/gs/tzgg.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 = 'http://gs.xjtu.edu.cn/tzgg.htm'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { method: 'get', url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.list_right_con ul li') .slice(0, 10) .map((_, item) => { @@ -22,18 +22,18 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '西安交通大学研究生院 - 通知公告', link: rootUrl, item: await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got(item.link); - const content = cheerio.load(res.data); + const content = load(res.data); item.description = content('#vsb_content').html() + (content('form ul').length > 0 ? content('form ul').html() : ''); return item; }) ) ), - }; + }); }; diff --git a/lib/v2/xjtu/international.js b/lib/v2/xjtu/international.js index 405058ca1..25ef566ce 100644 --- a/lib/v2/xjtu/international.js +++ b/lib/v2/xjtu/international.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 subpath = ctx.params.subpath; + const subpath = ctx.req.param('subpath'); const base = 'http://international.xjtu.edu.cn'; const url = `${base}/${subpath.split('.')[0]}.htm`; const resp = await got(url); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const name = $('div.pageTitle').text(); const list = $('.news-list-a > .c') .toArray() @@ -33,7 +33,7 @@ module.exports = async (ctx) => { } const resp = await got(item.link); - const $Des = cheerio.load(resp.data); + const $Des = load(resp.data); const description = $Des('div.ctnCont').html(); item.description = description; @@ -42,10 +42,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `西安交通大学国际处 - ${name}`, link: url, description: `西安交通大学国际处 - ${name}`, item, - }; + }); }; diff --git a/lib/v2/xjtu/job.js b/lib/v2/xjtu/job.js index 8196f3b94..42c2f1862 100644 --- a/lib/v2/xjtu/job.js +++ b/lib/v2/xjtu/job.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const baseUrl = 'https://job.xjtu.edu.cn'; const arr = { @@ -15,7 +15,7 @@ const arr = { }; module.exports = async (ctx) => { - const subpath = ctx.params.subpath ?? 'zxgg'; + const subpath = ctx.req.param('subpath') ?? 'zxgg'; const getTzgg = await got.post(`${baseUrl}/xsfw/sys/jyxtgktapp/modules/jywzManage/getTzgg.do`, { form: { requestParamStr: '{"pageSize":7,"pageNumber":1}', @@ -73,9 +73,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `西安交通大学学生就业创业信息网 - ${arr[subpath]}`, link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/xjtu/std.js b/lib/v2/xjtu/std.js index 8490745c8..4e6ae2adb 100644 --- a/lib/v2/xjtu/std.js +++ b/lib/v2/xjtu/std.js @@ -1,12 +1,12 @@ -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 category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; const rootUrl = 'http://std.xjtu.edu.cn'; const currentUrl = `${rootUrl}/tzgg${category ? `/${category}` : ''}.htm`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.c1017') .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 = art(path.join(__dirname, 'templates/std.art'), { description: content('#vsb_newscontent').html(), @@ -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/xkb/index.js b/lib/v2/xkb/index.js index e00dca6ad..4ed17b11f 100644 --- a/lib/v2/xkb/index.js +++ b/lib/v2/xkb/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +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 channel = ctx.params.channel ?? 350; + const channel = ctx.req.param('channel') ?? 350; const currentUrl = `https://www.xkb.com.cn/xkbapp/fundapi/article/api/articles?chnlId=${channel}&visibility=1&page=0&size=20&keyword=`; const { data: response } = await got({ @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `新快报新快网 - ${chnlName}`, link: `https://www.xkb.com.cn/home?id=${channel}`, item: items, - }; + }); }; diff --git a/lib/v2/xmanhua/index.js b/lib/v2/xmanhua/index.js index 6e1f497e3..f005be429 100644 --- a/lib/v2/xmanhua/index.js +++ b/lib/v2/xmanhua/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 uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const host = 'https://xmanhua.com'; const url = `https://xmanhua.com/${uid}/`; const response = await got({ @@ -15,7 +15,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('div #chapterlistload').find('.detail-list-form-item'); // 作者 const autherName = $('body > div.detail-info-1 > div > div > p.detail-info-tip > span:nth-child(1)').text().split(':')[1]; @@ -54,11 +54,11 @@ module.exports = async (ctx) => { .get(); const name = $('body > div.detail-info-1 > div > div > p.detail-info-title').text(); const description_ = finished ? '已完结' : '连载中'; - ctx.state.data = { + ctx.set('data', { title: `x漫画 ${name}`, link: `https://xmanhua.com/${uid}`, description: description_, allowEmpty: true, item: items, - }; + }); }; diff --git a/lib/v2/xmnn/epaper.js b/lib/v2/xmnn/epaper.js index 1fcb47d93..b5dc2857c 100644 --- a/lib/v2/xmnn/epaper.js +++ b/lib/v2/xmnn/epaper.js @@ -1,10 +1,10 @@ -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 ?? 'xmrb'; + const id = ctx.req.param('id') ?? 'xmrb'; const rootUrl = 'https://epaper.xmnn.cn'; let currentUrl = `${rootUrl}/${id === 'hxcb' ? '/hxcb/epaper/paperindex.htm' : `${id}/`}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - let $ = cheerio.load(response.data); + let $ = load(response.data); const title = id === 'hxcb' ? '海西晨报电子版_厦门网' : $('title').text(); @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - $ = cheerio.load(response.data); + $ = load(response.data); $('#pdfsrc').remove(); $('.bigImg, .smallImg').remove(); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { let items = $('.br1, .br2, .titss') .find('a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 80) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 80) .toArray() .map((item) => { item = $(item); @@ -65,7 +65,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#qw').remove(); @@ -77,9 +77,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/xmnn/news.js b/lib/v2/xmnn/news.js index d6eff105a..0e9fc9cd1 100644 --- a/lib/v2/xmnn/news.js +++ b/lib/v2/xmnn/news.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 = 'xmxw' } = 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 rootUrl = 'https://news.xmnn.cn'; const currentUrl = new URL(`${category}/`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div#sort_body ul li a') .slice(0, limit) @@ -34,7 +34,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); item.title = content('div.cont-h, div.tip h1').text().trim(); item.description = content('div.TRS_Editor').html(); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { const title = $('title').text(); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -61,5 +61,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('div.h').text(), author: title.split(/_/).pop(), - }; + }); }; diff --git a/lib/v2/xmut/jwc/bkjw.js b/lib/v2/xmut/jwc/bkjw.js index 40e29d91b..e322dd90a 100644 --- a/lib/v2/xmut/jwc/bkjw.js +++ b/lib/v2/xmut/jwc/bkjw.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 xmut = 'https://jwc.xmut.edu.cn'; module.exports = async (ctx) => { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const itemsArray = $('#result_list table tbody tr') .map((index, row) => { const res = $('td', row).eq(0); @@ -47,16 +47,16 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $item = cheerio.load(res.data); + const $item = load(res.data); const content = $item('table #result #content form div #vsb_content_6').html(); item.description = content; return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/xmut/jwc/yjs.js b/lib/v2/xmut/jwc/yjs.js index 31dbce149..a1222d919 100644 --- a/lib/v2/xmut/jwc/yjs.js +++ b/lib/v2/xmut/jwc/yjs.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 xmut = 'https://yjs.xmut.edu.cn'; module.exports = async (ctx) => { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = $('.mainWrap .main_con .main_conR ul li') .toArray() .map((item) => { @@ -36,16 +36,16 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $item = cheerio.load(detailResponse.data); + const $item = load(detailResponse.data); const content = $item('body .mainWrap .main_content .v_news_content').html(); item.description = content; return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: itemPromises, - }; + }); }; diff --git a/lib/v2/xsijishe/forum.js b/lib/v2/xsijishe/forum.js index 8757b1d46..8e0879ec0 100644 --- a/lib/v2/xsijishe/forum.js +++ b/lib/v2/xsijishe/forum.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 baseUrl = 'https://xsijishe.com'; module.exports = async (ctx) => { - const fid = ctx.params.fid; + const fid = ctx.req.param('fid'); const url = `${baseUrl}/forum-${fid}-1.html`; const resp = await got(url); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const forumCategory = $('.nex_bkinterls_top .nex_bkinterls_ls a').text(); let items = $('[id^="normalthread"]') .toArray() @@ -29,7 +29,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const resp = await got(item.link); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const firstViewBox = $('.t_f').first(); firstViewBox.find('img').each((_, img) => { @@ -47,10 +47,10 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: `司机社${forumCategory}论坛`, link: url, description: `司机社${forumCategory}论坛`, item: items, - }; + }); }; diff --git a/lib/v2/xsijishe/rank.js b/lib/v2/xsijishe/rank.js index 4b39ac44b..ed2aaf334 100644 --- a/lib/v2/xsijishe/rank.js +++ b/lib/v2/xsijishe/rank.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const baseUrl = 'https://xsijishe.com'; module.exports = async (ctx) => { - const rankType = ctx.params.type; + const rankType = ctx.req.param('type'); let title; let rankId; if (rankType === 'weekly') { @@ -17,7 +17,7 @@ module.exports = async (ctx) => { } const url = `${baseUrl}/portal.php`; const resp = await got(url); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); let items = $(`#${rankId} dd`) .toArray() .map((item) => { @@ -33,7 +33,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const resp = await got(item.link); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const firstViewBox = $('.t_f').first(); firstViewBox.find('img').each((_, img) => { @@ -51,10 +51,10 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title, link: url, description: title, item: items, - }; + }); }; diff --git a/lib/v2/xueqiu/column.js b/lib/v2/xueqiu/column.js index dbbe0b184..34de05a95 100644 --- a/lib/v2/xueqiu/column.js +++ b/lib/v2/xueqiu/column.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); const { CookieJar } = require('tough-cookie'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const cookieJar = new CookieJar(); const baseUrl = 'https://xueqiu.com'; @@ -33,10 +33,10 @@ module.exports = async (ctx) => { author: SNOWMAN_TARGET.screen_name, })); - ctx.state.data = { + ctx.set('data', { title: `${SNOWMAN_TARGET.screen_name} - 雪球`, link: pageUrl, description: SNOWMAN_TARGET.description, item: items, - }; + }); }; diff --git a/lib/v2/xueqiu/favorite.js b/lib/v2/xueqiu/favorite.js index cea30a788..86586cd69 100644 --- a/lib/v2/xueqiu/favorite.js +++ b/lib/v2/xueqiu/favorite.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const queryString = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const res1 = await got({ method: 'get', @@ -24,7 +24,7 @@ module.exports = async (ctx) => { }); const data = res2.data.list; - ctx.state.data = { + ctx.set('data', { title: `ID: ${id} 的雪球收藏动态`, link: `https://xueqiu.com/u/${id}`, description: `ID: ${id} 的雪球收藏动态`, @@ -34,5 +34,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.created_at), link: `https://xueqiu.com${item.target}`, })), - }; + }); }; diff --git a/lib/v2/xueqiu/fund.js b/lib/v2/xueqiu/fund.js index 9ed12ac17..4cd139906 100644 --- a/lib/v2/xueqiu/fund.js +++ b/lib/v2/xueqiu/fund.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const guid = ctx.params.id; + const guid = ctx.req.param('id'); const appUrl = `https://danjuanapp.com/funding/${guid}`; const url = `https://danjuanapp.com/djapi/fund/${guid}`; const response = await got({ @@ -41,10 +41,10 @@ module.exports = async (ctx) => { link: appUrl, }; - ctx.state.data = { + ctx.set('data', { title: fd_name, link: appUrl, description, item: [single], - }; + }); }; diff --git a/lib/v2/xueqiu/hots.js b/lib/v2/xueqiu/hots.js index 13e5f3146..f6c031b8d 100644 --- a/lib/v2/xueqiu/hots.js +++ b/lib/v2/xueqiu/hots.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const queryString = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const sanitizeHtml = require('sanitize-html'); module.exports = async (ctx) => { @@ -28,7 +28,7 @@ module.exports = async (ctx) => { }); const data = res2.data; - ctx.state.data = { + ctx.set('data', { title: `热帖 - 雪球`, link: `https://xueqiu.com/`, description: `雪球热门帖子`, @@ -42,5 +42,5 @@ module.exports = async (ctx) => { author: item.user.screen_name, }; }), - }; + }); }; diff --git a/lib/v2/xueqiu/snb.js b/lib/v2/xueqiu/snb.js index 28f441f23..aa3f03d29 100644 --- a/lib/v2/xueqiu/snb.js +++ b/lib/v2/xueqiu/snb.js @@ -1,9 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' }); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import randUserAgent from '@/utils/rand-user-agent'; + +const UA = randUserAgent({ browser: 'chrome', os: 'android', device: 'mobile' }); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const url = 'https://xueqiu.com/p/' + id; const response = await got(url, { @@ -36,10 +38,10 @@ module.exports = async (ctx) => { guid: `xueqiu::snb::${id}::${time}`, }; - ctx.state.data = { + ctx.set('data', { title: snb_title, link: url, description: snb_description, item: [single], - }; + }); }; diff --git a/lib/v2/xueqiu/stock-comments.js b/lib/v2/xueqiu/stock-comments.js index 769d65383..869261f0d 100644 --- a/lib/v2/xueqiu/stock-comments.js +++ b/lib/v2/xueqiu/stock-comments.js @@ -1,12 +1,12 @@ -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 { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const sanitizeHtml = require('sanitize-html'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const res = await got({ method: 'get', @@ -19,12 +19,12 @@ module.exports = async (ctx) => { method: 'get', url: `https://xueqiu.com/S/${id}`, }); - const $ = cheerio.load(res.data); // 使用 cheerio 加载返回的 HTML + const $ = load(res.data); // 使用 cheerio 加载返回的 HTML return $('.stock-name').text().split('(')[0]; }); const data = res.data.list; - ctx.state.data = { + ctx.set('data', { title: `${id} ${stock_name} - 评论`, link: `https://xueqiu.com/S/${id}`, description: `${stock_name} - 评论`, @@ -41,5 +41,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/xueqiu/stock-info.js b/lib/v2/xueqiu/stock-info.js index 3bd3589c7..a94c100e6 100644 --- a/lib/v2/xueqiu/stock-info.js +++ b/lib/v2/xueqiu/stock-info.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const queryString = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const sanitizeHtml = require('sanitize-html'); module.exports = async (ctx) => { - const id = ctx.params.id; - const type = ctx.params.type || 'announcement'; + const id = ctx.req.param('id'); + const type = ctx.req.param('type') || 'announcement'; const count = 10; const page = 1; const typename = { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { }); const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0]; - const $ = cheerio.load(res1.data); // 使用 cheerio 加载返回的 HTML + const $ = load(res1.data); // 使用 cheerio 加载返回的 HTML const stock_name = $('.stock-name').text().split('(')[0]; let query_url = 'https://xueqiu.com/statuses'; @@ -49,7 +49,7 @@ module.exports = async (ctx) => { }); const data = res2.data.list; - ctx.state.data = { + ctx.set('data', { title: `${id} ${stock_name} - ${source}`, link: `https://xueqiu.com/S/${id}`, description: `${stock_name} - ${source}`, @@ -65,5 +65,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/xueqiu/today.js b/lib/v2/xueqiu/today.js index 4ee9aff23..0d533b105 100644 --- a/lib/v2/xueqiu/today.js +++ b/lib/v2/xueqiu/today.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 size = ctx.query.limit ?? '20'; + const size = ctx.req.query('limit') ?? '20'; const rootUrl = 'https://xueqiu.com'; const currentUrl = `${rootUrl}/today`; @@ -48,7 +48,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article__bd__detail').html(); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '今日话题 - 雪球', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/xueqiu/user-stock.js b/lib/v2/xueqiu/user-stock.js index 4024d8484..838d47f38 100644 --- a/lib/v2/xueqiu/user-stock.js +++ b/lib/v2/xueqiu/user-stock.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const queryString = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const res1 = await got({ method: 'get', @@ -34,7 +34,7 @@ module.exports = async (ctx) => { }); const screen_name = res3.data.user.screen_name; - ctx.state.data = { + ctx.set('data', { title: `${screen_name} 的雪球自选动态`, link: `https://xueqiu.com/u/${id}`, description: `@${screen_name} 的雪球自选动态`, @@ -44,5 +44,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.created), link: `https://xueqiu.com/s/${item.symbol}`, })), - }; + }); }; diff --git a/lib/v2/xueqiu/user.js b/lib/v2/xueqiu/user.js index f2e6c7d87..00211b928 100644 --- a/lib/v2/xueqiu/user.js +++ b/lib/v2/xueqiu/user.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const queryString = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const sanitizeHtml = require('sanitize-html'); const rootUrl = 'https://xueqiu.com'; module.exports = async (ctx) => { - const id = ctx.params.id; - const type = ctx.params.type || 10; + const id = ctx.req.param('id'); + const type = ctx.req.param('type') || 10; const source = type === '11' ? '买卖' : ''; const typename = { 10: '全部', @@ -67,10 +67,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${data[0].user.screen_name} 的雪球${typename[type]}动态`, link: `${rootUrl}/u/${id}`, description: `${data[0].user.screen_name} 的雪球${typename[type]}动态`, item: items, - }; + }); }; diff --git a/lib/v2/xys/new.js b/lib/v2/xys/new.js index eb4096bcf..2f76aa8dd 100644 --- a/lib/v2/xys/new.js +++ b/lib/v2/xys/new.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); 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'; module.exports = async (ctx) => { const rootUrl = 'http://www.xys.org'; @@ -18,10 +18,10 @@ module.exports = async (ctx) => { // 转码 const data = iconv.decode(response.data, 'gb2312'); - const $ = cheerio.load(data); + const $ = load(data); let items = $('li a') - .slice(4, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(4, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -56,7 +56,7 @@ module.exports = async (ctx) => { // 转码 const detailData = iconv.decode(detailResponse.data, 'gb2312'); - const content = cheerio.load(detailData); + const content = load(detailData); item.description = content.text().replaceAll('\n', '
\n'); } @@ -66,9 +66,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '新语丝 - 新到资料', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/xyzrank/index.js b/lib/v2/xyzrank/index.js index e44540d00..0ccb94ed2 100644 --- a/lib/v2/xyzrank/index.js +++ b/lib/v2/xyzrank/index.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 category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; const rootUrl = 'https://xyzrank.com'; const currentUrl = `${rootUrl}/#/${category}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); response = await got({ method: 'get', @@ -58,7 +58,7 @@ module.exports = async (ctx) => { const type = categories[category].type; - const items = response.data.data[type].slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 250).map((item, index) => ({ + const items = response.data.data[type].slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 250).map((item, index) => ({ title: `#${index + 1} ${item.title ?? item.name}`, category: [item.primaryGenreName], author: item.authorsText, @@ -102,10 +102,10 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()} - ${categories[category].title}`, link: currentUrl, item: items, description: $('meta[property="og:description"]').attr('content'), - }; + }); }; diff --git a/lib/v2/yahoo/news/tw/index.js b/lib/v2/yahoo/news/tw/index.js index 00dadd617..c7f0f3e1e 100644 --- a/lib/v2/yahoo/news/tw/index.js +++ b/lib/v2/yahoo/news/tw/index.js @@ -6,7 +6,7 @@ module.exports = async (ctx) => { throw new Error(`Unknown region: ${region}`); } - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; const categoryMap = await getCategories(region, ctx.cache.tryGet); const tag = category ? categoryMap[category].yctMap : null; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `Yahoo 新聞 - ${category ? categoryMap[category].name : '所有類別'}`, link: `https://${region}.news.yahoo.com/${category ? `${category}/` : ''}archive`, image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png', item: items, - }; + }); }; diff --git a/lib/v2/yahoo/news/tw/provider-helper.js b/lib/v2/yahoo/news/tw/provider-helper.js index d4a043a1c..e6cd72b67 100644 --- a/lib/v2/yahoo/news/tw/provider-helper.js +++ b/lib/v2/yahoo/news/tw/provider-helper.js @@ -13,10 +13,10 @@ module.exports = async (ctx) => { description: provider.key, })); - ctx.state.data = { + ctx.set('data', { title: 'Yahoo 新聞 - 新聞來源列表', link: `https://${region}.news.yahoo.com`, image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png', item: items, - }; + }); }; diff --git a/lib/v2/yahoo/news/tw/provider.js b/lib/v2/yahoo/news/tw/provider.js index 3bdf579a0..839e959f5 100644 --- a/lib/v2/yahoo/news/tw/provider.js +++ b/lib/v2/yahoo/news/tw/provider.js @@ -6,7 +6,7 @@ module.exports = async (ctx) => { throw new Error(`Unknown region: ${region}`); } - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; const providerList = await getProviderList(region, ctx.cache.tryGet); const provider = providerList.find((p) => p.key === providerId); @@ -15,10 +15,10 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `Yahoo 新聞 - ${provider?.title ?? ''}`, link: provider?.link ?? `https://${region}.news.yahoo.com`, image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png', item: items, - }; + }); }; diff --git a/lib/v2/yahoo/news/tw/utils.js b/lib/v2/yahoo/news/tw/utils.js index d101b2672..e6523c9a4 100644 --- a/lib/v2/yahoo/news/tw/utils.js +++ b/lib/v2/yahoo/news/tw/utils.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 getArchive = async (region, limit, tag, providerId) => { const { data: response } = await got( @@ -53,7 +53,7 @@ const getProviderList = (region, tryGet) => const getStores = (region, tryGet) => tryGet(`yahoo:${region}:stores`, async () => { const { data: response } = await got(`https://${region}.news.yahoo.com/archive`); - const $ = cheerio.load(response); + const $ = load(response); const appData = JSON.parse( $('script:contains("root.App.main")') @@ -75,7 +75,7 @@ const parseList = (region, response) => const parseItem = (item, tryGet) => tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); const ldJson = JSON.parse($('script[type="application/ld+json"]').first().text()); const body = $('.caas-body'); diff --git a/lib/v2/yahoo/news/us/index.js b/lib/v2/yahoo/news/us/index.js index 4f3a8e713..88c458842 100644 --- a/lib/v2/yahoo/news/us/index.js +++ b/lib/v2/yahoo/news/us/index.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const parser = require('@/utils/rss-parser'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const region = ctx.params.region === 'en' ? '' : ctx.params.region.toLowerCase(); + const region = ctx.req.param('region') === 'en' ? '' : ctx.req.param('region').toLowerCase(); if (!isValidHost(region) && region !== '') { throw new Error('Invalid region'); } - const category = ctx.params.category ? ctx.params.category.toLowerCase() : ''; + const category = ctx.req.param('category') ? ctx.req.param('category').toLowerCase() : ''; const rssUrl = `https://${region ? `${region}.` : ''}news.yahoo.com/rss/${category}`; const feed = await parser.parseURL(rssUrl); const filteredItems = feed.items.filter((item) => !item.link.includes('promotions') && new URL(item.link).hostname.match(/.*\.yahoo\.com$/)); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const author = `${$('span.caas-author-byline-collapse').text()} @${$('span.caas-attr-provider').text()}`; $('.caas-content-byline-wrapper, .caas-xray-wrapper, .caas-header, .caas-readmore').remove(); const description = $('.caas-content-wrapper').html(); @@ -36,10 +36,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.description, item: items, - }; + }); }; diff --git a/lib/v2/yangtzeu/dongke.js b/lib/v2/yangtzeu/dongke.js index 3727f6223..6ba360171 100644 --- a/lib/v2/yangtzeu/dongke.js +++ b/lib/v2/yangtzeu/dongke.js @@ -1,17 +1,17 @@ -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 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://dongke.yangtzeu.edu.cn'; const currentUrl = new URL(`${ctx.path.replace(/^\/dongke/, '') || '/yqzl/xyxw'}.htm`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('ul.list-item li a') .slice(0, limit) @@ -30,7 +30,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); item.title = content('title').text(); item.description = content('div.v_news_content').html(); @@ -49,12 +49,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, language: 'zh-cn', image: new URL($('#head-img a img').prop('src'), rootUrl).href, author: '长江大学动物科学学院', - }; + }); }; diff --git a/lib/v2/ycwb/index.js b/lib/v2/ycwb/index.js index 50518dc48..a3ca6a343 100644 --- a/lib/v2/ycwb/index.js +++ b/lib/v2/ycwb/index.js @@ -1,12 +1,12 @@ -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 node = ctx.params.node ?? 1; + const node = ctx.req.param('node') ?? 1; const currentUrl = `https://6api.ycwb.com/app_if/jy/getArticles?nodeid=${node}&pagesize=15`; const { data: response } = await got(currentUrl); @@ -33,7 +33,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const $comments = content('.main_article') .contents() @@ -74,9 +74,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `羊城晚报金羊网 - ${nodeName}`, link: String(nodeLink === '' ? 'https://www.ycwb.com/' : nodeLink), item: items, - }; + }); }; diff --git a/lib/v2/yicai/author.js b/lib/v2/yicai/author.js index 2f123e4ee..2976c939a 100644 --- a/lib/v2/yicai/author.js +++ b/lib/v2/yicai/author.js @@ -1,26 +1,26 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '100005663'; + const id = ctx.req.param('id') ?? '100005663'; const currentUrl = `${rootUrl}/author/${id}.html`; - const apiUrl = `${rootUrl}/api/ajax/getlistbysid?id=${id}&page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/getlistbysid?id=${id}&page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const response = await got({ method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `第一财经一财号 - ${$('title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/brief.js b/lib/v2/yicai/brief.js index eeb1b6b1a..522dd9d2c 100644 --- a/lib/v2/yicai/brief.js +++ b/lib/v2/yicai/brief.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 { rootUrl } = require('./utils'); module.exports = async (ctx) => { const currentUrl = `${rootUrl}/brief`; - const apiUrl = `${rootUrl}/api/ajax/getbrieflist?type=0&page=1&pagesize=${ctx.query.limit ?? 50}`; + const apiUrl = `${rootUrl}/api/ajax/getbrieflist?type=0&page=1&pagesize=${ctx.req.query('limit') ?? 50}`; const response = await got({ method: 'get', @@ -20,9 +20,9 @@ module.exports = async (ctx) => { pubDate: timezone(parseDate(`${item.datekey} ${item.hm}`, 'YYYY.MM.DD HH:mm'), +8), })); - ctx.state.data = { + ctx.set('data', { title: '第一财经 - 正在', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/dt.js b/lib/v2/yicai/dt.js index 3cac298d6..423241823 100644 --- a/lib/v2/yicai/dt.js +++ b/lib/v2/yicai/dt.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'); const columns = { @@ -12,7 +12,7 @@ const columns = { module.exports = async (ctx) => { const { column = 'article', category = '0' } = 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 rootUrl = 'https://dt.yicai.com'; const apiUrl = new URL('api/getNewsList', rootUrl).href; @@ -57,7 +57,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.logintips').remove(); @@ -88,13 +88,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const title = $('title').text(); const image = $('div.logo a img').prop('src'); const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${$(`a[data-cid="${category}"]`).text()}${title}`, link: currentUrl, @@ -106,5 +106,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="description"]').prop('content'), author: title.split(/_/).pop(), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/yicai/feed.js b/lib/v2/yicai/feed.js index 04bafe8e9..3bf852997 100644 --- a/lib/v2/yicai/feed.js +++ b/lib/v2/yicai/feed.js @@ -1,26 +1,26 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '669'; + const id = ctx.req.param('id') ?? '669'; const currentUrl = `${rootUrl}/feed/${id}`; - const apiUrl = `${rootUrl}/api/ajax/getlistbytid?id=${id}&page=0&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/getlistbytid?id=${id}&page=0&pagesize=${ctx.req.query('limit') ?? 30}`; const response = await got({ method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `第一财经主题 - ${$('title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/headline.js b/lib/v2/yicai/headline.js index a04e29937..5045263a2 100644 --- a/lib/v2/yicai/headline.js +++ b/lib/v2/yicai/headline.js @@ -1,13 +1,13 @@ const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const apiUrl = `${rootUrl}/api/ajax/getlistbycid?cid=48&type=1&page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/getlistbycid?cid=48&type=1&page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: '第一财经 - 头条', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/latest.js b/lib/v2/yicai/latest.js index a01d4cb39..b03b24291 100644 --- a/lib/v2/yicai/latest.js +++ b/lib/v2/yicai/latest.js @@ -1,13 +1,13 @@ const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const apiUrl = `${rootUrl}/api/ajax/getlatest?page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/getlatest?page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: '第一财经 - 最新', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/news.js b/lib/v2/yicai/news.js index 1d51554b3..c4cd927ef 100644 --- a/lib/v2/yicai/news.js +++ b/lib/v2/yicai/news.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? ''; + const id = ctx.req.param('id') ?? ''; let channel; if (id) { @@ -27,13 +27,13 @@ module.exports = async (ctx) => { } const currentUrl = `${rootUrl}/news${id ? `/${channel.slug}` : ''}`; - const apiUrl = `${rootUrl}/api/ajax/${id ? `getlistbycid?cid=${channel.id}` : 'getjuhelist?action=news'}&page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/${id ? `getlistbycid?cid=${channel.id}` : 'getjuhelist?action=news'}&page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `第一财经 - ${channel?.name ?? '新闻'}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/utils.js b/lib/v2/yicai/utils.js index 3fa1843e3..fe3da052d 100644 --- a/lib/v2/yicai/utils.js +++ b/lib/v2/yicai/utils.js @@ -1,8 +1,8 @@ -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'); const rootUrl = 'https://www.yicai.com'; @@ -42,7 +42,7 @@ module.exports = { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('h1').remove(); content('.u-btn6, .m-smallshare, .topic-hot').remove(); diff --git a/lib/v2/yicai/video.js b/lib/v2/yicai/video.js index af738f25c..38e8761bf 100644 --- a/lib/v2/yicai/video.js +++ b/lib/v2/yicai/video.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? ''; + const id = ctx.req.param('id') ?? ''; let channel; if (id) { @@ -27,13 +27,13 @@ module.exports = async (ctx) => { } const currentUrl = `${rootUrl}/video${id ? `/${channel.slug}` : ''}`; - const apiUrl = `${rootUrl}/api/ajax/${id ? `getlistbycid?cid=${channel.id}` : 'getjuhelist?action=video'}&page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/${id ? `getlistbycid?cid=${channel.id}` : 'getjuhelist?action=video'}&page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `第一财经 - ${channel?.name ?? '视听'}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yicai/vip.js b/lib/v2/yicai/vip.js index 8a49754ad..c8c674341 100644 --- a/lib/v2/yicai/vip.js +++ b/lib/v2/yicai/vip.js @@ -1,26 +1,26 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '428'; + const id = ctx.req.param('id') ?? '428'; const currentUrl = `${rootUrl}/vip/product/${id}`; - const apiUrl = `${rootUrl}/api/ajax/getlistbypid?id=${id}&type=3&page=1&pagesize=${ctx.query.limit ?? 30}`; + const apiUrl = `${rootUrl}/api/ajax/getlistbypid?id=${id}&type=3&page=1&pagesize=${ctx.req.query('limit') ?? 30}`; const response = await got({ method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = await ProcessItems(apiUrl, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `第一财经VIP频道 - ${$('title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/ymgal/article.js b/lib/v2/ymgal/article.js index 9b58871b4..4eba3c333 100644 --- a/lib/v2/ymgal/article.js +++ b/lib/v2/ymgal/article.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 host = 'https://www.ymgal.games'; @@ -11,7 +11,7 @@ const types = { }; module.exports = async (ctx) => { - const type = ctx.params.type || 'all'; + const type = ctx.req.param('type') || 'all'; const link = `${host}/co/topic/list` + types[type]; let data = []; @@ -33,7 +33,7 @@ module.exports = async (ctx) => { const itemUrl = host + '/co/article/' + item.topicId; return ctx.cache.tryGet(itemUrl, async () => { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('article').html().trim(); return { title: item.title, @@ -52,10 +52,10 @@ module.exports = async (ctx) => { info = '专栏'; } - ctx.state.data = { + ctx.set('data', { title: `月幕 Galgame - ${info}`, link: `${host}/co/article`, description: `月幕 Galgame - ${info}`, item: items, - }; + }); }; diff --git a/lib/v2/ymgal/game.js b/lib/v2/ymgal/game.js index d3d749459..822868cb0 100644 --- a/lib/v2/ymgal/game.js +++ b/lib/v2/ymgal/game.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 cheerio = require('cheerio'); +import { load } from 'cheerio'; const host = 'https://www.ymgal.games'; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: `${host}/release-list/${year}/${month}`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.game-view-card').toArray(); const items = @@ -32,10 +32,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `月幕 Galgame - 本月新作`, link: `${host}/release-list/${year}/${month}`, description: '月幕 Galgame - 本月新作', item: items, - }; + }); }; diff --git a/lib/v2/yoasobi-music/info.js b/lib/v2/yoasobi-music/info.js index 13a79b1d5..fd85f04e9 100644 --- a/lib/v2/yoasobi-music/info.js +++ b/lib/v2/yoasobi-music/info.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { parseJSONP } = require('./jsonp-helper'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const category = ctx.params.category; + const category = ctx.req.param('category'); const ARTIST = 'YOASOBI', SONYJPURL = 'https://www.sonymusic.co.jp', @@ -39,7 +39,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { // the source title title, // the source url @@ -64,5 +64,5 @@ module.exports = async (ctx) => { link: i.id ? `${officialUrl}/${i.id}` : officialUrl, category: i.category, })), - }; + }); }; diff --git a/lib/v2/yoasobi-music/live.js b/lib/v2/yoasobi-music/live.js index be6a434f2..aeb9e00c7 100644 --- a/lib/v2/yoasobi-music/live.js +++ b/lib/v2/yoasobi-music/live.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseJSONP } = require('./jsonp-helper'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { sessions: item.liveItem, })); - ctx.state.data = { + ctx.set('data', { // the source title title, // the source url @@ -48,5 +48,5 @@ module.exports = async (ctx) => { // the article link link: item.link, })), - }; + }); }; diff --git a/lib/v2/yoasobi-music/media.js b/lib/v2/yoasobi-music/media.js index c636a5547..474c4fc53 100644 --- a/lib/v2/yoasobi-music/media.js +++ b/lib/v2/yoasobi-music/media.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseJSONP } = require('./jsonp-helper'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -30,7 +30,7 @@ module.exports = async (ctx) => { description: item.note, })); - ctx.state.data = { + ctx.set('data', { // the source title title, // the source url @@ -55,5 +55,5 @@ module.exports = async (ctx) => { // the article link link: officialUrl, })), - }; + }); }; diff --git a/lib/v2/yomiuri/news.js b/lib/v2/yomiuri/news.js index c47031d81..5868344a0 100644 --- a/lib/v2/yomiuri/news.js +++ b/lib/v2/yomiuri/news.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'; module.exports = async (ctx) => { const { category = 'news' } = ctx.params; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let list; if (category === 'news') { @@ -50,7 +50,7 @@ module.exports = async (ctx) => { } const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const mainContent = $('.p-main-contents'); mainContent.find('[class^=ev-article], svg').remove(); @@ -70,10 +70,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, image: 'https://www.yomiuri.co.jp/apple-touch-icon.png', item: items, - }; + }); }; diff --git a/lib/v2/yomujp/level.js b/lib/v2/yomujp/level.js index 4e78a5aa1..c5a9a9622 100644 --- a/lib/v2/yomujp/level.js +++ b/lib/v2/yomujp/level.js @@ -1,17 +1,17 @@ -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const md5 = require('@/utils/md5'); +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import md5 from '@/utils/md5'; module.exports = async (ctx) => { - const level = formatLevel(ctx.params.level); + const level = formatLevel(ctx.req.param('level')); const url = new URL('https://yomujp.com/wp-json/wp/v2/posts'); url.searchParams.append('categories', getLevel(level)); - url.searchParams.append('per_page', Number.parseInt(ctx.query.limit) || 10); + url.searchParams.append('per_page', Number.parseInt(ctx.req.query('limit')) || 10); const posts = await get(url); const item = posts.map((post) => { - const $ = cheerio.load(post.content.rendered.replaceAll(/[\t\n\r]/g, '')); + const $ = load(post.content.rendered.replaceAll(/[\t\n\r]/g, '')); const audio = $('audio.vapfem_audio>source'); const description = $('section') .slice(2, -2) @@ -42,7 +42,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: level ? `${level.toUpperCase()} | 日本語多読道場` : '日本語多読道場', link: `https://yomujp.com/${level}`, description: 'みなさん、こんにちは。 「 日本語多読道場(にほんごたどくどうじょう) Yomujp」は日本語を勉強する人のための読みものサイト(website)です。 日本の地理、食べもの、動物、植物、文化や歴史などを紹介します。', @@ -50,7 +50,7 @@ module.exports = async (ctx) => { itunes_author: 'Yomujp', image: 'https://yomujp.com/wp-content/uploads/2023/08/top1-2-300x99-1.png', item, - }; + }); }; const formatLevel = (level) => { diff --git a/lib/v2/youku/channel.js b/lib/v2/youku/channel.js index d21f6abd8..f68fd283b 100644 --- a/lib/v2/youku/channel.js +++ b/lib/v2/youku/channel.js @@ -1,12 +1,12 @@ -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 channelId = ctx.params.channelId; - const embed = !ctx.params.embed; + const channelId = ctx.req.param('channelId'); + const embed = !ctx.req.param('embed'); const response = await got({ method: 'get', @@ -18,10 +18,10 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('div.videoitem_pack'); - ctx.state.data = { + ctx.set('data', { title: $('.username').text(), link: `https://i.youku.com/i/${channelId}`, description: $('.desc').text(), @@ -52,5 +52,5 @@ module.exports = async (ctx) => { }) .get() .filter(Boolean), - }; + }); }; diff --git a/lib/v2/youtube/channel.js b/lib/v2/youtube/channel.js index 176e92ad6..984ea2727 100644 --- a/lib/v2/youtube/channel.js +++ b/lib/v2/youtube/channel.js @@ -1,13 +1,13 @@ const utils = require('./utils'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } - const id = ctx.params.id; - const embed = !ctx.params.embed; + const id = ctx.req.param('id'); + const embed = !ctx.req.param('embed'); if (!utils.isYouTubeChannelId(id)) { throw new Error(`Invalid YouTube channel ID. \nYou may want to use /youtube/user/:id instead.`); @@ -17,7 +17,7 @@ module.exports = async (ctx) => { const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; - ctx.state.data = { + ctx.set('data', { title: `${data[0].snippet.channelTitle} - YouTube`, link: `https://www.youtube.com/channel/${id}`, description: `YouTube channel ${data[0].snippet.channelTitle}`, @@ -35,5 +35,5 @@ module.exports = async (ctx) => { author: snippet.videoOwnerChannelTitle, }; }), - }; + }); }; diff --git a/lib/v2/youtube/charts.js b/lib/v2/youtube/charts.js index f9383bb83..584a73faf 100644 --- a/lib/v2/youtube/charts.js +++ b/lib/v2/youtube/charts.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { renderDescription } = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { const contentMap = { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }; const { category = 'TopVideos', country } = ctx.params; - const embed = !ctx.params.embed; + const embed = !ctx.req.param('embed'); const { content } = await ctx.cache.tryGet( `youtube:charts:${country ?? 'global'}`, @@ -87,9 +87,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `YouTube Music Charts - ${contentMap[category].title}`, link: `https://charts.youtube.com/charts/${category}/${country ?? 'global'}`, item: items, - }; + }); }; diff --git a/lib/v2/youtube/community.js b/lib/v2/youtube/community.js index 6c89b7b96..44dc366ff 100644 --- a/lib/v2/youtube/community.js +++ b/lib/v2/youtube/community.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { isYouTubeChannelId } = require('./utils'); @@ -14,7 +14,7 @@ module.exports = async (ctx) => { } const { data: response } = await got(`https://www.youtube.com/${urlPath}/community`); - const $ = cheerio.load(response); + const $ = load(response); const ytInitialData = JSON.parse( $('script') .text() @@ -47,10 +47,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${username} - Community - YouTube`, link: channelMetadata.channelUrl, description: channelMetadata.description, item: items, - }; + }); }; diff --git a/lib/v2/youtube/custom.js b/lib/v2/youtube/custom.js index 7e2695144..3293402f3 100644 --- a/lib/v2/youtube/custom.js +++ b/lib/v2/youtube/custom.js @@ -1,18 +1,18 @@ const utils = require('./utils'); -const config = require('@/config').value; -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { config } from '@/config'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } const { username } = ctx.params; - const embed = !ctx.params.embed; + const embed = !ctx.req.param('embed'); const { data: response } = await got(`https://www.youtube.com/c/${username}`); - const $ = cheerio.load(response); + const $ = load(response); const ytInitialData = JSON.parse( $('script') .text() @@ -23,7 +23,7 @@ module.exports = async (ctx) => { const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; - ctx.state.data = { + ctx.set('data', { title: `${username} - YouTube`, link: `https://www.youtube.com/c/${username}`, description: ytInitialData.metadata.channelMetadataRenderer.description, @@ -41,5 +41,5 @@ module.exports = async (ctx) => { author: snippet.videoOwnerChannelTitle, }; }), - }; + }); }; diff --git a/lib/v2/youtube/live.js b/lib/v2/youtube/live.js index 10cde17f2..790999b71 100644 --- a/lib/v2/youtube/live.js +++ b/lib/v2/youtube/live.js @@ -1,22 +1,22 @@ const utils = require('./utils'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } - const username = ctx.params.username; - const embed = !ctx.params.embed; + const username = ctx.req.param('username'); + const embed = !ctx.req.param('embed'); let channelName; let channelId; const link = `https://www.youtube.com/${username}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); channelId = $('meta[itemprop="identifier"]').attr('content'); channelName = $('meta[itemprop="name"]').attr('content'); @@ -28,7 +28,7 @@ module.exports = async (ctx) => { const data = (await utils.getLive(channelId, ctx.cache)).data.items; - ctx.state.data = { + ctx.set('data', { title: `${channelName || username}'s Live Status`, link: `https://www.youtube.com/channel/${channelId}`, description: `$${channelName || username}'s live streaming status`, @@ -45,5 +45,5 @@ module.exports = async (ctx) => { }; }), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/youtube/playlist.js b/lib/v2/youtube/playlist.js index c79fdf116..58c287ecb 100644 --- a/lib/v2/youtube/playlist.js +++ b/lib/v2/youtube/playlist.js @@ -1,19 +1,19 @@ const utils = require('./utils'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } - const id = ctx.params.id; - const embed = !ctx.params.embed; + const id = ctx.req.param('id'); + const embed = !ctx.req.param('embed'); const playlistTitle = (await utils.getPlaylist(id, 'snippet', ctx.cache)).data.items[0].snippet.title; const data = (await utils.getPlaylistItems(id, 'snippet', ctx.cache)).data.items.filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video'); - ctx.state.data = { + ctx.set('data', { title: `${playlistTitle} by ${data[0].snippet.channelTitle} - YouTube`, link: `https://www.youtube.com/playlist?list=${id}`, description: `YouTube playlist ${playlistTitle} by ${data[0].snippet.channelTitle}`, @@ -29,5 +29,5 @@ module.exports = async (ctx) => { author: snippet.videoOwnerChannelTitle, }; }), - }; + }); }; diff --git a/lib/v2/youtube/subscriptions.js b/lib/v2/youtube/subscriptions.js index 9298d9027..80acd1032 100644 --- a/lib/v2/youtube/subscriptions.js +++ b/lib/v2/youtube/subscriptions.js @@ -1,13 +1,13 @@ -const config = require('@/config').value; +import { config } from '@/config'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key || !config.youtube.clientId || !config.youtube.clientSecret || !config.youtube.refreshToken) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } - const embed = !ctx.params.embed; + const embed = !ctx.req.param('embed'); const channelIds = (await utils.getSubscriptions('snippet', ctx.cache)).data.items.map((item) => item.snippet.resourceId.channelId); @@ -40,17 +40,17 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'Subscriptions - YouTube', description: 'YouTube Subscriptions', item: items, - }; + }); - ctx.state.json = { + ctx.set('json', { title: 'Subscriptions - YouTube', description: 'YouTube Subscriptions', channelIds, playlistIds, item: items, - }; + }); }; diff --git a/lib/v2/youtube/user.js b/lib/v2/youtube/user.js index b5e93d70b..93c1da04e 100644 --- a/lib/v2/youtube/user.js +++ b/lib/v2/youtube/user.js @@ -1,22 +1,22 @@ const utils = require('./utils'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { if (!config.youtube || !config.youtube.key) { throw new Error('YouTube RSS is disabled due to the lack of relevant config'); } - const username = ctx.params.username; - const embed = !ctx.params.embed; + const username = ctx.req.param('username'); + const embed = !ctx.req.param('embed'); let playlistId; let channelName; if (username.startsWith('@')) { const link = `https://www.youtube.com/${username}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const channelId = $('meta[itemprop="identifier"]').attr('content'); channelName = $('meta[itemprop="name"]').attr('content'); playlistId = (await utils.getChannelWithId(channelId, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads; @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; - ctx.state.data = { + ctx.set('data', { title: `${channelName || username} - YouTube`, link: username.startsWith('@') ? `https://www.youtube.com/${username}` : `https://www.youtube.com/user/${username}`, description: `YouTube user ${username}`, @@ -43,5 +43,5 @@ module.exports = async (ctx) => { author: snippet.videoOwnerChannelTitle, }; }), - }; + }); }; diff --git a/lib/v2/youtube/utils.js b/lib/v2/youtube/utils.js index 8a9fcf757..bbeda71f4 100644 --- a/lib/v2/youtube/utils.js +++ b/lib/v2/youtube/utils.js @@ -1,8 +1,8 @@ const { google } = require('googleapis'); const { OAuth2 } = google.auth; -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; let count = 0; const youtube = {}; diff --git a/lib/v2/youzhiyouxing/materials.js b/lib/v2/youzhiyouxing/materials.js index 940c9758c..c62fe40a2 100644 --- a/lib/v2/youzhiyouxing/materials.js +++ b/lib/v2/youzhiyouxing/materials.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 ?? ''; + const id = ctx.req.param('id') ?? ''; const rootUrl = 'https://youzhiyouxing.cn'; const currentUrl = `${rootUrl}/materials?column_id=${id}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('li[id*="material"]') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('.tw-inline').text().replace('·', ''); item.description = content('#zx-material-marker-root') @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `有知有行 - ${$(`a[phx-value-column_id="${id === '' ? 0 : id}"]`).text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yuque/book.js b/lib/v2/yuque/book.js index f66380cf7..eef38a5bc 100644 --- a/lib/v2/yuque/book.js +++ b/lib/v2/yuque/book.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 { card2Html } = require('./utils'); const { CookieJar } = require('tough-cookie'); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const { data: bookHtml } = await got(bookUrl, { cookieJar, }); - const $ = cheerio.load(bookHtml); + const $ = load(bookHtml); const appData = JSON.parse(decodeURIComponent($('script').text().match(APP_DATA_REGEX)[1])); const bookId = appData.book.id; @@ -49,7 +49,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(data.content, null, false); + const $ = load(data.content, null, false); $('card').each((_, elem) => { card2Html($(elem), item.link); @@ -88,11 +88,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: appData.book.name, description: appData.book.description, image: appData.group.avatar, link: bookUrl, item: items, - }; + }); }; diff --git a/lib/v2/yxdown/news.js b/lib/v2/yxdown/news.js index 3853b8f61..623500ccd 100644 --- a/lib/v2/yxdown/news.js +++ b/lib/v2/yxdown/news.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'; const { rootUrl, getCookie } = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category ? `${ctx.params.category}/` : ''; + const category = ctx.req.param('category') ? `${ctx.req.param('category')}/` : ''; const currentUrl = `${rootUrl}/news/${category}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { cookie, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.div_zixun h2 a') .map((_, item) => { @@ -37,7 +37,7 @@ module.exports = async (ctx) => { cookie, }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('h1, .intro').remove(); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.now').text()} - 游讯网`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yxdown/recommend.js b/lib/v2/yxdown/recommend.js index cc41f5651..2e24a5d28 100644 --- a/lib/v2/yxdown/recommend.js +++ b/lib/v2/yxdown/recommend.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, getCookie } = require('./utils'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul li a b') .map((_, item) => { @@ -34,7 +34,7 @@ module.exports = async (ctx) => { cookie, }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('h1, .intro').remove(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '精彩推荐 - 游讯网', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/yxdown/utils.js b/lib/v2/yxdown/utils.js index 73eb4e2f5..dbe01d10c 100644 --- a/lib/v2/yxdown/utils.js +++ b/lib/v2/yxdown/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const rootUrl = 'http://www.yxdown.com'; diff --git a/lib/v2/yxdzqb/index.js b/lib/v2/yxdzqb/index.js index 97e050744..c30cda0fe 100644 --- a/lib/v2/yxdzqb/index.js +++ b/lib/v2/yxdzqb/index.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 host = 'https://www.yxdzqb.com'; @@ -14,12 +14,12 @@ const map = { }; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const link = `${host}/${Object.hasOwn(map, type) ? map[type] : `index_${type}.html`}`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('.btn-primary b').text() || $('.btn-danger b').text() || $('.btn-info b').text(); const list = $('tr.bg-none'); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `${title}-游戏打折情报`, link, item: out, - }; + }); }; diff --git a/lib/v2/yxrb/home.js b/lib/v2/yxrb/home.js index 02a530c18..5df7bcb5d 100644 --- a/lib/v2/yxrb/home.js +++ b/lib/v2/yxrb/home.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 baseUrl = 'http://news.yxrb.net'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const { category = 'info' } = ctx.params; const link = `${baseUrl}/${category}/`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.channel-news .item') .toArray() @@ -26,7 +26,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 = item.author ?? $('.author-info .name a').text().split('作者 : ')[1]; item.pubDate = timezone( @@ -51,11 +51,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name=description]').attr('content'), link, image: $('.channel-img img').attr('src'), item: items, - }; + }); }; diff --git a/lib/v2/yyets/article.js b/lib/v2/yyets/article.js index a43b9a161..76eff6cfe 100644 --- a/lib/v2/yyets/article.js +++ b/lib/v2/yyets/article.js @@ -1,16 +1,16 @@ -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 baseURL = 'https://yysub.net'; module.exports = async (ctx) => { - const type = ctx.params.type ?? ''; + const type = ctx.req.param('type') ?? ''; const url = `${baseURL}/article${type ? '?type=' + type : ''}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.article-list li .fl-info') .toArray() @@ -28,7 +28,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); item.description = content('.information-desc').html(); return item; @@ -36,10 +36,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()} - 人人影视`, description: $('meta[name="description"]').attr('content'), link: url, item: items, - }; + }); }; diff --git a/lib/v2/yyets/today.js b/lib/v2/yyets/today.js index 48b060e27..88ad9ea3b 100644 --- a/lib/v2/yyets/today.js +++ b/lib/v2/yyets/today.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) => { // 发起 HTTP GET 请求 @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const data = response.data; // response.data 为 HTTP GET 请求返回的 HTML,也就是简书首页的所有 HTML - const $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML + const $ = load(data); // 使用 cheerio 加载返回的 HTML const list = $('.today-list-wrap').find('ul').find('li'); // 使用 cheerio 选择器,选择带有 data-item_id 属性的所有 div 元素,返回 cheerio node 对象数组 @@ -18,7 +18,7 @@ module.exports = async (ctx) => { // 注:cheerio 选择器与 jquery 选择器几乎相同 // 参考 cheerio 文档:https://cheerio.js.org/ - ctx.state.data = { + ctx.set('data', { title: '人人影视-今日播出', link: 'https://yysub.net', item: @@ -33,5 +33,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/yystv/category.js b/lib/v2/yystv/category.js index 6003791d0..3427c872d 100644 --- a/lib/v2/yystv/category.js +++ b/lib/v2/yystv/category.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category; + const category = ctx.req.param('category'); const url = `https://www.yystv.cn/b/${category}`; const response = await got({ method: 'get', @@ -11,7 +11,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const first_part = $('.b-list-main-item') .slice(0, 2) @@ -48,7 +48,7 @@ module.exports = async (ctx) => { url: currentValue.link, method: 'get', }); - const $ = cheerio.load(r.data); + const $ = load(r.data); return $('.doc-content.rel').html(); }); return currentValue; diff --git a/lib/v2/yystv/docs.js b/lib/v2/yystv/docs.js index 64d08c6f5..0fd497d3d 100644 --- a/lib/v2/yystv/docs.js +++ b/lib/v2/yystv/docs.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const url = `https://www.yystv.cn/docs`; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const items = $('.list-container li') .slice(0, 18) @@ -26,9 +26,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '游研社-' + $('title').text(), link: `https://www.yystv.cn/docs`, item: items, - }; + }); }; diff --git a/lib/v2/zagg/new-arrivals.js b/lib/v2/zagg/new-arrivals.js index c0074c61d..b607dc379 100644 --- a/lib/v2/zagg/new-arrivals.js +++ b/lib/v2/zagg/new-arrivals.js @@ -1,10 +1,10 @@ -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 cheerio = require('cheerio'); +import { load } from 'cheerio'; const host = 'https://www.zagg.com/en_us'; module.exports = async (ctx) => { - const query = ctx.params.query; + const query = ctx.req.param('query'); const params = new URLSearchParams(query); const brands = params.get('brand'); const categories = params.get('cat'); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { }); const products = response.data.products; - const $ = cheerio.load(products); + const $ = load(products); const list = $('.item.product.product-item') .map(function () { const data = {}; @@ -39,7 +39,7 @@ module.exports = async (ctx) => { return data; }) .get(); - ctx.state.data = { + ctx.set('data', { title: 'Zagg - New Arrivals', link: response.url, description: 'Zagg - New Arrivals', @@ -48,5 +48,5 @@ module.exports = async (ctx) => { description: item.description, link: item.link, })), - }; + }); }; diff --git a/lib/v2/zaker/index.js b/lib/v2/zaker/index.js index 5fea55574..9b1c1ed6d 100644 --- a/lib/v2/zaker/index.js +++ b/lib/v2/zaker/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'channel'; - const id = ctx.params.id ?? 1; + const type = ctx.req.param('type') ?? 'channel'; + const id = ctx.req.param('id') ?? 1; const rootUrl = 'http://www.myzaker.com'; const link = type === 'focusread' ? `${rootUrl}/?pos=selected_article` : `${rootUrl}/${type}/${id}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { Referer: rootUrl, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const feedTitle = $('head title').text(); let items = $('div.content-block') @@ -39,7 +39,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('div.article_content div').html() ?? '原文已被删除'; item.author = $('a.article-auther.line').text(); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: type === 'focusread' ? 'ZAKER 精读新闻' : feedTitle, link, item: items.filter((t) => t.description !== '原文已被删除'), - }; + }); }; diff --git a/lib/v2/zaobao/index.js b/lib/v2/zaobao/index.js index 6e5053845..cb21dc7bb 100644 --- a/lib/v2/zaobao/index.js +++ b/lib/v2/zaobao/index.js @@ -2,16 +2,16 @@ const { parseList } = require('./util'); const baseUrl = 'https://www.zaobao.com'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'realtime'; - const section = ctx.params.section ?? 'china'; + const type = ctx.req.param('type') ?? 'realtime'; + const section = ctx.req.param('section') ?? 'china'; const sectionLink = `/${type}/${section}`; const { title, resultList } = await parseList(ctx, sectionLink); - ctx.state.data = { + ctx.set('data', { title: `《联合早报》${title}`, link: baseUrl + sectionLink, description: '新加坡、中国、亚洲和国际的即时、评论、商业、体育、生活、科技与多媒体新闻,尽在联合早报。', item: resultList, - }; + }); }; diff --git a/lib/v2/zaobao/interactive.js b/lib/v2/zaobao/interactive.js index 0ffc1bfe2..357fedd63 100644 --- a/lib/v2/zaobao/interactive.js +++ b/lib/v2/zaobao/interactive.js @@ -6,10 +6,10 @@ module.exports = async (ctx) => { const { resultList } = await parseList(ctx, sectionLink); - ctx.state.data = { + ctx.set('data', { title: `《联合早报》互动新闻`, link: baseUrl + sectionLink, description: '新加坡、中国、亚洲和国际的即时、评论、商业、体育、生活、科技与多媒体新闻,尽在联合早报。', item: resultList, - }; + }); }; diff --git a/lib/v2/zaobao/realtime.js b/lib/v2/zaobao/realtime.js index 090aaad16..dba85b7d2 100644 --- a/lib/v2/zaobao/realtime.js +++ b/lib/v2/zaobao/realtime.js @@ -2,7 +2,7 @@ const { parseList } = require('./util'); const baseUrl = 'https://www.zaobao.com'; module.exports = async (ctx) => { - const section = ctx.params.section ?? 'china'; + const section = ctx.req.param('section') ?? 'china'; let name; let sectionLink; @@ -36,10 +36,10 @@ module.exports = async (ctx) => { const { resultList } = await parseList(ctx, sectionLink); - ctx.state.data = { + ctx.set('data', { title: `《联合早报》-${name}-即时`, link: baseUrl + sectionLink, description: '新加坡、中国、亚洲和国际的即时、评论、商业、体育、生活、科技与多媒体新闻,尽在联合早报。', item: resultList, - }; + }); }; diff --git a/lib/v2/zaobao/util.js b/lib/v2/zaobao/util.js index d9819fef9..b085a9fe4 100644 --- a/lib/v2/zaobao/util.js +++ b/lib/v2/zaobao/util.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseRelativeDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); const { base32 } = require('rfc4648'); @@ -29,7 +29,7 @@ const got_ins = got.extend({ */ const parseList = async (ctx, sectionUrl) => { const response = await got_ins.get(baseUrl + sectionUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); let data = $('.article-list').find('.article-type'); if (data.length === 0) { // for HK version @@ -76,7 +76,7 @@ const parseList = async (ctx, sectionUrl) => { return ctx.cache.tryGet(link, async () => { const article = await got_ins.get(link); - const $1 = cheerio.load(article.data); + const $1 = load(article.data); const time = (() => $1("head script[type='application/json']").text() === '' diff --git a/lib/v2/zaobao/znews.js b/lib/v2/zaobao/znews.js index 5847d5d2c..68c904215 100644 --- a/lib/v2/zaobao/znews.js +++ b/lib/v2/zaobao/znews.js @@ -2,7 +2,7 @@ const { parseList } = require('./util'); const baseUrl = 'https://www.zaobao.com'; module.exports = async (ctx) => { - const section = ctx.params.section; + const section = ctx.req.param('section'); let info; let sectionLink; @@ -40,10 +40,10 @@ module.exports = async (ctx) => { const { resultList } = await parseList(ctx, sectionLink); - ctx.state.data = { + ctx.set('data', { title: `《联合早报》-${info}-新闻`, link: baseUrl + sectionLink, description: '新加坡、中国、亚洲和国际的即时、评论、商业、体育、生活、科技与多媒体新闻,尽在联合早报。', item: resultList, - }; + }); }; diff --git a/lib/v2/zaozao/article.js b/lib/v2/zaozao/article.js index 1d493f500..d1455368d 100644 --- a/lib/v2/zaozao/article.js +++ b/lib/v2/zaozao/article.js @@ -1,5 +1,5 @@ -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; module.exports = async (ctx) => { const { type = 'recommend' } = ctx.params; @@ -22,7 +22,7 @@ module.exports = async (ctx) => { const { data } = response.data; - ctx.state.data = { + ctx.set('data', { title: `前端早早聊 - 文章`, link: `https://www.zaozao.run/article/${type}`, description: `前端早早聊 - 文章`, @@ -32,5 +32,5 @@ module.exports = async (ctx) => { author: item.recommenderName, pubDate: parseDate(item.updateAt), })), - }; + }); }; diff --git a/lib/v2/zcmu/jwc/index.js b/lib/v2/zcmu/jwc/index.js index 3e7aabc96..a0c8945fd 100644 --- a/lib/v2/zcmu/jwc/index.js +++ b/lib/v2/zcmu/jwc/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 host = 'https://jwc.zcmu.edu.cn/'; @@ -14,14 +14,14 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const id = map.get(type).id; const res = await got({ method: 'get', url: `${host}/${id}.htm`, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = $('.winstyle196327 tr:lt(20)') .map((index, item) => { item = $(item); @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: `${host}${id}`, item: items, - }; + }); }; diff --git a/lib/v2/zcmu/yxy/index.js b/lib/v2/zcmu/yxy/index.js index 35e3ac108..2afcb40c5 100644 --- a/lib/v2/zcmu/yxy/index.js +++ b/lib/v2/zcmu/yxy/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 host = 'https://yxy.zcmu.edu.cn/'; @@ -15,14 +15,14 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const id = map.get(type).id; const res = await got({ method: 'get', url: `${host}/${id}.htm`, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = $('.lm_list li') .map((index, item) => { item = $(item); @@ -34,9 +34,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: `${host}${id}`, item: items, - }; + }); }; diff --git a/lib/v2/zcool/discover.js b/lib/v2/zcool/discover.js index 2f436553f..22789006d 100644 --- a/lib/v2/zcool/discover.js +++ b/lib/v2/zcool/discover.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'); const locations = require('./locations'); @@ -44,15 +44,15 @@ module.exports = async (ctx) => { const queries = { cate: '0', - subCate: ctx.params.subCate ?? '0', - city: ctx.params.city ?? '0', - college: ctx.params.college ?? '0', - recommendLevel: ctx.params.recommendLevel ?? '2', - sort: ctx.params.sort ?? '9', - limit: ctx.query.limit ?? '25', + subCate: ctx.req.param('subCate') ?? '0', + city: ctx.req.param('city') ?? '0', + college: ctx.req.param('college') ?? '0', + recommendLevel: ctx.req.param('recommendLevel') ?? '2', + sort: ctx.req.param('sort') ?? '9', + limit: ctx.req.query('limit') ?? '25', }; - let query = ctx.params.query ?? ''; + let query = ctx.req.param('query') ?? ''; if (query.includes('=')) { for (const q of query.split('&')) { @@ -77,7 +77,7 @@ module.exports = async (ctx) => { queries.recommendLevel = '2'; break; default: - queries.cate = ctx.params.query ?? '0'; + queries.cate = ctx.req.param('query') ?? '0'; } } @@ -118,7 +118,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.prism-player, .image-info-icons').remove(); @@ -147,9 +147,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `站酷 - ${categories[queries.cate]}${queries.subCate === '0' ? '' : ` - ${subCategories[queries.cate][queries.subCate]}`}`, link: `${rootUrl}/discover?${query}`, item: items, - }; + }); }; diff --git a/lib/v2/zcool/top.js b/lib/v2/zcool/top.js index 1524851a4..ab6b2dd78 100644 --- a/lib/v2/zcool/top.js +++ b/lib/v2/zcool/top.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 { extractArticle, extractWork } = require('./utils'); const baseUrl = 'https://www.zcool.com.cn'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const data = JSON.parse($('script#__NEXT_DATA__').text()); @@ -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); const data = JSON.parse($('script#__NEXT_DATA__').text()); item.pubDate = parseDate(data.props.pageProps.data.publishTime, 'x'); @@ -42,10 +42,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: data.props.pageProps.seo.title, description: data.props.pageProps.seo.description, link: url, item: items, - }; + }); }; diff --git a/lib/v2/zcool/user.js b/lib/v2/zcool/user.js index 2bff40fe7..f20814196 100644 --- a/lib/v2/zcool/user.js +++ b/lib/v2/zcool/user.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 { extractArticle, extractWork } = require('./utils'); const { isValidHost } = require('@/utils/valid-host'); @@ -14,7 +14,7 @@ module.exports = async (ctx) => { pageUrl = `https://${uid}.zcool.com.cn`; } const { data: response } = await got(pageUrl); - const $ = cheerio.load(response); + const $ = load(response); const data = JSON.parse($('script#__NEXT_DATA__').text()); const workList = data.props.pageProps.workList.map((item) => ({ @@ -28,7 +28,7 @@ module.exports = async (ctx) => { workList.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); const data = JSON.parse($('script#__NEXT_DATA__').text()); if (item.link.startsWith('https://www.zcool.com.cn/article/')) { @@ -42,11 +42,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: data.props.pageProps.seo.title, description: data.props.pageProps.seo.description, image: data.props.pageProps.userInfo.avatar.includes('?x-oss-process') ? data.props.pageProps.userInfo.avatar.split('?')[0] : data.props.pageProps.userInfo.avatar, link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/zcool/utils.js b/lib/v2/zcool/utils.js index 2706e719a..4dc1f08a5 100644 --- a/lib/v2/zcool/utils.js +++ b/lib/v2/zcool/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const extractArticle = (data) => data.props.pageProps.data.summary + data.props.pageProps.data.memo; diff --git a/lib/v2/zhangyoubao/index.js b/lib/v2/zhangyoubao/index.js index d68a20b29..3552a8778 100644 --- a/lib/v2/zhangyoubao/index.js +++ b/lib/v2/zhangyoubao/index.js @@ -1,10 +1,10 @@ -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 category = ctx.params.category; + const category = ctx.req.param('category'); const map = new Map([ ['lol', { title: '英雄联盟', id: 1 }], ['lscs', { title: '炉石传说', id: 2 }], @@ -33,10 +33,10 @@ module.exports = async (ctx) => { pubDate: parseDate(item.article.publish_time, 'X'), })); - ctx.state.data = { + ctx.set('data', { title: '掌游宝' + map.get(category).title + '分区', link: 'https://mobile.zhangyoubao.com/' + category, description: '掌游宝' + map.get(category).title + '分区', item: items, - }; + }); }; diff --git a/lib/v2/zhibo8/forum.js b/lib/v2/zhibo8/forum.js index 4372bb777..66c296419 100644 --- a/lib/v2/zhibo8/forum.js +++ b/lib/v2/zhibo8/forum.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 = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://bbs.zhibo8.cc/forum/list/?fid=${id}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.intro > h2').text(); const list = $('table.topic-list > tbody:nth-child(3) > tr'); @@ -24,7 +24,7 @@ module.exports = async (ctx) => { const date = item.find('td:nth-child(2) em').text(); const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('.detail_ent').html(); return { @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${title}—直播吧`, link, item: out, - }; + }); }; diff --git a/lib/v2/zhibo8/luxiang.js b/lib/v2/zhibo8/luxiang.js index c134fa333..e7c991b28 100644 --- a/lib/v2/zhibo8/luxiang.js +++ b/lib/v2/zhibo8/luxiang.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'; module.exports = async (ctx) => { const rootUrl = 'https://www.zhibo8.cc'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${rootUrl}/${category}/luxiang.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.box') .toArray() @@ -29,10 +29,10 @@ module.exports = async (ctx) => { }); }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, image: 'https://www.zhibo8.cc/favicon.ico', item: list, - }; + }); }; diff --git a/lib/v2/zhibo8/more.js b/lib/v2/zhibo8/more.js index 53b74ba27..2ed0f9090 100644 --- a/lib/v2/zhibo8/more.js +++ b/lib/v2/zhibo8/more.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 categories = { nba: 'NBA', @@ -11,7 +11,7 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'nba'; + const category = ctx.req.param('category') ?? 'nba'; const rootUrl = 'https://news.zhibo8.cc'; @@ -25,10 +25,10 @@ module.exports = async (ctx) => { response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); list = $('ul.articleList li') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100) .toArray() .map((item) => { item = $(item); @@ -58,7 +58,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got(item.link); - const content = cheerio.load(res.data); + const content = load(res.data); item.description = content('div.content').html(); return item; @@ -66,9 +66,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${categories[category]} - 直播吧`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/zhibo8/post.js b/lib/v2/zhibo8/post.js index 51844edf2..3d9c2a9a2 100644 --- a/lib/v2/zhibo8/post.js +++ b/lib/v2/zhibo8/post.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 = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://bbs.zhibo8.cc/forum/topic?tid=${id}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.topic-title > h1').text(); const list = $('.topic-content .topic-table'); @@ -41,9 +41,9 @@ module.exports = async (ctx) => { return single; }); - ctx.state.data = { + ctx.set('data', { title: `“${title}”的新回复—直播吧`, link, item: out, - }; + }); }; diff --git a/lib/v2/zhihu/activities.js b/lib/v2/zhihu/activities.js index c5f9bc7e6..c7957f8ae 100644 --- a/lib/v2/zhihu/activities.js +++ b/lib/v2/zhihu/activities.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const g_encrypt = require('./execlib/x-zse-96-v3'); -const md5 = require('@/utils/md5'); +import md5 from '@/utils/md5'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); // Because the API of zhihu.com has changed, we must use the value of `d_c0` (extracted from cookies) to calculate // `x-zse-96`. So first get `d_c0`, then get the actual data of a ZhiHu question. In this way, we don't need to @@ -49,7 +49,7 @@ module.exports = async (ctx) => { const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `${data[0].actor.name}的知乎动态`, link: `https://www.zhihu.com/people/${id}/activities`, image: data[0].actor.avatar_url, @@ -153,5 +153,5 @@ module.exports = async (ctx) => { link: url, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/answers.js b/lib/v2/zhihu/answers.js index 0f0089646..4eeff99e2 100644 --- a/lib/v2/zhihu/answers.js +++ b/lib/v2/zhihu/answers.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const headers = { 'User-Agent': 'ZhihuHybrid com.zhihu.android/Futureve/6.59.0 Mozilla/5.0 (Linux; Android 10; GM1900 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/85.0.4183.127 Mobile Safari/537.36', Referer: `https://www.zhihu.com/people/${id}/answers`, @@ -59,9 +59,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${name}的知乎回答`, link: `https://www.zhihu.com/people/${id}/answers`, item: items, - }; + }); }; diff --git a/lib/v2/zhihu/bookstore/newest.js b/lib/v2/zhihu/bookstore/newest.js index 26f53974b..9b851014d 100644 --- a/lib/v2/zhihu/bookstore/newest.js +++ b/lib/v2/zhihu/bookstore/newest.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const response = await got({ @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: '知乎书店-新书抢鲜', link: 'https://www.zhihu.com/pub/features/new', item: data.map((item) => { @@ -26,5 +26,5 @@ module.exports = async (ctx) => { `, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/collection.js b/lib/v2/zhihu/collection.js index 1722d4a93..87b1d5e7a 100644 --- a/lib/v2/zhihu/collection.js +++ b/lib/v2/zhihu/collection.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); const { generateData } = require('./pin/utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; - const getAll = ctx.params.getAll; + const id = ctx.req.param('id'); + const getAll = ctx.req.param('getAll'); const response = await got({ method: 'get', @@ -52,12 +52,12 @@ module.exports = async (ctx) => { }); const meta = response2.data; - const $ = cheerio.load(meta); + const $ = load(meta); const collection_title = $('.CollectionDetailPageHeader-title').text() + ' - 知乎收藏夹'; const collection_description = $('.CollectionDetailPageHeader-description').text(); const generateDataPin = (item) => generateData([item.content])[0]; - ctx.state.data = { + ctx.set('data', { title: collection_title, link: `https://www.zhihu.com/collection/${id}`, description: collection_description, @@ -73,5 +73,5 @@ module.exports = async (ctx) => { pubDate: parseDate((item.content.type === 'article' ? item.content.updated : item.content.updated_time) * 1000), } ), - }; + }); }; diff --git a/lib/v2/zhihu/daily-section.js b/lib/v2/zhihu/daily-section.js index 03e8328a0..a809e13df 100644 --- a/lib/v2/zhihu/daily-section.js +++ b/lib/v2/zhihu/daily-section.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // 参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90 // 文章给出了v7版 api的信息,包含全文api @@ -41,11 +41,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${listRes.data.name} - 知乎日报`, link: 'https://daily.zhihu.com', description: '每天3次,每次7分钟', image: 'http://static.daily.zhihu.com/img/new_home_v3/mobile_top_logo.png', item: resultItem, - }; + }); }; diff --git a/lib/v2/zhihu/daily.js b/lib/v2/zhihu/daily.js index 52f30d6e5..f724f86d8 100644 --- a/lib/v2/zhihu/daily.js +++ b/lib/v2/zhihu/daily.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // 参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90 // 文章给出了v4版 api的信息,包含全文api @@ -70,11 +70,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '知乎日报', link: 'https://daily.zhihu.com', description: '每天3次,每次7分钟', image: 'http://static.daily.zhihu.com/img/new_home_v3/mobile_top_logo.png', item: items, - }; + }); }; diff --git a/lib/v2/zhihu/hot.js b/lib/v2/zhihu/hot.js index d252a9bbc..b515ebbcb 100644 --- a/lib/v2/zhihu/hot.js +++ b/lib/v2/zhihu/hot.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 titles = { total: '全站', @@ -16,7 +16,7 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'total'; + const category = ctx.req.param('category') ?? 'total'; const response = await got({ method: 'get', @@ -30,9 +30,9 @@ module.exports = async (ctx) => { description: item.target.excerpt ? `

${item.target.excerpt}

` : '', })); - ctx.state.data = { + ctx.set('data', { title: `知乎热榜 - ${titles[category]}`, link: `https://www.zhihu.com/hot?list=${category}`, item: items, - }; + }); }; diff --git a/lib/v2/zhihu/hotlist.js b/lib/v2/zhihu/hotlist.js index cffd2f3b1..8e9f3812c 100644 --- a/lib/v2/zhihu/hotlist.js +++ b/lib/v2/zhihu/hotlist.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { @@ -10,7 +10,7 @@ module.exports = async (ctx) => { url: 'https://www.zhihu.com/api/v3/explore/guest/feeds?limit=40', }); - ctx.state.data = { + ctx.set('data', { title: '知乎热榜', link: 'https://www.zhihu.com/billboard', description: '知乎热榜', @@ -43,5 +43,5 @@ module.exports = async (ctx) => { }; } }), - }; + }); }; diff --git a/lib/v2/zhihu/pin/daily.js b/lib/v2/zhihu/pin/daily.js index d581d4bb2..e17aeb5f4 100644 --- a/lib/v2/zhihu/pin/daily.js +++ b/lib/v2/zhihu/pin/daily.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateData } = require('./utils'); module.exports = async (ctx) => { @@ -9,10 +9,10 @@ module.exports = async (ctx) => { url: 'https://api.zhihu.com/pins/special/972884951192113152/moments?order_by=newest&reverse_order=0&limit=20', }); - ctx.state.data = { + ctx.set('data', { title: '知乎想法-24小时新闻汇总', link: 'https://www.zhihu.com/pin/special/972884951192113152', description: '汇集每天的社会大事、行业资讯,让你用最简单的方式获得想法里的新闻', item: generateData(data), - }; + }); }; diff --git a/lib/v2/zhihu/pin/hotlist.js b/lib/v2/zhihu/pin/hotlist.js index 8a89419c0..1374fc40a 100644 --- a/lib/v2/zhihu/pin/hotlist.js +++ b/lib/v2/zhihu/pin/hotlist.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateData } = require('./utils'); module.exports = async (ctx) => { @@ -9,10 +9,10 @@ module.exports = async (ctx) => { url: 'https://api.zhihu.com/pins/hot_list?reverse_order=0', }); - ctx.state.data = { + ctx.set('data', { title: '知乎想法热榜', link: 'https://www.zhihu.com/', description: '整点更新', item: generateData(data), - }; + }); }; diff --git a/lib/v2/zhihu/pin/people.js b/lib/v2/zhihu/pin/people.js index e36d9cb8b..03a984feb 100644 --- a/lib/v2/zhihu/pin/people.js +++ b/lib/v2/zhihu/pin/people.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateData } = require('./utils'); module.exports = async (ctx) => { @@ -11,9 +11,9 @@ module.exports = async (ctx) => { url: `https://api.zhihu.com/pins/${id}/moments?limit=10&offset=0`, }); - ctx.state.data = { + ctx.set('data', { title: `${data[0].target.author.name}的知乎想法`, link: `https://www.zhihu.com/people/${id}/pins`, item: generateData(data), - }; + }); }; diff --git a/lib/v2/zhihu/pin/utils.js b/lib/v2/zhihu/pin/utils.js index 1f9f2b1fd..71ac91e80 100644 --- a/lib/v2/zhihu/pin/utils.js +++ b/lib/v2/zhihu/pin/utils.js @@ -1,4 +1,4 @@ -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const generateDescription = (target, init) => target.content.reduce((description, item) => { diff --git a/lib/v2/zhihu/posts.js b/lib/v2/zhihu/posts.js index 95211315f..8092c1c2e 100644 --- a/lib/v2/zhihu/posts.js +++ b/lib/v2/zhihu/posts.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; - const usertype = ctx.params.usertype; + const id = ctx.req.param('id'); + const usertype = ctx.req.param('usertype'); const { data } = await got(`https://www.zhihu.com/${usertype}/${id}/posts`, { headers: { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { Referer: `https://www.zhihu.com/${usertype}/${id}/`, }, }); - const $ = cheerio.load(data); + const $ = load(data); const jsondata = $('#js-initialData'); const authorname = $('.ProfileHeader-name') .contents() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const articlesdata = parsed.initialState.entities.articles; const list = Object.keys(articlesdata).map((key) => { - const $ = cheerio.load(articlesdata[key].content, null, false); + const $ = load(articlesdata[key].content, null, false); $('noscript').remove(); $('img').each((_, item) => { if (item.attribs['data-actualsrc'] || item.attribs['data-original']) { @@ -44,10 +44,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${authorname} 的知乎文章`, link: `https://www.zhihu.com/${usertype}/${id}/posts`, description: authordescription, item: list, - }; + }); }; diff --git a/lib/v2/zhihu/question.js b/lib/v2/zhihu/question.js index f393af5b7..c113315ec 100644 --- a/lib/v2/zhihu/question.js +++ b/lib/v2/zhihu/question.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const md5 = require('@/utils/md5'); +import md5 from '@/utils/md5'; const g_encrypt = require('./execlib/x-zse-96-v3'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { @@ -60,7 +60,7 @@ module.exports = async (ctx) => { const listRes = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `知乎-${listRes[0].question.title}`, link: `https://www.zhihu.com/question/${questionId}`, item: listRes.map((item) => { @@ -76,5 +76,5 @@ module.exports = async (ctx) => { link: `https://www.zhihu.com/question/${questionId}/answer/${item.id}`, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/timeline.js b/lib/v2/zhihu/timeline.js index 8b681f068..1f8549ff1 100644 --- a/lib/v2/zhihu/timeline.js +++ b/lib/v2/zhihu/timeline.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const cookie = config.zhihu.cookies; @@ -107,9 +107,9 @@ module.exports = async (ctx) => { return buildItem(e); }); - ctx.state.data = { + ctx.set('data', { title: `知乎关注动态`, link: `https://www.zhihu.com/follow`, item: out, - }; + }); }; diff --git a/lib/v2/zhihu/topic.js b/lib/v2/zhihu/topic.js index cecbd6b15..c17d8043c 100644 --- a/lib/v2/zhihu/topic.js +++ b/lib/v2/zhihu/topic.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const g_encrypt = require('./execlib/x-zse-96-v3'); -const md5 = require('@/utils/md5'); +import md5 from '@/utils/md5'; module.exports = async (ctx) => { const { topicId, isTop = false } = ctx.params; @@ -102,10 +102,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `知乎话题-${topicId}-${isTop ? '精华' : '讨论'}`, description: topicMeta.content.introduction, link, item: items, - }; + }); }; diff --git a/lib/v2/zhihu/utils.js b/lib/v2/zhihu/utils.js index 3b8bb533c..6efa3b566 100644 --- a/lib/v2/zhihu/utils.js +++ b/lib/v2/zhihu/utils.js @@ -1,11 +1,11 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; module.exports = { header: { 'x-api-version': '3.0.91', }, ProcessImage(content) { - const $ = cheerio.load(content, null, false); + const $ = load(content, null, false); $('noscript').remove(); diff --git a/lib/v2/zhihu/weekly.js b/lib/v2/zhihu/weekly.js index 572ca1210..792d12195 100644 --- a/lib/v2/zhihu/weekly.js +++ b/lib/v2/zhihu/weekly.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const host = 'https://www.zhihu.com'; module.exports = async (ctx) => { const link = 'https://www.zhihu.com/pub/weekly'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('p.Weekly-description').text(); const out = $('div.Card-section.PubBookListItem') @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '知乎周刊', link, description, item: out, - }; + }); }; diff --git a/lib/v2/zhihu/xhu/activities.js b/lib/v2/zhihu/xhu/activities.js index 168449f9f..a117a7c64 100644 --- a/lib/v2/zhihu/xhu/activities.js +++ b/lib/v2/zhihu/xhu/activities.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); const utils = require('../utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { }); const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `${data[0].actor.name}的知乎动态`, link, image: data[0].actor.avatar_url, @@ -123,5 +123,5 @@ module.exports = async (ctx) => { link: url, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/answers.js b/lib/v2/zhihu/xhu/answers.js index d6b6d42d6..cafbd58e4 100644 --- a/lib/v2/zhihu/xhu/answers.js +++ b/lib/v2/zhihu/xhu/answers.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }); const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `${data[0].author.name}的知乎回答`, link, item: data.map((item) => ({ @@ -27,5 +27,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.created_time * 1000), link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`, })), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/auth.js b/lib/v2/zhihu/xhu/auth.js index c9df3a12d..43a8ab89e 100644 --- a/lib/v2/zhihu/xhu/auth.js +++ b/lib/v2/zhihu/xhu/auth.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const ProcessCookie = (cookie) => cookie.map((cookie) => cookie.split(';')[0]).join('; '); diff --git a/lib/v2/zhihu/xhu/collection.js b/lib/v2/zhihu/xhu/collection.js index 3d21487c8..60255cdad 100644 --- a/lib/v2/zhihu/xhu/collection.js +++ b/lib/v2/zhihu/xhu/collection.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); const { generateData } = require('../pin/utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://www.zhihu.com/collection/${id}`; const titleResponse = await got({ @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }); const listRes = contentResponse.data.data; - ctx.state.data = { + ctx.set('data', { title: `知乎收藏夹-${titleResponse.data.title}`, description: titleResponse.data.description, link, @@ -72,5 +72,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/posts.js b/lib/v2/zhihu/xhu/posts.js index cceb648e6..2a42d84f3 100644 --- a/lib/v2/zhihu/xhu/posts.js +++ b/lib/v2/zhihu/xhu/posts.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }); const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `${data[0].author.name} 的知乎文章`, link, image: data[0].author.avatar_url, @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: `https://zhuanlan.zhihu.com/p/${item.id}`, author: item.author.name, })), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/question.js b/lib/v2/zhihu/xhu/question.js index 5cd94b296..f6ac9ab27 100644 --- a/lib/v2/zhihu/xhu/question.js +++ b/lib/v2/zhihu/xhu/question.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); const utils = require('../utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); @@ -22,7 +22,7 @@ module.exports = async (ctx) => { }); const listRes = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `知乎-${listRes[0].question.title}`, link, item: listRes.map((item) => { @@ -40,5 +40,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/topic.js b/lib/v2/zhihu/xhu/topic.js index 47c612520..f05beb5dd 100644 --- a/lib/v2/zhihu/xhu/topic.js +++ b/lib/v2/zhihu/xhu/topic.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); const utils = require('../utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); @@ -19,7 +19,7 @@ module.exports = async (ctx) => { }); const listRes = response.data.data; - ctx.state.data = { + ctx.set('data', { title: `知乎话题-${topicId}`, link, item: listRes.map(({ target: item }) => { @@ -66,5 +66,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/xhu/zhuanlan.js b/lib/v2/zhihu/xhu/zhuanlan.js index a5113496d..d6c948cbe 100644 --- a/lib/v2/zhihu/xhu/zhuanlan.js +++ b/lib/v2/zhihu/xhu/zhuanlan.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const auth = require('./auth'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const xhuCookie = await auth.getCookie(ctx); - const id = ctx.params.id; + const id = ctx.req.param('id'); const link = `https://www.zhihu.com/column/${id}`; const titleResponse = await got({ @@ -28,14 +28,14 @@ module.exports = async (ctx) => { const listRes = contentResponse.data.data; - ctx.state.data = { + ctx.set('data', { title: `知乎专栏-${titleResponse.data.title}`, description: titleResponse.data.description, link, item: listRes.map((item) => { let description = ''; if (item.content) { - const $ = cheerio.load(item.content); + const $ = load(item.content); $('img').css('max-width', '100%'); description = $.html(); } @@ -87,5 +87,5 @@ module.exports = async (ctx) => { link, }; }), - }; + }); }; diff --git a/lib/v2/zhihu/zhuanlan.js b/lib/v2/zhihu/zhuanlan.js index f464fa07a..26667826e 100644 --- a/lib/v2/zhihu/zhuanlan.js +++ b/lib/v2/zhihu/zhuanlan.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const listRes = await got({ method: 'get', @@ -33,7 +33,7 @@ module.exports = async (ctx) => { } const infoRes = await got(url); - const $ = cheerio.load(infoRes.data); + const $ = load(infoRes.data); const title = $('.css-zyehvu').text(); const description = $('.css-1bnklpv').text(); @@ -41,7 +41,7 @@ module.exports = async (ctx) => { // 当专栏内文章内容不含任何文字时, 返回空字符, 以免直接报错 let description = ''; if (item.content) { - const $ = cheerio.load(item.content); + const $ = load(item.content); description = $.html(); } $('img').css('max-width', '100%'); @@ -91,10 +91,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { description, item, title: `知乎专栏-${title}`, link: url, - }; + }); }; diff --git a/lib/v2/zhitongcaijing/index.js b/lib/v2/zhitongcaijing/index.js index 5ae90dba7..4d6a433a7 100644 --- a/lib/v2/zhitongcaijing/index.js +++ b/lib/v2/zhitongcaijing/index.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'); const ids = { @@ -64,10 +64,10 @@ const ids = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'recommend'; - const category = ctx.params.category ?? ''; + const id = ctx.req.param('id') ?? 'recommend'; + const category = ctx.req.param('category') ?? ''; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://www.zhitongcaijing.com'; const currentUrl = `${rootUrl}/${ids[id].url}.html${category === '' ? '' : `?category_key=${category}`}`; @@ -95,7 +95,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#subscribe-vip-box').remove(); content('#news-content').remove(); @@ -110,9 +110,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `智通财经 - ${ids[id].title}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/zhiy/letter.js b/lib/v2/zhiy/letter.js index cfa01dda9..2823075f6 100644 --- a/lib/v2/zhiy/letter.js +++ b/lib/v2/zhiy/letter.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 { baseUrl, fetchUserDate } = require('./utils'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { } = await got(`${baseUrl}/api/app/users/${authorId}/letters`, { searchParams: { page: 1, - limit: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100, + limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100, }, }); @@ -24,11 +24,11 @@ module.exports = async (ctx) => { link: `${baseUrl}/letter/${item.id}`, })); - ctx.state.data = { + ctx.set('data', { title: authorName, link: `${baseUrl}/${author}`, description: authorSignature, image: authorAvatarUrl, item: items, - }; + }); }; diff --git a/lib/v2/zhiy/post.js b/lib/v2/zhiy/post.js index 92816143d..05a973016 100644 --- a/lib/v2/zhiy/post.js +++ b/lib/v2/zhiy/post.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { baseUrl, fetchUserDate } = require('./utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const dayjs = require('dayjs'); @@ -21,7 +21,7 @@ module.exports = async (ctx) => { } = await got(`${baseUrl}/api/app/share/garden/users/${authorId}/posts`, { searchParams: { page: 1, - limit: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100, + limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100, }, }); @@ -59,11 +59,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: authorName, link: `${baseUrl}/${author}`, description: authorSignature, image: authorAvatarUrl, item: items, - }; + }); }; diff --git a/lib/v2/zhiy/utils.js b/lib/v2/zhiy/utils.js index 5cc0100d3..d8169c441 100644 --- a/lib/v2/zhiy/utils.js +++ b/lib/v2/zhiy/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const baseUrl = 'https://zhiy.cc'; diff --git a/lib/v2/zhubai/index.js b/lib/v2/zhubai/index.js index b5ecfb592..8505e9b1a 100644 --- a/lib/v2/zhubai/index.js +++ b/lib/v2/zhubai/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { const { id } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; if (!isValidHost(id)) { throw new Error('Invalid id'); } @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const data = response.data.data; const { name, description } = data[0].publication; - ctx.state.data = { + ctx.set('data', { title: name, link: `https://${id}.zhubai.love/`, description, @@ -29,5 +29,5 @@ module.exports = async (ctx) => { link: `https://${id}.zhubai.love/posts/${item.id}`, author: name, })), - }; + }); }; diff --git a/lib/v2/zhubai/top20.js b/lib/v2/zhubai/top20.js index a988b66a3..4649d1d5f 100644 --- a/lib/v2/zhubai/top20.js +++ b/lib/v2/zhubai/top20.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const parseContent = (content) => @@ -12,7 +12,7 @@ const parseContent = (content) => art.defaults.imports.parseContent = parseContent; module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'http://analy.zhubai.wiki'; const apiRootUrl = 'https://open.zhubai.wiki'; @@ -47,11 +47,11 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(rootUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const icon = $('link[rel="apple-touch-icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${$('meta[property="og:title"]').prop('content')} - TOP20`, link: rootUrl, @@ -62,5 +62,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[property="og:description"]').prop('content'), author: $('meta[name="twitter:site"]').prop('content'), - }; + }); }; diff --git a/lib/v2/zimuxia/index.js b/lib/v2/zimuxia/index.js index c3e129e99..b4a6b5ab1 100644 --- a/lib/v2/zimuxia/index.js +++ b/lib/v2/zimuxia/index.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 { category } = ctx.params; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.pg-item a') .toArray() @@ -40,7 +40,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const links = detailResponse.data.match(/磁力下载<\/a>/g); @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${category || 'ALL'} - FIX字幕侠`, link: response.url, item: items, - }; + }); }; diff --git a/lib/v2/zimuxia/portfolio.js b/lib/v2/zimuxia/portfolio.js index cb668f05b..f95225863 100644 --- a/lib/v2/zimuxia/portfolio.js +++ b/lib/v2/zimuxia/portfolio.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const allowlinktypes = new Set(['all', 'magnet', 'ed2k', 'baidu', 'subhd', 'quark', '115']); module.exports = async (ctx) => { - const id = ctx.params.id; - let linktype = ctx.query.linktype ?? 'magnet'; + const id = ctx.req.param('id'); + let linktype = ctx.req.query('linktype') ?? 'magnet'; linktype = allowlinktypes.has(linktype) ? linktype : 'magnet'; linktype = linktype === 'all' ? '.' : linktype; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('a') .filter((_, el) => $(el).attr('href')?.match(RegExp(linktype))) @@ -44,9 +44,9 @@ module.exports = async (ctx) => { }) .reverse(); - ctx.state.data = { + ctx.set('data', { title: `${$('.content-page-title').text()} - FIX字幕侠`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/zjgtjy/index.js b/lib/v2/zjgtjy/index.js index d0d400531..9490d1f10 100644 --- a/lib/v2/zjgtjy/index.js +++ b/lib/v2/zjgtjy/index.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { - const type = ctx.params.type === 'all' ? '' : ctx.params.type.toUpperCase(); + const type = ctx.req.param('type') === 'all' ? '' : ctx.req.param('type').toUpperCase(); const host = `https://td.zjgtjy.cn:8553/devops/noticeInfo/queryNoticeInfoList?pageSize=10&pageNumber=1¬iceType=${type}&sort=DESC`; const response = await got({ @@ -35,9 +35,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '浙江土地使用权挂牌公告', link: host, item: items, - }; + }); }; diff --git a/lib/v2/zjol/paper.js b/lib/v2/zjol/paper.js index 4f8085a12..48a000a85 100644 --- a/lib/v2/zjol/paper.js +++ b/lib/v2/zjol/paper.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 id = ctx.params.id ?? 'zjrb'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100; + const id = ctx.req.param('id') ?? 'zjrb'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; const query = id === 'jnyb' ? 'map[name="PagePicMap"] area' : 'ul.main-ed-articlenav-list li a'; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { url: `${rootUrl}/${url}`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $(query) .toArray() @@ -43,7 +43,7 @@ module.exports = async (ctx) => { url: p, }); - const page = cheerio.load(pageResponse.data); + const page = load(pageResponse.data); items.push( ...page(query) @@ -64,7 +64,7 @@ module.exports = async (ctx) => { url: link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const title = content('.main-article-title').text(); @@ -80,9 +80,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/zju/career/index.js b/lib/v2/zju/career/index.js index 8dabaad10..f26d7a348 100644 --- a/lib/v2/zju/career/index.js +++ b/lib/v2/zju/career/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 rootUrl = 'http://www.career.zju.edu.cn'; const host = 'http://www.career.zju.edu.cn/jyxt/jygz/new/getContent.zf?minCount=0&maxCount=10&'; @@ -13,11 +13,11 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const id = map.get(type).id; const res = await got(`${host}${id}`); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.com-list li'); const items = list && @@ -35,9 +35,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: `${host}${id}`, item: items, - }; + }); }; diff --git a/lib/v2/zju/cst/custom.js b/lib/v2/zju/cst/custom.js index 2aed34878..3a6bf9397 100644 --- a/lib/v2/zju/cst/custom.js +++ b/lib/v2/zju/cst/custom.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'; async function getPage(id) { const res = await got({ method: 'get', url: `http://www.cst.zju.edu.cn/${id}/list.htm`, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const content = $('.lm_new ul li'); return ( @@ -31,7 +31,7 @@ async function getPage(id) { } module.exports = async (ctx) => { - const id = ctx.params.id.split('+'); + const id = ctx.req.param('id').split('+'); const tasks = id.map((id) => getPage(id)); const results = await Promise.all(tasks); let items = []; @@ -39,9 +39,9 @@ module.exports = async (ctx) => { items = [...items, ...result]; } - ctx.state.data = { + ctx.set('data', { title: '浙江大学软件学院通知', link: 'http://www.cst.zju.edu.cn/', item: items, - }; + }); }; diff --git a/lib/v2/zju/cst/index.js b/lib/v2/zju/cst/index.js index 7b033647f..58a63b001 100644 --- a/lib/v2/zju/cst/index.js +++ b/lib/v2/zju/cst/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 host = 'http://www.cst.zju.edu.cn/'; @@ -24,7 +24,7 @@ async function getPage(id) { url: host + id, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.lm_new').find('li'); return ( @@ -43,7 +43,7 @@ async function getPage(id) { } module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const link = host + map.get(type).id; let items = []; if (type === 0) { @@ -69,16 +69,16 @@ module.exports = async (ctx) => { Referer: link, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.vid_wz').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link, item: out, - }; + }); }; diff --git a/lib/v2/zju/grs/index.js b/lib/v2/zju/grs/index.js index 38d94b1af..5a8b7d92f 100644 --- a/lib/v2/zju/grs/index.js +++ b/lib/v2/zju/grs/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 host = 'http://www.grs.zju.edu.cn/'; @@ -14,12 +14,12 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const tag = map.get(type).tag; const url = `${host}${tag}/list.htm`; const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('#wp_news_w09').find('.list-item'); const items = @@ -36,9 +36,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: `${host}${tag}/list.htm`, item: items, - }; + }); }; diff --git a/lib/v2/zju/list.js b/lib/v2/zju/list.js index 0736815d3..b6fb3ddee 100644 --- a/lib/v2/zju/list.js +++ b/lib/v2/zju/list.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'; const host = 'https://www.zju.edu.cn/'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'xs'; + const type = ctx.req.param('type') ?? 'xs'; const link = host + type + `/list.htm`; const response = await got({ method: 'get', @@ -12,7 +12,7 @@ module.exports = async (ctx) => { Referer: host, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); function sortUrl(e) { return e.search('redirect') === -1 ? e : link; @@ -43,7 +43,7 @@ module.exports = async (ctx) => { Referer: link, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('.right_content').html(); return { title, @@ -54,9 +54,9 @@ module.exports = async (ctx) => { }); }) ); - ctx.state.data = { + ctx.set('data', { title: `浙江大学` + $('ul.submenu .selected').text(), link, item: out, - }; + }); }; diff --git a/lib/v2/zju/physics/index.js b/lib/v2/zju/physics/index.js index b73115c56..f59d536a5 100644 --- a/lib/v2/zju/physics/index.js +++ b/lib/v2/zju/physics/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 host = 'http://physics.zju.edu.cn/redir.php?catalog_id='; const host = 'http://physics.zju.edu.cn'; @@ -23,14 +23,14 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = Number.parseInt(ctx.params.type); + const type = Number.parseInt(ctx.req.param('type')); const id = map.get(type).id; const res = await got({ method: 'get', url: `${host}/${id}/list.htm`, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = $('#arthd li') .map((index, item) => { item = $(item); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link: `${host}${id}`, item: items, - }; + }); }; diff --git a/lib/v2/zjuvag/blog.js b/lib/v2/zjuvag/blog.js index 5c1fa7dae..f1af200f2 100644 --- a/lib/v2/zjuvag/blog.js +++ b/lib/v2/zjuvag/blog.js @@ -1,13 +1,13 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { const baseUrl = 'https://zjuvag.org/blog/'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('div.post-preview-container') .find('.post-preview') @@ -24,10 +24,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: '浙江大学可视分析小组博客', link: 'https://zjuvag.org/blog/', item: items, - }; + }); }; diff --git a/lib/v2/zodgame/forum.js b/lib/v2/zodgame/forum.js index 312a2deb5..3547e1f3f 100644 --- a/lib/v2/zodgame/forum.js +++ b/lib/v2/zodgame/forum.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const rootUrl = 'https://zodgame.xyz'; module.exports = async (ctx) => { - const fid = ctx.params.fid; + const fid = ctx.req.param('fid'); const subUrl = `${rootUrl}/api/mobile/index.php?version=4&module=forumdisplay&fid=${fid}`; const cookie = config.zodgame.cookie; @@ -84,9 +84,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${info.forum.name} - ZodGame论坛`, link: `${rootUrl}/forum.php?mod=forumdisplay&fid=${fid}`, item: items, - }; + }); }; diff --git a/lib/v2/zotero/versions.js b/lib/v2/zotero/versions.js index 43a156cde..e46733b80 100644 --- a/lib/v2/zotero/versions.js +++ b/lib/v2/zotero/versions.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const url = 'https://www.zotero.org/support/changelog'; const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('h2'); - ctx.state.data = { + ctx.set('data', { title: 'Zotero - Version History', link: url, item: @@ -28,5 +28,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/zuel/notice.js b/lib/v2/zuel/notice.js index 9e7d31375..034a3f8c5 100644 --- a/lib/v2/zuel/notice.js +++ b/lib/v2/zuel/notice.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 = 'http://wap.zuel.edu.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list_item') .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('.wp_articlecontent, .psgCont, .infodetail').html(); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '中南财经大学 - 通知公告', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/zuvio/boards.js b/lib/v2/zuvio/boards.js index acb22c908..6d5fbd469 100644 --- a/lib/v2/zuvio/boards.js +++ b/lib/v2/zuvio/boards.js @@ -3,12 +3,12 @@ const { getBoards, rootUrl } = require('./utils'); module.exports = async (ctx) => { const items = await getBoards(ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: 'Zuvio 校園話題列表 - 大學生論壇', description: 'Zuvio 校園話題,Zuvio 校園話題千種動物頭像交流心得。最萌的匿名論壇,上千種逗趣動物頭像隨你變換,點頭像立即私訊功能,讓你找到共同話題的小夥伴!多人分享配對心得、聊天交友心情在此,快加入17分享!', image: 'https://s3.hicloud.net.tw/zuvio.public/public/system/images/irs_v4/chicken/shared/webshare.png', link: `${rootUrl}/articles`, item: items, language: 'zh-Hant', - }; + }); }; diff --git a/lib/v2/zuvio/student5.js b/lib/v2/zuvio/student5.js index a21efea6e..6c8de5c15 100644 --- a/lib/v2/zuvio/student5.js +++ b/lib/v2/zuvio/student5.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { token, apiUrl, rootUrl, renderDesc, getBoards } = require('./utils'); module.exports = async (ctx) => { @@ -47,12 +47,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Zuvio 校園${title}話題 - 大學生論壇`, description: 'Zuvio 校園話題千種動物頭像交流心得。最萌的匿名論壇,上千種逗趣動物頭像隨你變換,點頭像立即私訊功能,讓你找到共同話題的小夥伴!多人分享配對心得、聊天交友心情在此,快加入17分享!', image: 'https://s3.hicloud.net.tw/zuvio.public/public/system/images/irs_v4/chicken/shared/webshare.png', link: `${rootUrl}/articles`, item: items, language: 'zh-Hant', - }; + }); }; diff --git a/lib/v2/zuvio/utils.js b/lib/v2/zuvio/utils.js index efb3586cc..44d24886f 100644 --- a/lib/v2/zuvio/utils.js +++ b/lib/v2/zuvio/utils.js @@ -1,6 +1,6 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0OTcyMzI1MjMsInN5c3RlbV9uYW1lIjoiZm9ydW0iLCJ6dXZpb19pZCI6LTk5OSwiZW1haWwiOm51bGwsIm5hbWUiOm51bGwsInVuaXZlcnNpdHlfaWQiOm51bGwsInVuaXZlcnNpdHlfbmFtZSI6bnVsbH0.0KoJiSnyazsJxLCNEnqnuNUdKsJFhBdCn3R2BJpoUtk'; diff --git a/lib/v2/zyshow/index.js b/lib/v2/zyshow/index.js index 9b61004d7..51c93e1c7 100644 --- a/lib/v2/zyshow/index.js +++ b/lib/v2/zyshow/index.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) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('table') .last() @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `综艺秀 - ${$('h2').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/zyw/hot.js b/lib/v2/zyw/hot.js index 4f24ab45b..ab2f44a80 100644 --- a/lib/v2/zyw/hot.js +++ b/lib/v2/zyw/hot.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { - const site = ctx.params.site ?? ''; + const site = ctx.req.param('site') ?? ''; const rootUrl = 'https://hot.zyw.asia'; const apiRootUrl = 'https://api-hot.zyw.asia'; @@ -55,9 +55,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `今日热榜${site ? ` - ${sites[0].label}` : ''}`, link: currentUrl, item: items, - }; + }); };