From 185b5d1441ba3e5ce7a0e46cac569d2632dff2b3 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 28 Feb 2024 16:26:24 +0800 Subject: [PATCH] feat: v3 migration - 2/n --- lib/v2/gov/csrc/news.js | 18 ++++----- lib/v2/gov/customs/list.js | 19 ++++----- lib/v2/gov/forestry/gjlckjdjt.js | 18 ++++----- lib/v2/gov/general/general.js | 19 +++++---- lib/v2/gov/guangdong/tqyb/sncsyjxh.js | 12 +++--- lib/v2/gov/guangdong/tqyb/tfxtq.js | 10 ++--- lib/v2/gov/gz/index.js | 16 ++++---- lib/v2/gov/hebei/czt.js | 16 ++++---- lib/v2/gov/huizhou/zwgk/index.js | 18 ++++----- lib/v2/gov/hunan/changsha/major-email.js | 14 +++---- lib/v2/gov/immiau/news.js | 8 ++-- lib/v2/gov/jgjcndrc/index.js | 16 ++++---- .../healthcommission/medical-exam-notice.js | 16 ++++---- lib/v2/gov/maonan/maonan.js | 18 ++++----- lib/v2/gov/mee/ywdt.js | 18 ++++----- lib/v2/gov/mem/sgcc.js | 16 ++++---- lib/v2/gov/mfa/wjdt.js | 20 +++++----- lib/v2/gov/miit/wjfb.js | 18 ++++----- lib/v2/gov/miit/wjgs.js | 18 ++++----- lib/v2/gov/miit/yjzj.js | 16 ++++---- lib/v2/gov/miit/zcjd.js | 18 ++++----- lib/v2/gov/miit/zcwj.js | 14 +++---- lib/v2/gov/moa/moa.js | 14 +++---- lib/v2/gov/moa/zdscxx.js | 14 +++---- lib/v2/gov/moe/moe.js | 16 ++++---- lib/v2/gov/moe/s78.js | 16 ++++---- lib/v2/gov/mof/bond.js | 16 ++++---- lib/v2/gov/mofcom/article.js | 20 +++++----- lib/v2/gov/moj/aac/news.js | 16 ++++---- lib/v2/gov/moj/lfyjzj.js | 16 ++++---- lib/v2/gov/mot/index.js | 18 ++++----- lib/v2/gov/ndrc/fggz.js | 18 ++++----- lib/v2/gov/ndrc/xwdt.js | 14 +++---- lib/v2/gov/nea/ghs.js | 18 ++++----- lib/v2/gov/news/index.js | 20 +++++----- lib/v2/gov/nifdc/index.js | 18 ++++----- lib/v2/gov/nmpa/generic.js | 18 ++++----- lib/v2/gov/nopss/index.js | 18 ++++----- lib/v2/gov/npc/index.js | 16 ++++---- lib/v2/gov/nrta/dsj.js | 16 ++++---- lib/v2/gov/nrta/news.js | 18 ++++----- lib/v2/gov/nsfc/index.js | 16 ++++---- lib/v2/gov/pbc/goutongjiaoliu.js | 17 ++++---- lib/v2/gov/pbc/gzlw.js | 10 ++--- lib/v2/gov/pbc/trade-announcement.js | 17 ++++---- lib/v2/gov/pbc/utils.js | 6 +-- lib/v2/gov/pbc/zcyj.js | 14 +++---- lib/v2/gov/safe/business.js | 2 +- lib/v2/gov/safe/complaint.js | 2 +- lib/v2/gov/safe/util.js | 12 +++--- lib/v2/gov/samr/xgzlyhd.js | 16 ++++---- lib/v2/gov/sasac/generic.js | 14 +++---- lib/v2/gov/shaanxi/kjt.js | 18 ++++----- lib/v2/gov/shanghai/rsj/ksxm.js | 12 +++--- lib/v2/gov/shanghai/wgj/wgj.js | 18 ++++----- lib/v2/gov/shanghai/wsjkw/yqtb/index.js | 12 +++--- lib/v2/gov/shanghai/yjj/index.js | 16 ++++---- lib/v2/gov/shenzhen/hrss/szksy/index.js | 18 ++++----- lib/v2/gov/shenzhen/xxgk/zfxxgj.js | 18 ++++----- lib/v2/gov/shenzhen/zjj/index.js | 16 ++++---- lib/v2/gov/shenzhen/zzb/index.js | 18 ++++----- lib/v2/gov/sichuan/deyang/govpublicinfo.js | 22 +++++----- lib/v2/gov/sichuan/deyang/mztoday.js | 20 +++++----- lib/v2/gov/stats/index.js | 20 +++++----- lib/v2/gov/suzhou/doc.js | 16 ++++---- lib/v2/gov/suzhou/fg.js | 18 ++++----- lib/v2/gov/suzhou/news.js | 18 ++++----- lib/v2/gov/taiyuan/rsj.js | 18 ++++----- lib/v2/gov/wuhan/whyw.js | 16 ++++---- lib/v2/gov/xuzhou/hrss.js | 18 ++++----- lib/v2/gov/zhejiang/gwy.js | 16 ++++---- lib/v2/gov/zhengce/govall.js | 16 ++++---- lib/v2/gov/zhengce/index.js | 18 ++++----- lib/v2/gov/zhengce/wenjian.js | 18 ++++----- lib/v2/gov/zhengce/zhengceku.js | 2 +- lib/v2/greasyfork/feedback.js | 14 +++---- lib/v2/greasyfork/scripts.js | 20 +++++----- lib/v2/greasyfork/versions.js | 14 +++---- lib/v2/grist/featured.js | 10 ++--- lib/v2/grist/index.js | 4 +- lib/v2/grist/series.js | 4 +- lib/v2/grist/topic.js | 4 +- lib/v2/grist/utils.js | 6 +-- lib/v2/grubstreet/utils.js | 12 +++--- lib/v2/guancha/headline.js | 16 ++++---- lib/v2/guancha/index.js | 19 +++++---- lib/v2/guancha/member.js | 12 +++--- lib/v2/guancha/personalpage.js | 8 ++-- lib/v2/guancha/topic.js | 18 ++++----- lib/v2/guangdiu/cheaps.js | 14 +++---- lib/v2/guangdiu/index.js | 16 ++++---- lib/v2/guangdiu/rank.js | 14 +++---- lib/v2/guangdiu/search.js | 16 ++++---- lib/v2/guangzhoumetro/news.js | 12 +++--- lib/v2/guanhai/index.js | 16 ++++---- lib/v2/guduodata/daily.js | 8 ++-- lib/v2/gumroad/index.js | 16 ++++---- lib/v2/guokr/channel.js | 8 ++-- lib/v2/guokr/scientific.js | 10 ++--- lib/v2/gxmzu/ai.js | 4 +- lib/v2/gxmzu/lib.js | 16 ++++---- lib/v2/gxmzu/utils/index.js | 12 +++--- lib/v2/gxmzu/yjs.js | 4 +- lib/v2/gzdaily/app.js | 18 ++++----- lib/v2/gzhu/yjs.js | 12 +++--- lib/v2/hackernews/index.js | 22 +++++----- lib/v2/hackertalk/index.js | 13 +++--- lib/v2/hacking8/index.js | 16 ++++---- lib/v2/hacking8/search.js | 16 ++++---- lib/v2/hackmd/profile.js | 8 ++-- lib/v2/hackyournews/index.js | 12 +++--- lib/v2/hafu/news.js | 6 +-- lib/v2/hafu/utils.js | 16 ++++---- lib/v2/hakkatv/type.js | 10 ++--- lib/v2/hameln/chapter.js | 20 +++++----- lib/v2/harvard/health/blog.js | 14 +++---- lib/v2/hashnode/blog.js | 12 +++--- lib/v2/hbr/topic.js | 18 ++++----- lib/v2/hdu/cs/notice.js | 14 +++---- lib/v2/hdu/cs/pg.js | 14 +++---- lib/v2/hebtv/nong-bo-shi-zai-xing-dong.js | 18 ++++----- lib/v2/hellobtc/information.js | 18 ++++----- lib/v2/hellobtc/kepu.js | 14 +++---- lib/v2/hellobtc/news.js | 14 +++---- lib/v2/hellogithub/index.js | 20 +++++----- lib/v2/hellogithub/report.js | 12 +++--- lib/v2/hellogithub/volume.js | 12 +++--- lib/v2/hex-rays/index.js | 14 +++---- lib/v2/hicairo/rss.js | 10 ++--- lib/v2/hinatazaka46/blog.js | 18 ++++----- lib/v2/hinatazaka46/news.js | 16 ++++---- lib/v2/hit/hitgs.js | 14 +++---- lib/v2/hit/jwc.js | 14 +++---- lib/v2/hit/today.js | 18 ++++----- lib/v2/hitsz/article.js | 18 ++++----- lib/v2/hitwh/today.js | 16 ++++---- lib/v2/hizu/index.js | 16 ++++---- lib/v2/hk01/channel.js | 10 ++--- lib/v2/hk01/hot.js | 8 ++-- lib/v2/hk01/issue.js | 10 ++--- lib/v2/hk01/latest.js | 8 ++-- lib/v2/hk01/tag.js | 10 ++--- lib/v2/hk01/utils.js | 6 +-- lib/v2/hk01/zone.js | 10 ++--- lib/v2/hkej/index.js | 22 +++++----- lib/v2/hkepc/index.js | 20 +++++----- lib/v2/hket/index.js | 22 +++++----- lib/v2/hkjunkcall/index.js | 14 +++---- lib/v2/hljucm/yjsy.js | 18 ++++----- lib/v2/hnrb/index.js | 20 +++++----- lib/v2/hnu/careers.js | 6 +-- lib/v2/hongkong/chp.js | 16 ++++---- lib/v2/hongkong/dh.js | 16 ++++---- lib/v2/hostmonit/cloudflareyes.js | 18 ++++----- lib/v2/hotukdeals/hottest.js | 6 +-- lib/v2/hotukdeals/index.js | 12 +++--- lib/v2/houxu/events.js | 12 +++--- lib/v2/houxu/index.js | 12 +++--- lib/v2/houxu/lives.js | 12 +++--- lib/v2/houxu/memory.js | 12 +++--- lib/v2/howtoforge/rss.js | 10 ++--- lib/v2/hoyolab/news.js | 6 +-- lib/v2/hoyolab/utils.js | 2 +- lib/v2/hpoi/all.js | 2 +- lib/v2/hpoi/banner-item.js | 10 ++--- lib/v2/hpoi/character.js | 2 +- lib/v2/hpoi/info.js | 14 +++---- lib/v2/hpoi/user.js | 10 ++--- lib/v2/hpoi/utils.js | 6 +-- lib/v2/hpoi/work.js | 2 +- lib/v2/hrbeu/gx/card.js | 16 ++++---- lib/v2/hrbeu/gx/list.js | 18 ++++----- lib/v2/hrbeu/job/bigemploy.js | 12 +++--- lib/v2/hrbeu/job/calendar.js | 10 ++--- lib/v2/hrbeu/job/list.js | 16 ++++---- lib/v2/hrbeu/uae/news.js | 18 ++++----- lib/v2/hrbeu/ugs/news.js | 18 ++++----- lib/v2/hrbeu/yjsy/list.js | 16 ++++---- lib/v2/hrbust/jwzx.js | 14 +++---- lib/v2/hrbust/utils.js | 16 ++++---- lib/v2/huanqiu/index.js | 16 ++++---- lib/v2/huggingface/blog-zh.js | 12 +++--- lib/v2/huggingface/daily-papers.js | 12 +++--- lib/v2/hunanpea/rsks.js | 16 ++++---- lib/v2/hunau/utils/common.js | 10 ++--- lib/v2/hunau/utils/news-content.js | 10 ++--- lib/v2/huoxian/zone.js | 8 ++-- lib/v2/hupu/all.js | 18 ++++----- lib/v2/hupu/bbs.js | 22 +++++----- lib/v2/hupu/index.js | 16 ++++---- lib/v2/hust/aia/news.js | 12 +++--- lib/v2/hust/aia/notice.js | 12 +++--- lib/v2/hust/yjs.js | 12 +++--- lib/v2/huxiu/brief-column.js | 8 ++-- lib/v2/huxiu/channel.js | 8 ++-- lib/v2/huxiu/club.js | 8 ++-- lib/v2/huxiu/collection.js | 8 ++-- lib/v2/huxiu/member.js | 8 ++-- lib/v2/huxiu/moment.js | 8 ++-- lib/v2/huxiu/search.js | 8 ++-- lib/v2/huxiu/tag.js | 8 ++-- lib/v2/huxiu/util.js | 16 ++++---- lib/v2/ianspriggs/index.js | 18 ++++----- lib/v2/icac/news.js | 20 +++++----- lib/v2/icbc/whpj.js | 8 ++-- lib/v2/idolypride/news.js | 10 ++--- lib/v2/ieee-security/sp.js | 12 +++--- lib/v2/ieee/earlyaccess.js | 18 ++++----- lib/v2/ieee/journal.js | 18 ++++----- lib/v2/ieee/recent.js | 18 ++++----- lib/v2/ielts/index.js | 21 +++++----- lib/v2/ifeng/feng.js | 16 ++++---- lib/v2/ifeng/news.js | 18 ++++----- lib/v2/ifeng/utils.js | 2 +- lib/v2/ifi-audio/download.js | 10 ++--- lib/v2/iguoguo/index.js | 16 ++++---- lib/v2/ikea/cn/family-offers.js | 6 +-- lib/v2/ikea/cn/low-price.js | 6 +-- lib/v2/ikea/cn/new.js | 6 +-- lib/v2/ikea/cn/utils.js | 4 +- lib/v2/ikea/gb/new.js | 8 ++-- lib/v2/ikea/gb/offer.js | 12 +++--- lib/v2/imagemagick/changelog.js | 12 +++--- lib/v2/imiker/jinghua.js | 16 ++++---- lib/v2/indiansinkuwait/latest.js | 14 +++---- lib/v2/indienova/article.js | 12 +++--- lib/v2/indienova/column.js | 10 ++--- lib/v2/indienova/gamedb.js | 16 ++++---- lib/v2/indienova/usergames.js | 16 ++++---- lib/v2/indienova/utils.js | 10 ++--- lib/v2/inewsweek/index.js | 18 ++++----- lib/v2/infoq/recommend.js | 8 ++-- lib/v2/infoq/topic.js | 10 ++--- lib/v2/infoq/utils.js | 4 +- lib/v2/informs/index.js | 20 +++++----- lib/v2/inoreader/index.js | 18 ++++----- lib/v2/inoreader/rss.js | 12 +++--- lib/v2/instagram/common-utils.js | 4 +- lib/v2/instagram/private-api/index.js | 6 +-- lib/v2/instagram/private-api/utils.js | 2 +- lib/v2/instagram/web-api/index.js | 6 +-- lib/v2/instagram/web-api/utils.js | 8 ++-- lib/v2/instructables/projects.js | 8 ++-- lib/v2/iqilu/program.js | 18 ++++----- lib/v2/iqiyi/album.js | 14 +++---- lib/v2/iqiyi/video.js | 14 ++++--- lib/v2/iqnew/latest.js | 18 ++++----- lib/v2/iresearch/report.js | 14 +++---- lib/v2/iresearch/weekly.js | 14 +++---- lib/v2/issuehunt/funded.js | 6 +-- lib/v2/itch/devlog.js | 22 +++++----- lib/v2/itch/index.js | 14 +++---- lib/v2/itch/posts.js | 16 ++++---- lib/v2/ithome/index.js | 16 ++++---- lib/v2/ithome/ranking.js | 14 +++---- lib/v2/ithome/tag.js | 18 ++++----- lib/v2/ithome/tw/feeds.js | 18 ++++----- lib/v2/ithome/zt.js | 18 ++++----- lib/v2/iwara/index.js | 14 +++---- lib/v2/iwara/subscriptions.js | 12 +++--- lib/v2/ixigua/user-video.js | 18 ++++----- lib/v2/jandan/index.js | 10 ++--- lib/v2/jandan/section.js | 16 ++++---- lib/v2/japanpost/track.js | 16 ++++---- lib/v2/javbus/index.js | 28 ++++++------- lib/v2/javdb/actors.js | 4 +- lib/v2/javdb/index.js | 6 +-- lib/v2/javdb/lists.js | 6 +-- lib/v2/javdb/makers.js | 4 +- lib/v2/javdb/rankings.js | 4 +- lib/v2/javdb/search.js | 6 +-- lib/v2/javdb/series.js | 4 +- lib/v2/javdb/tags.js | 4 +- lib/v2/javdb/utils.js | 18 ++++----- lib/v2/javlibrary/bestrated.js | 4 +- lib/v2/javlibrary/bestreviews.js | 4 +- lib/v2/javlibrary/genre.js | 6 +-- lib/v2/javlibrary/maker.js | 6 +-- lib/v2/javlibrary/mostwanted.js | 4 +- lib/v2/javlibrary/newentries.js | 2 +- lib/v2/javlibrary/newrelease.js | 4 +- lib/v2/javlibrary/star.js | 6 +-- lib/v2/javlibrary/update.js | 2 +- lib/v2/javlibrary/user.js | 6 +-- lib/v2/javlibrary/utils.js | 12 +++--- lib/v2/jd/price.js | 10 ++--- lib/v2/jianshu/collection.js | 12 +++--- lib/v2/jianshu/home.js | 10 ++--- lib/v2/jianshu/user.js | 12 +++--- lib/v2/jianshu/utils.js | 16 ++++---- lib/v2/jiaoliudao/index.js | 10 ++--- lib/v2/jiemian/lists.js | 18 ++++----- lib/v2/jike/topic-text.js | 2 +- lib/v2/jike/topic.js | 8 ++-- lib/v2/jike/user.js | 16 ++++---- lib/v2/jike/utils.js | 12 +++--- lib/v2/jin10/index.js | 14 +++---- lib/v2/jin10/topic.js | 14 +++---- lib/v2/jinse/catalogue.js | 18 ++++----- lib/v2/jinse/lives.js | 16 ++++---- lib/v2/jinse/timeline.js | 18 ++++----- lib/v2/jisilu/index.js | 24 +++++------ lib/v2/jjwxc/author.js | 16 ++++---- lib/v2/jjwxc/book.js | 20 +++++----- lib/v2/jornada/index.js | 12 +++--- lib/v2/jou/home.js | 4 +- lib/v2/jou/utils/index.js | 12 +++--- lib/v2/jou/yz.js | 4 +- lib/v2/jseea/news.js | 22 +++++----- lib/v2/jsu/cxzx.js | 12 +++--- lib/v2/jsu/jwc.js | 12 +++--- lib/v2/jsu/math.js | 12 +++--- lib/v2/jsu/rjxy.js | 12 +++--- lib/v2/jsu/universityindex.js | 12 +++--- lib/v2/jsu/utils/index.js | 8 ++-- lib/v2/juejin/books.js | 8 ++-- lib/v2/juejin/category.js | 6 +-- lib/v2/juejin/collection.js | 6 +-- lib/v2/juejin/column.js | 6 +-- lib/v2/juejin/favorites.js | 6 +-- lib/v2/juejin/pins.js | 10 ++--- lib/v2/juejin/posts.js | 6 +-- lib/v2/juejin/tag.js | 6 +-- lib/v2/juejin/trending.js | 6 +-- lib/v2/juejin/utils.js | 12 +++--- lib/v2/jump/discount.js | 14 +++---- lib/v2/kamen-rider-official/news.js | 18 ++++----- lib/v2/kantarworldpanel/index.js | 18 ++++----- lib/v2/kbs/news.js | 20 +++++----- lib/v2/kbs/today.js | 18 ++++----- lib/v2/kcna/news.js | 14 +++---- lib/v2/kcna/utils.js | 10 ++--- lib/v2/ke/results.js | 8 ++-- lib/v2/keep/user.js | 10 ++--- lib/v2/keepass/news.js | 16 ++++---- lib/v2/kemono/index.js | 22 +++++----- lib/v2/kepu/live.js | 14 +++---- lib/v2/keylol/index.js | 18 ++++----- lib/v2/kimlaw/thesis.js | 16 ++++---- lib/v2/konghq/blog-posts.js | 14 +++---- lib/v2/kuaidi100/index.js | 4 +- lib/v2/kuaidi100/supported-company.js | 4 +- lib/v2/kuaidi100/utils.js | 2 +- lib/v2/kunchengblog/essay.js | 16 ++++---- lib/v2/kuwaitlocal/index.js | 14 +++---- lib/v2/kyodonews/index.js | 22 +++++----- lib/v2/laimanhua/index.js | 14 +++---- lib/v2/lala/rss.js | 10 ++--- lib/v2/lang/room.js | 10 ++--- lib/v2/lanqiao/author.js | 8 ++-- lib/v2/lanqiao/courses.js | 10 ++--- lib/v2/lanqiao/questions.js | 10 ++--- lib/v2/lanqiao/utils.js | 2 +- lib/v2/laohu8/personal.js | 14 +++---- lib/v2/latepost/index.js | 16 ++++---- lib/v2/layoffs/index.js | 12 +++--- lib/v2/learnblockchain/posts.js | 16 ++++---- lib/v2/learnku/topic.js | 22 +++++----- lib/v2/leetcode/articles.js | 12 +++--- lib/v2/leetcode/dailyquestion-cn.js | 8 ++-- lib/v2/leetcode/dailyquestion-en.js | 8 ++-- lib/v2/leetcode/dailyquestion-solution-cn.js | 10 ++--- lib/v2/leetcode/dailyquestion-solution-en.js | 10 ++--- lib/v2/leiphone/index.js | 14 +++---- lib/v2/leiphone/newsflash.js | 8 ++-- lib/v2/leiphone/utils.js | 8 ++-- lib/v2/lemmy/index.js | 18 ++++----- lib/v2/lfsyd/home.js | 8 ++-- lib/v2/lfsyd/old-home.js | 10 ++--- lib/v2/lfsyd/tag.js | 8 ++-- lib/v2/lfsyd/user.js | 10 ++--- lib/v2/lfsyd/utils.js | 10 ++--- lib/v2/lifeweek/channel.js | 8 ++-- lib/v2/lifeweek/tag.js | 8 ++-- lib/v2/lifeweek/utils.js | 6 +-- lib/v2/lightnovel/light-novel.js | 16 ++++---- lib/v2/line/publisher.js | 6 +-- lib/v2/line/today.js | 10 ++--- lib/v2/line/utils.js | 8 ++-- lib/v2/linkedin/cn/index.js | 4 +- lib/v2/linkedin/cn/utils.js | 16 ++++---- lib/v2/linkedin/jobs.js | 20 +++++----- lib/v2/linkedin/utils.js | 6 +-- lib/v2/linkresearcher/index.js | 8 ++-- lib/v2/linovelib/novel.js | 14 +++---- lib/v2/liquipedia/cs-matches.js | 12 +++--- lib/v2/liquipedia/dota2-matches.js | 14 +++---- lib/v2/literotica/category.js | 16 ++++---- lib/v2/literotica/new.js | 14 +++---- lib/v2/liulinblog/index.js | 16 ++++---- lib/v2/liveuamap/index.js | 14 +++---- lib/v2/lkong/forum.js | 14 +++---- lib/v2/lkong/thread.js | 12 +++--- lib/v2/lofter/tag.js | 16 ++++---- lib/v2/lofter/user.js | 12 +++--- lib/v2/logclub/index.js | 18 ++++----- lib/v2/logclub/report.js | 20 +++++----- lib/v2/logonews/index.js | 18 ++++----- lib/v2/loltw/news.js | 12 +++--- lib/v2/lovelive-anime/news.js | 16 ++++---- lib/v2/lovelive-anime/schedules.js | 12 +++--- lib/v2/lovelive-anime/topics.js | 22 +++++----- lib/v2/lsnu/jiaowc/tzgg.js | 16 ++++---- lib/v2/luogu/contest.js | 17 ++++---- lib/v2/luogu/daily.js | 16 ++++---- lib/v2/luogu/user-blog.js | 14 +++---- lib/v2/luogu/user-feed.js | 13 +++--- lib/v2/luxiangdong/archive.js | 8 ++-- lib/v2/lvv2/news.js | 22 +++++----- lib/v2/lvv2/top.js | 24 +++++------ lib/v2/lxixsxa/discography.js | 10 ++--- lib/v2/lxixsxa/information.js | 10 ++--- lib/v2/m4/index.js | 20 +++++----- lib/v2/macfilos/blog.js | 16 ++++---- lib/v2/macmenubar/recently.js | 8 ++-- lib/v2/macupdate/app.js | 16 ++++---- lib/v2/magazinelib/latest-magazine.js | 14 +++---- lib/v2/mail/imap.js | 8 ++-- lib/v2/mangadex/index.js | 8 ++-- lib/v2/manhuagui/comic.js | 10 ++--- lib/v2/manhuagui/subscribe.js | 16 ++++---- lib/v2/mastodon/account-id.js | 14 +++---- lib/v2/mastodon/acct.js | 8 ++-- lib/v2/mastodon/timeline-local.js | 16 ++++---- lib/v2/mastodon/timeline-remote.js | 16 ++++---- lib/v2/mastodon/utils.js | 6 +-- lib/v2/mckinsey/cn/index.js | 8 ++-- lib/v2/mdpi/journal.js | 16 ++++---- lib/v2/medieval-china/post.js | 18 ++++----- lib/v2/medium/following.js | 8 ++-- lib/v2/medium/for-you.js | 8 ++-- lib/v2/medium/graphql.js | 2 +- lib/v2/medium/list.js | 10 ++--- lib/v2/medium/parse-article.js | 8 ++-- lib/v2/medium/tag.js | 10 ++--- lib/v2/medsci/index.js | 16 ++++---- lib/v2/metacritic/index.js | 16 ++++---- lib/v2/metacritic/release.js | 20 +++++----- lib/v2/meteor/boards.js | 4 +- lib/v2/meteor/index.js | 10 ++--- lib/v2/meteor/utils.js | 4 +- lib/v2/metmuseum/exhibitions.js | 10 ++--- lib/v2/mihoyo/bbs/cache.js | 4 +- lib/v2/mihoyo/bbs/follow-list.js | 6 +-- lib/v2/mihoyo/bbs/img-ranking.js | 6 +-- lib/v2/mihoyo/bbs/official.js | 2 +- lib/v2/mihoyo/bbs/timeline.js | 6 +-- lib/v2/mihoyo/bbs/user-post.js | 4 +- lib/v2/mihoyo/bbs/utils.js | 4 +- lib/v2/mihoyo/sr/news.js | 10 ++--- lib/v2/mihoyo/ys/news.js | 18 ++++----- lib/v2/mindmeister/example.js | 12 +++--- lib/v2/minecraft/version.js | 6 +-- lib/v2/mingpao/index.js | 18 ++++----- lib/v2/mirror/index.js | 10 ++--- lib/v2/missav/new.js | 12 +++--- lib/v2/misskey/featured-notes.js | 12 +++--- lib/v2/misskey/utils.js | 4 +- lib/v2/mittrchina/index.js | 12 +++--- lib/v2/mixcloud/index.js | 20 +++++----- lib/v2/modb/topic.js | 16 ++++---- lib/v2/modelscope/community.js | 18 ++++----- lib/v2/modelscope/datasets.js | 12 +++--- lib/v2/modelscope/models.js | 10 ++--- lib/v2/modelscope/studios.js | 12 +++--- lib/v2/modrinth/versions.js | 15 +++---- lib/v2/mohw/clarification.js | 14 +++---- lib/v2/mox/index.js | 16 ++++---- lib/v2/mpaypass/main.js | 16 ++++---- lib/v2/mpaypass/news.js | 16 ++++---- lib/v2/mrdx/daily.js | 14 +++---- lib/v2/mrm/index.js | 14 +++---- lib/v2/mvm/index.js | 18 ++++----- lib/v2/mydrivers/cid.js | 8 ++-- lib/v2/mydrivers/index.js | 18 ++++----- lib/v2/mydrivers/rank.js | 12 +++--- lib/v2/mydrivers/util.js | 12 +++--- lib/v2/myfigurecollection/activity.js | 28 ++++++------- lib/v2/myfigurecollection/index.js | 20 +++++----- lib/v2/mygopen/index.js | 12 +++--- lib/v2/mymusicsheet/usersheets.js | 8 ++-- lib/v2/mysql/release.js | 16 ++++---- lib/v2/nasa/apod-cn.js | 10 ++--- lib/v2/nasa/apod-ncku.js | 16 ++++---- lib/v2/nasa/apod.js | 18 ++++----- lib/v2/natgeo/dailyphoto.js | 16 ++++---- lib/v2/natgeo/dailyselection.js | 12 +++--- lib/v2/natgeo/natgeo.js | 22 +++++----- lib/v2/nationalgeographic/latest-stories.js | 16 ++++---- lib/v2/nature/cover.js | 12 +++--- lib/v2/nature/highlight.js | 10 ++--- lib/v2/nature/news-and-comment.js | 12 +++--- lib/v2/nature/news.js | 12 +++--- lib/v2/nature/research.js | 12 +++--- lib/v2/nature/siteindex.js | 16 ++++---- lib/v2/nature/utils.js | 8 ++-- lib/v2/nautil/topics.js | 22 +++++----- lib/v2/nbd/index.js | 18 ++++----- lib/v2/nbd/router.js | 2 +- lib/v2/nber/index.js | 16 ++++---- lib/v2/ncc-cma/cmdp.js | 16 ++++---- lib/v2/ncepu/master/masterinfo.js | 18 ++++----- lib/v2/ncu/jwc.js | 12 +++--- lib/v2/ncwu/notice.js | 12 +++--- lib/v2/ndss-symposium/ndss.js | 14 +++---- lib/v2/neatdownloadmanager/download.js | 12 +++--- lib/v2/neea/index.js | 18 ++++----- lib/v2/neea/jlpt.js | 14 +++---- lib/v2/nenu/sohac.js | 16 ++++---- lib/v2/nenu/yjsy.js | 16 ++++---- lib/v2/netflav/index.js | 14 +++---- lib/v2/neu/bmie.js | 18 ++++----- lib/v2/neu/news.js | 16 ++++---- lib/v2/newmuseum/exhibitions.js | 2 +- lib/v2/newrank/douyin.js | 10 ++--- lib/v2/newrank/utils.js | 6 +-- lib/v2/newrank/wechat.js | 14 +++---- lib/v2/news/xhsxw.js | 20 +++++----- lib/v2/newsmarket/index.js | 18 ++++----- lib/v2/newzmz/index.js | 12 +++--- lib/v2/newzmz/util.js | 14 +++---- lib/v2/nextapple/realtime.js | 16 ++++---- lib/v2/nga/forum.js | 10 ++--- lib/v2/nga/post.js | 22 +++++----- lib/v2/ngocn2/index.js | 16 ++++---- lib/v2/nhentai/other.js | 6 +-- lib/v2/nhentai/search.js | 6 +-- lib/v2/nhentai/util.js | 14 +++---- lib/v2/nhk/news-web-easy.js | 18 ++++----- lib/v2/nhk/news.js | 10 ++--- lib/v2/niaogebiji/cat.js | 18 ++++----- lib/v2/niaogebiji/index.js | 12 +++--- lib/v2/niaogebiji/today.js | 8 ++-- lib/v2/nifd/research.js | 16 ++++---- lib/v2/nikkei/asia/index.js | 12 +++--- lib/v2/nikkei/cn/index.js | 18 ++++----- lib/v2/nikkei/index.js | 10 ++--- lib/v2/nikkei/news.js | 16 ++++---- lib/v2/nintendo/direct.js | 14 +++---- lib/v2/nintendo/eshop-cn.js | 8 ++-- lib/v2/nintendo/eshop-hk.js | 16 ++++---- lib/v2/nintendo/eshop-jp.js | 12 +++--- lib/v2/nintendo/eshop-us.js | 8 ++-- lib/v2/nintendo/news-china.js | 6 +-- lib/v2/nintendo/news.js | 10 ++--- lib/v2/nintendo/system-update.js | 10 ++--- lib/v2/nintendo/utils.js | 16 ++++---- lib/v2/nippon/index.js | 12 +++--- lib/v2/njglyy/utils/index.js | 12 +++--- lib/v2/njglyy/ygbjypx.js | 4 +- lib/v2/njit/jwc.js | 16 ++++---- lib/v2/njit/tzgg.js | 14 +++---- lib/v2/njnu/ceai/ceai.js | 12 +++--- lib/v2/njnu/ceai/utils.js | 16 ++++---- lib/v2/njnu/jwc/jwc.js | 12 +++--- lib/v2/njnu/jwc/utils.js | 16 ++++---- lib/v2/nju/admission.js | 12 +++--- lib/v2/nju/dafls.js | 14 +++---- lib/v2/nju/exchangesys.js | 8 ++-- lib/v2/nju/gra.js | 14 +++---- lib/v2/nju/hosptial.js | 12 +++--- lib/v2/nju/hqjt.js | 14 +++---- lib/v2/nju/itsc.js | 14 +++---- lib/v2/nju/jjc.js | 14 +++---- lib/v2/nju/jw.js | 12 +++--- lib/v2/nju/rczp.js | 12 +++--- lib/v2/nju/scit.js | 16 ++++---- lib/v2/nju/zbb.js | 14 +++---- lib/v2/nju/zcc.js | 12 +++--- lib/v2/njucm/grabs.js | 4 +- lib/v2/njucm/utils/index.js | 12 +++--- lib/v2/njupt/jwc.js | 16 ++++---- lib/v2/njust/cwc.js | 14 +++---- lib/v2/njust/dgxg.js | 14 +++---- lib/v2/njust/eo.js | 16 ++++---- lib/v2/njust/eoe.js | 14 +++---- lib/v2/njust/gs.js | 16 ++++---- lib/v2/njust/jwc.js | 14 +++---- lib/v2/njust/utils.js | 6 ++- lib/v2/njxzc/home.js | 4 +- lib/v2/njxzc/lib.js | 4 +- lib/v2/njxzc/utils/index.js | 12 +++--- lib/v2/nltimes/news.js | 18 ++++----- lib/v2/nmtv/column.js | 16 ++++---- lib/v2/nodejs/blog.js | 16 ++++---- lib/v2/nogizaka46/blog.js | 10 ++--- lib/v2/nogizaka46/news.js | 10 ++--- lib/v2/notateslaapp/update.js | 10 ++--- lib/v2/notefolio/search.js | 10 ++--- lib/v2/notion/database.js | 20 +++++----- lib/v2/now/news.js | 18 ++++----- lib/v2/nowcoder/discuss.js | 20 +++++----- lib/v2/nowcoder/experience.js | 18 ++++----- lib/v2/nowcoder/jobcenter.js | 20 +++++----- lib/v2/nowcoder/recommend.js | 6 +-- lib/v2/nowcoder/schedule.js | 12 +++--- lib/v2/npm/package.js | 8 ++-- lib/v2/npr/full.js | 12 +++--- lib/v2/ntdtv/channel.js | 20 +++++----- lib/v2/nua/dc.js | 6 +-- lib/v2/nua/gra.js | 6 +-- lib/v2/nua/index.js | 6 +-- lib/v2/nua/lib.js | 6 +-- lib/v2/nua/sxw.js | 6 +-- lib/v2/nua/utils.js | 12 +++--- lib/v2/nuaa/college/cae.js | 18 ++++----- lib/v2/nuaa/college/cs.js | 18 ++++----- lib/v2/nuaa/jwc/jwc.js | 18 ++++----- lib/v2/nuaa/utils/pypasswaf.js | 3 +- lib/v2/nuaa/yjsy/yjsy.js | 18 ++++----- lib/v2/nuist/bulletin.js | 14 +++---- lib/v2/nuist/cas.js | 16 ++++---- lib/v2/nuist/jwc.js | 14 +++---- lib/v2/nuist/library/lib.js | 14 +++---- lib/v2/nuist/scs.js | 14 +++---- lib/v2/nuist/sese.js | 14 +++---- lib/v2/nuist/xgc.js | 14 +++---- lib/v2/nuist/yjs.js | 16 ++++---- lib/v2/nwafu/all.js | 14 +++---- lib/v2/nyaa/main.js | 6 +-- lib/v2/nytimes/book.js | 12 +++--- lib/v2/nytimes/daily-briefing-chinese.js | 14 +++---- lib/v2/nytimes/index.js | 13 +++--- lib/v2/nytimes/utils.js | 6 +-- lib/v2/oceanengine/arithmetic-index.js | 23 ++++++----- lib/v2/odaily/activity.js | 16 ++++---- lib/v2/odaily/newsflash.js | 12 +++--- lib/v2/odaily/post.js | 18 ++++----- lib/v2/odaily/search-news.js | 14 +++---- lib/v2/odaily/user.js | 18 ++++----- lib/v2/oeeee/app/channel.js | 14 +++---- lib/v2/oeeee/app/reporter.js | 10 ++--- lib/v2/oeeee/utils.js | 10 ++--- lib/v2/oeeee/web.js | 14 +++---- lib/v2/oilchem/index.js | 22 +++++----- lib/v2/oncc/index.js | 20 +++++----- lib/v2/oncc/money18.js | 20 +++++----- lib/v2/onehu/common.js | 14 +++---- lib/v2/onet/news.js | 14 +++---- lib/v2/onet/utils.js | 2 +- lib/v2/oo-software/changelog.js | 14 +++---- lib/v2/openai/blog.js | 8 ++-- lib/v2/openai/chatgpt.js | 12 +++--- lib/v2/openai/common.js | 8 ++-- lib/v2/openai/research.js | 6 +-- lib/v2/openwrt/releases.js | 14 +++---- lib/v2/orcid/index.js | 14 +++---- lib/v2/oreno3d/get-sec-page-data.js | 6 +-- lib/v2/oreno3d/main.js | 40 +++++++++---------- lib/v2/oschina/news.js | 18 ++++----- lib/v2/oschina/topic.js | 20 +++++----- lib/v2/oschina/user.js | 14 +++---- lib/v2/oshwhub/explore.js | 20 +++++----- lib/v2/osu/beatmaps/packs.js | 12 +++--- lib/v2/otobanana/cast.js | 10 ++--- lib/v2/otobanana/livestream.js | 10 ++--- lib/v2/otobanana/timeline.js | 10 ++--- lib/v2/otobanana/utils.js | 6 +-- lib/v2/ouc/it-postgraduate.js | 12 +++--- lib/v2/ouc/it-tx.js | 16 ++++---- lib/v2/ouc/it.js | 16 ++++---- lib/v2/ouc/jwc.js | 14 +++---- lib/v2/ouc/jwgl.js | 14 +++---- lib/v2/ouc/yjs.js | 12 +++--- lib/v2/oup/index.js | 18 ++++----- lib/v2/outagereport/index.js | 10 ++--- lib/v2/panewslab/author.js | 16 ++++---- lib/v2/panewslab/index.js | 16 ++++---- lib/v2/panewslab/news.js | 10 ++--- lib/v2/panewslab/topic.js | 16 ++++---- lib/v2/papers/index.js | 16 ++++---- lib/v2/paradigm/writing.js | 14 +++---- lib/v2/parliament/section77.js | 10 ++--- lib/v2/patagonia/new-arrivals.js | 12 +++--- lib/v2/paulgraham/article.js | 16 ++++---- lib/v2/penguin-random-house/articles.js | 10 ++--- lib/v2/penguin-random-house/thereaddown.js | 10 ++--- lib/v2/penguin-random-house/utils.js | 16 ++++---- lib/v2/people/index.js | 18 ++++----- lib/v2/people/liuyan.js | 16 ++++---- lib/v2/people/xjpjh.js | 16 ++++---- lib/v2/peopo/topic.js | 16 ++++---- lib/v2/phoronix/index.js | 10 ++--- lib/v2/pianyuan/app.js | 10 ++--- lib/v2/pianyuan/search.js | 10 ++--- lib/v2/pianyuan/utils.js | 8 ++-- lib/v2/picnob/user.js | 19 ++++----- lib/v2/picuki/profile.js | 25 ++++++------ lib/v2/pikabu/community.js | 12 +++--- lib/v2/pikabu/user.js | 12 +++--- lib/v2/pikabu/utils.js | 2 +- lib/v2/pincong/hot.js | 10 ++--- lib/v2/pincong/index.js | 14 +++---- lib/v2/pincong/topic.js | 14 +++---- lib/v2/pincong/utils.js | 4 +- lib/v2/pingwest/status.js | 14 +++---- lib/v2/pingwest/tag.js | 12 +++--- lib/v2/pingwest/user.js | 12 +++--- lib/v2/pingwest/utils.js | 12 +++--- lib/v2/pixabay/search.js | 12 +++--- lib/v2/pixiv/bookmarks.js | 10 ++--- lib/v2/pixiv/illustfollow.js | 8 ++-- lib/v2/pixiv/novels.js | 8 ++-- lib/v2/pixiv/pixiv-got.js | 14 +++---- lib/v2/pixiv/ranking.js | 16 ++++---- lib/v2/pixiv/search.js | 14 +++---- lib/v2/pixiv/token.js | 2 +- lib/v2/pixiv/user.js | 10 ++--- lib/v2/pixiv/utils.js | 2 +- lib/v2/piyao/jrpy.js | 14 +++---- lib/v2/pkmer/recent.js | 10 ++--- lib/v2/pku/bbs/hot.js | 18 ++++----- lib/v2/pku/cls/announcement.js | 14 +++---- lib/v2/pku/cls/lecture.js | 12 +++--- lib/v2/pku/eecs.js | 16 ++++---- lib/v2/pku/hr.js | 16 ++++---- lib/v2/pku/nsd.js | 16 ++++---- lib/v2/pku/pkuyjs.js | 12 +++--- lib/v2/pku/rccp/mzyt.js | 12 +++--- lib/v2/pku/scc/recruit.js | 16 ++++---- lib/v2/pku/ss/admission.js | 4 +- lib/v2/pku/ss/common.js | 10 ++--- lib/v2/pku/ss/notice.js | 4 +- lib/v2/pku/ss/pg-admin.js | 4 +- lib/v2/playno1/av.js | 14 +++---- lib/v2/playno1/st.js | 14 +++---- lib/v2/playno1/utils.js | 6 +-- lib/v2/playpcesor/rss.js | 12 +++--- lib/v2/plurk/anonymous.js | 8 ++-- lib/v2/plurk/hotlinks.js | 8 ++-- lib/v2/plurk/news.js | 6 +-- lib/v2/plurk/search.js | 6 +-- lib/v2/plurk/top.js | 8 ++-- lib/v2/plurk/topic.js | 12 +++--- lib/v2/plurk/user.js | 10 ++--- lib/v2/plurk/utils.js | 8 ++-- lib/v2/pnas/index.js | 19 ++++----- lib/v2/pornhub/category-url.js | 10 ++--- lib/v2/pornhub/category.js | 12 +++--- lib/v2/pornhub/model.js | 10 ++--- lib/v2/pornhub/pornstar.js | 10 ++--- lib/v2/pornhub/search.js | 8 ++-- lib/v2/pornhub/users.js | 10 ++--- lib/v2/pornhub/utils.js | 4 +- lib/v2/postman/release-notes.js | 6 +-- lib/v2/producthunt/today.js | 16 ++++---- lib/v2/ps/monthly-games.js | 12 +++--- lib/v2/ps/trophy.js | 14 +++---- lib/v2/pts/curations.js | 14 +++---- lib/v2/pts/index.js | 20 +++++----- lib/v2/pts/live.js | 14 +++---- lib/v2/pts/projects.js | 14 +++---- lib/v2/pubmed/trending.js | 18 ++++----- lib/v2/pumc/mdadmission.js | 16 ++++---- lib/v2/putty/changes.js | 12 +++--- lib/v2/pwc/sustainability.js | 13 +++--- lib/v2/qbitai/category.js | 6 +-- lib/v2/qbitai/tag.js | 6 +-- lib/v2/qbittorrent/news.js | 18 ++++----- lib/v2/qdu/houqin.js | 16 ++++---- lib/v2/qdu/jwc.js | 16 ++++---- lib/v2/qianp/news.js | 14 +++---- lib/v2/qianp/utils.js | 2 +- lib/v2/qianzhan/column.js | 16 ++++---- lib/v2/qianzhan/rank.js | 18 ++++----- lib/v2/qidian/author.js | 16 ++++---- lib/v2/qidian/chapter.js | 16 ++++---- lib/v2/qidian/forum.js | 14 +++---- lib/v2/qidian/free-next.js | 12 +++--- lib/v2/qidian/free.js | 14 +++---- lib/v2/qingting/channel.js | 18 ++++----- lib/v2/qingting/podcast.js | 22 +++++----- lib/v2/qipamaijia/index.js | 12 +++--- lib/v2/qiyoujiage/price.js | 12 +++--- lib/v2/qlu/notice.js | 16 ++++---- lib/v2/qm120/news.js | 18 ++++----- lib/v2/qoo-app/apps/card.js | 14 +++---- lib/v2/qoo-app/apps/comment.js | 16 ++++---- lib/v2/qoo-app/apps/note.js | 16 ++++---- lib/v2/qoo-app/apps/post.js | 16 ++++---- lib/v2/qoo-app/news.js | 14 +++---- lib/v2/qoo-app/notes/note.js | 16 ++++---- lib/v2/qoo-app/notes/topic.js | 10 ++--- lib/v2/qoo-app/notes/user.js | 10 ++--- lib/v2/qoo-app/user/app-comment.js | 16 ++++---- lib/v2/qoo-app/utils.js | 4 +- lib/v2/qq/ac/comic.js | 12 +++--- lib/v2/qq/ac/rank.js | 4 +- lib/v2/qq/ac/utils.js | 12 +++--- lib/v2/qq/fact/index.js | 14 +++---- lib/v2/qq/kg/cache.js | 2 +- lib/v2/qq/kg/reply.js | 8 ++-- lib/v2/qq/kg/user.js | 10 ++--- lib/v2/qq88/index.js | 16 ++++---- lib/v2/qqorw/index.js | 18 ++++----- lib/v2/questmobile/report.js | 18 ++++----- lib/v2/quicker/qa.js | 20 +++++----- lib/v2/quicker/share.js | 18 ++++----- lib/v2/quicker/user.js | 20 +++++----- lib/v2/quicker/versions.js | 12 +++--- lib/v2/qweather/3days.js | 24 +++++------ lib/v2/qweather/now.js | 24 +++++------ lib/v2/radio-canada/latest.js | 14 +++---- lib/v2/radio/album.js | 14 +++---- lib/v2/radio/index.js | 14 +++---- lib/v2/radio/zhibo.js | 14 +++---- lib/v2/rarehistoricalphotos/index.js | 10 ++--- lib/v2/rattibha/user.js | 8 ++-- lib/v2/rawkuma/manga.js | 18 ++++----- lib/v2/reactnewsletter/reactnewsletter.js | 12 +++--- lib/v2/readhub/daily.js | 12 +++--- lib/v2/readhub/index.js | 14 +++---- lib/v2/readhub/util.js | 6 +-- lib/v2/remnote/changelog.js | 8 ++-- lib/v2/researchgate/publications.js | 19 ++++----- lib/v2/reuters/common.js | 24 +++++------ lib/v2/reuters/investigates.js | 14 +++---- lib/v2/rfa/index.js | 24 +++++------ lib/v2/rfi/news.js | 16 ++++---- lib/v2/right/forum.js | 20 +++++----- lib/v2/rodong/news.js | 14 +++---- lib/v2/routledge/book-series.js | 16 ++++---- lib/v2/rsc/journal.js | 22 +++++----- lib/v2/rsshub/routes.js | 14 +++---- lib/v2/rsshub/transform/html.js | 16 ++++---- lib/v2/rsshub/transform/json.js | 16 ++++---- lib/v2/rsshub/transform/sitemap.js | 16 ++++---- lib/v2/ruancan/category.js | 2 +- lib/v2/ruancan/search.js | 2 +- lib/v2/ruancan/user.js | 2 +- lib/v2/ruancan/utils.js | 12 +++--- lib/v2/ruc/hr.js | 16 ++++---- lib/v2/runtrail/posts.js | 10 ++--- lib/v2/rustcc/jobs.js | 16 ++++---- lib/v2/sakurazaka46/blog.js | 20 +++++----- lib/v2/sakurazaka46/news.js | 16 ++++---- lib/v2/samsung/research/blog.js | 12 +++--- lib/v2/saraba1st/digest.js | 24 +++++------ lib/v2/saraba1st/thread.js | 18 ++++----- lib/v2/sass/gs/index.js | 16 ++++---- lib/v2/scau/yjs.js | 12 +++--- lib/v2/scau/yjsy.js | 12 +++--- lib/v2/science/blogs.js | 15 +++---- lib/v2/science/cover.js | 14 +++---- lib/v2/science/current.js | 13 +++--- lib/v2/science/early.js | 13 +++--- lib/v2/science/utils.js | 8 ++-- lib/v2/sciencedirect/journal.js | 14 +++---- lib/v2/sciencenet/blog.js | 24 +++++------ lib/v2/sciencenet/user.js | 22 +++++----- lib/v2/scmp/index.js | 18 ++++----- lib/v2/scmp/router.js | 2 +- lib/v2/scmp/topic.js | 18 ++++----- lib/v2/scmp/utils.js | 8 ++-- lib/v2/scnu/cs/match.js | 12 +++--- lib/v2/scnu/jw.js | 12 +++--- lib/v2/scnu/library.js | 12 +++--- .../physics-school-announcements-and-news.js | 20 +++++----- lib/v2/scnu/ss.js | 12 +++--- lib/v2/scnu/yjs.js | 10 ++--- lib/v2/sctv/programme.js | 20 +++++----- lib/v2/scut/jwc/news.js | 6 +-- lib/v2/scut/jwc/notice.js | 8 ++-- lib/v2/scut/jwc/school.js | 8 ++-- lib/v2/scut/scet/notice.js | 10 ++--- lib/v2/scut/seie/news-ccenter.js | 14 +++---- lib/v2/scut/smae/notice.js | 16 ++++---- lib/v2/scut/yjs.js | 12 +++--- lib/v2/scvtc/xygg.js | 14 +++---- lib/v2/sdu/cmse.js | 16 ++++---- lib/v2/sdu/cs.js | 16 ++++---- lib/v2/sdu/epe.js | 18 ++++----- lib/v2/sdu/extractor/sdrj.js | 10 ++--- lib/v2/sdu/extractor/view.js | 10 ++--- lib/v2/sdu/extractor/wh/jwc.js | 10 ++--- lib/v2/sdu/extractor/wh/news.js | 10 ++--- lib/v2/sdu/mech.js | 18 ++++----- lib/v2/sdu/sc.js | 16 ++++---- lib/v2/sdu/wh/jwc.js | 16 ++++---- lib/v2/sdu/wh/news.js | 14 +++---- lib/v2/sdust/yjsy/zhaosheng.js | 16 ++++---- lib/v2/sdzk/index.js | 18 ++++----- lib/v2/sec-in/index.js | 8 ++-- lib/v2/sec-wiki/weekly.js | 8 ++-- lib/v2/secrss/author.js | 14 +++---- lib/v2/secrss/category.js | 14 +++---- lib/v2/seekingalpha/index.js | 14 +++---- lib/v2/segmentfault/blogs.js | 6 +-- lib/v2/segmentfault/channel.js | 12 +++--- lib/v2/segmentfault/user.js | 6 +-- lib/v2/segmentfault/utils.js | 10 ++--- lib/v2/sehuatang/index.js | 20 +++++----- lib/v2/sehuatang/user.js | 20 +++++----- lib/v2/sensortower/blog.js | 16 ++++---- lib/v2/setn/index.js | 18 ++++----- lib/v2/seu/cse/index.js | 14 +++---- lib/v2/seu/radio/academic.js | 14 +++---- lib/v2/seu/yjs.js | 12 +++--- lib/v2/seu/yzb/index.js | 14 +++---- lib/v2/shcstheatre/programs.js | 16 ++++---- lib/v2/shiep/index.js | 20 +++++----- lib/v2/shisu/news.js | 16 ++++---- lib/v2/shmeea/index.js | 18 ++++----- 903 files changed, 5852 insertions(+), 5829 deletions(-) diff --git a/lib/v2/gov/csrc/news.js b/lib/v2/gov/csrc/news.js index 41656c2d3..dc3bdeaf6 100644 --- a/lib/v2/gov/csrc/news.js +++ b/lib/v2/gov/csrc/news.js @@ -1,8 +1,8 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +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) => { @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const { suffix = 'c100028/common_xq_list.shtml' } = ctx.params; const link = `${baseUrl}/csrc/${suffix}`; const { data: res } = await got(link); - const $ = cheerio.load(res); + const $ = load(res); const channelId = $('meta[name="channelid"]').attr('content'); @@ -52,7 +52,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: res } = await got(item.link); - const $ = cheerio.load(res); + const $ = load(res); item.description = $('.detail-news').html(); return item; }) @@ -60,10 +60,10 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `中国证券监督管理委员会 - ${data?.data.channelName || $('head title').text()}`, link, image: 'http://www.csrc.gov.cn/favicon.ico', item: out, - }; + }); }; diff --git a/lib/v2/gov/customs/list.js b/lib/v2/gov/customs/list.js index ea51292ed..a9d18ce21 100644 --- a/lib/v2/gov/customs/list.js +++ b/lib/v2/gov/customs/list.js @@ -1,8 +1,9 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const { host, puppeteerGet } = require('./utils'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { gchannel = 'paimai' } = ctx.params; @@ -24,13 +25,13 @@ module.exports = async (ctx) => { break; } - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); const list = await ctx.cache.tryGet( link, async () => { const response = await puppeteerGet(link, browser); - const $ = cheerio.load(response); + const $ = load(response); const list = $('[class^="conList_ul"] li') .toArray() .map((item) => { @@ -51,7 +52,7 @@ module.exports = async (ctx) => { list.map((info) => ctx.cache.tryGet(info.link, async () => { const response = await puppeteerGet(info.link, browser); - const $ = cheerio.load(response); + const $ = load(response); let date; $('.easysite-news-operation').remove(); @@ -72,9 +73,9 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: `中国海关-${channelName}`, link, item: out, - }; + }); }; diff --git a/lib/v2/gov/forestry/gjlckjdjt.js b/lib/v2/gov/forestry/gjlckjdjt.js index afb4a68b7..a779f4891 100644 --- a/lib/v2/gov/forestry/gjlckjdjt.js +++ b/lib/v2/gov/forestry/gjlckjdjt.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 = 'gjlckjdjt' } = 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 = 'http://www.forestry.gov.cn'; const currentUrl = new URL(`${category}.jhtml`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a.items') .slice(0, limit) @@ -43,7 +43,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('p').each((_, e) => { e = content(e); @@ -81,7 +81,7 @@ module.exports = async (ctx) => { const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -92,5 +92,5 @@ module.exports = async (ctx) => { subtitle: $('div.weizhi').contents().last().text(), author: '国家林业和草原局', allowEmpty: true, - }; + }); }; diff --git a/lib/v2/gov/general/general.js b/lib/v2/gov/general/general.js index f09a4c6ac..3196ac11e 100644 --- a/lib/v2/gov/general/general.js +++ b/lib/v2/gov/general/general.js @@ -35,10 +35,11 @@ // await gdgov(info, ctx); // }; -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'; +import { art } from '@/utils/render'; const gdgov = async (info, ctx) => { const path = ctx.path.split('/').filter((item) => item !== ''); @@ -116,7 +117,7 @@ const gdgov = async (info, ctx) => { } else { const res = await got(currentUrl); const dataArray = res.data; - $ = cheerio.load(dataArray); + $ = load(dataArray); switch (name_match_type) { case 'name': name = name_element; @@ -168,8 +169,6 @@ const gdgov = async (info, ctx) => { // http://fgj.maoming.gov.cn/zcjdpt?id=4993 // https://zcjd.cloud.gd.gov.cn/api/home/article?id=4993 return ctx.cache.tryGet(link, async () => { - const { art } = require('@/utils/render'); - const zcjdlink = 'https://zcjd.cloud.gd.gov.cn/api/home/article' + idlink.search; const response = await got(zcjdlink); const data = response.data.data; @@ -192,7 +191,7 @@ const gdgov = async (info, ctx) => { return ctx.cache.tryGet(link, async () => { // 获取网页 const { data: res } = await got(link); - const content = cheerio.load(res); + const content = load(res); // 获取来源 let author = ''; @@ -224,11 +223,11 @@ const gdgov = async (info, ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: name, link: currentUrl, item: items, - }; + }); }; module.exports = { diff --git a/lib/v2/gov/guangdong/tqyb/sncsyjxh.js b/lib/v2/gov/guangdong/tqyb/sncsyjxh.js index 4dedf975b..96dd6a2fd 100644 --- a/lib/v2/gov/guangdong/tqyb/sncsyjxh.js +++ b/lib/v2/gov/guangdong/tqyb/sncsyjxh.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const rootUrl = 'http://www.tqyb.com.cn'; @@ -29,9 +29,9 @@ module.exports = async (ctx) => { guid: timezone(parseDate(item.datetime, 'YYYY年MM月DD日 HH:mm'), +8) + item.cname + item.sigtypename, })); - ctx.state.data = { + ctx.set('data', { title: '广东省内城市预警信号', link: `http://www.tqyb.com.cn/gz/weatherAlarm/otherCity/`, item: items, - }; + }); }; diff --git a/lib/v2/gov/guangdong/tqyb/tfxtq.js b/lib/v2/gov/guangdong/tqyb/tfxtq.js index cfb299b35..ece011f69 100644 --- a/lib/v2/gov/guangdong/tqyb/tfxtq.js +++ b/lib/v2/gov/guangdong/tqyb/tfxtq.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 { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const rootUrl = 'http://www.tqyb.com.cn'; @@ -22,9 +22,9 @@ module.exports = async (ctx) => { guid: parseDate(item.ddate) + item.title, })); - ctx.state.data = { + ctx.set('data', { title: '突发性天气提示', link: 'http://www.tqyb.com.cn/gz/weatherAlarm/suddenWeather/', item: items, - }; + }); }; diff --git a/lib/v2/gov/gz/index.js b/lib/v2/gov/gz/index.js index 06e17bf69..055d807b8 100644 --- a/lib/v2/gov/gz/index.js +++ b/lib/v2/gov/gz/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.gz.gov.cn'; @@ -12,11 +12,11 @@ const urlMap = { }; module.exports = async (ctx) => { - const channel = ctx.params.channel; - const category = ctx.params.category; + const channel = ctx.req.param('channel'); + const category = ctx.req.param('category'); const url = `${rootUrl}/${channel}/${urlMap[category]}/`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.news_list li') .toArray() @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `广州市人民政府 - ${$('.main_title').text()}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/hebei/czt.js b/lib/v2/gov/hebei/czt.js index d5603de56..28f829d13 100644 --- a/lib/v2/gov/hebei/czt.js +++ b/lib/v2/gov/hebei/czt.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 ?? 'gzdt'; + const category = ctx.req.param('category') ?? 'gzdt'; const rootUrl = 'http://czt.hebei.gov.cn'; const currentUrl = `${rootUrl}/xwdt/${category}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('td li a[title]') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('meta[name="ContentSource"]').attr('content'); item.pubDate = parseDate(content('meta[name="PubDate"]').attr('content')); @@ -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/gov/huizhou/zwgk/index.js b/lib/v2/gov/huizhou/zwgk/index.js index c42d748ab..a6520d2e0 100644 --- a/lib/v2/gov/huizhou/zwgk/index.js +++ b/lib/v2/gov/huizhou/zwgk/index.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://www.huizhou.gov.cn'; module.exports = async (ctx) => { - const cate = ctx.params.category ?? 'zwyw'; + const cate = ctx.req.param('category') ?? 'zwyw'; const url = `${rootURL}/zwgk/hzsz/${cate}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('span#navigation').children('a').last().text(); const list = $('ul.ul_art_row') .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); try { item.description = content('div.artContent').html(); @@ -50,9 +50,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `惠州市人民政府 - ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/hunan/changsha/major-email.js b/lib/v2/gov/hunan/changsha/major-email.js index 7d62d800f..dcca43e4f 100644 --- a/lib/v2/gov/hunan/changsha/major-email.js +++ b/lib/v2/gov/hunan/changsha/major-email.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 { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const baseUrl = 'http://wlwz.changsha.gov.cn'; module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); listPage.data = iconv.decode(listPage.data, 'gbk'); - const $ = cheerio.load(listPage.data); + const $ = load(listPage.data); const list = $('.table1 tbody tr') .slice(1) .map((_, tr) => { @@ -30,7 +30,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); postPage.data = iconv.decode(postPage.data, 'gbk'); - const $ = cheerio.load(postPage.data); + const $ = load(postPage.data); const data = { title: item.title, @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '来信反馈 - 长沙市市长信箱', link: `${baseUrl}/webapp/cs2020/email/index.jsp`, item: items, - }; + }); }; diff --git a/lib/v2/gov/immiau/news.js b/lib/v2/gov/immiau/news.js index b85994b85..4a51e050c 100644 --- a/lib/v2/gov/immiau/news.js +++ b/lib/v2/gov/immiau/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 url = 'https://immi.homeaffairs.gov.au/_layouts/15/api/Data.aspx/GetNews'; @@ -34,10 +34,10 @@ module.exports = async (ctx) => { link: getItemUrl(item.Id), })); - ctx.state.data = { + ctx.set('data', { title: 'News - Immigration and Citizenship', link: 'https://immi.homeaffairs.gov.au/news-media/archive', description: 'Australia Government, Department of Home Affairs', item: list, - }; + }); }; diff --git a/lib/v2/gov/jgjcndrc/index.js b/lib/v2/gov/jgjcndrc/index.js index f3d47a54e..94a03bf9e 100644 --- a/lib/v2/gov/jgjcndrc/index.js +++ b/lib/v2/gov/jgjcndrc/index.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 = 'sytzgg' } = 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 = 'http://www.jgjcndrc.org.cn'; const currentUrl = new URL(`list.aspx?clmId=${id}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('ul.list_02 li.li a[title]') .slice(0, limit) @@ -31,7 +31,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.txt_title1').text(); item.description = content('div#zoom').html(); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { const subtitle = $('li.L').first().text(); const image = new URL($('img.logo2').prop('src'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -55,5 +55,5 @@ module.exports = async (ctx) => { image, subtitle, author, - }; + }); }; diff --git a/lib/v2/gov/jinan/healthcommission/medical-exam-notice.js b/lib/v2/gov/jinan/healthcommission/medical-exam-notice.js index 5b9d16b9f..83f6c7210 100644 --- a/lib/v2/gov/jinan/healthcommission/medical-exam-notice.js +++ b/lib/v2/gov/jinan/healthcommission/medical-exam-notice.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 baseUrl = 'https://jnmhc.jinan.gov.cn'; @@ -18,11 +18,11 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(res.data, { xmlMode: true }); + const $ = load(res.data, { xmlMode: true }); const list = $('record'); - ctx.state.data = { + ctx.set('data', { title: '济南卫建委-执业考试通知', link: `${baseUrl}/col/col14418/index.html`, item: list @@ -31,7 +31,7 @@ module.exports = async (ctx) => { item = $(item).text(); // 解析上一步中的html - const html = cheerio.load(item); + const html = load(item); const title = html('td[width="620"] a').attr('title'); const link = html('td[width="620"] a').attr('href'); @@ -45,5 +45,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/gov/maonan/maonan.js b/lib/v2/gov/maonan/maonan.js index 765c3cdd9..060b7b109 100644 --- a/lib/v2/gov/maonan/maonan.js +++ b/lib/v2/gov/maonan/maonan.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.maonan.gov.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { let id = ''; let name = ''; - switch (ctx.params.category) { + switch (ctx.req.param('category')) { case 'zwgk': id = 'zwgk'; name = '政务公开'; @@ -42,7 +42,7 @@ module.exports = async (ctx) => { const res = await got(`${host}/${id}/`); const dataArray = res.data; - const $ = cheerio.load(dataArray); + const $ = load(dataArray); const list = $('li.clearfix a[href*="www.maonan.gov.cn"], li.clearfix a[href*="mp.weixin.qq.com"]'); const items = await Promise.all( @@ -57,7 +57,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(link, async () => { // 获取网页 const { data: res } = await got(link); - const content = cheerio.load(res); + const content = load(res); switch (url.host) { case 'mp.weixin.qq.com': @@ -92,9 +92,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `茂名市茂南区人民政府 - ${name}`, link: `${host}/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/gov/mee/ywdt.js b/lib/v2/gov/mee/ywdt.js index 475849c91..a8ed12f92 100644 --- a/lib/v2/gov/mee/ywdt.js +++ b/lib/v2/gov/mee/ywdt.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.mee.gov.cn/'; const columns = { @@ -14,11 +14,11 @@ const columns = { }; module.exports = async (ctx) => { - const cate = ctx.params.category ?? 'szyw'; + const cate = ctx.req.param('category') ?? 'szyw'; const url = `${baseUrl}ywdt/`; const title = `${columns[cate].name} - 要闻动态 - 中华人民共和国生态环境部`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const all = $('.bd'); const list = all .find(`div:nth-child(${columns[cate].order})`) @@ -47,7 +47,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); try { item.pubDate = timezone(parseDate(content('meta[name=PubDate]').attr('content')), +8); // 视频新闻规则不一样 @@ -72,9 +72,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/mem/sgcc.js b/lib/v2/gov/mem/sgcc.js index 7368b3689..d95f653ed 100644 --- a/lib/v2/gov/mem/sgcc.js +++ b/lib/v2/gov/mem/sgcc.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 { category = 'sggpdbqk' } = 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://www.mem.gov.cn'; const currentUrl = new URL(`gk/sgcc/${category}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('table.center_main02') .find('a[title]') @@ -38,7 +38,7 @@ module.exports = async (ctx) => { if (item.link.endsWith('html')) { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description = content('#content').html(); } @@ -49,7 +49,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: $('title').text(), link: currentUrl, @@ -60,5 +60,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="ColumnName"]').prop('content'), author: $('meta[name="SiteName"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/mfa/wjdt.js b/lib/v2/gov/mfa/wjdt.js index 8e5c88f51..b15ac25c2 100644 --- a/lib/v2/gov/mfa/wjdt.js +++ b/lib/v2/gov/mfa/wjdt.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 = { gjldrhd: 'gjldrhd_674881', @@ -16,7 +16,7 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'gjldrhd'; + const category = ctx.req.param('category') ?? 'gjldrhd'; const rootUrl = 'https://www.mfa.gov.cn'; const currentUrl = `${rootUrl}/web/wjdt_674879/${categories[category]}`; @@ -26,10 +26,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('ul.list1 li a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 35) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 35) .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); item.description = content('#News_Body_Txt_A').html(); item.pubDate = timezone(parseDate(content('.time span').last().text()), +8); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/miit/wjfb.js b/lib/v2/gov/miit/wjfb.js index 88f22522b..6f0f88b4e 100644 --- a/lib/v2/gov/miit/wjfb.js +++ b/lib/v2/gov/miit/wjfb.js @@ -1,16 +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 rootUrl = 'https://www.miit.gov.cn'; module.exports = async (ctx) => { - const ministry = ctx.params.ministry; + const ministry = ctx.req.param('ministry'); const url = `${rootUrl}/jgsj/${ministry}/wjfb/index.html`; const cookieResponse = await got(url); const cookie = cookieResponse.headers['set-cookie'][0].split(';')[0]; - const indexContent = cheerio.load(cookieResponse.data); + const indexContent = load(cookieResponse.data); const title = indexContent('div.dqwz > a:nth-child(4)').text(); const dataRequestUrl = indexContent('div.lmy_main_rb > script:nth-child(2)') .map((_, item) => ({ @@ -29,7 +29,7 @@ module.exports = async (ctx) => { Cookie: cookie, }, }); - const $ = cheerio.load(response.data.data.html); + const $ = load(response.data.data.html); const list = $('ul > li') .map((_, item) => ({ title: $(item).find('a').text(), @@ -42,7 +42,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('#con_con') .html() @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `工业和信息化部 - ${title} 文件发布`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/miit/wjgs.js b/lib/v2/gov/miit/wjgs.js index cb77d998f..eab4600b5 100644 --- a/lib/v2/gov/miit/wjgs.js +++ b/lib/v2/gov/miit/wjgs.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'; const baseUrl = 'https://www.miit.gov.cn'; const siteUrl = `${baseUrl}/zwgk/wjgs/index.html`; module.exports = async (ctx) => { const response = await got(siteUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const buildStatic = $('script[parseType=buildstatic]'); const requestUrl = buildStatic.attr('url'); const queryData = JSON.parse(buildStatic.attr('querydata').replaceAll("'", '"')); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, searchParams: queryData, }); - const list = cheerio.load(data.data.html, null, false); + const list = load(data.data.html, null, false); let items = list('.page-content ul li') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); $('iframe').each((_, e) => { e = $(e); @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('head title').text()} - ${$('meta[name=SiteName]').attr('content')}`, link: siteUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/miit/yjzj.js b/lib/v2/gov/miit/yjzj.js index 59e1de417..8069ed130 100644 --- a/lib/v2/gov/miit/yjzj.js +++ b/lib/v2/gov/miit/yjzj.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.miit.gov.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const cookieResponse = await got(url); const cookie = cookieResponse.headers['set-cookie'][0].split(';')[0]; - const indexContent = cheerio.load(cookieResponse.data); + const indexContent = load(cookieResponse.data); const dataRequestUrl = indexContent('div.clist_con > script:nth-child(2)') .map((_, item) => ({ url: `${rootUrl}${indexContent(item).attr('url')}`, @@ -27,7 +27,7 @@ module.exports = async (ctx) => { Cookie: cookie, }, }); - const $ = cheerio.load(response.data.data.html); + const $ = load(response.data.data.html); const list = $('ul > li') .map((_, item) => ({ title: $(item).find('a').text(), @@ -40,7 +40,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('#con_con') .html() @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `工业和信息化部 - 意见征集`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/miit/zcjd.js b/lib/v2/gov/miit/zcjd.js index 1a6e19f92..a341aca38 100644 --- a/lib/v2/gov/miit/zcjd.js +++ b/lib/v2/gov/miit/zcjd.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'; const baseUrl = 'https://www.miit.gov.cn'; const siteUrl = `${baseUrl}/zwgk/zcjd/index.html`; module.exports = async (ctx) => { const response = await got(siteUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const buildStatic = $('script[parseType=buildstatic]'); const requestUrl = buildStatic.attr('url'); const queryData = JSON.parse(buildStatic.attr('querydata').replaceAll("'", '"')); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, searchParams: queryData, }); - const list = cheerio.load(data.data.html, null, false); + const list = load(data.data.html, null, false); let items = list('.page-content ul li') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); $('iframe').each((_, e) => { e = $(e); @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('head title').text()} - ${$('meta[name=SiteName]').attr('content')}`, link: siteUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/miit/zcwj.js b/lib/v2/gov/miit/zcwj.js index 64c6398fd..bfdd6de47 100644 --- a/lib/v2/gov/miit/zcwj.js +++ b/lib/v2/gov/miit/zcwj.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 base_url = 'http://www.miit.gov.cn/n1146295/n1652858/'; const response = await got.get(base_url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.clist_con li').get(); const ProcessFeed = (data) => { - const $ = cheerio.load(data); + const $ = load(data); const content = $('p'); return content.text(); @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const $a = $('a'); let link = $a.attr('href'); if (link.startsWith('..')) { @@ -44,10 +44,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '中国工业化和信息部', link: 'http://www.miit.gov.cn', description: '政策文件', item: items, - }; + }); }; diff --git a/lib/v2/gov/moa/moa.js b/lib/v2/gov/moa/moa.js index c8e0f3525..9e3d3b164 100644 --- a/lib/v2/gov/moa/moa.js +++ b/lib/v2/gov/moa/moa.js @@ -1,12 +1,12 @@ -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'; const hostUrl = 'http://www.moa.gov.cn/'; const hostUrlObj = new URL(hostUrl); // 用于在下面判断host module.exports = async (ctx) => { - const rawSuburl = ctx.params.suburl; + const rawSuburl = ctx.req.param('suburl'); const suburl = rawSuburl.slice(-1) === '/' ? rawSuburl : rawSuburl + '/'; // 特殊处理两个, 其他的栏目都可以找到那种一个列表下去的目录 @@ -43,7 +43,7 @@ async function dealChannel(ctx, suburl, selectors) { // 为了与下面解析相对链接的dealLink配合, 这里末尾必须保证有一条斜杠 const url = hostUrl + suburl; const respone = await got.get(url); - const $ = cheerio.load(respone.data); + const $ = load(respone.data); const channelTitle = $(channelTitleSelector).text(); @@ -104,7 +104,7 @@ async function dealChannel(ctx, suburl, selectors) { // 处理正常文章, 例子: http://www.moa.gov.cn/gk/rsxx_1/202004/t20200421_6342037.htm async function dealNormalPage(link, item) { const reponse = await got.get(link); - const $ = cheerio.load(reponse.data); + const $ = load(reponse.data); const metaElements = $('.bjjMAuthorBox span.dc_3').toArray(); // 政府网站变动不频繁, 写死第几个应该没有多大关系 @@ -127,7 +127,7 @@ async function dealNormalPage(link, item) { // 处理那种带索引号的公示文章, 例子: http://www.moa.gov.cn/govpublic/XZQYJ/202004/t20200420_6341913.htm async function dealGovpublicPage(link, item) { const respone = await got.get(link); - const $ = cheerio.load(respone.data); + const $ = load(respone.data); const head = $('ul.head'); const body = $('.arc_body'); diff --git a/lib/v2/gov/moa/zdscxx.js b/lib/v2/gov/moa/zdscxx.js index 09661b6f7..d26a0828f 100644 --- a/lib/v2/gov/moa/zdscxx.js +++ b/lib/v2/gov/moa/zdscxx.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; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5; const domain = 'moa.gov.cn'; const rootFrameUrl = `http://www.${domain}`; @@ -80,13 +80,13 @@ module.exports = async (ctx) => { const { data: frameResponse } = await got(frameUrl); - const $ = cheerio.load(frameResponse); + const $ = load(frameResponse); const title = $('title').text(); const description = '数据'; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${title} - ${description} - ${category}`, link: currentUrl, @@ -98,5 +98,5 @@ module.exports = async (ctx) => { subtitle: category, author: title, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/gov/moe/moe.js b/lib/v2/gov/moe/moe.js index 334679448..06587899c 100644 --- a/lib/v2/gov/moe/moe.js +++ b/lib/v2/gov/moe/moe.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const logger = require('@/utils/logger'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const moeUrl = 'https://www.moe.gov.cn/'; const typesIdMap = [ @@ -13,7 +13,7 @@ const typesIdMap = [ ]; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let id = ''; let name = ''; @@ -31,10 +31,10 @@ module.exports = async (ctx) => { const response = await got(moeUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const newsLis = $('div#' + id + '>ul>li'); - ctx.state.data = { + ctx.set('data', { title: name, link: moeUrl, item: await Promise.all( @@ -59,7 +59,7 @@ module.exports = async (ctx) => { Referer: moeUrl, }, }); - const data = cheerio.load(response.data); + const data = load(response.data); if (itemUrl.includes('www.gov.cn')) { res.description = data('#UCAP-CONTENT').html(); @@ -81,5 +81,5 @@ module.exports = async (ctx) => { }) .get() ), - }; + }); }; diff --git a/lib/v2/gov/moe/s78.js b/lib/v2/gov/moe/s78.js index 661849591..d6f74a356 100644 --- a/lib/v2/gov/moe/s78.js +++ b/lib/v2/gov/moe/s78.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 baseUrl = 'https://www.moe.gov.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/s78/${column}/tongzhi/`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#list li') .toArray() @@ -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); $('#moe-detail-page-set, #moeCode, .moe-detail-shuxing, h1').remove(); item.description = $('.moe-detail-box').html(); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('meta[name="ColumnType"]').attr('content')} - ${$('head title').text()}`, link, item: items, - }; + }); }; diff --git a/lib/v2/gov/mof/bond.js b/lib/v2/gov/mof/bond.js index 70051bdec..9f032b803 100644 --- a/lib/v2/gov/mof/bond.js +++ b/lib/v2/gov/mof/bond.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 domain = 'gks.mof.gov.cn'; const theme = 'guozaiguanli'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const { category = 'gzfxgzdt' } = ctx.params; const currentUrl = `https://${domain}/ztztz/${theme}/${category}/`; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const title = $('title').text(); const author = $('div.zzName').text(); const siteName = $('meta[name="SiteName"]').prop('content'); @@ -33,7 +33,7 @@ module.exports = async (ctx) => { indexes.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.my_doccontent').html(); item.author = author; return item; @@ -41,11 +41,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, description: `${description} - ${siteName}`, author, - }; + }); }; diff --git a/lib/v2/gov/mofcom/article.js b/lib/v2/gov/mofcom/article.js index 7c2a0cbac..06d3a2ec1 100644 --- a/lib/v2/gov/mofcom/article.js +++ b/lib/v2/gov/mofcom/article.js @@ -1,15 +1,15 @@ -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 host = 'http://www.mofcom.gov.cn'; module.exports = async (ctx) => { - const suffix = ctx.params.suffix; + const suffix = ctx.req.param('suffix'); const url = `http://www.mofcom.gov.cn/article/${suffix}/`; const { data: res } = await got(url); - const $ = cheerio.load(res); + const $ = load(res); $('.listline').remove(); const list = $('.txtList_01 li') .toArray() @@ -45,11 +45,11 @@ module.exports = async (ctx) => { }, }); } - const $ = cheerio.load(responses.data); + const $ = load(responses.data); const iframe = $('.art-con iframe').attr('src'); if ($('.art-con iframe').attr('src')) { const { data: res } = await got(iframe); - item.description = cheerio.load(res)('tbody').html(); + item.description = load(res)('tbody').html(); } else { item.description = $('.art-con').html() || /* xwfb/xwztfbh */ $('.textlive').html(); } @@ -59,10 +59,10 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: $('head > title').text(), description: $('meta[name=description]').attr('content'), link: url, item: list, - }; + }); }; diff --git a/lib/v2/gov/moj/aac/news.js b/lib/v2/gov/moj/aac/news.js index 0caa24a68..bd9b95a31 100644 --- a/lib/v2/gov/moj/aac/news.js +++ b/lib/v2/gov/moj/aac/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const baseUrl = 'https://www.aac.moj.gov.tw'; module.exports = async (ctx) => { const { type } = ctx.params; const url = `${baseUrl}/7204/7246/?Page=1&PageSize=40${type ? `&type=${type}` : ''}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.num').remove(); const list = $('.list ul li a') .toArray() @@ -28,7 +28,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (!item.isDownload) { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.pubDate = timezone(parseDate($('.info time').attr('datetime'), 'YYYY-MM-DD HH:mm:ss'), +8); $('.info, button').remove(); @@ -40,10 +40,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, item: items, language: 'zh-TW', - }; + }); }; diff --git a/lib/v2/gov/moj/lfyjzj.js b/lib/v2/gov/moj/lfyjzj.js index 2e826fbd9..b16ef952b 100644 --- a/lib/v2/gov/moj/lfyjzj.js +++ b/lib/v2/gov/moj/lfyjzj.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 DOMAIN = 'www.moj.gov.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const rootUrl = `https://${DOMAIN}`; const currentUrl = `${rootUrl}/lfyjzj/lflfyjzj/index.html`; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const siteName = $('title:first').text(); const theme = $('div.list_title').text(); const description = `${siteName} - ${theme}`; @@ -32,7 +32,7 @@ module.exports = async (ctx) => { indexes.map((item) => ctx.cache.tryGet(`gov:mof:${item.link}`, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description = content('div.TRS_Editor').html(); item.author = content('div.sT_left span:first').text().split(':')[1]; const pubDate = content('div.sT_left span:last').text().split(':')[1]; @@ -42,12 +42,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { item: items, title: theme, link: currentUrl, description, author: siteName, icon, - }; + }); }; diff --git a/lib/v2/gov/mot/index.js b/lib/v2/gov/mot/index.js index 7624d825d..dd7231502 100644 --- a/lib/v2/gov/mot/index.js +++ b/lib/v2/gov/mot/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category = 'tongjishuju/gonglu' } = 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://www.mot.gov.cn'; const currentUrl = new URL(`${category}/`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.tab-pane a[title]') .slice(0, limit) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { if (/\.gov\.cn/.test(item.link) && item.link.endsWith('.html')) { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.title = content('meta[name="ArticleTitle"]').prop('content') || content('h1#ti').text(); item.description = content('div.TRS_UEDITOR').html(); @@ -53,7 +53,7 @@ module.exports = async (ctx) => { const image = new URL($('a.navbar-brand img').prop('src'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -62,5 +62,5 @@ module.exports = async (ctx) => { image, subtitle: $('meta[name="ColumnName"]').prop('content'), author: $('meta[name="SiteName"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/ndrc/fggz.js b/lib/v2/gov/ndrc/fggz.js index 449198dfd..6e089c7c1 100644 --- a/lib/v2/gov/ndrc/fggz.js +++ b/lib/v2/gov/ndrc/fggz.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 25; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 25; const rootUrl = 'https://www.ndrc.gov.cn'; const currentUrl = new URL(`fggz${category ? `/${category.endsWith('/') ? category : `${category}/`}` : '/'}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('ul.u-list li a') .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); item.title = content('meta[name="ArticleTitle"]').prop('content'); item.description = content('div.TRS_Editor').html(); @@ -49,7 +49,7 @@ module.exports = async (ctx) => { const image = $('div.logo a img').prop('src'); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -58,5 +58,5 @@ module.exports = async (ctx) => { image, subtitle: $('meta[name="ColumnName"]').prop('content'), author: $('meta[name="SiteName"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/ndrc/xwdt.js b/lib/v2/gov/ndrc/xwdt.js index 09f87159d..c7fbc2d99 100644 --- a/lib/v2/gov/ndrc/xwdt.js +++ b/lib/v2/gov/ndrc/xwdt.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 category = ctx.params.category || 'xwfb'; + const category = ctx.req.param('category') || 'xwfb'; const rootUrl = 'https://www.ndrc.gov.cn'; const currentUrl = category.includes('dt') ? `${rootUrl}/xwdt/dt/${category}` : `${rootUrl}/xwdt/${category}`; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.u-list li a') .slice(0, 10) .map((_, item) => { @@ -36,7 +36,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.TRS_Editor').html() || content('.article_con').html(); item.pubDate = new Date(content('meta[name="PubDate"]').attr('content') + ' GMT+8').toUTCString(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/nea/ghs.js b/lib/v2/gov/nea/ghs.js index 3b10bbdae..60f2ddb25 100644 --- a/lib/v2/gov/nea/ghs.js +++ b/lib/v2/gov/nea/ghs.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) : 35; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 35; const rootUrl = 'https://www.nea.gov.cn'; const currentUrl = new URL('sjzz/ghs/', rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.right_box ul li') .slice(0, limit) @@ -33,7 +33,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('meta[name="ArticleTitle"]').prop('content'); item.description = content('td.detail').html() || content('div.article-content td').html(); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -54,5 +54,5 @@ module.exports = async (ctx) => { language: 'zh', subtitle: $('meta[name="ColumnType"]').prop('content'), author: $('meta[name="ColumnKeywords"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/news/index.js b/lib/v2/gov/news/index.js index 56df08d65..023cc1d18 100644 --- a/lib/v2/gov/news/index.js +++ b/lib/v2/gov/news/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 logger = require('@/utils/logger'); -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 uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const originDomain = 'https://www.gov.cn'; let url = ''; let title = ''; @@ -36,7 +36,7 @@ module.exports = async (ctx) => { logger.error('pattern not matched'); } const listData = await got.get(url); - const $ = cheerio.load(listData.data); + const $ = load(listData.data); if (url.includes('zhengcelibrary')) { list = $('.dys_middle_result_content_item'); } else if (url.includes('bumen')) { @@ -45,7 +45,7 @@ module.exports = async (ctx) => { list = $('.news_box .list li:not(.line)'); } - ctx.state.data = { + ctx.set('data', { title, link: url, item: await Promise.all( @@ -63,7 +63,7 @@ module.exports = async (ctx) => { if (/dysMiddleResultConItemTitle/g.test(item.html())) { if (contentUrl.includes('content')) { fullTextGet = await got.get(contentUrl); - fullTextData = cheerio.load(fullTextGet.data); + fullTextData = load(fullTextGet.data); fullTextData('.shuzi').remove(); // 移除videobg的图片 fullTextData('#myFlash').remove(); // 移除flash description = /pages_content/g.test(fullTextData.html()) ? fullTextData('.pages_content').html() : fullTextData('#UCAP-CONTENT').html(); @@ -73,7 +73,7 @@ module.exports = async (ctx) => { } else { if (contentUrl.includes('content')) { fullTextGet = await got.get(contentUrl); - fullTextData = cheerio.load(fullTextGet.data); + fullTextData = load(fullTextGet.data); const $1 = fullTextData.html(); pubDate = timezone(parseDate(fullTextData('meta[name="firstpublishedtime"]').attr('content'), 'YYYY-MM-DD HH:mm:ss'), 8); author = fullTextData('meta[name="author"]').attr('content'); @@ -101,5 +101,5 @@ module.exports = async (ctx) => { }); }) ), - }; + }); }; diff --git a/lib/v2/gov/nifdc/index.js b/lib/v2/gov/nifdc/index.js index edf651d46..b92112a51 100644 --- a/lib/v2/gov/nifdc/index.js +++ b/lib/v2/gov/nifdc/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { path = 'bshff/ylqxbzhgl/qxggtzh' } = 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://www.nifdc.org.cn'; const currentUrl = new URL(`nifdc/${path}/`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.list ul li') .slice(0, limit) @@ -36,7 +36,7 @@ module.exports = async (ctx) => { try { 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.text').append(content('div.fujian')).html(); @@ -63,7 +63,7 @@ module.exports = async (ctx) => { const image = new URL($('div.logo img').prop('src'), currentUrl).href; const icon = new URL($('link[rel="shortcut icon"]').prop('href'), currentUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text().replace(/----/, ' - '), link: currentUrl, @@ -74,5 +74,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[ name="ColumnName"]').prop('content'), author: $('meta[name="SiteName"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/nmpa/generic.js b/lib/v2/gov/nmpa/generic.js index ea6000416..7f512e82a 100644 --- a/lib/v2/gov/nmpa/generic.js +++ b/lib/v2/gov/nmpa/generic.js @@ -1,10 +1,10 @@ -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); -const config = require('@/config').value; +import { config } from '@/config'; const baseUrl = 'https://www.nmpa.gov.cn'; -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const path = ctx.params[0]; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url, async () => { const { data: html } = await got(url); - const $ = cheerio.load(html); + const $ = load(html); return { title: $('head title').text(), @@ -39,7 +39,7 @@ module.exports = async (ctx) => { if (/^https:\/\/www\.nmpa\.gov\.cn\//.test(item.link)) { return ctx.cache.tryGet(item.link, async () => { const { data: html } = await got(item.link); - const $ = cheerio.load(html); + const $ = load(html); item.description = $('.text').html(); item.pubDate = timezone(parseDate($('meta[name="PubDate"]').attr('content')), +8); return item; @@ -52,10 +52,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: data.title, description: data.description, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/nopss/index.js b/lib/v2/gov/nopss/index.js index 87432275f..577fce6e5 100644 --- a/lib/v2/gov/nopss/index.js +++ b/lib/v2/gov/nopss/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 timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const params = ctx.path === '/nopss' ? '/GB/219469' : ctx.path.replace(/^\/nopss/, ''); @@ -16,10 +16,10 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); let items = $('.p2j_list_con .clearfix li a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 40) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 40) .toArray() .map((item) => { item = $(item); @@ -40,7 +40,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + const content = load(iconv.decode(detailResponse.data, 'gbk')); item.description = content('.text_con').html(); @@ -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/gov/npc/index.js b/lib/v2/gov/npc/index.js index 3271a450a..ad3829e21 100644 --- a/lib/v2/gov/npc/index.js +++ b/lib/v2/gov/npc/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'; module.exports = async (ctx) => { const { caty } = ctx.params; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const baseurl = `http://www.npc.gov.cn/npc/c2/${caty}/`; const response = await got(baseurl); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const title = $('title').text(); // 获取每条的链接 const links = $('.clist a') @@ -21,7 +21,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(link, async () => { const response = await got(link); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const title = $('title').text().replace('_中国人大网', ''); const time = $('script:contains("fbrq")') .text() @@ -38,10 +38,10 @@ module.exports = async (ctx) => { ) ); // 整合 - ctx.state.data = { + ctx.set('data', { title, link: baseurl, description: title, item: items, - }; + }); }; diff --git a/lib/v2/gov/nrta/dsj.js b/lib/v2/gov/nrta/dsj.js index afc174094..f78ed2184 100644 --- a/lib/v2/gov/nrta/dsj.js +++ b/lib/v2/gov/nrta/dsj.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'; const asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { const { category = 'note' } = 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://dsj.nrta.gov.cn'; const currentUrl = new URL(`tims/site/views/applications.shanty?appName=${category}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('img[src="/site/styles/default/images/icon_arrow_r.gif"]') .slice(0, limit) @@ -35,7 +35,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('table').last().remove(); @@ -47,7 +47,7 @@ module.exports = async (ctx) => { results.push(item); } - ctx.state.data = { + ctx.set('data', { item: results, title: `${$('title').text()}-${$('div.headbottom_menu_selected').text()}`, link: currentUrl, @@ -55,5 +55,5 @@ module.exports = async (ctx) => { language: 'zh-cn', image: $('img').first().prop('src'), author: '国家广播电影电视总局电视剧管理司', - }; + }); }; diff --git a/lib/v2/gov/nrta/news.js b/lib/v2/gov/nrta/news.js index e07c3142c..cee8d581d 100644 --- a/lib/v2/gov/nrta/news.js +++ b/lib/v2/gov/nrta/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 categories = { 112: '总局要闻', @@ -10,7 +10,7 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 112; + const category = ctx.req.param('category') ?? 112; const rootUrl = 'http://www.nrta.gov.cn'; @@ -24,7 +24,7 @@ module.exports = async (ctx) => { const regex = /(?=\s*<)/gi; const data = response.data.replaceAll(regex, '$1'); - const $ = cheerio.load(data, { + const $ = load(data, { xmlMode: true, }); @@ -43,7 +43,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('td[id="artTitMob"]').text(); item.description = content('div[id="c"]').html(); item.pubDate = timezone(parseDate(content('.mobile_time.shareWarpTime').text().trim()), +8); @@ -52,11 +52,11 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: category in categories ? categories[category] : '其他', link: `http://www.nrta.gov.cn/col/col${category}/index.html`, description: '国家广播电视总局', language: 'zh-cn', item: items, - }; + }); }; diff --git a/lib/v2/gov/nsfc/index.js b/lib/v2/gov/nsfc/index.js index 68e8aff35..79053636d 100644 --- a/lib/v2/gov/nsfc/index.js +++ b/lib/v2/gov/nsfc/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const shortcuts = require('./shortcuts'); module.exports = async (ctx) => { let thePath = ctx.path.replace(/^\/nsfc/, ''); - 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 shortcutMatches = thePath.match(/(\/news)?\/([\w-]+)/); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); let items = $('span.fl a, ul.dp_lia li a') .slice(0, limit) @@ -52,7 +52,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.title = content('div.title_xilan').text(); item.description = content('#zoom').html(); @@ -69,7 +69,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { item: items, title: `国家自然科学基金委员会 - ${$('#ess_essBREADCRUMB_lblBreadCrumb a.break') .toArray() @@ -81,5 +81,5 @@ module.exports = async (ctx) => { language: 'zh-cn', subtitle: $('meta[name="KEYWORDS"]').prop('content'), author: $('meta[name="AUTHOR"]').prop('content'), - }; + }); }; diff --git a/lib/v2/gov/pbc/goutongjiaoliu.js b/lib/v2/gov/pbc/goutongjiaoliu.js index 25171cdca..b17aea54b 100644 --- a/lib/v2/gov/pbc/goutongjiaoliu.js +++ b/lib/v2/gov/pbc/goutongjiaoliu.js @@ -1,11 +1,12 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const link = 'http://www.pbc.gov.cn/goutongjiaoliu/113456/113469/index.html'; - 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) => { @@ -16,7 +17,7 @@ module.exports = async (ctx) => { }); const html = await page.evaluate(() => document.documentElement.innerHTML); - const $ = cheerio.load(html); + const $ = load(html); const list = $('font.newslist_style') .map((_, item) => { item = $(item); @@ -40,7 +41,7 @@ module.exports = async (ctx) => { waitUntil: 'domcontentloaded', }); const detailHtml = await detailPage.evaluate(() => document.documentElement.innerHTML); - const content = cheerio.load(detailHtml); + const content = load(detailHtml); item.description = content('#zoom').html(); item.pubDate = timezone(parseDate(content('.hui12').eq(5).text()), +8); return item; @@ -50,9 +51,9 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: '中国人民银行 - 沟通交流', link, item: items, - }; + }); }; diff --git a/lib/v2/gov/pbc/gzlw.js b/lib/v2/gov/pbc/gzlw.js index a9edee375..0e71887ba 100644 --- a/lib/v2/gov/pbc/gzlw.js +++ b/lib/v2/gov/pbc/gzlw.js @@ -1,6 +1,6 @@ const { processItems } = require('./utils'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const host = 'http://www.pbc.gov.cn'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${host}/redianzhuanti/118742/4122386/4122692/index.html`; const response = await got.post(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('li.clearfix') .map((_index, item) => ({ title: $(item).find('a').text(), @@ -19,9 +19,9 @@ module.exports = async (ctx) => { const items = await processItems(list, ctx); - ctx.state.data = { + ctx.set('data', { title: '中国人民银行 工作论文', link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/pbc/trade-announcement.js b/lib/v2/gov/pbc/trade-announcement.js index 4f8984f3c..b45800962 100644 --- a/lib/v2/gov/pbc/trade-announcement.js +++ b/lib/v2/gov/pbc/trade-announcement.js @@ -1,11 +1,12 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const link = 'http://www.pbc.gov.cn/zhengcehuobisi/125207/125213/125431/125475/index.html'; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -15,7 +16,7 @@ module.exports = async (ctx) => { waitUntil: 'domcontentloaded', }); const html = await page.evaluate(() => document.documentElement.innerHTML); - const $ = cheerio.load(html); + const $ = load(html); const list = $('font.newslist_style') .map((_, item) => { item = $(item); @@ -39,7 +40,7 @@ module.exports = async (ctx) => { waitUntil: 'domcontentloaded', }); const detailHtml = await detailPage.evaluate(() => document.documentElement.innerHTML); - const content = cheerio.load(detailHtml); + const content = load(detailHtml); item.description = content('#zoom').html(); item.pubDate = timezone(parseDate(content('#shijian').text()), +8); return item; @@ -49,9 +50,9 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: '中国人民银行 - 货币政策司公开市场交易公告', link, item: items, - }; + }); }; diff --git a/lib/v2/gov/pbc/utils.js b/lib/v2/gov/pbc/utils.js index bd06f3778..b5f3b749c 100644 --- a/lib/v2/gov/pbc/utils.js +++ b/lib/v2/gov/pbc/utils.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const processItems = (list, ctx) => Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.post(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.xxy_text').html(); diff --git a/lib/v2/gov/pbc/zcyj.js b/lib/v2/gov/pbc/zcyj.js index 86ecd1b79..0e88fb73c 100644 --- a/lib/v2/gov/pbc/zcyj.js +++ b/lib/v2/gov/pbc/zcyj.js @@ -1,8 +1,8 @@ const { processItems } = require('./utils'); -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.pbc.gov.cn'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const url = `${host}/redianzhuanti/118742/4122386/4122510/index.html`; const response = await got.post(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('li.clearfix') .map((_index, item) => ({ title: $(item).find('a').text(), @@ -21,9 +21,9 @@ module.exports = async (ctx) => { const items = await processItems(list, ctx); - ctx.state.data = { + ctx.set('data', { title: '中国人民银行 政策研究', link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/safe/business.js b/lib/v2/gov/safe/business.js index 3fe219000..a4f82573a 100644 --- a/lib/v2/gov/safe/business.js +++ b/lib/v2/gov/safe/business.js @@ -2,7 +2,7 @@ const { processZxfkItems } = require('./util'); module.exports = async (ctx) => { const { site = 'beijing' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 3; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 3; ctx.state.data = await processZxfkItems(site, 'ywzx', limit); }; diff --git a/lib/v2/gov/safe/complaint.js b/lib/v2/gov/safe/complaint.js index f97a261fd..c2eb9ffff 100644 --- a/lib/v2/gov/safe/complaint.js +++ b/lib/v2/gov/safe/complaint.js @@ -2,7 +2,7 @@ const { processZxfkItems } = require('./util'); module.exports = async (ctx) => { const { site = 'beijing' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5; ctx.state.data = await processZxfkItems(site, 'tsjy', limit); }; diff --git a/lib/v2/gov/safe/util.js b/lib/v2/gov/safe/util.js index a9a05a692..bafaac240 100644 --- a/lib/v2/gov/safe/util.js +++ b/lib/v2/gov/safe/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 rootUrl = 'https://www.safe.gov.cn'; @@ -20,7 +20,7 @@ const processZxfkItems = async (site = 'beijing', category = 'ywzx', limit = '3' const { data: response } = await got(apiUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('#complaint') .slice(0, limit) @@ -58,7 +58,7 @@ const processZxfkItems = async (site = 'beijing', category = 'ywzx', limit = '3' const { data: currentResponse } = await got(currentUrl); - const content = cheerio.load(currentResponse); + const content = load(currentResponse); const author = content('meta[name="ColumnName"]').prop('content'); const subtitle = content('meta[name="ColumnType"]').prop('content'); diff --git a/lib/v2/gov/samr/xgzlyhd.js b/lib/v2/gov/samr/xgzlyhd.js index aa9397674..f066bcd94 100644 --- a/lib/v2/gov/samr/xgzlyhd.js +++ b/lib/v2/gov/samr/xgzlyhd.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 rootUrl = 'https://xgzlyhd.samr.gov.cn'; @@ -36,7 +36,7 @@ const getOption = async (type, name) => { module.exports = async (ctx) => { const { category, department } = 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; let categoryOption; let departmentOption; @@ -77,14 +77,14 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = '国家市场监督管理总局'; const title = $('title').text(); const subtitle = [categoryOption ? categoryOption.name : undefined, departmentOption ? departmentOption.name : undefined].filter(Boolean).join(' - '); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${title}${subtitle ? ` - ${subtitle}` : ''}`, link: currentUrl, @@ -96,5 +96,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/gov/sasac/generic.js b/lib/v2/gov/sasac/generic.js index dbc3ab83f..501f3fe8c 100644 --- a/lib/v2/gov/sasac/generic.js +++ b/lib/v2/gov/sasac/generic.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 { path } = ctx.params; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${baseUrl}/${path}/index.html`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.zsy_conlist li') .toArray() .filter((item) => !$(item).attr('style')) @@ -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); $('style, #qr_container, #div_div, [class^=jiathis]').remove(); item.description = $('.zsy_comain').html(); return item; @@ -33,10 +33,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim(), link: url, image: 'http://www.sasac.gov.cn/dbsource/11869722/11869731.jpg', item: items, - }; + }); }; diff --git a/lib/v2/gov/shaanxi/kjt.js b/lib/v2/gov/shaanxi/kjt.js index 9a057364c..6134fcc54 100644 --- a/lib/v2/gov/shaanxi/kjt.js +++ b/lib/v2/gov/shaanxi/kjt.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 ?? '221'; + const id = ctx.req.param('id') ?? '221'; const rootUrl = 'https://kjt.shaanxi.gov.cn'; const currentUrl = `${rootUrl}/view/iList.jsp?cat_id=${id}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.textlist li a') .toArray() @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.info_content').html(); item.author = content('meta[name="Author"]').attr('content'); @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `陕西省科学技术厅 - ${$('.catnm').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/shanghai/rsj/ksxm.js b/lib/v2/gov/shanghai/rsj/ksxm.js index 726467592..86b105dfe 100644 --- a/lib/v2/gov/shanghai/rsj/ksxm.js +++ b/lib/v2/gov/shanghai/rsj/ksxm.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 { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const rootUrl = 'http://www.rsj.sh.gov.cn'; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); const dataHtml = iconv.decode(response.data, 'gbk'); - const $ = cheerio.load(dataHtml); + const $ = load(dataHtml); const items = $('kwap') .map((_, item) => ({ @@ -31,9 +31,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: '上海市职业能力考试院 - 考试项目', link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/shanghai/wgj/wgj.js b/lib/v2/gov/shanghai/wgj/wgj.js index a5072d3f6..6e86ad7d1 100644 --- a/lib/v2/gov/shanghai/wgj/wgj.js +++ b/lib/v2/gov/shanghai/wgj/wgj.js @@ -1,13 +1,13 @@ -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 baseUrl = 'http://wsbs.wgj.sh.gov.cn'; const currentUrl = `${baseUrl}/shwgj_ywtb/core/web/welcome/index!toResultNotice.action`; - const page = ctx.params.page ?? 1; + const page = ctx.req.param('page') ?? 1; const searchParams = { flag: 1, 'pageDoc.pageNo': page, @@ -18,7 +18,7 @@ module.exports = async (ctx) => { searchParams, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#div_md > table > tbody > tr > td:nth-child(1) > a') .map((_, item) => { item = $(item); @@ -35,7 +35,7 @@ module.exports = async (ctx) => { method: 'get', url: baseUrl + item.link, }); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const dateElement = $('div[align="right"][style*="padding: 10px"]').last(); const dateText = dateElement.text().trim(); const hostingUnit = $('td:contains("举办单位:")').next().text().trim(); @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/shanghai/wsjkw/yqtb/index.js b/lib/v2/gov/shanghai/wsjkw/yqtb/index.js index 82f84404e..0027fc8cf 100644 --- a/lib/v2/gov/shanghai/wsjkw/yqtb/index.js +++ b/lib/v2/gov/shanghai/wsjkw/yqtb/index.js @@ -1,14 +1,14 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const url = `https://wsjkw.sh.gov.cn/yqtb/index.html`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.uli16.nowrapli.list-date li'); - ctx.state.data = { + ctx.set('data', { title: '疫情通报-上海卫健委', link: url, item: @@ -29,5 +29,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/gov/shanghai/yjj/index.js b/lib/v2/gov/shanghai/yjj/index.js index 409453841..bf9c86270 100644 --- a/lib/v2/gov/shanghai/yjj/index.js +++ b/lib/v2/gov/shanghai/yjj/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'; module.exports = async (ctx) => { const params = ctx.path === '/shanghai/yjj' ? '/shanghai/yjj/zx-ylqx' : ctx.path; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.pageList li a') .toArray() @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const pubDate = content('meta[name="pubdate"]').attr('content') || content('meta[name="PubDate"]').attr('content'); @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text().replace(/--/, ' - '), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/shenzhen/hrss/szksy/index.js b/lib/v2/gov/shenzhen/hrss/szksy/index.js index 5ed07df79..f07f5c7a7 100644 --- a/lib/v2/gov/shenzhen/hrss/szksy/index.js +++ b/lib/v2/gov/shenzhen/hrss/szksy/index.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'; const rootURL = 'http://hrss.sz.gov.cn/'; module.exports = async (ctx) => { - const categoryID = ctx.params.caty; - const page = ctx.params.page ?? '1'; + const categoryID = ctx.req.param('caty'); + const page = ctx.req.param('page') ?? '1'; const pageParam = Number.parseInt(page) > 1 ? `_${page}` : ''; const pagePath = `/szksy/zwgk/${categoryID}/index${pageParam}.html`; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { throw new Error(response.statusMessage); } - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('.zx_rm_tit span').text().trim(); const list = $('.zx_ml_list ul li') .slice(1) @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '深圳市考试院 - ' + title, link: currentURL.href, item: list, - }; + }); }; diff --git a/lib/v2/gov/shenzhen/xxgk/zfxxgj.js b/lib/v2/gov/shenzhen/xxgk/zfxxgj.js index 46fa4eb66..d16d56aea 100644 --- a/lib/v2/gov/shenzhen/xxgk/zfxxgj.js +++ b/lib/v2/gov/shenzhen/xxgk/zfxxgj.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 = 'http://www.sz.gov.cn/cn/xxgk/zfxxgj/'; const config = { @@ -24,14 +24,14 @@ const config = { }; module.exports = async (ctx) => { - const cfg = config[ctx.params.caty]; + const cfg = config[ctx.req.param('caty')]; if (!cfg) { throw new Error('Bad category. See docs'); } const currentUrl = new URL(cfg.link, rootUrl).href; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.zx_ml_list ul li span.tit') .toArray() .map((item) => { @@ -46,7 +46,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.news_cont_d_wrap').html(); if (content('div.fjdown').html() !== null) { item.description += content('div.fjdown').html(); @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '广东省深圳市人民政府 - ' + cfg.title, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/shenzhen/zjj/index.js b/lib/v2/gov/shenzhen/zjj/index.js index ba1414c44..34201b251 100644 --- a/lib/v2/gov/shenzhen/zjj/index.js +++ b/lib/v2/gov/shenzhen/zjj/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 config = { tzgg: { @@ -12,7 +12,7 @@ const config = { module.exports = async (ctx) => { const baseUrl = 'http://zjj.sz.gov.cn/xxgk/'; - const cfg = config[ctx.params.caty]; + const cfg = config[ctx.req.param('caty')]; if (!cfg) { throw new Error('Bad category. See docs'); } @@ -20,7 +20,7 @@ module.exports = async (ctx) => { const currentUrl = new URL(cfg.link, baseUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const items = $('div.listcontent_right ul li') // 使用“toArray()”方法将选择的所有 DOM 元素以数组的形式返回。 @@ -37,9 +37,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: '深圳市住房和建设局 - ' + cfg.title, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/shenzhen/zzb/index.js b/lib/v2/gov/shenzhen/zzb/index.js index 888fe3d7e..16f123dc8 100644 --- a/lib/v2/gov/shenzhen/zzb/index.js +++ b/lib/v2/gov/shenzhen/zzb/index.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'; const rootURL = 'http://www.zzb.sz.gov.cn/'; module.exports = async (ctx) => { - const categoryID = ctx.params.caty; - const page = ctx.params.page ?? '1'; + const categoryID = ctx.req.param('caty'); + const page = ctx.req.param('page') ?? '1'; const pageParam = Number.parseInt(page) > 1 ? `_${page}` : ''; const pagePath = `/${categoryID}/index${pageParam}.html`; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { throw new Error(response.statusMessage); } - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('#Title').text().trim(); const list = $('#List tbody tr td table tbody tr td[width="96%"]') .map((_, item) => { @@ -32,9 +32,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '深圳组工在线 - ' + title, link: currentURL.href, item: list, - }; + }); }; diff --git a/lib/v2/gov/sichuan/deyang/govpublicinfo.js b/lib/v2/gov/sichuan/deyang/govpublicinfo.js index b5a23ea18..f292c40f2 100644 --- a/lib/v2/gov/sichuan/deyang/govpublicinfo.js +++ b/lib/v2/gov/sichuan/deyang/govpublicinfo.js @@ -1,9 +1,9 @@ -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 timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; // 各地区url信息 const basicInfoDict = { @@ -24,7 +24,7 @@ const basicInfoDict = { const getInfoUrlList = async (rootUrl, infoBasicUrl) => { const response = await got(infoBasicUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 非当前日期文章计数,部分旧文章可能会置顶,目前为发现置顶数超过10 const infoList = $('body > div.container > div.ewb-white > div.ewb-job > ul > li') .toArray() @@ -41,7 +41,7 @@ const getInfoContent = (ctx, rootUrl, item) => const response = await got(item.url); // 部分网页会跳转其他类型网站,则不解析,直接附超链接 try { - const $ = cheerio.load(response.data); + const $ = load(response.data); const fileList = $('#symbol > div:nth-child(4) > div > span > a') .toArray() .map((item) => ({ @@ -72,14 +72,14 @@ const getInfoContent = (ctx, rootUrl, item) => }); module.exports = async (ctx) => { - const countyName = ctx.params.countyName; - const infoType = ctx.params.infoType || 'fdzdnr'; + const countyName = ctx.req.param('countyName'); + const infoType = ctx.req.param('infoType') || 'fdzdnr'; const infoBasicUrl = basicInfoDict[countyName].infoType[infoType].basicUrl; const rootUrl = basicInfoDict[countyName].rootUrl; const infoUrlList = await getInfoUrlList(rootUrl, infoBasicUrl); const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, rootUrl, item))); - ctx.state.data = { + ctx.set('data', { title: `政府公开信息-${countyName}-${basicInfoDict[countyName].infoType[infoType].name}`, link: infoBasicUrl, item: items.map((item) => ({ @@ -88,5 +88,5 @@ module.exports = async (ctx) => { link: item.link, pubDate: item.pubDate, })), - }; + }); }; diff --git a/lib/v2/gov/sichuan/deyang/mztoday.js b/lib/v2/gov/sichuan/deyang/mztoday.js index d6edbdde7..8c258cbda 100644 --- a/lib/v2/gov/sichuan/deyang/mztoday.js +++ b/lib/v2/gov/sichuan/deyang/mztoday.js @@ -1,9 +1,9 @@ -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 timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; const rootUrl = 'http://www.mztoday.gov.cn'; const basicInfoDict = { @@ -91,7 +91,7 @@ const basicInfoDict = { const getInfoUrlList = async (url) => { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const infoList = $('div.sl') .toArray() .map((item) => ({ @@ -106,7 +106,7 @@ const getInfoUrlList = async (url) => { const getInfoContent = (ctx, item) => ctx.cache.tryGet(item.url, async () => { const response = await got(item.url); - const $ = cheerio.load(response.data); + const $ = load(response.data); return { title: item.title, content: $('td:nth-child(2)').html(), @@ -116,12 +116,12 @@ const getInfoContent = (ctx, item) => }); module.exports = async (ctx) => { - const infoType = ctx.params.infoType || 'zx'; + const infoType = ctx.req.param('infoType') || 'zx'; const infoBasicUrl = `${rootUrl}${basicInfoDict[infoType].url}`; const infoUrlList = await getInfoUrlList(infoBasicUrl); const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, item))); - ctx.state.data = { + ctx.set('data', { title: `今日绵竹-${basicInfoDict[infoType].name}`, link: `${infoBasicUrl}1`, item: items.map((item) => ({ @@ -130,5 +130,5 @@ module.exports = async (ctx) => { link: item.link, pubDate: item.pubDate, })), - }; + }); }; diff --git a/lib/v2/gov/stats/index.js b/lib/v2/gov/stats/index.js index 647025394..1f8e9a611 100644 --- a/lib/v2/gov/stats/index.js +++ b/lib/v2/gov/stats/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 limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 15; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15; const defaultPath = '/sj/zxfb/'; @@ -28,7 +28,7 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $($('a.pchide').length === 0 ? 'a[title]' : '.list-content a.pchide') .slice(0, limit) @@ -51,7 +51,7 @@ module.exports = async (ctx) => { headers, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); // articles from www.news.cn or www.gov.cn @@ -104,9 +104,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/suzhou/doc.js b/lib/v2/gov/suzhou/doc.js index fddf23269..0ad94e492 100644 --- a/lib/v2/gov/suzhou/doc.js +++ b/lib/v2/gov/suzhou/doc.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://www.suzhou.gov.cn/szxxgk/front/xxgk_right.jsp'; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.tr_main_value_odd') .toArray() .map((item) => { @@ -24,7 +24,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('.article-content').html(); item.author = $('dd.addWidth:nth-child(3) div').text().trim(); @@ -38,9 +38,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '苏州市政府 - 政策公开文件', link, item: items, - }; + }); }; diff --git a/lib/v2/gov/suzhou/fg.js b/lib/v2/gov/suzhou/fg.js index a0120b0c8..4029c0c63 100644 --- a/lib/v2/gov/suzhou/fg.js +++ b/lib/v2/gov/suzhou/fg.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 = 'szfgw/ggl/nav_list' } = 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://fg.suzhou.gov.cn'; const currentUrl = new URL(`${category}.shtml`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('h4 a[title]') .slice(0, limit) @@ -33,7 +33,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('ucaptitle').text().trim(); item.description = content('ucapcontent').html(); @@ -49,7 +49,7 @@ module.exports = async (ctx) => { const subtitle = $('meta[name="ColumnName"]').prop('content'); const image = new URL($('div.logo img').prop('src'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -58,5 +58,5 @@ module.exports = async (ctx) => { image, subtitle, author, - }; + }); }; diff --git a/lib/v2/gov/suzhou/news.js b/lib/v2/gov/suzhou/news.js index d75d39322..df51e92df 100644 --- a/lib/v2/gov/suzhou/news.js +++ b/lib/v2/gov/suzhou/news.js @@ -1,11 +1,11 @@ -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.suzhou.gov.cn'; - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); let url = ''; let title = ''; let apiUrl = ''; @@ -84,7 +84,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); item.description = $('ucapcontent').html(); return item; @@ -94,7 +94,7 @@ module.exports = async (ctx) => { } else { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); items = $('ul.infolist li') .toArray() .map((item) => { @@ -108,9 +108,9 @@ module.exports = async (ctx) => { }); } - ctx.state.data = { + ctx.set('data', { title, link: url, item: items, - }; + }); }; diff --git a/lib/v2/gov/taiyuan/rsj.js b/lib/v2/gov/taiyuan/rsj.js index 9c6636bfb..a04f7243f 100644 --- a/lib/v2/gov/taiyuan/rsj.js +++ b/lib/v2/gov/taiyuan/rsj.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'; const rootURL = 'http://rsj.taiyuan.gov.cn/'; module.exports = async (ctx) => { - const categoryID = ctx.params.caty; - const page = ctx.params.page ?? '1'; + const categoryID = ctx.req.param('caty'); + const page = ctx.req.param('page') ?? '1'; const pageParam = Number.parseInt(page) > 1 ? `_${page}` : ''; const pagePath = `/zfxxgk/${categoryID}/index${pageParam}.shtml`; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { throw new Error(response.statusMessage); } - const $ = cheerio.load(response.data, { decodeEntities: false }); + const $ = load(response.data, { decodeEntities: false }); const title = $('.tit').find('a:eq(2)').text(); const list = $('.RightSide_con ul li') .map((_, item) => { @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '太原市人力资源和社会保障局 - ' + title, link: currentURL.href, item: list, - }; + }); }; diff --git a/lib/v2/gov/wuhan/whyw.js b/lib/v2/gov/wuhan/whyw.js index 7789bc168..37bba319b 100644 --- a/lib/v2/gov/wuhan/whyw.js +++ b/lib/v2/gov/wuhan/whyw.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 rootUrl = 'http://www.wuhan.gov.cn'; const currentUrl = `${rootUrl}/sy/whyw/`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.articleList li') .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('.view').html(); item.author = content('meta[name=ContentSource]').attr('content'); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('h2').text()} - 武汉市人民政府`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/xuzhou/hrss.js b/lib/v2/gov/xuzhou/hrss.js index 85ca6c845..5f4da4640 100644 --- a/lib/v2/gov/xuzhou/hrss.js +++ b/lib/v2/gov/xuzhou/hrss.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 rootUrl = 'http://hrss.xz.gov.cn'; const currentUrl = `${rootUrl}${category ? `/001/${category}/subPage.html` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = (category ? $('.module-items a') : $('.bdl[data-target="1"]').eq(1).find('a')).toArray().map((item) => { item = $(item); @@ -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, .mian-cont, .ewb-article-info, #UCAP-CONTENT').html(); item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `徐州市人力资源和社会保障局 - ${category ? $('.wb-tree-items.current').text() : '通知公告'}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/gov/zhejiang/gwy.js b/lib/v2/gov/zhejiang/gwy.js index 4f7b9e1b8..604dfee5e 100644 --- a/lib/v2/gov/zhejiang/gwy.js +++ b/lib/v2/gov/zhejiang/gwy.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, column } = 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 = 'http://gwy.zjks.gov.cn'; const currentUrl = new URL(`zjgwy/website/${category ? 'queryMore' : 'init'}.htm`, rootUrl).href; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a[onclick^="queryDetail"]') .slice(0, limit) @@ -50,7 +50,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description = content('div.ibox-content').last().html(); item.category = [content('div.ibox-title').last().find('h5').first().text()]; @@ -72,7 +72,7 @@ module.exports = async (ctx) => { const columnName = $('button.btn-success').last().text(); const categoryName = $('table').parent().prev().find('h5').text(); - ctx.state.data = { + ctx.set('data', { item: items, title: `${$('title').text()} - ${columnName}${categoryName}`, link: currentUrl, @@ -80,5 +80,5 @@ module.exports = async (ctx) => { subtitle: `${columnName}${categoryName}`, author: $('div.title-font').text(), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/gov/zhengce/govall.js b/lib/v2/gov/zhengce/govall.js index 82436dd45..dc618e2e4 100644 --- a/lib/v2/gov/zhengce/govall.js +++ b/lib/v2/gov/zhengce/govall.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 { advance } = ctx.params; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const res = await got.get(link, { searchParams: query.replaceAll(/([\u4E00-\u9FA5])/g, (str) => encodeURIComponent(str)), }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('body > div.dataBox > table > tbody > tr') .slice(1) @@ -36,7 +36,7 @@ module.exports = async (ctx) => { let description = ''; try { const contentData = await got(item.link); - const $ = cheerio.load(contentData.data); + const $ = load(contentData.data); description = $('#UCAP-CONTENT').html(); } catch { description = '文章已被删除'; @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '信息稿件 - 中国政府网', link: `${link}?${query}`, item: items, - }; + }); }; diff --git a/lib/v2/gov/zhengce/index.js b/lib/v2/gov/zhengce/index.js index 3ded1c7e5..898e43c4b 100644 --- a/lib/v2/gov/zhengce/index.js +++ b/lib/v2/gov/zhengce/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category = 'zuixin' } = ctx.params; - 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 rootUrl = 'https://www.gov.cn'; const currentUrl = new URL(`zhengce/${category.replace(/\/$/, '')}/`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('h4 a, div.subtitle a[title]') .toArray() @@ -35,7 +35,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 processElementText = (el) => content(el).text().split(/:/).pop().trim() || content(el).next().text().trim(); @@ -84,7 +84,7 @@ module.exports = async (ctx) => { const subtitle = $('meta[name="lanmu"]').prop('content'); const author = $('div.header_logo a[aria-label]').prop('aria-label'); - ctx.state.data = { + ctx.set('data', { item: items, title: author && subtitle ? `${author} - ${subtitle}` : $('title').text(), link: currentUrl, @@ -95,5 +95,5 @@ module.exports = async (ctx) => { logo: icon, subtitle, author, - }; + }); }; diff --git a/lib/v2/gov/zhengce/wenjian.js b/lib/v2/gov/zhengce/wenjian.js index 3e90b60fe..a85240287 100644 --- a/lib/v2/gov/zhengce/wenjian.js +++ b/lib/v2/gov/zhengce/wenjian.js @@ -1,20 +1,20 @@ -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 { pcodeJiguan } = ctx.params; const link = 'http://sousuo.gov.cn/list.htm'; const res = await got(link, { searchParams: { - n: ctx.query.limit ? Number(ctx.query.limit) : 20, + n: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20, sort: 'pubtime', t: 'paper', pcodeJiguan: pcodeJiguan ?? '', }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('body > div.dataBox > table > tbody > tr') .slice(1) @@ -32,16 +32,16 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const contentData = await got(item.link); - const $ = cheerio.load(contentData.data); + const $ = load(contentData.data); item.description = $('#UCAP-CONTENT').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: '最新文件 - 中国政府网', link: res.url, item: items, - }; + }); }; diff --git a/lib/v2/gov/zhengce/zhengceku.js b/lib/v2/gov/zhengce/zhengceku.js index f74c6c033..98335b88a 100644 --- a/lib/v2/gov/zhengce/zhengceku.js +++ b/lib/v2/gov/zhengce/zhengceku.js @@ -1,7 +1,7 @@ const buildData = require('@/utils/common-config'); module.exports = async (ctx) => { - const department = ctx.params.department; + const department = ctx.req.param('department'); const link = `http://www.gov.cn/zhengce/zhengceku/${department}/`; ctx.state.data = await buildData({ diff --git a/lib/v2/greasyfork/feedback.js b/lib/v2/greasyfork/feedback.js index ab8aaf134..0bf7dc6f0 100644 --- a/lib/v2/greasyfork/feedback.js +++ b/lib/v2/greasyfork/feedback.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 script = ctx.params.script; + const script = ctx.req.param('script'); const rootUrl = 'https://greasyfork.org'; const currentUrl = `${rootUrl}/scripts/${script}/feedback`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, description: $('meta[name=description]').attr('content'), @@ -27,5 +27,5 @@ module.exports = async (ctx) => { link: rootUrl + discussionTitle.attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/greasyfork/scripts.js b/lib/v2/greasyfork/scripts.js index cf5b27a3b..0b3eec772 100644 --- a/lib/v2/greasyfork/scripts.js +++ b/lib/v2/greasyfork/scripts.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 language = ctx.params.language === 'all' ? 'zh-CN' : ctx.params.language || 'zh-CN'; - const domain = ctx.params.domain; - const filter_locale = ctx.params.language === 'all' ? 0 : 1; - const sort = ctx.params.sort ?? 'updated'; + const language = ctx.req.param('language') === 'all' ? 'zh-CN' : ctx.req.param('language') || 'zh-CN'; + const domain = ctx.req.param('domain'); + const filter_locale = ctx.req.param('language') === 'all' ? 0 : 1; + const sort = ctx.req.param('sort') ?? 'updated'; const url = domain ? `/by-site/${domain}` : ''; const currentUrl = `https://greasyfork.org/${language}/scripts${url}`; const res = await got({ @@ -17,10 +17,10 @@ module.exports = async (ctx) => { sort, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.script-list').find('article'); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), link: currentUrl, description: $('meta[name=description]').attr('content'), @@ -40,5 +40,5 @@ module.exports = async (ctx) => { .join(', '), }; }), - }; + }); }; diff --git a/lib/v2/greasyfork/versions.js b/lib/v2/greasyfork/versions.js index 74e0bb320..5de40421f 100644 --- a/lib/v2/greasyfork/versions.js +++ b/lib/v2/greasyfork/versions.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 script = ctx.params.script; + const script = ctx.req.param('script'); const currentUrl = `https://greasyfork.org/scripts/${script}/versions`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, description: $('meta[name=description]').attr('content'), @@ -25,5 +25,5 @@ module.exports = async (ctx) => { link: versionNumberLink.attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/grist/featured.js b/lib/v2/grist/featured.js index 9f6afc73e..6a01a5265 100644 --- a/lib/v2/grist/featured.js +++ b/lib/v2/grist/featured.js @@ -1,11 +1,11 @@ const { getData, getList } = require('./utils'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const baseUrl = 'https://grist.org/'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const listItems = $('li.hp-featured__tease') .toArray() @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const itemData = await Promise.all(listItems.map((item) => ctx.cache.tryGet(item.link, async () => (await getData(`https://grist.org/wp-json/wp/v2/posts?slug='${item.link}'&_embed`))[0]))); const items = await getList(itemData); - ctx.state.data = { + ctx.set('data', { title: 'Gist Featured Articles', link: baseUrl, item: items, @@ -27,5 +27,5 @@ module.exports = async (ctx) => { logo: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=192', icon: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=32', language: 'en-us', - }; + }); }; diff --git a/lib/v2/grist/index.js b/lib/v2/grist/index.js index e79e9496d..cb8d43cff 100644 --- a/lib/v2/grist/index.js +++ b/lib/v2/grist/index.js @@ -7,7 +7,7 @@ module.exports = async (ctx) => { const data = await getData(`${baseUrl}${route}`); const items = await getList(data); - ctx.state.data = { + ctx.set('data', { title: 'Gist Latest Articles', link: `${baseUrl}/articles`, item: items, @@ -15,5 +15,5 @@ module.exports = async (ctx) => { logo: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=192', icon: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=32', language: 'en-us', - }; + }); }; diff --git a/lib/v2/grist/series.js b/lib/v2/grist/series.js index 12ed38776..cfd8510fe 100644 --- a/lib/v2/grist/series.js +++ b/lib/v2/grist/series.js @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const data = await getData(`${baseUrl}${articleRoute}${id}&_embed`); const items = await getList(data); - ctx.state.data = { + ctx.set('data', { title: `${series[0].toUpperCase() + series.slice(1)} - Gist Articles`, link: `${baseUrl}/${series}`, item: items, @@ -17,5 +17,5 @@ module.exports = async (ctx) => { logo: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=192', icon: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=32', language: 'en-us', - }; + }); }; diff --git a/lib/v2/grist/topic.js b/lib/v2/grist/topic.js index 630db4103..38e1de30e 100644 --- a/lib/v2/grist/topic.js +++ b/lib/v2/grist/topic.js @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const data = await getData(`${baseUrl}${articleRoute}${id}&_embed`); const items = await getList(data); - ctx.state.data = { + ctx.set('data', { title: `${topic[0].toUpperCase() + topic.slice(1)} - Gist Articles`, link: `${baseUrl}/${topic}`, item: items, @@ -17,5 +17,5 @@ module.exports = async (ctx) => { logo: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=192', icon: 'https://grist.org/wp-content/uploads/2021/03/cropped-Grist-Favicon.png?w=32', language: 'en-us', - }; + }); }; diff --git a/lib/v2/grist/utils.js b/lib/v2/grist/utils.js index 20569af43..da52e48cf 100644 --- a/lib/v2/grist/utils.js +++ b/lib/v2/grist/utils.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 getData = (url) => got.get(url).json(); diff --git a/lib/v2/grubstreet/utils.js b/lib/v2/grubstreet/utils.js index 2c1444422..23b635e50 100644 --- a/lib/v2/grubstreet/utils.js +++ b/lib/v2/grubstreet/utils.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; -async function load(link) { +async function loadContent(link) { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('div.article-content'); @@ -53,7 +53,7 @@ function ProcessFeed(list, caches) { single.author = bylineString; } - const { description } = await load(itemUrl); + const { description } = await loadContent(itemUrl); single.description = description; return single; @@ -68,7 +68,7 @@ const getData = async (ctx, url, title, description) => { const data = response.data; // limit the list to only 25 articles, to make sure that load times remain reasonable - const list = data.articles.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 25); + const list = data.articles.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 25); const result = await ProcessFeed(list, ctx.cache); return { diff --git a/lib/v2/guancha/headline.js b/lib/v2/guancha/headline.js index 002f7f313..6347a4db2 100644 --- a/lib/v2/guancha/headline.js +++ b/lib/v2/guancha/headline.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 rootUrl = 'https://www.guancha.cn'; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.headline-list li .content-headline h3 a') .toArray() @@ -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('.all-txt').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '观察者网 - 头条', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/guancha/index.js b/lib/v2/guancha/index.js index 972147ed7..a03390799 100644 --- a/lib/v2/guancha/index.js +++ b/lib/v2/guancha/index.js @@ -1,8 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { parseRelativeDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate, parseRelativeDate } from '@/utils/parse-date'; const config = { review: { @@ -36,7 +35,7 @@ const config = { module.exports = async (ctx) => { const total = 10; - const category = ctx.params.category ?? 'all'; + const category = ctx.req.param('category') ?? 'all'; const rootUrl = 'https://www.guancha.cn'; let newsList = [], @@ -51,7 +50,7 @@ module.exports = async (ctx) => { url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const fetchPost = (slice) => slice @@ -130,7 +129,7 @@ module.exports = async (ctx) => { }); } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const dateMatch = detailResponse.data.match(/"pubDate": "(.*)"/); item.pubDate = @@ -145,9 +144,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `观察者网 - ${config[category].title}`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/guancha/member.js b/lib/v2/guancha/member.js index 8dea919d8..73058ced0 100644 --- a/lib/v2/guancha/member.js +++ b/lib/v2/guancha/member.js @@ -1,6 +1,6 @@ -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 titles = { recommend: '精选', @@ -10,7 +10,7 @@ const titles = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'recommend'; + const category = ctx.req.param('category') ?? 'recommend'; const rootUrl = 'https://member.guancha.cn'; const apiUrl = `${rootUrl}/zaixianke/home`; @@ -78,9 +78,9 @@ module.exports = async (ctx) => { }); } - ctx.state.data = { + ctx.set('data', { title: `观学院 - ${titles[category]}`, link: `${rootUrl}/index.html`, item: items, - }; + }); }; diff --git a/lib/v2/guancha/personalpage.js b/lib/v2/guancha/personalpage.js index bf16be16a..e9fa34af6 100644 --- a/lib/v2/guancha/personalpage.js +++ b/lib/v2/guancha/personalpage.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const host = 'https://user.guancha.cn'; const link = `https://app.guancha.cn/user/get-published-list?page_size=20&page_no=1&uid=${uid}`; const response = await got({ @@ -57,7 +57,7 @@ module.exports = async (ctx) => { } return time; } - ctx.state.data = { + ctx.set('data', { title: `${user_nick}-观察者-风闻社区`, link, description: `${user_nick} 的个人主页`, @@ -68,5 +68,5 @@ module.exports = async (ctx) => { link: `https://user.guancha.cn/main/content?id=${item.id}`, author: item.user_nick, })), - }; + }); }; diff --git a/lib/v2/guancha/topic.js b/lib/v2/guancha/topic.js index c1abe7c37..c3c7167cc 100644 --- a/lib/v2/guancha/topic.js +++ b/lib/v2/guancha/topic.js @@ -1,10 +1,10 @@ -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 id = ctx.params.id ?? '0'; - const order = ctx.params.order ?? '1'; + const id = ctx.req.param('id') ?? '0'; + const order = ctx.req.param('order') ?? '1'; const rootUrl = 'https://user.guancha.cn'; const currentUrl = `${rootUrl}/${id === '0' ? 'main/index-list.json?' : 'topic/post-list?topic_id=' + id}&page=1&order=${order}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list-item h4 a, ul.home li .list-item h4 a') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = parseRelativeDate(content('.time1').text()); item.author = content('.user-main h4 a').first().text(); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { $('h1.title span').remove(); - ctx.state.data = { + ctx.set('data', { title: `观察者网 - ${id === '0' ? '风闻' : $('h1.title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/guangdiu/cheaps.js b/lib/v2/guangdiu/cheaps.js index cea2fa26f..d5abc171c 100644 --- a/lib/v2/guangdiu/cheaps.js +++ b/lib/v2/guangdiu/cheaps.js @@ -1,15 +1,15 @@ -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'; const host = 'https://guangdiu.com'; module.exports = async (ctx) => { - const query = ctx.params.query ?? ''; + const query = ctx.req.param('query') ?? ''; const url = `${host}/cheaps.php${query ? `?${query}` : ''}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.cheapitem.rightborder') .map((_index, item) => ({ @@ -20,9 +20,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: `逛丢 - 九块九`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/guangdiu/index.js b/lib/v2/guangdiu/index.js index 830c2dc88..81d5b0665 100644 --- a/lib/v2/guangdiu/index.js +++ b/lib/v2/guangdiu/index.js @@ -1,15 +1,15 @@ -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'; const host = 'https://guangdiu.com'; module.exports = async (ctx) => { - const query = ctx.params.query ?? ''; + const query = ctx.req.param('query') ?? ''; const url = query === 'c=us' ? `${host}/?c=us` : `${host}/${query ? `cate.php?${query}` : ''}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#mainleft > div.zkcontent > div.gooditem') .map((_index, item) => ({ title: $(item).find('a.goodname').text().trim(), @@ -21,7 +21,7 @@ module.exports = async (ctx) => { list.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 = $('#dabstract').html() + $('a.dgotobutton').html('前往购买'); item.pubDate = parseRelativeDate($('span.latesttime').text()); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `逛丢 - ${query.includes('c=us') ? '海外' : '国内'}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/guangdiu/rank.js b/lib/v2/guangdiu/rank.js index e02fde3dd..9bcd66dc0 100644 --- a/lib/v2/guangdiu/rank.js +++ b/lib/v2/guangdiu/rank.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'; const host = 'https://guangdiu.com'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${host}/rank.php`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.hourrankitem') .map((_index, item) => ({ title: $(item).find('a.hourranktitle').text(), @@ -20,7 +20,7 @@ module.exports = async (ctx) => { list.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 = $('#dabstract').html() + $('a.dgotobutton').html('前往购买'); item.pubDate = parseRelativeDate($('div.hourranktime').text()); @@ -30,9 +30,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `逛丢 - 一小时风云榜`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/guangdiu/search.js b/lib/v2/guangdiu/search.js index 6313b62c9..8b30e9674 100644 --- a/lib/v2/guangdiu/search.js +++ b/lib/v2/guangdiu/search.js @@ -1,14 +1,14 @@ -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'; const host = 'https://guangdiu.com'; module.exports = async (ctx) => { - const query = ctx.params.query ?? ''; + const query = ctx.req.param('query') ?? ''; const url = `${host}/${query ? `search.php?${query}` : ''}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#mainleft > div.zkcontent > div.gooditem') .map((_index, item) => ({ title: $(item).find('a.goodname').text().trim(), @@ -20,7 +20,7 @@ module.exports = async (ctx) => { list.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 = $('#dabstract').html() + $('a.dgotobutton').html('前往购买'); item.pubDate = parseRelativeDate($('span.latesttime').text()); @@ -32,9 +32,9 @@ module.exports = async (ctx) => { const match = /q=(.+)/.exec(query); - ctx.state.data = { + ctx.set('data', { title: `逛丢 - ${match[1]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/guangzhoumetro/news.js b/lib/v2/guangzhoumetro/news.js index 2c71825aa..17d24164d 100644 --- a/lib/v2/guangzhoumetro/news.js +++ b/lib/v2/guangzhoumetro/news.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 newsUrl = 'https://www.gzmtr.com/ygwm/xwzx/gsxw/'; const response = await got(newsUrl); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('ul.ag_h_w li') .map((_, item) => { item = $(item); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '广州地铁新闻', url: newsUrl, description: '广州地铁新闻', @@ -33,5 +33,5 @@ module.exports = async (ctx) => { link: item.link, author: item.author, })), - }; + }); }; diff --git a/lib/v2/guanhai/index.js b/lib/v2/guanhai/index.js index 44e95278e..e0a1ef187 100644 --- a/lib/v2/guanhai/index.js +++ b/lib/v2/guanhai/index.js @@ -1,11 +1,11 @@ -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 { data: response } = await got('https://www.guanhai.com.cn'); - const $ = cheerio.load(response); + const $ = load(response); const recommand = $('.img-box ul > a') .toArray() @@ -35,7 +35,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.author = $('.source').text(); item.description = $('.article-content').html() ?? $('.video-content').html(); item.pubDate = item.pubDate ?? timezone(parseDate($('.date').text(), 'YYYY-MM-DD HH:mm'), 8); @@ -44,11 +44,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name=description]').text(), image: 'https://www.guanhai.com.cn/favicon.ico', link: 'https://www.guanhai.com.cn', item: items, - }; + }); }; diff --git a/lib/v2/guduodata/daily.js b/lib/v2/guduodata/daily.js index de5c5a45a..7bddc1e00 100644 --- a/lib/v2/guduodata/daily.js +++ b/lib/v2/guduodata/daily.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const dayjs = require('dayjs'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const host = 'http://data.guduodata.com'; @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: `${host}/show/datalist?type=DAILY&category=${category.toUpperCase()}&date=${yestoday}`, })) ); - ctx.state.data = { + ctx.set('data', { title: `骨朵数据 - 日榜`, link: host, description: yestoday, @@ -59,5 +59,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/gumroad/index.js b/lib/v2/gumroad/index.js index 5dc87adbd..36e2130d6 100644 --- a/lib/v2/gumroad/index.js +++ b/lib/v2/gumroad/index.js @@ -1,19 +1,19 @@ -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 { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const username = ctx.params.username; - const products = ctx.params.products; + const username = ctx.req.param('username'); + const products = ctx.req.param('products'); if (!isValidHost(username)) { throw new Error('Invalid username'); } const url = `https://${username}.gumroad.com/l/${products}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('section.product-content.product-content__row > header > h1').text(); const userFullName = $('section.product-content.product-content__row > section.details > a').text(); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { link: url, title: `Gumroad - ${userFullName}/${title}`, item, - }; + }); }; diff --git a/lib/v2/guokr/channel.js b/lib/v2/guokr/channel.js index 67409142c..7e9b130dd 100644 --- a/lib/v2/guokr/channel.js +++ b/lib/v2/guokr/channel.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; async function loadFullPage(ctx, id) { const link = `https://apis.guokr.com/minisite/article/${id}.json`; @@ -17,7 +17,7 @@ const channelMap = { }; module.exports = async (ctx) => { - const channel = channelMap[ctx.params.channel] ?? ctx.params.channel; + const channel = channelMap[ctx.req.param('channel')] ?? ctx.req.param('channel'); const response = await got(`https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_wx&channel_key=${channel}&offset=0&limit=10`); const items = response.data.result; @@ -39,9 +39,9 @@ module.exports = async (ctx) => { })) ); - ctx.state.data = { + ctx.set('data', { title: `果壳网 ${channel_name}`, link: channel_url, item: result, - }; + }); }; diff --git a/lib/v2/guokr/scientific.js b/lib/v2/guokr/scientific.js index 92ee525e0..2dbc39cd8 100644 --- a/lib/v2/guokr/scientific.js +++ b/lib/v2/guokr/scientific.js @@ -1,12 +1,12 @@ -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://www.guokr.com/apis/minisite/article.json?retrieve_type=by_subject&limit=20&offset=0'); const result = response.data.result; - ctx.state.data = { + ctx.set('data', { title: '果壳网 科学人', link: 'https://www.guokr.com/scientific', description: '果壳网 科学人', @@ -14,7 +14,7 @@ module.exports = async (ctx) => { result.map((item) => ctx.cache.tryGet(item.url, async () => { const res = await got(item.url); - const $ = cheerio.load(res.data); + const $ = load(res.data); item.description = $('.eflYNZ #js_content').css('visibility', 'visible').html() ?? $('.bxHoEL').html(); return { title: item.title, @@ -26,5 +26,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/gxmzu/ai.js b/lib/v2/gxmzu/ai.js index e8228057d..90bcf6f97 100644 --- a/lib/v2/gxmzu/ai.js +++ b/lib/v2/gxmzu/ai.js @@ -10,9 +10,9 @@ module.exports = async (ctx) => { date: '.timestyle55269', }); - ctx.state.data = { + ctx.set('data', { title: '广西民族大学人工智能学院 -- 通知公告', link: url, item: out, - }; + }); }; diff --git a/lib/v2/gxmzu/lib.js b/lib/v2/gxmzu/lib.js index 6f1d3a720..8ecf44758 100644 --- a/lib/v2/gxmzu/lib.js +++ b/lib/v2/gxmzu/lib.js @@ -1,11 +1,11 @@ // 导入got库,该库用来请求网页数据 -const got = require('@/utils/got'); +import got from '@/utils/got'; // 导入cheerio库,该库用来解析网页数据 -const cheerio = require('cheerio'); +import { load } from 'cheerio'; // 导入parseDate函数,该函数用于日期处理 -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // 导入timezone库,该库用于时区处理 -const timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; // 广西民大的url链接 const url = 'https://library.gxmzu.edu.cn/news/news_list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1010'; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { const response = await got(url); // 解析网页数据 - const $ = cheerio.load(response.data); + const $ = load(response.data); // 通知公告的items的标题、url链接、发布日期 const list = $('#newslist ul li') @@ -49,7 +49,7 @@ module.exports = async (ctx) => { item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('h2').text(); item.description = $('.v_news_content').html(); } @@ -59,12 +59,12 @@ module.exports = async (ctx) => { ); // 生成RSS源 - ctx.state.data = { + ctx.set('data', { // 项目标题 title: '广西民族大学图书馆 -- 最新消息', // 项目链接 link: url, // items的内容 item: out, - }; + }); }; diff --git a/lib/v2/gxmzu/utils/index.js b/lib/v2/gxmzu/utils/index.js index c8f13bd38..61912b870 100644 --- a/lib/v2/gxmzu/utils/index.js +++ b/lib/v2/gxmzu/utils/index.js @@ -1,11 +1,11 @@ -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'; async function getNoticeList(ctx, url, host, titleSelector, dateSelector, contentSelector) { const response = await got({ url, https: { rejectUnauthorized: false } }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(`tr[height=20]`) .toArray() @@ -29,7 +29,7 @@ async function getNoticeList(ctx, url, host, titleSelector, dateSelector, conten item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $(contentSelector.title).text(); const hasEmbeddedPDFScript = $('script:contains("showVsbpdfIframe")').length > 0; diff --git a/lib/v2/gxmzu/yjs.js b/lib/v2/gxmzu/yjs.js index 485f3c481..59d75aca4 100644 --- a/lib/v2/gxmzu/yjs.js +++ b/lib/v2/gxmzu/yjs.js @@ -10,9 +10,9 @@ module.exports = async (ctx) => { date: '.timestyle55269', }); - ctx.state.data = { + ctx.set('data', { title: '广西民族大学研究生院 -- 招生公告', link: url, item: out, - }; + }); }; diff --git a/lib/v2/gzdaily/app.js b/lib/v2/gzdaily/app.js index ad790a3c3..e8bff5ee8 100644 --- a/lib/v2/gzdaily/app.js +++ b/lib/v2/gzdaily/app.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 column = ctx.params.column ?? 74; + const column = ctx.req.param('column') ?? 74; const currentUrl = `https://app.gzdaily.cn/app_if/getArticles?columnId=${column}&page=1`; const { data: response } = await got(currentUrl); @@ -33,7 +33,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); colName = colName === '' ? item.colName : colName; if (content('.abstract').text()) { content('.abstract').find('span').remove(); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `广州日报客户端 - ${colName}`, link: `https://www.gzdaily.cn/amucsite/web/index.html#/home/${column}`, item: items, - }; + }); }; diff --git a/lib/v2/gzhu/yjs.js b/lib/v2/gzhu/yjs.js index df9412ca1..041c2381e 100644 --- a/lib/v2/gzhu/yjs.js +++ b/lib/v2/gzhu/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'; module.exports = async (ctx) => { const link = 'https://yjsy.gzhu.edu.cn/zsxx/zsdt/zsdt.htm'; @@ -9,10 +9,10 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.picnews_cont li'); - ctx.state.data = { + ctx.set('data', { title: '广州大学研究生院', link, description: '广州大学研招网通知公告', @@ -27,5 +27,5 @@ module.exports = async (ctx) => { pubDate: parseDate(a.text(), 'YYYY-MM-DD'), }; }), - }; + }); }; diff --git a/lib/v2/hackernews/index.js b/lib/v2/hackernews/index.js index f6dae5892..97a634d49 100644 --- a/lib/v2/hackernews/index.js +++ b/lib/v2/hackernews/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const section = ctx.params.section ?? 'index'; - const type = ctx.params.type ?? 'sources'; - const user = ctx.params.user ?? ''; + const section = ctx.req.param('section') ?? 'index'; + const type = ctx.req.param('type') ?? 'sources'; + const user = ctx.req.param('user') ?? ''; const rootUrl = 'https://news.ycombinator.com'; const sectionUrl = section === 'index' ? '' : `/${section}`; @@ -18,10 +18,10 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}${sectionUrl}${optUrl}`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.athing') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .map((_, thing) => { thing = $(thing); @@ -58,7 +58,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.reply').remove(); @@ -104,9 +104,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hackertalk/index.js b/lib/v2/hackertalk/index.js index 56c7906bd..85ae4f9e6 100644 --- a/lib/v2/hackertalk/index.js +++ b/lib/v2/hackertalk/index.js @@ -1,15 +1,16 @@ -const got = require('@/utils/got'); -const md = require('markdown-it')(); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import MarkdownIt from 'markdown-it'; +const md = MarkdownIt(); module.exports = async (ctx) => { - const limit = ctx.query.limit ?? 25; + const limit = ctx.req.query('limit') ?? 25; const response = await got(`https://api.hackertalk.net/v1/posts?limit=${limit}&orderBy=time`); const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: '黑客说的最新帖子', link: 'https://hackertalk.net/?tab=new', description: '黑客说 - 技术驱动优质交流', @@ -19,5 +20,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.createdAt), link: `https://hackertalk.net/posts/${item.id}`, })), - }; + }); }; diff --git a/lib/v2/hacking8/index.js b/lib/v2/hacking8/index.js index 83b5d131f..d41002da3 100644 --- a/lib/v2/hacking8/index.js +++ b/lib/v2/hacking8/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 ?? 'index'; + const category = ctx.req.param('category') ?? 'index'; const rootUrl = 'https://i.hacking8.com'; const currentUrl = `${rootUrl}/index/${category}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.media') .toArray() @@ -37,9 +37,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Hacking8 安全信息流 - ${$('div.btn-group a.btn-primary').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hacking8/search.js b/lib/v2/hacking8/search.js index 4d27c58bc..ff38e0b5f 100644 --- a/lib/v2/hacking8/search.js +++ b/lib/v2/hacking8/search.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 keyword = ctx.params.keyword ?? ''; + const keyword = ctx.req.param('keyword') ?? ''; const rootUrl = 'https://i.hacking8.com'; const currentUrl = `${rootUrl}/search/?q=${keyword}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.media') .toArray() @@ -37,12 +37,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Hacking8 安全信息流 - ${$('title') .text() .replaceAll(/总数:\d+/g, '') .trim()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hackmd/profile.js b/lib/v2/hackmd/profile.js index 3d057a40f..0cd899de5 100644 --- a/lib/v2/hackmd/profile.js +++ b/lib/v2/hackmd/profile.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { - const path = ctx.params.path; + const path = ctx.req.param('path'); const response = await got({ method: 'get', @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const data = response.data; const profile = data.user || data.team; - ctx.state.data = { + ctx.set('data', { title: `${profile.name}'s Profile`, link: `https://hackmd.io/@${path}`, description: `${profile.name}'s profile on HackMD`, @@ -20,5 +20,5 @@ module.exports = async (ctx) => { pubDate: new Date(note.publishedAt).toUTCString(), link: `https://hackmd.io/@${path}/${note.permalink || note.shortId}`, })), - }; + }); }; diff --git a/lib/v2/hackyournews/index.js b/lib/v2/hackyournews/index.js index 337f5b415..3dddb73b9 100644 --- a/lib/v2/hackyournews/index.js +++ b/lib/v2/hackyournews/index.js @@ -1,12 +1,12 @@ // Require necessary modules -const got = require('@/utils/got'); // a customised got -const cheerio = require('cheerio'); // an HTML parser with a jQuery-like API -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // a customised got +import { load } from 'cheerio'; // an HTML parser with a jQuery-like API +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://hackyournews.com'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const item = $('tr.story') .map((_, story) => { @@ -42,9 +42,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: 'Index', link: baseUrl, item, - }; + }); }; diff --git a/lib/v2/hafu/news.js b/lib/v2/hafu/news.js index dff795084..acf4fa3b8 100644 --- a/lib/v2/hafu/news.js +++ b/lib/v2/hafu/news.js @@ -2,14 +2,14 @@ const parseList = require('./utils'); module.exports = async (ctx) => { // set default router type - const type = ctx.params.type ?? 'ggtz'; + const type = ctx.req.param('type') ?? 'ggtz'; const { link, title, resultList } = await parseList(ctx, type); - ctx.state.data = { + ctx.set('data', { title, link, description: '河南财政金融学院 - 公告通知', item: resultList, - }; + }); }; diff --git a/lib/v2/hafu/utils.js b/lib/v2/hafu/utils.js index 15073f16b..2f64c206d 100644 --- a/lib/v2/hafu/utils.js +++ b/lib/v2/hafu/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 typeMap = { @@ -18,9 +18,9 @@ module.exports = async (ctx, type) => { const title = typeMap[type].title; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); - limit = ctx.query.limit || limit; + limit = ctx.req.query('limit') || limit; const resultList = await typeMap[type].parseFn(ctx, $); return { @@ -36,7 +36,7 @@ async function tryGetFullText(href, link, type) { // for some unexpected href link try { const articleRes = await got(link); - articleData = cheerio.load(articleRes.data); + articleData = load(articleRes.data); // fullText let articleBody = articleData('div[class=v_news_content]').html(); // attachments diff --git a/lib/v2/hakkatv/type.js b/lib/v2/hakkatv/type.js index 77cfc5eaf..f9335a200 100644 --- a/lib/v2/hakkatv/type.js +++ b/lib/v2/hakkatv/type.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 typeMap = ['hakka', 'political', 'medical', 'local', 'international']; const baseUrl = 'https://www.hakkatv.org.tw'; @@ -54,11 +54,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '新聞首頁 - 客家電視台', description: '客家電視是屬於全民、以至於全世界客家族群的頻道,亦是為傳播客家文化而存在,定位為「全體客家族群之媒體」。', link: `${baseUrl}/news`, language: 'zh-TW', item: items, - }; + }); }; diff --git a/lib/v2/hameln/chapter.js b/lib/v2/hameln/chapter.js index 38b056173..b3f9d0ceb 100644 --- a/lib/v2/hameln/chapter.js +++ b/lib/v2/hameln/chapter.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const 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://syosetu.org/novel/${id}`; - const $ = cheerio.load(await get(link)); + const $ = load(await get(link)); const title = $('span[itemprop="name"]').text(); const description = $('div.ss:nth-child(2)').text(); @@ -30,20 +30,20 @@ module.exports = async (ctx) => { chapter_list.map((chapter) => { chapter.link = `${link}/${chapter.link}`; return ctx.cache.tryGet(chapter.link, async () => { - const content = cheerio.load(await get(chapter.link)); + const content = load(await get(chapter.link)); chapter.description = content('#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/harvard/health/blog.js b/lib/v2/harvard/health/blog.js index 8de8d9e68..d1404be57 100644 --- a/lib/v2/harvard/health/blog.js +++ b/lib/v2/harvard/health/blog.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.health.harvard.edu'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.lg\\:text-2xl') .toArray() @@ -31,7 +31,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const ldJson = JSON.parse(content('script[type="application/ld+json"]').text())['@graph'].find((i) => i['@type'] === 'Article'); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Harvard Health Blog', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hashnode/blog.js b/lib/v2/hashnode/blog.js index 075bd1807..53234d961 100644 --- a/lib/v2/hashnode/blog.js +++ b/lib/v2/hashnode/blog.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const baseApiUrl = 'https://api.hashnode.com'; module.exports = async (ctx) => { - const username = ctx.params.username; + const username = ctx.req.param('username'); if (!username) { return; } @@ -44,7 +44,7 @@ module.exports = async (ctx) => { } const list = publication.posts; - ctx.state.data = { + ctx.set('data', { title: `Hashnode by ${username}`, link: userUrl, item: list @@ -58,5 +58,5 @@ module.exports = async (ctx) => { link: `${userUrl}/${item.slug}`, })) .filter((item) => item !== ''), - }; + }); }; diff --git a/lib/v2/hbr/topic.js b/lib/v2/hbr/topic.js index 7369cb05a..ce8c8a382 100644 --- a/lib/v2/hbr/topic.js +++ b/lib/v2/hbr/topic.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 topic = ctx.params.topic ?? 'leadership'; - const type = ctx.params.type ?? 'Latest'; + const topic = ctx.req.param('topic') ?? 'leadership'; + const type = ctx.req.param('type') ?? 'Latest'; const rootUrl = 'https://hbr.org'; const currentUrl = `${rootUrl}/topic/${topic}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(`stream-content[data-stream-name="${type}"]`) .find('.stream-item') @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article-body, article[itemprop="description"]').html(); item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content')); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').eq(0).text()} - ${type}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hdu/cs/notice.js b/lib/v2/hdu/cs/notice.js index 00f68e84f..cb7b48c5b 100644 --- a/lib/v2/hdu/cs/notice.js +++ b/lib/v2/hdu/cs/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'; const link = 'https://computer.hdu.edu.cn'; const host = 'https://computer.hdu.edu.cn/6738/list.htm'; @@ -8,7 +8,7 @@ const host = 'https://computer.hdu.edu.cn/6738/list.htm'; const getSingleRecord = async () => { const res = await got(host); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.posts-list').find('li'); return ( @@ -34,7 +34,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); return { title: item.title, link: item.link, @@ -45,10 +45,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '杭电计算机-通知公告', description: '杭州电子科技大学计算机学院-通知公告', link: host, item: out, - }; + }); }; diff --git a/lib/v2/hdu/cs/pg.js b/lib/v2/hdu/cs/pg.js index 78c0e4356..c3f0542b8 100644 --- a/lib/v2/hdu/cs/pg.js +++ b/lib/v2/hdu/cs/pg.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 link = 'https://computer.hdu.edu.cn'; const host = 'https://computer.hdu.edu.cn/6769/list.htm'; @@ -8,7 +8,7 @@ const host = 'https://computer.hdu.edu.cn/6769/list.htm'; const getSingleRecord = async () => { const res = await got(host); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.posts-list').find('li'); return ( @@ -34,7 +34,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); return { title: item.title, link: item.link, @@ -45,10 +45,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '杭电计算机-研究生通知', description: '杭州电子科技大学计算机学院-研究生教学通知', link: host, item: out, - }; + }); }; diff --git a/lib/v2/hebtv/nong-bo-shi-zai-xing-dong.js b/lib/v2/hebtv/nong-bo-shi-zai-xing-dong.js index 8b1d335a5..a2d550226 100644 --- a/lib/v2/hebtv/nong-bo-shi-zai-xing-dong.js +++ b/lib/v2/hebtv/nong-bo-shi-zai-xing-dong.js @@ -1,20 +1,20 @@ -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 baseUrl = 'https://web.cmc.hebtv.com/cms/rmt0336/19/19js/st/ds/nmpd/nbszxd/index.shtml'; module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 40; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 40; const apiRootUrl = 'http://api.cmc.hebtv.com'; const apiUrl = new URL('cmsback/api/article/getMyArticleDetail', apiRootUrl).href; const response = await got(baseUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 获取当前页面的 list const list = $('.video_box .tv_items') @@ -91,7 +91,7 @@ module.exports = async (ctx) => { const author = description.split(/,/)[0]; const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: baseUrl, @@ -105,5 +105,5 @@ module.exports = async (ctx) => { itunes_author: author, itunes_category: 'News', allowEmpty: true, - }; + }); }; diff --git a/lib/v2/hellobtc/information.js b/lib/v2/hellobtc/information.js index 008374233..207458ca4 100644 --- a/lib/v2/hellobtc/information.js +++ b/lib/v2/hellobtc/information.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.hellobtc.com'; @@ -16,11 +16,11 @@ const titleMap = { }; module.exports = async (ctx) => { - const channel = ctx.params.channel ?? 'latest'; + const channel = ctx.req.param('channel') ?? 'latest'; const url = rootUrl; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(channelSelector[channel]) .find('div.new_item') .map((_, item) => ({ @@ -33,7 +33,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('#nr').html(); item.pubDate = timezone(parseDate(content('span.date').text(), 'YYYY-MM-DD HH:mm:ss'), +8); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `白话区块链 - 首页 ${titleMap[channel]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/hellobtc/kepu.js b/lib/v2/hellobtc/kepu.js index 1f0e47b7a..2e6d8da3a 100644 --- a/lib/v2/hellobtc/kepu.js +++ b/lib/v2/hellobtc/kepu.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const rootUrl = 'https://www.hellobtc.com'; @@ -28,11 +28,11 @@ const titleMap = { }; module.exports = async (ctx) => { - const channel = ctx.params.channel ?? 'latest'; + const channel = ctx.req.param('channel') ?? 'latest'; const url = `${rootUrl}/kepu.html`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(channelSelector[channel]) .find('div.new_item') .map((_, item) => ({ @@ -45,7 +45,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('#js_content') .html() @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `白话区块链 - 科普 ${titleMap[channel]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/hellobtc/news.js b/lib/v2/hellobtc/news.js index 68d5336cf..12487956e 100644 --- a/lib/v2/hellobtc/news.js +++ b/lib/v2/hellobtc/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 rootUrl = 'https://www.hellobtc.com'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const url = `${rootUrl}/news`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('nav.js-nav') .find('div.item') .map((_, item) => ({ @@ -21,9 +21,9 @@ module.exports = async (ctx) => { .filter(Boolean) .get(); - ctx.state.data = { + ctx.set('data', { title: `白话区块链 - 快讯`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/hellogithub/index.js b/lib/v2/hellogithub/index.js index b2f801243..b596b6c00 100644 --- a/lib/v2/hellogithub/index.js +++ b/lib/v2/hellogithub/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 sorts = { @@ -10,9 +10,9 @@ const sorts = { }; module.exports = async (ctx) => { - const sort = ctx.params.sort ?? 'hot'; - const id = ctx.params.id ?? ''; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const sort = ctx.req.param('sort') ?? 'hot'; + const id = ctx.req.param('id') ?? ''; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://hellogithub.com'; const apiRootUrl = 'https://api.hellogithub.com'; @@ -33,7 +33,7 @@ module.exports = async (ctx) => { url: tagUrl, }); - const $ = cheerio.load(tagResponse.data); + const $ = load(tagResponse.data); tag = $('meta[property="og:title"]').attr('content').split(' ').pop(); buildId = tagResponse.data.match(/"buildId":"(.*?)",/)[1]; @@ -94,9 +94,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `HelloGithub - ${sorts[sort]}${tag || ''}项目`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hellogithub/report.js b/lib/v2/hellogithub/report.js index 28500eb0d..287f9c347 100644 --- a/lib/v2/hellogithub/report.js +++ b/lib/v2/hellogithub/report.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 types = { @@ -10,7 +10,7 @@ const types = { }; module.exports = async (ctx) => { - let type = ctx.params.type ?? 'tiobe'; + let type = ctx.req.param('type') ?? 'tiobe'; type = type === 'webserver' ? 'netcraft' : type === 'db' ? 'db-engines' : type; @@ -48,9 +48,9 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: `HelloGitHub - ${types[type]}排行榜`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hellogithub/volume.js b/lib/v2/hellogithub/volume.js index 0c2ac5655..746480de5 100644 --- a/lib/v2/hellogithub/volume.js +++ b/lib/v2/hellogithub/volume.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 md = require('markdown-it')({ html: true, }); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; art.defaults.imports.render = function (string) { return md.render(string); @@ -25,7 +25,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(buildResponse.data); + const $ = load(buildResponse.data); const text = $('#__NEXT_DATA__').text(); const response = JSON.parse(text); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: 'HelloGithub - 月刊', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hex-rays/index.js b/lib/v2/hex-rays/index.js index 4d162daf1..12272276f 100644 --- a/lib/v2/hex-rays/index.js +++ b/lib/v2/hex-rays/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'https://www.hex-rays.com/blog/'; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.post-list-container') .map((_, ele) => ({ @@ -20,7 +20,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.category = ( content('.category-link') @@ -39,9 +39,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Hex-Rays Blog', link, item: items, - }; + }); }; diff --git a/lib/v2/hicairo/rss.js b/lib/v2/hicairo/rss.js index b68a020b5..a466855ee 100644 --- a/lib/v2/hicairo/rss.js +++ b/lib/v2/hicairo/rss.js @@ -1,10 +1,10 @@ -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://www.hicairo.com'; const response = await got(`${currentUrl}/feed.php`); - const $ = cheerio.load(response.data, { xmlMode: true }); + const $ = load(response.data, { xmlMode: true }); const title_main = $('channel > title').text(); const description_main = $('channel > description').text(); const items = $('channel > item') @@ -23,10 +23,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: title_main, description: description_main, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hinatazaka46/blog.js b/lib/v2/hinatazaka46/blog.js index 30cbfa2e9..daf809d8f 100644 --- a/lib/v2/hinatazaka46/blog.js +++ b/lib/v2/hinatazaka46/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 rootUrl = 'https://www.hinatazaka46.com'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'all'; - const page = ctx.params.page ?? '0'; + const id = ctx.req.param('id') ?? 'all'; + const page = ctx.req.param('page') ?? '0'; const params = id === 'all' ? `?page=${page}` : `?page=${page}&ct=${id}`; const currentUrl = `${rootUrl}/s/official/diary/member/list${params}`; @@ -16,11 +16,11 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div.p-blog-group .p-blog-article') .toArray() .map((item) => { - const content = cheerio.load(item); + const content = load(item); return { title: content('.c-blog-article__title').text(), @@ -31,10 +31,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { allowEmpty: true, title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hinatazaka46/news.js b/lib/v2/hinatazaka46/news.js index a13bf2a0f..3c6f5fa1c 100644 --- a/lib/v2/hinatazaka46/news.js +++ b/lib/v2/hinatazaka46/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.hinatazaka46.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.p-news__list .p-news__item a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.p-article__text').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hit/hitgs.js b/lib/v2/hit/hitgs.js index 2ef23b831..4ca277f3c 100644 --- a/lib/v2/hit/hitgs.js +++ b/lib/v2/hit/hitgs.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://hitgs.hit.edu.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news_list li') .map((i, e) => ({ pubDate: parseDate($('span:nth-child(4)', e).text()), @@ -29,7 +29,7 @@ module.exports = async (ctx) => { Referer: host, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.wp_articlecontent').html(); item.author = $('div.infobox > div > p > span:nth-child(3)').text().slice(3); return item; @@ -37,10 +37,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '哈工大研究生院通知公告', link: host + '/tzgg/list.htm', description: '哈尔滨工业大学研究生院通知公告', item: out, - }; + }); }; diff --git a/lib/v2/hit/jwc.js b/lib/v2/hit/jwc.js index c08e07dfb..fad58c4c4 100644 --- a/lib/v2/hit/jwc.js +++ b/lib/v2/hit/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.hit.edu.cn'; const type = (filename) => filename.split('.').pop(); @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const response = await got(`${baseUrl}/2591/list.htm`); const { data } = response; - const $ = cheerio.load(data); + const $ = load(data); const links = $('.news_list li') .toArray() .map((el) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { if (type(item.link) === 'htm') { try { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const author = $('p.arti_metas>span:nth-child(3)').text().trim(); const description = @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '哈尔滨工业大学教务处通知公告', link: `${baseUrl}/2591/list.htm`, item: items, - }; + }); }; diff --git a/lib/v2/hit/today.js b/lib/v2/hit/today.js index 61934ef47..253fc0b04 100644 --- a/lib/v2/hit/today.js +++ b/lib/v2/hit/today.js @@ -1,11 +1,11 @@ -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 host = 'https://today.hit.edu.cn'; - const category = ctx.params.category; + const category = ctx.req.param('category'); const response = await got(host + '/category/' + category, { headers: { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.paragraph li') .toArray() .map((e) => ({ @@ -33,7 +33,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.pubDate = timezone(parseDate($('.left-attr.first').text().trim()), 8); item.description = $('.article-content').html() && @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim(), link: host + '/category/' + category, item: out, - }; + }); }; diff --git a/lib/v2/hitsz/article.js b/lib/v2/hitsz/article.js index dd770d30b..3872239d1 100644 --- a/lib/v2/hitsz/article.js +++ b/lib/v2/hitsz/article.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 host = 'https://www.hitsz.edu.cn'; - const category = ctx.params.category ?? 'id-77'; + const category = ctx.req.param('category') ?? 'id-77'; const link = `${host}/article/${category}.html`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const category_name = $('div.title_page').text().trim(); const lists = $('.mainside_news ul li') @@ -24,7 +24,7 @@ module.exports = async (ctx) => { lists.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.description = $('div.edittext').html().trim(); item.pubDate = timezone(parseDate($('.item').first().text().replace('发布时间:', '')), 8); return item; @@ -32,10 +32,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '哈尔滨工业大学(深圳)-' + category_name, link, description: '哈尔滨工业大学(深圳)-' + category_name, item: items, - }; + }); }; diff --git a/lib/v2/hitwh/today.js b/lib/v2/hitwh/today.js index c21251c35..4dd3ca929 100644 --- a/lib/v2/hitwh/today.js +++ b/lib/v2/hitwh/today.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://today.hitwh.edu.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const type = (filename) => filename.split('.').pop(); const links = $('.list_list_wrap #wp_news_w10002 ul > li') .map((_, el) => ({ @@ -21,7 +21,7 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: '哈尔滨工业大学(威海)通知公告', link: `${baseUrl}/1024/list.htm`, item: await Promise.all( @@ -34,7 +34,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(data); + const $ = load(data); item.description = $('div.wp_articlecontent').html() && $('div.wp_articlecontent').html().replaceAll('src="/', `src="${baseUrl}/`).replaceAll('href="/', `href="${baseUrl}/`).trim(); return item; } catch { @@ -50,5 +50,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/hizu/index.js b/lib/v2/hizu/index.js index 3f9da391a..dbaffb1e8 100644 --- a/lib/v2/hizu/index.js +++ b/lib/v2/hizu/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 titles = { '5dd92265e4b0bf88dd8c1175': '热点', @@ -30,7 +30,7 @@ const titles = { }; module.exports = async (ctx) => { - const column = ctx.params.column ?? '5dd92265e4b0bf88dd8c1175'; + const column = ctx.req.param('column') ?? '5dd92265e4b0bf88dd8c1175'; const rootUrl = 'https://www.hizh.cn'; const currentUrl = `${rootUrl}/channels/zjyapp/columns/${column}/stories.json`; @@ -40,7 +40,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - let items = response.data.stories.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50).map((item) => ({ + let items = response.data.stories.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50).map((item) => ({ title: item.title, author: item.author, link: item.jsonUrl, @@ -56,7 +56,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data.content); + const content = load(detailResponse.data.content); content('figure').last().remove(); @@ -68,9 +68,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${titles[column]} - 珠海网`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/hk01/channel.js b/lib/v2/hk01/channel.js index 95cacf8ea..f195f704d 100644 --- a/lib/v2/hk01/channel.js +++ b/lib/v2/hk01/channel.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '1'; + const id = ctx.req.param('id') ?? '1'; const currentUrl = `${rootUrl}/channel/${id}`; const apiUrl = `${apiRootUrl}/v2/feed/category/${id}`; @@ -12,12 +12,12 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.items, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.items, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: response.data.category ? `${response.data.category.publishName} | 香港01` : `Channel: ${id} | 香港01`, link: currentUrl, item: items, image: response.data.category ? response.data.category.icon : null, - }; + }); }; diff --git a/lib/v2/hk01/hot.js b/lib/v2/hk01/hot.js index 2bb0723ed..367f0c1c6 100644 --- a/lib/v2/hk01/hot.js +++ b/lib/v2/hk01/hot.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.items, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.items, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: '熱門新聞、全城熱話及社會時事 | 香港01', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hk01/issue.js b/lib/v2/hk01/issue.js index fb63ad216..1536e9b99 100644 --- a/lib/v2/hk01/issue.js +++ b/lib/v2/hk01/issue.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '649'; + const id = ctx.req.param('id') ?? '649'; const currentUrl = `${rootUrl}/issue/${id}`; const apiUrl = `${apiRootUrl}/v2/issues/${id}`; @@ -12,11 +12,11 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.blocks[0].articles, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.blocks[0].articles, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${response.data.title} | 香港01`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hk01/latest.js b/lib/v2/hk01/latest.js index 4018ca5e9..3ac3911e2 100644 --- a/lib/v2/hk01/latest.js +++ b/lib/v2/hk01/latest.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.items, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.items, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: '即時 | 香港01', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hk01/tag.js b/lib/v2/hk01/tag.js index be6ebc0ce..38fe5c3f6 100644 --- a/lib/v2/hk01/tag.js +++ b/lib/v2/hk01/tag.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '1'; + const id = ctx.req.param('id') ?? '1'; const currentUrl = `${rootUrl}/tag/${id}`; const apiUrl = `${apiRootUrl}/v2/feed/tag/${id}`; @@ -12,11 +12,11 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.items, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.items, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${id} | 香港01`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hk01/utils.js b/lib/v2/hk01/utils.js index f3b9515ca..9e1c4716c 100644 --- a/lib/v2/hk01/utils.js +++ b/lib/v2/hk01/utils.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://hk01.com'; diff --git a/lib/v2/hk01/zone.js b/lib/v2/hk01/zone.js index df139976c..cdca60317 100644 --- a/lib/v2/hk01/zone.js +++ b/lib/v2/hk01/zone.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiRootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '1'; + const id = ctx.req.param('id') ?? '1'; const currentUrl = `${rootUrl}/zone/${id}`; const apiUrl = `${apiRootUrl}/v2/feed/zone/${id}`; @@ -12,12 +12,12 @@ module.exports = async (ctx) => { url: apiUrl, }); - const items = await ProcessItems(response.data.items, ctx.query.limit, ctx.cache.tryGet); + const items = await ProcessItems(response.data.items, ctx.req.query('limit'), ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${response.data.category.publishName} | 香港01`, link: currentUrl, item: items, image: response.data.category.icon, - }; + }); }; diff --git a/lib/v2/hkej/index.js b/lib/v2/hkej/index.js index 3f589a7e8..12e56d136 100644 --- a/lib/v2/hkej/index.js +++ b/lib/v2/hkej/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 { parseDate, parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); const { CookieJar } = require('tough-cookie'); @@ -54,7 +54,7 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'index'; + const category = ctx.req.param('category') ?? 'index'; const cat = categories[category]; const baseUrl = 'https://www2.hkej.com'; @@ -67,7 +67,7 @@ module.exports = async (ctx) => { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('h3.in_news_u_t a, h4.hkej_hl-news_topic_2014 a, div.hkej_toc_listingAll_news2_2014 h3 a, div.hkej_toc_cat_top_detail h3 a, div.allNews div.news h1 a, div#div_listingAll div.news2 h3 a') .map((_, item) => { @@ -102,7 +102,7 @@ module.exports = async (ctx) => { }, cookieJar, }); - const content = cheerio.load(article.data); + const content = load(article.data); // remove unwanted elements content('#ad_popup').remove(); @@ -135,20 +135,20 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `信報網站 - ${cat.title} - 信報網站 hkej.com`, link: baseUrl + cat.link, description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`, item: items, language: 'zh-hk', - }; + }); - ctx.state.json = { + ctx.set('json', { title: `信報網站 - ${cat.title} - 信報網站 hkej.com`, link: baseUrl + cat.link, description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`, item: items, language: 'zh-hk', cookieJar, - }; + }); }; diff --git a/lib/v2/hkepc/index.js b/lib/v2/hkepc/index.js index bb5a900fb..fad2868b3 100644 --- a/lib/v2/hkepc/index.js +++ b/lib/v2/hkepc/index.js @@ -1,11 +1,11 @@ -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, categoryMap } = require('./data'); module.exports = async (ctx) => { - const category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; const { data: response } = await got(categoryMap[category].url, { headers: { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $(categoryMap[category].selector) .find('a') @@ -32,7 +32,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const content = $('#view'); const nextPages = $('#articleFooter .navigation a') .toArray() @@ -47,7 +47,7 @@ module.exports = async (ctx) => { referer: item.link, }, }); - const $ = cheerio.load(response); + const $ = load(response); return $('#view').html(); }) ); @@ -87,11 +87,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `電腦領域 HKEPC${categoryMap[category].feedSuffix}`, link: `https://www.hkepc.com/${category}`, description: '電腦領域 HKEPC Hardware - 全港 No.1 PC網站', language: 'zh-hk', item: items, - }; + }); }; diff --git a/lib/v2/hket/index.js b/lib/v2/hket/index.js index 88ca791ad..6f699f1ce 100644 --- a/lib/v2/hket/index.js +++ b/lib/v2/hket/index.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 urlMap = { srac: { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { const { data: response } = await got(`${baseUrl}/${category}`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('div.listing-title > a') .toArray() @@ -78,7 +78,7 @@ module.exports = async (ctx) => { } const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.category = $('.contentTags-container > .hotkey-container-wrapper > .hotkey-container > a') .toArray() @@ -119,19 +119,19 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head meta[name=title]').attr('content').trim(), link: baseUrl + '/' + category, description: $('head meta[name=description]').attr('content').trim(), item: items, language: 'zh-hk', - }; + }); - ctx.state.json = { + ctx.set('json', { title: $('head meta[name=title]').attr('content').trim(), link: baseUrl + '/' + category, description: $('head meta[name=description]').attr('content').trim(), item: items, language: 'zh-hk', - }; + }); }; diff --git a/lib/v2/hkjunkcall/index.js b/lib/v2/hkjunkcall/index.js index c0a57d13a..8c0fc7c7f 100644 --- a/lib/v2/hkjunkcall/index.js +++ b/lib/v2/hkjunkcall/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://hkjunkcall.com'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.hh15') .map((_, item) => { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.card').find('div, h2').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/hljucm/yjsy.js b/lib/v2/hljucm/yjsy.js index 56bf1458e..c43d70372 100644 --- a/lib/v2/hljucm/yjsy.js +++ b/lib/v2/hljucm/yjsy.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 category = ctx.params.category ?? 'xwdt'; + const category = ctx.req.param('category') ?? 'xwdt'; const rootUrl = 'https://yjsy.hljucm.net'; const currentUrl = `${rootUrl}/index/${category}.htm`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.postlist a') .toArray() @@ -29,7 +29,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#vsb_newscontent').html(); item.pubDate = timezone(parseDate(content('.timestyle56043').text()), +8); @@ -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/hnrb/index.js b/lib/v2/hnrb/index.js index 3ac5ea2a7..87550973c 100644 --- a/lib/v2/hnrb/index.js +++ b/lib/v2/hnrb/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; + const id = ctx.req.param('id'); const rootUrl = 'https://hnrb.voc.com.cn'; const currentUrl = `${rootUrl}/hnrb_epaper`; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { url: `${currentUrl}/${id ? response.data.match(/URL=(.*)"/)[1].replace(/node_\d+\.htm$/, `node_20${id}.htm`) : response.data.match(/URL=(.*)"/)[1]}`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const matches = response.data.match(/images\/(\d{4}-\d{2}\/\d{2})\/\d{2}\/\d+_brief/); const link = `${rootUrl}/hnrb_epaper/html/${matches[1]}`; @@ -43,7 +43,7 @@ module.exports = async (ctx) => { url: p, }); - const page = cheerio.load(pageResponse.data); + const page = load(pageResponse.data); items.push( ...page('tbody') @@ -65,7 +65,7 @@ module.exports = async (ctx) => { url: item, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); return { link: item, @@ -77,9 +77,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `湖南日报${id ? ` - ${$('strong').first().parent().text()}` : ''}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hnu/careers.js b/lib/v2/hnu/careers.js index acbafffa8..2c3a83533 100644 --- a/lib/v2/hnu/careers.js +++ b/lib/v2/hnu/careers.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const rootUrl = 'http://scc.hnu.edu.cn/'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }); const company_list = response.data.data; - ctx.state.data = { + ctx.set('data', { title: '校园招聘', link: currentRoute, item: company_list.map((company_info) => { @@ -29,5 +29,5 @@ module.exports = async (ctx) => { }; return ret; }), - }; + }); }; diff --git a/lib/v2/hongkong/chp.js b/lib/v2/hongkong/chp.js index 1a558b995..01b901213 100644 --- a/lib/v2/hongkong/chp.js +++ b/lib/v2/hongkong/chp.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 titles = { title: { @@ -42,8 +42,8 @@ module.exports = async (ctx) => { zh_tw: 'tc', }; - const category = ctx.params.category ?? 'important_ft'; - const language = ctx.params.language ?? 'zh_tw'; + const category = ctx.req.param('category') ?? 'important_ft'; + const language = ctx.req.param('language') ?? 'zh_tw'; const rootUrl = 'https://www.chp.gov.hk'; const apiUrl = `${rootUrl}/js/${category}.js`; @@ -82,7 +82,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#btmNav, script').remove(); content('.contHeader, .title_display_date').remove(); @@ -95,9 +95,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${titles[category][language]} - ${titles.title[language]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hongkong/dh.js b/lib/v2/hongkong/dh.js index a27763100..3b897ec05 100644 --- a/lib/v2/hongkong/dh.js +++ b/lib/v2/hongkong/dh.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 ?? 'tc_chi'; + const language = ctx.req.param('language') ?? 'tc_chi'; const rootUrl = 'https://www.dh.gov.hk'; const currentUrl = `${rootUrl}/${language}/press/press.html`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: textonlyUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('td[headers="title"]') .toArray() @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#pressrelease').html(); @@ -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/hostmonit/cloudflareyes.js b/lib/v2/hostmonit/cloudflareyes.js index 48837a1e5..d79bb8b89 100644 --- a/lib/v2/hostmonit/cloudflareyes.js +++ b/lib/v2/hostmonit/cloudflareyes.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 lines = { @@ -13,7 +13,7 @@ const lines = { module.exports = async (ctx) => { const { type = 'v4' } = 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 domain = 'hostmonit.com'; const title = `CloudFlareYes${type === 'v6' ? type.toUpperCase() : ''}`; @@ -72,11 +72,11 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text().replace(/- .*$/, `- ${title}`), link: currentUrl, @@ -87,5 +87,5 @@ module.exports = async (ctx) => { subtitle: title, author: $('title').text().split(/\s-/)[0], allowEmpty: true, - }; + }); }; diff --git a/lib/v2/hotukdeals/hottest.js b/lib/v2/hotukdeals/hottest.js index 117699b9b..bdd848e1d 100644 --- a/lib/v2/hotukdeals/hottest.js +++ b/lib/v2/hotukdeals/hottest.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }); const threads = dom.window.__INITIAL_STATE__.widgets.hottestWidget.threads; - ctx.state.data = { + ctx.set('data', { title: `hotukdeals hottest`, link: `https://www.hotukdeals.com/`, item: threads.map((item) => ({ @@ -21,5 +21,5 @@ module.exports = async (ctx) => { description: `
${item.temperature}° ${item.title}
${item.displayPrice}`, link: item.url, })), - }; + }); }; diff --git a/lib/v2/hotukdeals/index.js b/lib/v2/hotukdeals/index.js index b112ff33f..5efac2718 100644 --- a/lib/v2/hotukdeals/index.js +++ b/lib/v2/hotukdeals/index.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) => { - let type = ctx.params.type; + let type = ctx.req.param('type'); if (type === 'highlights') { type = ''; } @@ -12,11 +12,11 @@ module.exports = async (ctx) => { Referer: `https://www.hotukdeals.com/${type}`, }, }); - const $ = cheerio.load(data.data.data.content); + const $ = load(data.data.data.content); const list = $('article.thread'); - ctx.state.data = { + ctx.set('data', { title: `hotukdeals ${type}`, link: `https://www.hotukdeals.com/${type}`, item: list @@ -30,5 +30,5 @@ module.exports = async (ctx) => { }) .get() .reverse(), - }; + }); }; diff --git a/lib/v2/houxu/events.js b/lib/v2/houxu/events.js index 1b5fb08ef..8b94b6d32 100644 --- a/lib/v2/houxu/events.js +++ b/lib/v2/houxu/events.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const rootUrl = 'https://houxu.app'; - const apiUrl = `${rootUrl}/api/1/events?limit=${ctx.query.limit ?? 50}`; + const apiUrl = `${rootUrl}/api/1/events?limit=${ctx.req.query('limit') ?? 50}`; const currentUrl = `${rootUrl}/events`; const response = await got({ @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: '后续 - 专栏', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/houxu/index.js b/lib/v2/houxu/index.js index dd599458a..b9acd1db3 100644 --- a/lib/v2/houxu/index.js +++ b/lib/v2/houxu/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const rootUrl = 'https://houxu.app'; - const apiUrl = `${rootUrl}/api/1/records/index?limit=${ctx.query.limit ?? 50}`; + const apiUrl = `${rootUrl}/api/1/records/index?limit=${ctx.req.query('limit') ?? 50}`; const response = await got({ method: 'get', @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: '后续 - 热点', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/houxu/lives.js b/lib/v2/houxu/lives.js index d3c0b5f3a..328a7dd99 100644 --- a/lib/v2/houxu/lives.js +++ b/lib/v2/houxu/lives.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 rootUrl = 'https://houxu.app'; const apiUrl = `${rootUrl}/api/1/lives/${id}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', - url: `${apiUrl}/threads?limit=${ctx.query.limit ?? 500}`, + url: `${apiUrl}/threads?limit=${ctx.req.query('limit') ?? 500}`, }); const items = response.data.results.map((item) => ({ @@ -26,10 +26,10 @@ module.exports = async (ctx) => { description: item.link.description, })); - ctx.state.data = { + ctx.set('data', { title: `后续 - ${pageResponse.data.title}`, link: currentUrl, item: items, description: pageResponse.data.summary, - }; + }); }; diff --git a/lib/v2/houxu/memory.js b/lib/v2/houxu/memory.js index b988e166f..1410f7630 100644 --- a/lib/v2/houxu/memory.js +++ b/lib/v2/houxu/memory.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const rootUrl = 'https://houxu.app'; - const apiUrl = `${rootUrl}/api/1/lives/updated?limit=${ctx.query.limit ?? 50}`; + const apiUrl = `${rootUrl}/api/1/lives/updated?limit=${ctx.req.query('limit') ?? 50}`; const currentUrl = `${rootUrl}/memory`; const response = await got({ @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: '后续 - 跟踪', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/howtoforge/rss.js b/lib/v2/howtoforge/rss.js index 74ffa6860..25d25d534 100644 --- a/lib/v2/howtoforge/rss.js +++ b/lib/v2/howtoforge/rss.js @@ -1,10 +1,10 @@ -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://www.howtoforge.com'; const response = await got(`${currentUrl}/feed.rss`); - const $ = cheerio.load(response.data, { xmlMode: true }); + const $ = load(response.data, { xmlMode: true }); const titleMain = $('channel > title').text(); const descriptionMain = $('channel > description').text(); const items = $('channel > item') @@ -23,10 +23,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: titleMain, description: descriptionMain, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hoyolab/news.js b/lib/v2/hoyolab/news.js index 7bc3cd664..72fe1ed1d 100644 --- a/lib/v2/hoyolab/news.js +++ b/lib/v2/hoyolab/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const logger = require('@/utils/logger'); -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'); const { HOST, NEW_LIST, OFFICIAL_PAGE_TYPE, POST_FULL, LINK, PUBLIC_IMG, PRIVATE_IMG } = require('./constant'); const { getI18nGameInfo, getI18nType } = require('./utils'); diff --git a/lib/v2/hoyolab/utils.js b/lib/v2/hoyolab/utils.js index 71790dcc8..64feb1be0 100644 --- a/lib/v2/hoyolab/utils.js +++ b/lib/v2/hoyolab/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const getGameInfoList = (tryGet) => tryGet('hoyolab:gameNameList', async () => { diff --git a/lib/v2/hpoi/all.js b/lib/v2/hpoi/all.js index 593123a11..898049ac1 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.params.order)); +module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('all', 0, ctx.req.param('order'))); diff --git a/lib/v2/hpoi/banner-item.js b/lib/v2/hpoi/banner-item.js index 2a4df24bb..8eb61c298 100644 --- a/lib/v2/hpoi/banner-item.js +++ b/lib/v2/hpoi/banner-item.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const link = 'https://www.hpoi.net/bannerItem/list?categoryId=0&bannerItemType=0&subType=0&page=1'; @@ -7,8 +7,8 @@ module.exports = async (ctx) => { method: 'get', url: link, }); - const $ = cheerio.load(response.data); - ctx.state.data = { + const $ = load(response.data); + ctx.set('data', { title: `Hpoi 手办维基 - 热门推荐`, link, item: $('#content .item') @@ -22,5 +22,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/hpoi/character.js b/lib/v2/hpoi/character.js index 5e6e67e6a..9cdb6dbd8 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.params.id, ctx.params.order)); +module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('character', ctx.req.param('id'), ctx.req.param('order'))); diff --git a/lib/v2/hpoi/info.js b/lib/v2/hpoi/info.js index c35f935f7..9dec70655 100644 --- a/lib/v2/hpoi/info.js +++ b/lib/v2/hpoi/info.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 { type = 'all' } = ctx.params; @@ -13,11 +13,11 @@ module.exports = async (ctx) => { catType: type, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.home-info') .map((_, ele) => { - const $item = cheerio.load(ele); + const $item = load(ele); const leftNode = $item('.overlay-container'); const relativeLink = leftNode.find('a').first().attr('href'); const typeName = leftNode.find('.type-name').first().text(); @@ -42,10 +42,10 @@ module.exports = async (ctx) => { model: '模型', }; const title = `手办维基 - 情报 - ${typeToLabel[type]}`; - ctx.state.data = { + ctx.set('data', { title, link: `${baseUrl}/user/home?type=info&catType=${type}`, description: title, item: items, - }; + }); }; diff --git a/lib/v2/hpoi/user.js b/lib/v2/hpoi/user.js index adcf14b68..5ca89d6b9 100644 --- a/lib/v2/hpoi/user.js +++ b/lib/v2/hpoi/user.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const root_url = 'https://www.hpoi.net'; @@ -20,7 +20,7 @@ module.exports = async (ctx) => { url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.collect-hobby-list-small') .map((_, item) => { item = $(item); @@ -34,10 +34,10 @@ module.exports = async (ctx) => { const title = $('.hpoi-collect-head .info p').eq(0).text() + '的手办 - ' + titleMap[caty]; - ctx.state.data = { + ctx.set('data', { title, link: url, item: list, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/hpoi/utils.js b/lib/v2/hpoi/utils.js index 354c128ee..b5d4d4c56 100644 --- a/lib/v2/hpoi/utils.js +++ b/lib/v2/hpoi/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 host = 'https://www.hpoi.net'; @@ -27,7 +27,7 @@ const ProcessFeed = async (type, id, order) => { Referer: host, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); return { title: `Hpoi 手办维基 - ${MAPs[type].title}${id ? ` ${id}` : ''}`, link, diff --git a/lib/v2/hpoi/work.js b/lib/v2/hpoi/work.js index 5b9c1980b..59dd1c960 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.params.id, ctx.params.order)); +module.exports = async (ctx) => (ctx.state.data = await ProcessFeed('work', ctx.req.param('id'), ctx.req.param('order'))); diff --git a/lib/v2/hrbeu/gx/card.js b/lib/v2/hrbeu/gx/card.js index 7b1315935..a89f180a3 100644 --- a/lib/v2/hrbeu/gx/card.js +++ b/lib/v2/hrbeu/gx/card.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 rootUrl = 'http://news.hrbeu.edu.cn'; module.exports = async (ctx) => { - const column = ctx.params.column; - const id = ctx.params.id || ''; + const column = ctx.req.param('column'); + const id = ctx.req.param('id') || ''; const toUrl = id === '' ? `${rootUrl}/${column}.htm` : `${rootUrl}/${column}/${id}.htm`; const response = await got(toUrl, { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const bigTitle = $('div.list-left-tt') .text() @@ -29,9 +29,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: '工学-' + bigTitle, link: toUrl, item: card, - }; + }); }; diff --git a/lib/v2/hrbeu/gx/list.js b/lib/v2/hrbeu/gx/list.js index 557aaa0cf..1cf068aa6 100644 --- a/lib/v2/hrbeu/gx/list.js +++ b/lib/v2/hrbeu/gx/list.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 rootUrl = 'http://news.hrbeu.edu.cn'; module.exports = async (ctx) => { - const column = ctx.params.column; - const id = ctx.params.id || ''; + const column = ctx.req.param('column'); + const id = ctx.req.param('id') || ''; const toUrl = id === '' ? `${rootUrl}/${column}.htm` : `${rootUrl}/${column}/${id}.htm`; const response = await got(toUrl, { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const bigTitle = $('div.list-left-tt') .text() @@ -42,7 +42,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (item.link.includes('info')) { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.v_news_content').html(); } else { item.description = '本文需跳转,请点击标题后阅读'; @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '工学-' + bigTitle, link: toUrl, item: items, - }; + }); }; diff --git a/lib/v2/hrbeu/job/bigemploy.js b/lib/v2/hrbeu/job/bigemploy.js index 0a3986fb7..b4bf2a84a 100644 --- a/lib/v2/hrbeu/job/bigemploy.js +++ b/lib/v2/hrbeu/job/bigemploy.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const response = await got('http://job.hrbeu.edu.cn/HrbeuJY/web'); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.articlecontent') .map((_, item) => ({ @@ -16,10 +16,10 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: '大型招聘会', link: 'http://job.hrbeu.edu.cn/HrbeuJY/web', item: list, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/hrbeu/job/calendar.js b/lib/v2/hrbeu/job/calendar.js index f3b3f1a46..0da755197 100644 --- a/lib/v2/hrbeu/job/calendar.js +++ b/lib/v2/hrbeu/job/calendar.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const rootUrl = 'http://job.hrbeu.edu.cn'; @@ -27,7 +27,7 @@ module.exports = async (ctx) => { const todayResponse = await got(`${rootUrl}${link}`); - const $ = cheerio.load(todayResponse.data); + const $ = load(todayResponse.data); const list = $('li.clearfix') .map((_, item) => ({ @@ -37,10 +37,10 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: '今日招聘会', link: 'http://job.hrbeu.edu.cn/HrbeuJY/web', item: list, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/hrbeu/job/list.js b/lib/v2/hrbeu/job/list.js index 1227099b2..c752b7303 100644 --- a/lib/v2/hrbeu/job/list.js +++ b/lib/v2/hrbeu/job/list.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); const rootUrl = 'http://job.hrbeu.edu.cn'; @@ -16,7 +16,7 @@ const idMap = { }; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got(idMap[id].url, { headers: { @@ -24,7 +24,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('li.list_item.i1') .map((_, item) => { @@ -45,7 +45,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (item.link.includes('HrbeuJY')) { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article').html(); } else if (new URL(item.link).hostname === 'mp.weixin.qq.com') { await finishArticleItem(item); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '就业服务平台-' + idMap[id].name, link: idMap[id].url, item: items, - }; + }); }; diff --git a/lib/v2/hrbeu/uae/news.js b/lib/v2/hrbeu/uae/news.js index d40e4ceba..3173789ad 100644 --- a/lib/v2/hrbeu/uae/news.js +++ b/lib/v2/hrbeu/uae/news.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'; const { finishArticleItem } = require('@/utils/wechat-mp'); module.exports = async (ctx) => { - const id = ctx.params.id.replaceAll('-', '/'); + const id = ctx.req.param('id').replaceAll('-', '/'); const host = 'http://uae.hrbeu.edu.cn'; const url = `${host}/${id}.htm`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('h2').text(); const items = $('li.wow.fadeInUp') .map((_, item) => { @@ -42,11 +42,11 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (new URL(item.link).hostname === 'uae.hrbeu.edu.cn') { const resp = await got(item.link); - const $1 = cheerio.load(resp.data); + const $1 = load(resp.data); item.description = $1('div.art-body').html(); } else if (new URL(item.link).hostname === 'news.hrbeu.edu.cn') { const resp = await got(item.link); - const $1 = cheerio.load(resp.data); + const $1 = load(resp.data); item.description = $1('div#print').html(); } else if (new URL(item.link).hostname === 'mp.weixin.qq.com') { await finishArticleItem(item); @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `水声工程学院 - ${title}`, link: url, item, - }; + }); }; diff --git a/lib/v2/hrbeu/ugs/news.js b/lib/v2/hrbeu/ugs/news.js index 84a5b189a..570319f10 100644 --- a/lib/v2/hrbeu/ugs/news.js +++ b/lib/v2/hrbeu/ugs/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 baseUrl = 'http://ugs.hrbeu.edu.cn'; @@ -53,15 +53,15 @@ const authorMap = { }; module.exports = async (ctx) => { - const author = ctx.params.author || 'gztz'; - const category = ctx.params.category || 'all'; + const author = ctx.req.param('author') || 'gztz'; + const category = ctx.req.param('category') || 'all'; const link = baseUrl + authorMap[author][category] + '/list.htm'; const response = await got(link, { headers: { Referer: baseUrl, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.wp_article_list_table .border9') .toArray() @@ -79,7 +79,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (item.link.includes('.htm')) { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.wp_articlecontent').html().trim(); } else { @@ -90,9 +90,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '哈尔滨工程大学本科生院工作通知', link, item: out, - }; + }); }; diff --git a/lib/v2/hrbeu/yjsy/list.js b/lib/v2/hrbeu/yjsy/list.js index be655c41e..3bd8dd987 100644 --- a/lib/v2/hrbeu/yjsy/list.js +++ b/lib/v2/hrbeu/yjsy/list.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'; const rootUrl = 'http://yjsy.hrbeu.edu.cn'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got(`${rootUrl}/${id}/list.htm`, { headers: { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const bigTitle = $('div [id=lanmuInnerMiddleBigClass_right]') .find('div [portletmode=simpleColumnAttri]') @@ -39,7 +39,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (item.link.includes('page.htm')) { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.wp_articlecontent').html(); } else { item.description = '本文需跳转,请点击标题后阅读'; @@ -49,9 +49,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '研究生院-' + bigTitle, link: rootUrl.concat('/', id, '/list.htm'), item: items, - }; + }); }; diff --git a/lib/v2/hrbust/jwzx.js b/lib/v2/hrbust/jwzx.js index a3c363375..67eb4090c 100644 --- a/lib/v2/hrbust/jwzx.js +++ b/lib/v2/hrbust/jwzx.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); const typeMap = { @@ -17,20 +17,20 @@ const typeMap = { }; module.exports = async (ctx) => { - const page = ctx.params.page || '12'; - const base = utils.columnIdBase(ctx.params.type) + '&pagingNumberPer=' + page; + const page = ctx.req.param('page') || '12'; + const base = utils.columnIdBase(ctx.req.param('type')) + '&pagingNumberPer=' + page; const res = await got(base); const info = utils.fetchAllArticle(res.data, utils.JWZXBASE); const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache))); - // ctx.state.json = { + // ctx.set('json', { // info, // }; - ctx.state.data = { - title: '哈理工教务处' + typeMap[ctx.params.type || 354].name, + ctx.set('data', { + title: '哈理工教务处' + typeMap[ctx.req.param('type') || 354].name, link: base, item: details, - }; + }); }; diff --git a/lib/v2/hrbust/utils.js b/lib/v2/hrbust/utils.js index bb1899d63..a9ea122d9 100644 --- a/lib/v2/hrbust/utils.js +++ b/lib/v2/hrbust/utils.js @@ -1,9 +1,9 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; // const base = 'http://hrbust.edu.cn'; const jwzxBase = 'http://jwzx.hrbust.edu.cn/homepage/'; @@ -18,7 +18,7 @@ const renderDesc = (desc) => const detailPage = (e, cache) => cache.tryGet(e.detailPage, async () => { const result = await got(e.detailPage); - const $ = cheerio.load(result.data); + const $ = load(result.data); const title = $('div#article h2').text().trim(); const desc = $('div.body').html() && @@ -36,11 +36,11 @@ const detailPage = (e, cache) => }); const fetchAllArticle = (data, base) => { - const $ = cheerio.load(data); + const $ = load(data); const article = $('.articleList li div'); const info = article .map((i, e) => { - const c = cheerio.load(e); + const c = load(e); const r = { title: c('a').first().text().trim(), detailPage: new URL(c('a').attr('href'), base).href, diff --git a/lib/v2/huanqiu/index.js b/lib/v2/huanqiu/index.js index 8a45cc6d2..f24b83a8f 100644 --- a/lib/v2/huanqiu/index.js +++ b/lib/v2/huanqiu/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 { isValidHost } = require('@/utils/valid-host'); function getKeysRecursive(dic, key, attr, array) { @@ -15,7 +15,7 @@ function getKeysRecursive(dic, key, attr, array) { } module.exports = async (ctx) => { - const category = ctx.params.category ?? 'china'; + const category = ctx.req.param('category') ?? 'china'; if (!isValidHost(category)) { throw new Error('Invalid category'); } @@ -33,7 +33,7 @@ module.exports = async (ctx) => { .join(','); const req = await got({ method: 'get', - url: `${host}/api/list?node=${nodes}&offset=0&limit=${ctx.query.limit ?? 20}`, + url: `${host}/api/list?node=${nodes}&offset=0&limit=${ctx.req.query('limit') ?? 20}`, }).json(); let items = req.list @@ -50,7 +50,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('textarea.article-content').text(); item.author = content('span', '.source').text(); @@ -62,11 +62,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${name} - 环球网`, link: host, description: '环球网', language: 'zh-cn', item: items, - }; + }); }; diff --git a/lib/v2/huggingface/blog-zh.js b/lib/v2/huggingface/blog-zh.js index 0682fc1c9..1ebce09f9 100644 --- a/lib/v2/huggingface/blog-zh.js +++ b/lib/v2/huggingface/blog-zh.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 { body: response } = await got('https://huggingface.co/blog/zh'); - const $ = cheerio.load(response); + const $ = load(response); /** @type {Array<{blog: {local: string, title: string, author: string, thumbnail: string, date: string, tags: Array}, blogUrl: string, lang: 'zh', link: string}>} */ const papers = $('div[data-target="BlogThumbnail"]') @@ -26,9 +26,9 @@ module.exports = async (ctx) => { author: item.blog.author, })); - ctx.state.data = { + ctx.set('data', { title: 'Huggingface 中文博客', link: 'https://huggingface.co/blog/zh', item: items, - }; + }); }; diff --git a/lib/v2/huggingface/daily-papers.js b/lib/v2/huggingface/daily-papers.js index 53bbafe36..aeb0ffd0e 100644 --- a/lib/v2/huggingface/daily-papers.js +++ b/lib/v2/huggingface/daily-papers.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 { body: response } = await got('https://huggingface.co/papers'); - const $ = cheerio.load(response); + const $ = load(response); const papers = $('main > div[data-target="DailyPapers"]').data('props'); const items = papers.dailyPapers @@ -18,9 +18,9 @@ module.exports = async (ctx) => { })) .sort((a, b) => b.upvotes - a.upvotes); - ctx.state.data = { + ctx.set('data', { title: 'Huggingface Daily Papers', link: 'https://huggingface.co/papers', item: items, - }; + }); }; diff --git a/lib/v2/hunanpea/rsks.js b/lib/v2/hunanpea/rsks.js index 4d566d076..bfdb9c606 100644 --- a/lib/v2/hunanpea/rsks.js +++ b/lib/v2/hunanpea/rsks.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 baseUrl = 'http://rsks.hunanpea.com'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/Category/${guid}/ArticlesByCategory.do?PageIndex=1`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#column_content > ul > li') .toArray() .map((item) => { @@ -25,7 +25,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 = $('.content_area').html(); @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.sitemap h2').text()} - ${$('head title').text()}`, link, item: items, - }; + }); }; diff --git a/lib/v2/hunau/utils/common.js b/lib/v2/hunau/utils/common.js index 83c86ce1d..21e34f13d 100644 --- a/lib/v2/hunau/utils/common.js +++ b/lib/v2/hunau/utils/common.js @@ -1,6 +1,6 @@ // common.js -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const categoryTitle = require('./category-title'); const newsContent = require('./news-content'); const indexPage = require('./index-page'); @@ -16,7 +16,7 @@ async function getContent(ctx, { baseHost, baseCategory, baseType, baseTitle, ba const url = `${baseURl}/${indexPage(page)}`; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $(baseClass) .toArray() @@ -47,7 +47,7 @@ async function getContent(ctx, { baseHost, baseCategory, baseType, baseTitle, ba ) ); - ctx.state.data = { + ctx.set('data', { // 源标题 title, description, @@ -55,7 +55,7 @@ async function getContent(ctx, { baseHost, baseCategory, baseType, baseTitle, ba link: url, // 源文章 item: items, - }; + }); } module.exports = getContent; diff --git a/lib/v2/hunau/utils/news-content.js b/lib/v2/hunau/utils/news-content.js index 1168aa81e..815f30a3c 100644 --- a/lib/v2/hunau/utils/news-content.js +++ b/lib/v2/hunau/utils/news-content.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; async function newsContent(link, department = '') { try { @@ -12,7 +12,7 @@ async function newsContent(link, department = '') { }, }); // 加载文章内容 - const $ = cheerio.load(response); + const $ = load(response); let reg = /\d{4}(?:\/\d{2}){2}/; let element = '.newscontent'; diff --git a/lib/v2/huoxian/zone.js b/lib/v2/huoxian/zone.js index 3ecd56a65..d0c301ffc 100644 --- a/lib/v2/huoxian/zone.js +++ b/lib/v2/huoxian/zone.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got('https://zone.huoxian.cn/api/discussions?sort=-createdAt'); @@ -11,9 +11,9 @@ module.exports = async (ctx) => { author: data.included.find((i) => i.id === item.relationships.user.data.id).attributes.displayName, category: data.included.filter((i) => item.relationships.tags.data.map((t) => t.id).includes(i.id) && i.type === 'tags').map((i) => i.attributes.name), })); - ctx.state.data = { + ctx.set('data', { title: '火线 Zone-安全攻防社区', link: 'https://zone.huoxian.cn/', item: items, - }; + }); }; diff --git a/lib/v2/hupu/all.js b/lib/v2/hupu/all.js index bb3c177d1..da1515323 100644 --- a/lib/v2/hupu/all.js +++ b/lib/v2/hupu/all.js @@ -1,12 +1,12 @@ -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'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? 'topic-daily'; + const id = ctx.req.param('id') ?? 'topic-daily'; const rootUrl = 'https://bbs.hupu.com'; const currentUrl = `${rootUrl}/${id}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('div.t-info > a, a.p-title') .toArray() @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const videos = []; @@ -65,9 +65,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `虎扑社区 - ${$('.middle-title, .bbs-sl-web-intro-detail-title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hupu/bbs.js b/lib/v2/hupu/bbs.js index e77916a39..13a798eb8 100644 --- a/lib/v2/hupu/bbs.js +++ b/lib/v2/hupu/bbs.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '34'; - const order = ctx.params.order ?? '1'; + const id = ctx.req.param('id') ?? '34'; + const order = ctx.req.param('order') ?? '1'; const rootUrl = 'https://bbs.hupu.com'; const apiRootUrl = 'https://games.mobileapi.hupu.com'; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.page-icon').remove(); @@ -43,7 +43,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.seo-dom').remove(); @@ -76,10 +76,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `虎扑社区 - ${$('.bbs-sl-web-intro-detail-title').text()}`, link: currentUrl, item: items, description: $('.bbs-sl-web-intro-detail-desc-text').first().text(), - }; + }); }; diff --git a/lib/v2/hupu/index.js b/lib/v2/hupu/index.js index 9494f4eff..7bb06255c 100644 --- a/lib/v2/hupu/index.js +++ b/lib/v2/hupu/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 categories = { nba: { @@ -19,7 +19,7 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'soccer'; + const category = ctx.req.param('category') ?? 'soccer'; const rootUrl = 'https://m.hupu.com'; const currentUrl = `${rootUrl}/${category}`; @@ -48,7 +48,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('.bbs-user-info-name, .bbs-user-wrapper-content-name-span').text(); item.category = content('.basketballTobbs_tag > a, .tag-player-team') @@ -72,9 +72,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `虎扑 - ${categories[category].title}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/hust/aia/news.js b/lib/v2/hust/aia/news.js index 4a86a685f..00121e8fc 100755 --- a/lib/v2/hust/aia/news.js +++ b/lib/v2/hust/aia/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'https://aia.hust.edu.cn/xyxw.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list li'); - ctx.state.data = { + ctx.set('data', { title: '华科人工智能和自动化学院新闻', link, item: @@ -22,5 +22,5 @@ module.exports = async (ctx) => { link: new URL(item.find('a').attr('href'), link).href, }; }), - }; + }); }; diff --git a/lib/v2/hust/aia/notice.js b/lib/v2/hust/aia/notice.js index 7d8b15b79..398e0dc99 100755 --- a/lib/v2/hust/aia/notice.js +++ b/lib/v2/hust/aia/notice.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 { type } = ctx.params; const baseUrl = 'https://aia.hust.edu.cn'; const link = `${baseUrl}/tzgg${type ? `/${type}` : ''}.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list li'); const title = $('title').text(); - ctx.state.data = { + ctx.set('data', { title, link, item: @@ -25,5 +25,5 @@ module.exports = async (ctx) => { link: new URL(item.find('a').attr('href'), link).href, }; }), - }; + }); }; diff --git a/lib/v2/hust/yjs.js b/lib/v2/hust/yjs.js index 608fdbbdb..1c9fa39ce 100644 --- a/lib/v2/hust/yjs.js +++ b/lib/v2/hust/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://gszs.hust.edu.cn/zsxx/ggtz.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.main_conRCb 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/huxiu/brief-column.js b/lib/v2/huxiu/brief-column.js index 0fc61b0e4..02259189f 100644 --- a/lib/v2/huxiu/brief-column.js +++ b/lib/v2/huxiu/brief-column.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { apiBriefRootUrl, processItems, fetchBriefColumnData } = require('./util'); module.exports = async (ctx) => { const { id } = ctx.params; - 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 apiUrl = new URL('briefColumn/getContentListByCategoryId', apiBriefRootUrl).href; @@ -22,8 +22,8 @@ module.exports = async (ctx) => { const data = await fetchBriefColumnData(id); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/channel.js b/lib/v2/huxiu/channel.js index ff171d407..c49895017 100644 --- a/lib/v2/huxiu/channel.js +++ b/lib/v2/huxiu/channel.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { const { id } = ctx.params; - 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 apiUrl = new URL(`web/${id ? 'channel' : 'article'}/articleList`, apiArticleRootUrl).href; const currentUrl = new URL(id ? `channel/${id}.html` : 'article', rootUrl).href; @@ -21,8 +21,8 @@ module.exports = async (ctx) => { const data = await fetchData(currentUrl); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/club.js b/lib/v2/huxiu/club.js index 4ad6db90e..d536295c9 100644 --- a/lib/v2/huxiu/club.js +++ b/lib/v2/huxiu/club.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { apiBriefRootUrl, processItems, fetchClubData } = require('./util'); module.exports = async (ctx) => { const { id } = ctx.params; - 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 apiUrl = new URL('club/briefList', apiBriefRootUrl).href; @@ -23,8 +23,8 @@ module.exports = async (ctx) => { const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/collection.js b/lib/v2/huxiu/collection.js index 4ab183cf6..58e19d799 100644 --- a/lib/v2/huxiu/collection.js +++ b/lib/v2/huxiu/collection.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { const { id } = 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 apiUrl = new URL('web/collection/articleList', apiArticleRootUrl).href; const currentUrl = new URL(`collection/${id}.html`, rootUrl).href; @@ -20,8 +20,8 @@ module.exports = async (ctx) => { const data = await fetchData(currentUrl); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/member.js b/lib/v2/huxiu/member.js index 321973852..4de314d73 100644 --- a/lib/v2/huxiu/member.js +++ b/lib/v2/huxiu/member.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiMemberRootUrl, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { const { id, type = 'article' } = 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 apiUrl = new URL(`web/${type}/${type}List`, apiMemberRootUrl).href; const currentUrl = new URL(`member/${id}${type === 'article' ? '' : `/${type}`}.html`, rootUrl).href; @@ -20,8 +20,8 @@ module.exports = async (ctx) => { const data = await fetchData(currentUrl); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/moment.js b/lib/v2/huxiu/moment.js index 96804a038..5c6da1603 100644 --- a/lib/v2/huxiu/moment.js +++ b/lib/v2/huxiu/moment.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiMomentRootUrl, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { - 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 apiUrl = new URL('web-v2/moment/feed', apiMomentRootUrl).href; const currentUrl = new URL('moment', rootUrl).href; @@ -18,8 +18,8 @@ module.exports = async (ctx) => { const data = await fetchData(currentUrl); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/search.js b/lib/v2/huxiu/search.js index 041b09d78..49ee29e3e 100644 --- a/lib/v2/huxiu/search.js +++ b/lib/v2/huxiu/search.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, apiSearchRootUrl, generateSignature, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { const { keyword } = ctx.params; - 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 apiUrl = new URL('api/article', apiSearchRootUrl).href; const currentUrl = rootUrl; @@ -28,8 +28,8 @@ module.exports = async (ctx) => { ctx.state.json = response.data.datalist; - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/tag.js b/lib/v2/huxiu/tag.js index 296831594..4353599c7 100644 --- a/lib/v2/huxiu/tag.js +++ b/lib/v2/huxiu/tag.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { rootUrl, processItems, fetchData } = require('./util'); module.exports = async (ctx) => { const { id } = 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 apiUrl = new URL('v2_action/tag_article_list', rootUrl).href; const currentUrl = new URL(`tags/${id}.html`, rootUrl).href; @@ -19,8 +19,8 @@ module.exports = async (ctx) => { const data = await fetchData(currentUrl); - ctx.state.data = { + ctx.set('data', { item: items, ...data, - }; + }); }; diff --git a/lib/v2/huxiu/util.js b/lib/v2/huxiu/util.js index d25c85b67..c2a0bde90 100644 --- a/lib/v2/huxiu/util.js +++ b/lib/v2/huxiu/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 CryptoJS = require('crypto-js'); @@ -21,7 +21,7 @@ const apiSearchRootUrl = `https://search-api.${domain}`; * @returns {string} - The cleaned up HTML data. */ const cleanUpHTML = (data) => { - const $ = cheerio.load(data); + const $ = load(data); $('div.neirong-shouquan').remove(); $('em.vote__bar, div.vote__btn, div.vote__time').remove(); @@ -85,7 +85,7 @@ const fetchBriefColumnData = async (id) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const subtitle = `${data.name}-${data.sub_name}`; const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; @@ -120,7 +120,7 @@ const fetchClubData = async (id) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const title = $('title').text(); const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; @@ -155,7 +155,7 @@ const fetchClubData = async (id) => { const fetchData = async (url) => { const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; const author = $('meta[name="author"]').prop('content'); diff --git a/lib/v2/ianspriggs/index.js b/lib/v2/ianspriggs/index.js index b563df633..a36ece900 100644 --- a/lib/v2/ianspriggs/index.js +++ b/lib/v2/ianspriggs/index.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 = 'portraits' } = 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 author = 'Ian Spriggs'; const rootUrl = 'https://ianspriggs.com'; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.work-item') .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); const images = content('div.work-item img') .toArray() @@ -76,7 +76,7 @@ module.exports = async (ctx) => { const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -86,5 +86,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('a[aria-current="page"] span.menu-title-text').text(), author, - }; + }); }; diff --git a/lib/v2/icac/news.js b/lib/v2/icac/news.js index 8744b56eb..38bc1fa2f 100644 --- a/lib/v2/icac/news.js +++ b/lib/v2/icac/news.js @@ -1,16 +1,16 @@ -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'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const BASE_WITH_LANG = utils.langBase(ctx.params.lang); + const BASE_WITH_LANG = utils.langBase(ctx.req.param('lang')); const res = await got.get(`${BASE_WITH_LANG}/press/index.html`); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.pressItem.clearfix') .map((_, e) => { - const c = cheerio.load(e); + const c = load(e); return { title: c('.hd a').text(), link: `${utils.BASE_URL}${c('.hd a').attr('href')}`, @@ -25,7 +25,7 @@ module.exports = async (ctx) => { url: item.link, }); - const c = cheerio.load(detailResponse.data); + const c = load(detailResponse.data); c('.btn_download').remove(); c('.col-3-wrap.clearfix.pressPhoto div').removeAttr('class'); const des = c('.pressContent.full').html(); @@ -36,11 +36,11 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: 'ICAC 新闻公布', link: `${BASE_WITH_LANG}/press/index.html`, description: 'ICAC 新闻公布', - language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc, + language: ctx.req.param('lang') ? utils.LANG_TYPE[ctx.req.param('lang')] : utils.LANG_TYPE.sc, item: items, - }; + }); }; diff --git a/lib/v2/icbc/whpj.js b/lib/v2/icbc/whpj.js index 3a4f2632e..e1361a799 100644 --- a/lib/v2/icbc/whpj.js +++ b/lib/v2/icbc/whpj.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { // yes, insecure // their openssl version isn't safe anyway (https://stackoverflow.com/questions/75763525/curl-35-error0a000152ssl-routinesunsafe-legacy-renegotiation-disabled) const { data } = await got('http://papi.icbc.com.cn/exchanges/ns/getLatest'); - const format = ctx.params.format; + const format = ctx.req.param('format'); - ctx.state.data = { + ctx.set('data', { title: '中国工商银行外汇牌价', link: 'https://www.icbc.com.cn/column/1438058341489590354.html', item: data.data.map((item) => { @@ -53,5 +53,5 @@ module.exports = async (ctx) => { guid: `${name} ${item.publishDate} ${item.publishTime}`, }; }), - }; + }); }; diff --git a/lib/v2/idolypride/news.js b/lib/v2/idolypride/news.js index b49ba727a..eb868e8f7 100644 --- a/lib/v2/idolypride/news.js +++ b/lib/v2/idolypride/news.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 response = await got({ @@ -9,7 +9,7 @@ module.exports = async (ctx) => { }); const list = response.data; - ctx.state.data = { + ctx.set('data', { title: '偶像荣耀-新闻', link: 'https://idolypride.jp/news', item: list.map((item) => { @@ -25,5 +25,5 @@ module.exports = async (ctx) => { description: rendered, }; }), - }; + }); }; diff --git a/lib/v2/ieee-security/sp.js b/lib/v2/ieee-security/sp.js index 74bab5a6e..75448fd44 100644 --- a/lib/v2/ieee-security/sp.js +++ b/lib/v2/ieee-security/sp.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 url = 'https://www.ieee-security.org/'; // https://www.ieee-security.org/TC/SP2023/program-papers.html @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const responses = await got.all(urlList.map((url) => got(url))); const items = responses.map((response) => { - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('div.panel-body > div.list-group-item') .toArray() .map((item) => { @@ -26,11 +26,11 @@ module.exports = async (ctx) => { }); }); - ctx.state.data = { + ctx.set('data', { title: 'S&P', link: `${url}TC/SP-Index.html`, description: 'IEEE Symposium on Security and Privacy Accepted Papers', allowEmpty: true, item: items.flat(), - }; + }); }; diff --git a/lib/v2/ieee/earlyaccess.js b/lib/v2/ieee/earlyaccess.js index e745714ed..887440c48 100644 --- a/lib/v2/ieee/earlyaccess.js +++ b/lib/v2/ieee/earlyaccess.js @@ -1,14 +1,14 @@ -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 isnumber = ctx.params.journal; - const sortType = ctx.params.sortType ?? 'vol-only-seq'; + const isnumber = ctx.req.param('journal'); + const sortType = ctx.req.param('sortType') ?? 'vol-only-seq'; const host = 'https://ieeexplore.ieee.org'; const jrnlUrl = `${host}/xpl/tocresult.jsp?isnumber=${isnumber}`; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { }) .json(); let list = response2.records.map((item) => { - const $2 = cheerio.load(item.articleTitle); + const $2 = load(item.articleTitle); const title = $2.text(); const link = item.htmlLink; const doi = item.doi; @@ -60,7 +60,7 @@ module.exports = async (ctx) => { if (item.abstract !== '') { const response3 = await got(`${host}${item.link}`); const { abstract } = JSON.parse(response3.body.match(/metadata=(.*);/)[1]); - const $3 = cheerio.load(abstract); + const $3 = load(abstract); item.abstract = $3.text(); item.description = renderDesc(item); } @@ -69,9 +69,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: jrnlName, link: jrnlUrl, item: list, - }; + }); }; diff --git a/lib/v2/ieee/journal.js b/lib/v2/ieee/journal.js index 3f177d0af..1ba924196 100644 --- a/lib/v2/ieee/journal.js +++ b/lib/v2/ieee/journal.js @@ -1,14 +1,14 @@ -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 punumber = ctx.params.journal; - const sortType = ctx.params.sortType ?? 'vol-only-seq'; + const punumber = ctx.req.param('journal'); + const sortType = ctx.req.param('sortType') ?? 'vol-only-seq'; const host = 'https://ieeexplore.ieee.org'; const jrnlUrl = `${host}/xpl/mostRecentIssue.jsp?punumber=${punumber}`; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { }) .json(); let list = response2.records.map((item) => { - const $2 = cheerio.load(item.articleTitle); + const $2 = load(item.articleTitle); const title = $2.text(); const link = item.htmlLink; const doi = item.doi; @@ -61,7 +61,7 @@ module.exports = async (ctx) => { if (item.abstract !== '') { const response3 = await got(`${host}${item.link}`); const { abstract } = JSON.parse(response3.body.match(/metadata=(.*);/)[1]); - const $3 = cheerio.load(abstract); + const $3 = load(abstract); item.abstract = $3.text(); item.description = renderDesc(item); } @@ -70,9 +70,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: jrnlName, link: jrnlUrl, item: list, - }; + }); }; diff --git a/lib/v2/ieee/recent.js b/lib/v2/ieee/recent.js index abd7d9ebf..285a89997 100644 --- a/lib/v2/ieee/recent.js +++ b/lib/v2/ieee/recent.js @@ -1,14 +1,14 @@ -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 punumber = ctx.params.journal; - const sortType = ctx.params.sortType ?? 'vol-only-seq'; + const punumber = ctx.req.param('journal'); + const sortType = ctx.req.param('sortType') ?? 'vol-only-seq'; const host = 'https://ieeexplore.ieee.org'; const jrnlUrl = `${host}/xpl/mostRecentIssue.jsp?punumber=${punumber}`; @@ -48,7 +48,7 @@ module.exports = async (ctx) => { }) .json(); let list = response2.records.map((item) => { - const $2 = cheerio.load(item.articleTitle); + const $2 = load(item.articleTitle); const title = $2.text(); const link = item.htmlLink; const doi = item.doi; @@ -78,7 +78,7 @@ module.exports = async (ctx) => { if (item.abstract !== '') { const response3 = await got(`${host}${item.link}`); const { abstract } = JSON.parse(response3.body.match(/metadata=(.*);/)[1]); - const $3 = cheerio.load(abstract); + const $3 = load(abstract); item.abstract = $3.text(); item.description = renderDesc(item); } @@ -87,9 +87,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${jrnlName} - Recent`, link: jrnlUrl, item: list, - }; + }); }; diff --git a/lib/v2/ielts/index.js b/lib/v2/ielts/index.js index 8737f819c..04c298a95 100644 --- a/lib/v2/ielts/index.js +++ b/lib/v2/ielts/index.js @@ -1,15 +1,16 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const targetUrl = 'https://ielts.neea.cn/allnews?locale=zh_CN'; -const config = require('@/config').value; +import { config } from '@/config'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const html = await ctx.cache.tryGet( targetUrl, async () => { - 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) => { @@ -28,7 +29,7 @@ module.exports = async (ctx) => { false ); - const $ = cheerio.load(html); + const $ = load(html); const list = $('#newsListUl li') .get() @@ -49,16 +50,16 @@ module.exports = async (ctx) => { url: item.link, }); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); item.description = $('.content').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: 'IELTS雅思最新消息', link: targetUrl, item: items, - }; + }); }; diff --git a/lib/v2/ifeng/feng.js b/lib/v2/ifeng/feng.js index c3e6057d8..38fd51015 100644 --- a/lib/v2/ifeng/feng.js +++ b/lib/v2/ifeng/feng.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { extractDoc, renderVideo } = require('./utils'); -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, type } = ctx.params; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(userResponse); + const $ = load(userResponse); const { sockpuppetInfo: allData } = JSON.parse( $('script') .text() @@ -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); const _allData = JSON.parse( $('script') @@ -59,11 +59,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `大风号-${mediaName}-${type === 'doc' ? '文章' : '视频'}`, description: `${honorDesc} ${description}`, image: `https:${logo}`, link: `https://ishare.ifeng.com/mediaShare/home/${id}/media`, item: items, - }; + }); }; diff --git a/lib/v2/ifeng/news.js b/lib/v2/ifeng/news.js index 6d3e7815f..95d36d072 100644 --- a/lib/v2/ifeng/news.js +++ b/lib/v2/ifeng/news.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 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://news.ifeng.com'; const currentUrl = `${rootUrl}${ctx.path.replace(/^\/news/, '')}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const newsStream = JSON.parse(response.data.match(/"newsstream":(\[.*?]),"cooperation"/)[1]); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/ifeng/utils.js b/lib/v2/ifeng/utils.js index 1cfb88054..582f6068d 100644 --- a/lib/v2/ifeng/utils.js +++ b/lib/v2/ifeng/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const extractDoc = (data) => diff --git a/lib/v2/ifi-audio/download.js b/lib/v2/ifi-audio/download.js index 85761ee3d..1b4eca3b0 100644 --- a/lib/v2/ifi-audio/download.js +++ b/lib/v2/ifi-audio/download.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://ifi-audio.com'; @@ -16,10 +16,10 @@ module.exports = async (ctx) => { body: 'action=ifi-ff-get-firmware&val=' + val + '&id=' + id, }); const markup = response.data.data.markup; - const $ = cheerio.load(markup); + const $ = load(markup); const latestTitle = $('li[data-category=firmware]:first h4').text(); const latestDownloadLink = $('li[data-category=firmware]:first a').attr('href'); - ctx.state.data = { + ctx.set('data', { title: 'iFi audio Download Hub', link: 'https://ifi-audio.com/download-hub/', description: 'iFi audio Download Hub', @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: latestDownloadLink, }, ], - }; + }); }; diff --git a/lib/v2/iguoguo/index.js b/lib/v2/iguoguo/index.js index 00fa98ea8..1ad3f15a9 100644 --- a/lib/v2/iguoguo/index.js +++ b/lib/v2/iguoguo/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 rootUrl = 'https://www.iguoguo.net'; const getChildrenFromCheerioRoot = (cheerioInstance) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a', '.post') .filter((_, x) => $(x).attr('href').endsWith('.html')) .filter((_, x) => $(x).children().eq(0).attr('src')) @@ -49,7 +49,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', '.post-info').text(); item.description = content('div.clearfix', '.post_content').html(); const comments = getChildrenFromCheerioRoot(content).reduce((accumulator, element) => getComments(accumulator, element), []); @@ -65,11 +65,11 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: '爱果果', link: currentUrl, description: '爱果果iguoguo是一个优秀酷站、h5、UI素材资源的发布分享平台,是设计师的灵感聚合地和素材下载源。', language: 'zh-cn', item: items, - }; + }); }; diff --git a/lib/v2/ikea/cn/family-offers.js b/lib/v2/ikea/cn/family-offers.js index ea2a8c3d9..0b9d14697 100644 --- a/lib/v2/ikea/cn/family-offers.js +++ b/lib/v2/ikea/cn/family-offers.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateProductItem } = require('./utils'); const familyPriceProductsRequest = ({ pageIndex = 1 }) => @@ -61,10 +61,10 @@ module.exports = async (ctx) => { const productResponses = await Promise.all(productRequests); const products = productResponses.flat(); - ctx.state.data = { + ctx.set('data', { title: 'IKEA 宜家 - 会员特惠', link: 'https://www.ikea.cn/cn/zh/offers/family-offers/', description: '会员特惠', item: products.map((element) => generateProductItem(element)), - }; + }); }; diff --git a/lib/v2/ikea/cn/low-price.js b/lib/v2/ikea/cn/low-price.js index 1057997f9..db5a944cd 100644 --- a/lib/v2/ikea/cn/low-price.js +++ b/lib/v2/ikea/cn/low-price.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateRequestHeaders, generateProductItem } = require('./utils'); module.exports = async (ctx) => { @@ -13,10 +13,10 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: 'IKEA 宜家 - 低价优选', link: 'https://www.ikea.cn/cn/zh/campaigns/wo3-men2-de-chao1-zhi2-di1-jia4-pub8b08af40', description: '低价优选', item: response.data.products.map((element) => generateProductItem(element)), - }; + }); }; diff --git a/lib/v2/ikea/cn/new.js b/lib/v2/ikea/cn/new.js index de36d3141..467f8ea3e 100644 --- a/lib/v2/ikea/cn/new.js +++ b/lib/v2/ikea/cn/new.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { generateRequestHeaders, generateProductItem } = require('./utils'); const request = ({ moreToken = '' }) => @@ -30,10 +30,10 @@ module.exports = async (ctx) => { const products = allProductSummaries.flat(); - ctx.state.data = { + ctx.set('data', { title: 'IKEA 宜家 - 当季新品推荐', link: 'https://www.ikea.cn/cn/zh/new/', description: '当季新品推荐', item: products.map((element) => generateProductItem(element)), - }; + }); }; diff --git a/lib/v2/ikea/cn/utils.js b/lib/v2/ikea/cn/utils.js index 404680874..0df848373 100644 --- a/lib/v2/ikea/cn/utils.js +++ b/lib/v2/ikea/cn/utils.js @@ -1,5 +1,5 @@ -const { art } = require('@/utils/render'); -const md5 = require('@/utils/md5'); +import { art } from '@/utils/render'; +import md5 from '@/utils/md5'; const path = require('path'); const generateRequestHeaders = () => { diff --git a/lib/v2/ikea/gb/new.js b/lib/v2/ikea/gb/new.js index 90cb78b3e..2ee504655 100644 --- a/lib/v2/ikea/gb/new.js +++ b/lib/v2/ikea/gb/new.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) => { @@ -45,10 +45,10 @@ module.exports = async (ctx) => { category: p.categoryPath.map((c) => c.name), })); - ctx.state.data = { + ctx.set('data', { title: 'New Products - Browse All New Furniture & Home Decor - IKEA', link, description: 'New products released by IKEA UK.', item: items, - }; + }); }; diff --git a/lib/v2/ikea/gb/offer.js b/lib/v2/ikea/gb/offer.js index 8e8bc2ea0..e2d4dfd05 100644 --- a/lib/v2/ikea/gb/offer.js +++ b/lib/v2/ikea/gb/offer.js @@ -1,13 +1,13 @@ -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'); module.exports = async (ctx) => { const link = 'https://www.ikea.com/gb/en/offers/'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const carousel = $('.pub__carousel-slide') .toArray() .map((e) => { @@ -60,10 +60,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'IKEA UK - Offers', link, description: 'Offers by IKEA UK.', item: [...carousel, ...banner], - }; + }); }; diff --git a/lib/v2/imagemagick/changelog.js b/lib/v2/imagemagick/changelog.js index a2fde8a64..863a60317 100644 --- a/lib/v2/imagemagick/changelog.js +++ b/lib/v2/imagemagick/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'; const md = require('markdown-it')({ html: true, }); @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: rawLogUrl, }); - const $ = cheerio.load(md.render(response.data)); + const $ = load(md.render(response.data)); const items = $('h2') .toArray() @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'ImageMagick - ChangeLog', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/imiker/jinghua.js b/lib/v2/imiker/jinghua.js index 1186e4682..7c91635bf 100644 --- a/lib/v2/imiker/jinghua.js +++ b/lib/v2/imiker/jinghua.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 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://ask.imiker.com'; const apiUrl = new URL('explore/main/list/', rootUrl).href; @@ -40,7 +40,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('h5.img-for-lazyload').each((_, e) => { const image = content(e).find('img'); @@ -72,7 +72,7 @@ module.exports = async (ctx) => { const description = '精华'; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${description}`, link: currentUrl, @@ -83,5 +83,5 @@ module.exports = async (ctx) => { subtitle: description, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/indiansinkuwait/latest.js b/lib/v2/indiansinkuwait/latest.js index a588bff9f..b02dafcf3 100644 --- a/lib/v2/indiansinkuwait/latest.js +++ b/lib/v2/indiansinkuwait/latest.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.indiansinkuwait.com'; module.exports = async (ctx) => { const { data: response } = await got(`${baseUrl}/latest-news`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.paragraphs .span4') .toArray() @@ -22,7 +22,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.pubDate = parseDate($('#ctl00_ContentPlaceHolder1_SpanAuthor').text()); $('#newsdetails h3, #ctl00_ContentPlaceHolder1_SpanAuthor, .noprint, [id^=div-gpt-ad]').remove(); @@ -33,11 +33,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.indiansinkuwait.com/apple-touch-icon-152x152-precomposed.png', link: `${baseUrl}/latest-news`, item: items, - }; + }); }; diff --git a/lib/v2/indienova/article.js b/lib/v2/indienova/article.js index fa3e89b0f..083e10098 100644 --- a/lib/v2/indienova/article.js +++ b/lib/v2/indienova/article.js @@ -1,24 +1,24 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { parseList, parseItem } = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let link = 'https://indienova.com/indie-game-news/'; if (type === 'development') { link = 'https://indienova.com/indie-game-development/'; } const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = parseList($); const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => parseItem(item)))); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, description: '独立游戏资讯 | indienova 独立游戏', item: items, - }; + }); }; diff --git a/lib/v2/indienova/column.js b/lib/v2/indienova/column.js index ccecbbe15..e2f693b58 100644 --- a/lib/v2/indienova/column.js +++ b/lib/v2/indienova/column.js @@ -1,20 +1,20 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { baseUrl, parseList, parseItem } = require('./utils'); module.exports = async (ctx) => { const { columnId } = ctx.params; const { data: response, url: link } = await got(`${baseUrl}/column/${columnId}`); - const $ = cheerio.load(response); + const $ = load(response); const list = parseList($); const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => parseItem(item)))); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/indienova/gamedb.js b/lib/v2/indienova/gamedb.js index e9c00e0c5..5a64cebbd 100644 --- a/lib/v2/indienova/gamedb.js +++ b/lib/v2/indienova/gamedb.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 { platform = 'all' } = ctx.params; const baseUrl = 'https://indienova.com'; const { data: response, url: link } = await got(`${baseUrl}/gamedb/recent/${platform}/p/1`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.related-game') .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); const featureBox = $('.feature-box'); if (featureBox.length) { @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/indienova/usergames.js b/lib/v2/indienova/usergames.js index 17053d462..732c871b2 100644 --- a/lib/v2/indienova/usergames.js +++ b/lib/v2/indienova/usergames.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 baseUrl = 'https://indienova.com'; const { data: response, url: link } = await got(`${baseUrl}/usergames`); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.steam-game') .toArray() @@ -24,7 +24,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 = $('.cover-image').prop('outerHTML') + $('.tab-container').html() + $('.swiper-wrapper').prop('outerHTML') + $('.postcontent').html(); item.pubDate = $('.gamedb-release').length ? timezone(parseDate($('.gamedb-release').text().replaceAll(/[()]/g, '')), +8) : null; @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/indienova/utils.js b/lib/v2/indienova/utils.js index 68f9cb141..96b419877 100644 --- a/lib/v2/indienova/utils.js +++ b/lib/v2/indienova/utils.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://indienova.com'; @@ -21,7 +21,7 @@ const parseList = ($) => const parseItem = async (item) => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('.single-post').html(); item.author = $('.header-info > a').text(); diff --git a/lib/v2/inewsweek/index.js b/lib/v2/inewsweek/index.js index 3b2813fed..d938ba3b9 100644 --- a/lib/v2/inewsweek/index.js +++ b/lib/v2/inewsweek/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const iconv = require('iconv-lite'); const rootUrl = 'http://news.inewsweek.cn'; module.exports = async (ctx) => { - const channel = ctx.params.channel; + const channel = ctx.req.param('channel'); const url = `${rootUrl}/${channel}`; const response = await got(url, { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); const items = await Promise.all( $('div.grid-item') .toArray() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); const fullText = $('div.contenttxt').html(); const time = timezone( parseDate( @@ -45,9 +45,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: items, - }; + }); }; diff --git a/lib/v2/infoq/recommend.js b/lib/v2/infoq/recommend.js index 9296f174b..056e22a66 100644 --- a/lib/v2/infoq/recommend.js +++ b/lib/v2/infoq/recommend.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); module.exports = async (ctx) => { @@ -10,16 +10,16 @@ module.exports = async (ctx) => { Referer: pageUrl, }, json: { - size: ctx.query.limit ? Number(ctx.query.limit) : 30, + size: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30, }, }); const data = resp.data.data; const items = await utils.ProcessFeed(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: 'InfoQ 推荐', link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/infoq/topic.js b/lib/v2/infoq/topic.js index a7632ce54..566fcdc2b 100644 --- a/lib/v2/infoq/topic.js +++ b/lib/v2/infoq/topic.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); module.exports = async (ctx) => { - const paramId = ctx.params.id; + const paramId = ctx.req.param('id'); const apiUrl = 'https://www.infoq.cn/public/v1/article/getList'; const infoUrl = 'https://www.infoq.cn/public/v1/topic/getInfo'; const pageUrl = `https://www.infoq.cn/topic/${paramId}`; @@ -23,7 +23,7 @@ module.exports = async (ctx) => { Referer: pageUrl, }, json: { - size: ctx.query.limit ? Number(ctx.query.limit) : 30, + size: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30, type, id: info.data.data.id, }, @@ -32,11 +32,11 @@ module.exports = async (ctx) => { const data = resp.data.data; const items = await utils.ProcessFeed(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `InfoQ 话题 - ${topicName}`, description: info.data.data.desc, image: info.data.data.cover, link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/infoq/utils.js b/lib/v2/infoq/utils.js index bb416d559..192e48c75 100644 --- a/lib/v2/infoq/utils.js +++ b/lib/v2/infoq/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 ProcessFeed = async (list, cache) => { const detailUrl = 'https://www.infoq.cn/public/v1/article/getDetail'; diff --git a/lib/v2/informs/index.js b/lib/v2/informs/index.js index 73a0cf490..5e28304eb 100644 --- a/lib/v2/informs/index.js +++ b/lib/v2/informs/index.js @@ -1,14 +1,14 @@ -const config = require('@/config').value; -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import { config } from '@/config'; +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 rootUrl = 'https://pubsonline.informs.org'; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'orsc'; + const category = ctx.req.param('category') ?? 'orsc'; const cateUrl = `${rootUrl}/toc/${category}/0/0`; const getCookie = () => @@ -35,7 +35,7 @@ module.exports = async (ctx) => { cookie: await getCookie(), }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.issue-item') .slice(0, 10) .map((_, item) => ({ @@ -55,7 +55,7 @@ module.exports = async (ctx) => { cookie: await getCookie(), }, }); - const detail = cheerio.load(detailResponse.data); + const detail = load(detailResponse.data); item.description = art(path.join(__dirname, 'templates/content.art'), { author: detail('div.accordion-tabbed.loa-accordion').text(), content: detail('div.hlFld-Abstract').find('h2').replaceWith($('

Abstract

')).end().html(), @@ -66,9 +66,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `INFORMS - ${category}`, link: cateUrl, item: items, - }; + }); }; diff --git a/lib/v2/inoreader/index.js b/lib/v2/inoreader/index.js index 563ff6197..15d6e441a 100644 --- a/lib/v2/inoreader/index.js +++ b/lib/v2/inoreader/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 type = 'html'; - const user = ctx.params.user; - const tag = ctx.params.tag; - const num = ctx.query.limit || 20; + const user = ctx.req.param('user'); + const tag = ctx.req.param('tag'); + const num = ctx.req.query('limit') || 20; const rootUrl = 'https://www.inoreader.com/stream'; const currentUrl = `${rootUrl}/user/${user}/tag/${tag}/view/${type}?n=${num}`; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { url: currentUrl, }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const entries = $('#snip_body>.article_content'); - ctx.state.data = { + ctx.set('data', { title: $('.header_text').text().trim(), link: currentUrl, item: entries @@ -41,6 +41,6 @@ module.exports = async (ctx) => { }) .get(), allowEmpty: true, - }; + }); ctx.state.json = ctx.state.data; }; diff --git a/lib/v2/inoreader/rss.js b/lib/v2/inoreader/rss.js index 39f0d9bc3..465d610a2 100644 --- a/lib/v2/inoreader/rss.js +++ b/lib/v2/inoreader/rss.js @@ -1,9 +1,9 @@ const parser = require('@/utils/rss-parser'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; module.exports = async (ctx) => { - const user = ctx.params.user; - const tag = ctx.params.tag; + const user = ctx.req.param('user'); + const tag = ctx.req.param('tag'); const rootUrl = 'https://www.inoreader.com/stream'; const rssUrl = `${rootUrl}/user/${user}/tag/${tag}`; const feed = await parser.parseURL(rssUrl); @@ -13,7 +13,7 @@ module.exports = async (ctx) => { // get first image in content let firstImgSrc = ''; if (item.content !== null) { - const $ = cheerio.load(item.content); + const $ = load(item.content); firstImgSrc = $('img').first().attr('src'); } return { @@ -36,12 +36,12 @@ module.exports = async (ctx) => { category: item?.categories ?? [], }; }); - ctx.state.data = { + ctx.set('data', { title: feed.title, itunes_author: 'Inoreader', image: 'https://www.inoreader.com/brand/img/ino_app_icon.png', link: feed.link, description: feed.description, item: feed.items, - }; + }); }; diff --git a/lib/v2/instagram/common-utils.js b/lib/v2/instagram/common-utils.js index 96dcf91b0..3cb7398f9 100644 --- a/lib/v2/instagram/common-utils.js +++ b/lib/v2/instagram/common-utils.js @@ -1,5 +1,5 @@ -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'); const renderItems = (items) => diff --git a/lib/v2/instagram/private-api/index.js b/lib/v2/instagram/private-api/index.js index 936343fbf..5328007e5 100644 --- a/lib/v2/instagram/private-api/index.js +++ b/lib/v2/instagram/private-api/index.js @@ -1,6 +1,6 @@ const { ig, login } = require('./utils'); const logger = require('@/utils/logger'); -const config = require('@/config').value; +import { config } from '@/config'; const { renderItems } = require('../common-utils'); // loadContent pulls the desired user/tag/etc @@ -81,7 +81,7 @@ module.exports = async (ctx) => { throw error; } - ctx.state.data = { + ctx.set('data', { title: data.feedTitle, link: data.feedLink, description: data.feedDescription, @@ -90,5 +90,5 @@ module.exports = async (ctx) => { logo: data.feedLogo, image: data.feedLogo, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/instagram/private-api/utils.js b/lib/v2/instagram/private-api/utils.js index 9f1a23ccd..ccf6b29fc 100644 --- a/lib/v2/instagram/private-api/utils.js +++ b/lib/v2/instagram/private-api/utils.js @@ -1,6 +1,6 @@ const { IgApiClient } = require('instagram-private-api'); const logger = require('@/utils/logger'); -const config = require('@/config').value; +import { config } from '@/config'; const ig = new IgApiClient(); diff --git a/lib/v2/instagram/web-api/index.js b/lib/v2/instagram/web-api/index.js index fae1a5fc3..453294e77 100644 --- a/lib/v2/instagram/web-api/index.js +++ b/lib/v2/instagram/web-api/index.js @@ -1,5 +1,5 @@ const { CookieJar } = require('tough-cookie'); -const config = require('@/config').value; +import { config } from '@/config'; const { renderItems } = require('../common-utils'); const { baseUrl, COOKIE_URL, checkLogin, getUserInfo, getUserFeedItems, getTagsFeedItems, getLoggedOutTagsFeedItems, renderGuestItems } = require('./utils'); @@ -75,7 +75,7 @@ module.exports = async (ctx) => { await ctx.cache.set('instagram:cookieJar', cookieJar.toJSON(), 31_536_000); - ctx.state.data = { + ctx.set('data', { title: feedTitle, link: feedLink, description: feedDescription, @@ -84,5 +84,5 @@ module.exports = async (ctx) => { logo: feedLogo, image: feedLogo, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/instagram/web-api/utils.js b/lib/v2/instagram/web-api/utils.js index 6e1062bdc..d1eaeb5d7 100644 --- a/lib/v2/instagram/web-api/utils.js +++ b/lib/v2/instagram/web-api/utils.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; +import { art } from '@/utils/render'; const path = require('path'); const baseUrl = 'https://www.instagram.com'; diff --git a/lib/v2/instructables/projects.js b/lib/v2/instructables/projects.js index 00dbd5966..7bcd1bfca 100644 --- a/lib/v2/instructables/projects.js +++ b/lib/v2/instructables/projects.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'all'; + const category = ctx.req.param('category') ?? 'all'; const siteDomain = 'www.instructables.com'; const apiKey = 'NU5CdGwyRDdMVnVmM3l4cWNqQzFSVzJNZU5jaUxFU3dGK3J2L203MkVmVT02ZWFYeyJleGNsdWRlX2ZpZWxkcyI6WyJvdXRfb2YiLCJzZWFyY2hfdGltZV9tcyIsInN0ZXBCb2R5Il0sInBlcl9wYWdlIjo1MH0='; @@ -39,7 +39,7 @@ module.exports = async (ctx) => { const data = response.data; - ctx.state.data = { + ctx.set('data', { title: 'Instructables Projects', // 项目的标题 link, // 指向项目的链接 description: 'Instructables Projects', // 描述项目 @@ -52,5 +52,5 @@ module.exports = async (ctx) => { pubDate: new Date(item.document.publishDate).toUTCString(), category: item.document.primaryClassification, })), - }; + }); }; diff --git a/lib/v2/iqilu/program.js b/lib/v2/iqilu/program.js index 666787874..61fb3f5c2 100644 --- a/lib/v2/iqilu/program.js +++ b/lib/v2/iqilu/program.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 = 'sdws/sdxwlb' } = 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 = 'http://v.iqilu.com'; const currentUrl = new URL(category, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('#jmzhanshi1 dl') .slice(0, limit) @@ -51,7 +51,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.vtitle').text(); item.enclosure_url = content('#copy_mp4text').prop('value'); @@ -80,7 +80,7 @@ module.exports = async (ctx) => { .map((a) => $(a).text()) .join('/'); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -94,5 +94,5 @@ module.exports = async (ctx) => { itunes_author: author, itunes_category: 'News', allowEmpty: true, - }; + }); }; diff --git a/lib/v2/iqiyi/album.js b/lib/v2/iqiyi/album.js index 551c383d4..83568ede1 100644 --- a/lib/v2/iqiyi/album.js +++ b/lib/v2/iqiyi/album.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) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const { data: response } = await got(`https://www.iq.com/album/${id}`); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const { album } = nextData.props.initialState; @@ -51,12 +51,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.initIssueTime), })); - ctx.state.data = { + ctx.set('data', { title: baseInfo.name, description: baseInfo.description, image: album.videoAlbumInfo.albumFocus1024, link: `https://www.iq.com/album/${album.videoAlbumInfo.albumLocSuffix}`, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/iqiyi/video.js b/lib/v2/iqiyi/video.js index 5c0dbe712..cd58656fe 100644 --- a/lib/v2/iqiyi/video.js +++ b/lib/v2/iqiyi/video.js @@ -1,15 +1,17 @@ -const cheerio = require('cheerio'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; const logger = require('@/utils/logger'); +import puppeteer from '@/utils/puppeteer'; + // /iqiyi/user/video/:uid // http://localhost:1200/iqiyi/user/video/2289191062 module.exports = async (ctx) => { - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const link = `https://www.iqiyi.com/u/${uid}/videos`; // Use puppeteer because iqiyi page has a delay. - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const data = await ctx.cache.tryGet( link, async () => { @@ -25,7 +27,7 @@ module.exports = async (ctx) => { await page.waitForSelector('li.pic-txt-li'); const html = await page.content(); - const $ = cheerio.load(html); + const $ = load(html); const list = $('li.pic-txt-li'); return { diff --git a/lib/v2/iqnew/latest.js b/lib/v2/iqnew/latest.js index fc7e33b73..8f3009018 100644 --- a/lib/v2/iqnew/latest.js +++ b/lib/v2/iqnew/latest.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'; module.exports = async (ctx) => { const rootUrl = 'https://www.iqnew.com'; @@ -13,9 +13,9 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gb2312')); + const $ = load(iconv.decode(response.data, 'gb2312')); const list = $('.page-main-list .list-item a') - .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); @@ -34,7 +34,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gb2312')); + const content = load(iconv.decode(detailResponse.data, 'gb2312')); item.title = content('.main-article .title').text(); item.pubDate = timezone(parseDate(content('.time').eq(0).text()), 8); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '爱Q生活网 - 最近更新', link: url, item: items, - }; + }); }; diff --git a/lib/v2/iresearch/report.js b/lib/v2/iresearch/report.js index d1db3cf58..b5e29a799 100644 --- a/lib/v2/iresearch/report.js +++ b/lib/v2/iresearch/report.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; function processReport(item, ctx) { const apiUrl = `https://www.iresearch.com.cn/api/Detail/reportM?id=${item.NewsId}&isfree=0`; @@ -28,7 +28,7 @@ function processReport(item, ctx) { } module.exports = async (ctx) => { - const limit = isNaN(Number.parseInt(ctx.query.limit)) ? 20 : Number.parseInt(ctx.query.limit); + const limit = isNaN(Number.parseInt(ctx.req.query('limit'))) ? 20 : Number.parseInt(ctx.req.query('limit')); const apiUrl = `https://www.iresearch.com.cn/api/products/GetReportList?fee=0&date=&lastId=&pageSize=${limit}`; const pageUrl = 'https://www.iresearch.com.cn/m/report.shtml'; @@ -51,10 +51,10 @@ module.exports = async (ctx) => { })) ); - ctx.state.data = { + ctx.set('data', { title: '艾瑞产业研究报告', link: pageUrl, description: '艾瑞产业研究报告', item: items, - }; + }); }; diff --git a/lib/v2/iresearch/weekly.js b/lib/v2/iresearch/weekly.js index a4e3e7389..76376a8b2 100644 --- a/lib/v2/iresearch/weekly.js +++ b/lib/v2/iresearch/weekly.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 rootUrl = 'https://www.iresearch.com.cn'; const currentUrl = `${rootUrl}/report?type=3`; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { const items = JSON.parse(response.data.slice(1)) .filter((item) => (category ? item.classname === category : true)) - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 200) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 200) .map((item) => ({ title: item.reportname, pubDate: parseDate(item.addtime), @@ -31,9 +31,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: '艾瑞咨询 - 周度市场观察', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/issuehunt/funded.js b/lib/v2/issuehunt/funded.js index fd519cc02..3ea269b5b 100644 --- a/lib/v2/issuehunt/funded.js +++ b/lib/v2/issuehunt/funded.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const MarkdownIt = require('markdown-it'); module.exports = async (ctx) => { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const md = MarkdownIt({ html: true, }); - ctx.state.data = { + ctx.set('data', { title: `Issue Hunt 的悬赏 -- ${username}/${repo}`, link: `https://issuehunt.io/r/${username}/${repo}`, description: ``, @@ -24,5 +24,5 @@ module.exports = async (ctx) => { link: `https://issuehunt.io/r/${username}/${repo}/issues/${item.number}`, author: item.userName, })), - }; + }); }; diff --git a/lib/v2/itch/devlog.js b/lib/v2/itch/devlog.js index af0b60a1c..2d7fc6deb 100644 --- a/lib/v2/itch/devlog.js +++ b/lib/v2/itch/devlog.js @@ -1,14 +1,14 @@ -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 { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const user = ctx.params.user ?? ''; - const id = ctx.params.id ?? ''; + const user = ctx.req.param('user') ?? ''; + const id = ctx.req.param('id') ?? ''; if (!isValidHost(user)) { throw new Error('Invalid user'); } @@ -20,7 +20,7 @@ module.exports = async (ctx) => { url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.title') .toArray() @@ -42,7 +42,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = detailResponse.data.match(/"author":{".*?","name":"(.*?)"/)[1]; item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*?)"/)[1]); @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/itch/index.js b/lib/v2/itch/index.js index c49873a24..b94c29512 100644 --- a/lib/v2/itch/index.js +++ b/lib/v2/itch/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'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.title.game_link') .toArray() @@ -33,7 +33,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('title').text().split('by ').pop(); item.description = art(path.join(__dirname, 'templates/description.art'), { @@ -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/itch/posts.js b/lib/v2/itch/posts.js index 3d8490781..33d043323 100644 --- a/lib/v2/itch/posts.js +++ b/lib/v2/itch/posts.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 topic = ctx.params.topic; - const id = ctx.params.id; + const topic = ctx.req.param('topic'); + const id = ctx.req.param('id'); const rootUrl = 'https://itch.io'; const currentUrl = `${rootUrl}/t/${topic}/${id}?before=999999999`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.post_grid') .toArray() @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/ithome/index.js b/lib/v2/ithome/index.js index adaad5053..d9c80551f 100644 --- a/lib/v2/ithome/index.js +++ b/lib/v2/ithome/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 get_url = (caty) => `https://${caty}.ithome.com/`; @@ -34,18 +34,18 @@ const config = { }; module.exports = async (ctx) => { - const cfg = config[ctx.params.caty]; + const cfg = config[ctx.req.param('caty')]; if (!cfg) { throw new Error('Bad category. See https://docs.rsshub.app/routes/new-media#it-zhi-jia'); } - const current_url = get_url(ctx.params.caty); + const current_url = get_url(ctx.req.param('caty')); const response = await got({ method: 'get', url: current_url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#list > div.fl > ul > li > div > h2 > a') .slice(0, 10) .map((_, item) => { @@ -61,7 +61,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got({ method: 'get', url: item.link }); - const content = cheerio.load(res.data); + const content = load(res.data); const post = content('#paragraph'); post.find('img[data-original]').each((_, ele) => { ele = $(ele); @@ -76,10 +76,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'IT 之家 - ' + cfg.title, link: current_url, image: 'https://img.ithome.com/m/images/logo.png', item: items, - }; + }); }; diff --git a/lib/v2/ithome/ranking.js b/lib/v2/ithome/ranking.js index 4bc47ae61..c302f4cde 100644 --- a/lib/v2/ithome/ranking.js +++ b/lib/v2/ithome/ranking.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 option = ctx.params.type; + const option = ctx.req.param('type'); const response = await got({ method: 'get', url: 'https://www.ithome.com/block/rank.html', }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const config = { '24h': '24 小时最热', @@ -46,7 +46,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(res.data); + const content = load(res.data); const paragraph = content('#paragraph'); paragraph.find('img[data-original]').each((_, ele) => { ele = $(ele); @@ -61,9 +61,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `IT之家-${title}`, link: 'https://www.ithome.com', item: items, - }; + }); }; diff --git a/lib/v2/ithome/tag.js b/lib/v2/ithome/tag.js index a5848cc87..d568644cd 100644 --- a/lib/v2/ithome/tag.js +++ b/lib/v2/ithome/tag.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 rootUrl = 'https://www.ithome.com/'; module.exports = async (ctx) => { - const name = ctx.params.name; + const name = ctx.req.param('name'); const url = `${rootUrl}tag/${name}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul.bl > li') .map((_, item) => ({ title: $(item).find('h2 > a').text(), @@ -34,7 +34,7 @@ module.exports = async (ctx) => { return; } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const article = content('div.post_content'); article.find('img[data-original]').each((_, ele) => { @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `IT之家 - ${name}标签`, link: url, item: items.filter(Boolean), - }; + }); }; diff --git a/lib/v2/ithome/tw/feeds.js b/lib/v2/ithome/tw/feeds.js index 68dfa92a1..e6e31bd91 100644 --- a/lib/v2/ithome/tw/feeds.js +++ b/lib/v2/ithome/tw/feeds.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 baseUrl = 'https://www.ithome.com.tw'; - const currentUrl = `${baseUrl}/${ctx.params.category}/feeds`; + const currentUrl = `${baseUrl}/${ctx.req.param('category')}/feeds`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const name = $('a.active-trail').text(); const items = await Promise.all( $('.title a') @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const link = baseUrl + $(item).attr('href'); return ctx.cache.tryGet(link, async () => { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); return { title: $('.page-header').text(), author: $('.author a').text(), @@ -29,10 +29,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${name} | iThome`, link: currentUrl, description: 'iThome Online 是臺灣第一個網路原生報,提供IT產業即時新聞、企業IT產品報導與測試、技術專題、IT應用報導、IT書訊,以及面向豐富的名家專欄。', item: items, - }; + }); }; diff --git a/lib/v2/ithome/zt.js b/lib/v2/ithome/zt.js index 8d47f5891..37c01aaa4 100644 --- a/lib/v2/ithome/zt.js +++ b/lib/v2/ithome/zt.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.ithome.com'; const currentUrl = `${rootUrl}/zt/${id}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.newsbody a') .map((_, item) => { @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const post = content('.post_content'); post.find('img[data-original]').each((_, ele) => { @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()} - IT之家`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/iwara/index.js b/lib/v2/iwara/index.js index 42cf9d6d9..a8e30e8ad 100644 --- a/lib/v2/iwara/index.js +++ b/lib/v2/iwara/index.js @@ -1,6 +1,6 @@ -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 rootUrl = 'https://www.iwara.tv'; const apiRootUrl = 'https://api.iwara.tv'; @@ -35,9 +35,9 @@ const parseThumbnail = (type, item) => { }; module.exports = async (ctx) => { - const username = ctx.params.username; + const username = ctx.req.param('username'); const id = await ctx.cache.tryGet(`${apiRootUrl}/profile/${username}`, async () => (await got(`${apiRootUrl}/profile/${username}`)).data.user.id); - const type = ctx.params.type ?? 'video'; + const type = ctx.req.param('type') ?? 'video'; const items = (await ctx.cache.tryGet(`${apiUrlMap[type]}?user=${id}`, async () => (await got(`${apiUrlMap[type]}?user=${id}`)).data.results, config.cache.routeExpire, false)).map((item) => ({ title: item.title, author: username, @@ -47,9 +47,9 @@ module.exports = async (ctx) => { pubDate: parseDate(item.createdAt), })); - ctx.state.data = { + ctx.set('data', { title: `${username}'s iwara - ${typeMap[type]}`, link: `${rootUrl}/users/${username}`, item: items, - }; + }); }; diff --git a/lib/v2/iwara/subscriptions.js b/lib/v2/iwara/subscriptions.js index 2211b3e62..3bc8f57b3 100644 --- a/lib/v2/iwara/subscriptions.js +++ b/lib/v2/iwara/subscriptions.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); const md = require('markdown-it')({ html: true, @@ -135,9 +135,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Iwara Subscription`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/ixigua/user-video.js b/lib/v2/ixigua/user-video.js index be385a3f9..1274076ce 100644 --- a/lib/v2/ixigua/user-video.js +++ b/lib/v2/ixigua/user-video.js @@ -1,25 +1,25 @@ -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 host = 'https://www.ixigua.com'; module.exports = async (ctx) => { - const uid = ctx.params.uid; - const disableEmbed = ctx.params.disableEmbed; + const uid = ctx.req.param('uid'); + const disableEmbed = ctx.req.param('disableEmbed'); const url = `${host}/home/${uid}/?wid_try=1`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const jsData = $('#SSR_HYDRATED_DATA').html().replace('window._SSR_HYDRATED_DATA=', '').replaceAll('undefined', '""'); const data = JSON.parse(jsData); const videoInfos = data.AuthorVideoList.videoList; const userInfo = data.AuthorDetailInfo; - ctx.state.data = { + ctx.set('data', { title: `${userInfo.name} 的西瓜视频`, link: url, description: userInfo.introduce, @@ -33,5 +33,5 @@ module.exports = async (ctx) => { pubDate: parseDate(i.publishTime * 1000), author: userInfo.name, })), - }; + }); }; diff --git a/lib/v2/jandan/index.js b/lib/v2/jandan/index.js index cd0c19710..560ea5c1f 100644 --- a/lib/v2/jandan/index.js +++ b/lib/v2/jandan/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 parser = require('@/utils/rss-parser'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { feed.items.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.wechat-hide').prev().nextAll().remove(); const single = { title: item.title, @@ -23,9 +23,9 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: '煎蛋', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/jandan/section.js b/lib/v2/jandan/section.js index bd69bc3ce..09374d834 100644 --- a/lib/v2/jandan/section.js +++ b/lib/v2/jandan/section.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 ?? 'top'; + const category = ctx.req.param('category') ?? 'top'; const rootUrl = 'http://i.jandan.net'; const currentUrl = `${rootUrl}/${category}`; @@ -13,11 +13,11 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('ol.commentlist li') .not('.row') - .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); @@ -40,9 +40,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()} - 煎蛋`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/japanpost/track.js b/lib/v2/japanpost/track.js index 930f70ca1..ad700eb1b 100644 --- a/lib/v2/japanpost/track.js +++ b/lib/v2/japanpost/track.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; +import { load } from 'cheerio'; const path = require('path'); const utils = require('./utils'); @@ -8,11 +8,11 @@ let baseTitle = '日本郵便'; const baseUrl = 'https://trackings.post.japanpost.jp/services/srv/search/direct?'; module.exports = async (ctx) => { - const reqCode = ctx.params.reqCode; + const reqCode = ctx.req.param('reqCode'); const reqReqCode = 'reqCodeNo1=' + reqCode; let locale = 'ja'; - if (ctx.params.locale === 'en') { + if (ctx.req.param('locale') === 'en') { locale = 'en'; baseTitle = 'Japanpost'; } @@ -25,7 +25,7 @@ module.exports = async (ctx) => { url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); utils.expandEven($); utils.expandOdd($); @@ -61,7 +61,7 @@ module.exports = async (ctx) => { let lastItemTimeStamp; let tz; - ctx.state.data = { + ctx.set('data', { title: `${baseTitle} ${reqCode} ${packageType}`, link, description: `${baseTitle} ${reqCode} ${packageType}`, @@ -108,5 +108,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/javbus/index.js b/lib/v2/javbus/index.js index c909a5f1c..7042dcc91 100644 --- a/lib/v2/javbus/index.js +++ b/lib/v2/javbus/index.js @@ -1,9 +1,9 @@ -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 config = require('@/config').value; +import { config } from '@/config'; const toSize = (raw) => { const matches = raw.match(/(\d+(\.\d+)?)(\w+)/); @@ -14,14 +14,14 @@ const allowDomain = new Set(['javbus.com', 'javbus.org', 'javsee.icu', 'javsee.o module.exports = async (ctx) => { const isWestern = /^\/western/.test(ctx.path); - const domain = ctx.query.domain ?? 'javbus.com'; - const westernDomain = ctx.query.western_domain ?? 'javbus.org'; + const domain = ctx.req.query('domain') ?? 'javbus.com'; + const westernDomain = ctx.req.query('western_domain') ?? 'javbus.org'; const rootUrl = `https://www.${domain}`; const westernUrl = `https://www.${westernDomain}`; if (!config.feature.allow_user_supply_unsafe_domain && (!allowDomain.has(new URL(`https://${domain}/`).hostname) || !allowDomain.has(new URL(`https://${westernDomain}/`).hostname))) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const currentUrl = `${isWestern ? westernUrl : rootUrl}${ctx.path.replace(/^\/western/, '').replace(/\/home/, '')}`; @@ -36,10 +36,10 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.movie-box') - .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); @@ -60,7 +60,7 @@ module.exports = async (ctx) => { headers, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.genre').last().parent().remove(); content('input[type="checkbox"], button').remove(); @@ -109,7 +109,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(`${magnetResponse.data}
`); + const content = load(`${magnetResponse.data}
`); magnets = content('tr') .toArray() @@ -169,10 +169,10 @@ module.exports = async (ctx) => { const title = $('head title').text(); - ctx.state.data = { + ctx.set('data', { title: `${title.startsWith('JavBus') ? '' : 'JavBus - '}${title.replace(/ - AV磁力連結分享/, '')}`, link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/javdb/actors.js b/lib/v2/javdb/actors.js index ed4db8cbb..1eae14aea 100644 --- a/lib/v2/javdb/actors.js +++ b/lib/v2/javdb/actors.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const filter = ctx.params.filter ?? ''; + const id = ctx.req.param('id'); + const filter = ctx.req.param('filter') ?? ''; const currentUrl = `/actors/${id}${filter ? `?t=${filter}` : ''}`; diff --git a/lib/v2/javdb/index.js b/lib/v2/javdb/index.js index fdc13900f..b55da6837 100644 --- a/lib/v2/javdb/index.js +++ b/lib/v2/javdb/index.js @@ -1,9 +1,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'censored'; - const sort = ctx.params.sort ?? '2'; - const filter = ctx.params.filter ?? '1'; + const category = ctx.req.param('category') ?? 'censored'; + const sort = ctx.req.param('sort') ?? '2'; + const filter = ctx.req.param('filter') ?? '1'; const currentUrl = `${category === 'censored' ? '' : category}?vft=${filter}&vst=${sort}`; diff --git a/lib/v2/javdb/lists.js b/lib/v2/javdb/lists.js index fcff8526f..1507f35df 100644 --- a/lib/v2/javdb/lists.js +++ b/lib/v2/javdb/lists.js @@ -1,9 +1,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const filter = ctx.params.filter ?? ''; - const sort = ctx.params.sort ?? '0'; + const id = ctx.req.param('id'); + const filter = ctx.req.param('filter') ?? ''; + const sort = ctx.req.param('sort') ?? '0'; const currentUrl = `/lists/${id}?lst=${sort}${filter && filter !== 'none' ? `&f=${filter}` : ''}`; diff --git a/lib/v2/javdb/makers.js b/lib/v2/javdb/makers.js index 77a6b1b57..7fb0d91f0 100644 --- a/lib/v2/javdb/makers.js +++ b/lib/v2/javdb/makers.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const filter = ctx.params.filter ?? ''; + const id = ctx.req.param('id'); + const filter = ctx.req.param('filter') ?? ''; const currentUrl = `/makers/${id}${filter ? `?f=${filter}` : ''}`; diff --git a/lib/v2/javdb/rankings.js b/lib/v2/javdb/rankings.js index b3618ad50..aecd33e28 100644 --- a/lib/v2/javdb/rankings.js +++ b/lib/v2/javdb/rankings.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'censored'; - const time = ctx.params.time ?? 'daily'; + const category = ctx.req.param('category') ?? 'censored'; + const time = ctx.req.param('time') ?? 'daily'; const currentUrl = `/rankings/movies?p=${time}&t=${category}`; diff --git a/lib/v2/javdb/search.js b/lib/v2/javdb/search.js index f28f58461..413401449 100644 --- a/lib/v2/javdb/search.js +++ b/lib/v2/javdb/search.js @@ -1,9 +1,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const filter = ctx.params.filter ?? ''; - const keyword = ctx.params.keyword ?? ''; - const sort = ctx.params.sort ?? '0'; + const filter = ctx.req.param('filter') ?? ''; + const keyword = ctx.req.param('keyword') ?? ''; + const sort = ctx.req.param('sort') ?? '0'; const currentUrl = `/search?q=${keyword}${filter && filter !== 'none' ? `&f=${filter}` : ''}&sb=${sort}`; diff --git a/lib/v2/javdb/series.js b/lib/v2/javdb/series.js index fd730cae9..d1d0fc59b 100644 --- a/lib/v2/javdb/series.js +++ b/lib/v2/javdb/series.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const filter = ctx.params.filter ?? ''; + const id = ctx.req.param('id'); + const filter = ctx.req.param('filter') ?? ''; const currentUrl = `/series/${id}${filter ? `?f=${filter}` : ''}`; diff --git a/lib/v2/javdb/tags.js b/lib/v2/javdb/tags.js index e1691b18a..866732d60 100644 --- a/lib/v2/javdb/tags.js +++ b/lib/v2/javdb/tags.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'censored'; - const query = ctx.params.query ?? ''; + const category = ctx.req.param('category') ?? 'censored'; + const query = ctx.req.param('query') ?? ''; const currentUrl = `/tags${category === 'censored' ? '' : `/${category}`}?${query}`; diff --git a/lib/v2/javdb/utils.js b/lib/v2/javdb/utils.js index 3b524935c..3fcaf6049 100644 --- a/lib/v2/javdb/utils.js +++ b/lib/v2/javdb/utils.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const allowDomain = new Set(['javdb.com', 'javdb36.com', 'javdb007.com', 'javdb521.com']); module.exports = { ProcessItems: async (ctx, currentUrl, title) => { - const domain = ctx.query.domain ?? 'javdb.com'; + const domain = ctx.req.query('domain') ?? 'javdb.com'; const url = new URL(currentUrl, `https://${domain}`); if (!config.feature.allow_user_supply_unsafe_domain && !allowDomain.has(url.hostname)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const rootUrl = `https://${domain}`; @@ -19,12 +19,12 @@ module.exports = { url: url.href, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.tags, .tag-can-play, .over18-modal').remove(); let items = $('div.item') - .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); @@ -43,7 +43,7 @@ module.exports = { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.enclosure_type = 'application/x-bittorrent'; item.enclosure_url = content('#magnets-content button[data-clipboard-text]').first().attr('data-clipboard-text'); diff --git a/lib/v2/javlibrary/bestrated.js b/lib/v2/javlibrary/bestrated.js index da7b2e099..d419f05b9 100644 --- a/lib/v2/javlibrary/bestrated.js +++ b/lib/v2/javlibrary/bestrated.js @@ -1,8 +1,8 @@ const { defaultMode, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + 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); diff --git a/lib/v2/javlibrary/bestreviews.js b/lib/v2/javlibrary/bestreviews.js index b0a61bd58..51a313929 100644 --- a/lib/v2/javlibrary/bestreviews.js +++ b/lib/v2/javlibrary/bestreviews.js @@ -1,8 +1,8 @@ const { defaultMode, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + 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); diff --git a/lib/v2/javlibrary/genre.js b/lib/v2/javlibrary/genre.js index 271211fcf..32ce76136 100644 --- a/lib/v2/javlibrary/genre.js +++ b/lib/v2/javlibrary/genre.js @@ -1,9 +1,9 @@ const { defaultMode, defaultGenre, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const genre = ctx.params.genre ?? defaultGenre; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + const genre = ctx.req.param('genre') ?? defaultGenre; + 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); diff --git a/lib/v2/javlibrary/maker.js b/lib/v2/javlibrary/maker.js index 63c93d7de..6b5d24cbe 100644 --- a/lib/v2/javlibrary/maker.js +++ b/lib/v2/javlibrary/maker.js @@ -1,9 +1,9 @@ const { defaultMode, defaultLanguage, defaultMaker, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const maker = ctx.params.maker ?? defaultMaker; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + const maker = ctx.req.param('maker') ?? defaultMaker; + 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); diff --git a/lib/v2/javlibrary/mostwanted.js b/lib/v2/javlibrary/mostwanted.js index 46d68d157..546a9f250 100644 --- a/lib/v2/javlibrary/mostwanted.js +++ b/lib/v2/javlibrary/mostwanted.js @@ -1,8 +1,8 @@ const { defaultMode, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + 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); diff --git a/lib/v2/javlibrary/newentries.js b/lib/v2/javlibrary/newentries.js index 7b844d421..ca935979a 100644 --- a/lib/v2/javlibrary/newentries.js +++ b/lib/v2/javlibrary/newentries.js @@ -1,7 +1,7 @@ const { defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const language = ctx.params.language ?? defaultLanguage; + 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); diff --git a/lib/v2/javlibrary/newrelease.js b/lib/v2/javlibrary/newrelease.js index f98b732b8..0db9df82b 100644 --- a/lib/v2/javlibrary/newrelease.js +++ b/lib/v2/javlibrary/newrelease.js @@ -1,8 +1,8 @@ const { defaultMode, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const mode = ctx.params.mode ?? defaultMode; - const language = ctx.params.language ?? defaultLanguage; + const mode = ctx.req.param('mode') ?? defaultMode; + 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); diff --git a/lib/v2/javlibrary/star.js b/lib/v2/javlibrary/star.js index 044ac346d..12e850f3f 100644 --- a/lib/v2/javlibrary/star.js +++ b/lib/v2/javlibrary/star.js @@ -1,9 +1,9 @@ const { defaultMode, defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const mode = ctx.params.mode ?? defaultMode; - const language = ctx.params.language ?? defaultLanguage; + const id = ctx.req.param('id'); + const mode = ctx.req.param('mode') ?? defaultMode; + 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); diff --git a/lib/v2/javlibrary/update.js b/lib/v2/javlibrary/update.js index d97682f14..efcf3b30d 100644 --- a/lib/v2/javlibrary/update.js +++ b/lib/v2/javlibrary/update.js @@ -1,7 +1,7 @@ const { defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const language = ctx.params.language ?? defaultLanguage; + 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); diff --git a/lib/v2/javlibrary/user.js b/lib/v2/javlibrary/user.js index 5989353c7..b241d3709 100644 --- a/lib/v2/javlibrary/user.js +++ b/lib/v2/javlibrary/user.js @@ -1,9 +1,9 @@ const { defaultLanguage, rootUrl, ProcessItems } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const type = ctx.params.type; - const language = ctx.params.language ?? defaultLanguage; + const id = ctx.req.param('id'); + const type = ctx.req.param('type'); + 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); diff --git a/lib/v2/javlibrary/utils.js b/lib/v2/javlibrary/utils.js index b55dcebaf..e5fcb6d7f 100644 --- a/lib/v2/javlibrary/utils.js +++ b/lib/v2/javlibrary/utils.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 rootUrl = 'https://www.javlibrary.com'; @@ -19,7 +19,7 @@ module.exports = { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.toolbar, .info, .videoinfo').remove(); @@ -51,7 +51,7 @@ module.exports = { url: item.url, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.icn_edit, .btn_videoplayer, a[rel="bookmark"]').remove(); content('span').each(function () { diff --git a/lib/v2/jd/price.js b/lib/v2/jd/price.js index 39001cb6b..3ef4e72b5 100644 --- a/lib/v2/jd/price.js +++ b/lib/v2/jd/price.js @@ -1,9 +1,9 @@ -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) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://item.jd.com'; const currentUrl = `${rootUrl}/${id}.html`; @@ -23,7 +23,7 @@ module.exports = async (ctx) => { const title = response.data.match(/name: '(.*?)'/)[1]; - ctx.state.data = { + ctx.set('data', { title: `京东商品价格 - ${title}`, link: currentUrl, item: [ @@ -38,5 +38,5 @@ module.exports = async (ctx) => { }), }, ], - }; + }); }; diff --git a/lib/v2/jianshu/collection.js b/lib/v2/jianshu/collection.js index f09d8a6dc..5543e38bf 100644 --- a/lib/v2/jianshu/collection.js +++ b/lib/v2/jianshu/collection.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const util = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got({ method: 'get', @@ -15,15 +15,15 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.note-list li').get(); const result = await util.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: `https://www.jianshu.com/c/${id}`, description: $('meta[name="description"]').attr('content') || $('title').text(), item: result, - }; + }); }; diff --git a/lib/v2/jianshu/home.js b/lib/v2/jianshu/home.js index a6daa92cd..1406d8974 100644 --- a/lib/v2/jianshu/home.js +++ b/lib/v2/jianshu/home.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'); module.exports = async (ctx) => { @@ -13,15 +13,15 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.note-list li').get(); const result = await util.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '简书首页', link: 'https://www.jianshu.com', description: $('meta[name="description"]').attr('content'), item: result, - }; + }); }; diff --git a/lib/v2/jianshu/user.js b/lib/v2/jianshu/user.js index 6b25952d6..d5638aa1a 100644 --- a/lib/v2/jianshu/user.js +++ b/lib/v2/jianshu/user.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const util = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got({ method: 'get', @@ -15,15 +15,15 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.note-list li').get(); const result = await util.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: `https://www.jianshu.com/u/${id}`, description: $('meta[name="description"]').attr('content') || $('title').text(), item: result, - }; + }); }; diff --git a/lib/v2/jianshu/utils.js b/lib/v2/jianshu/utils.js index c8715741d..c213f29f5 100644 --- a/lib/v2/jianshu/utils.js +++ b/lib/v2/jianshu/utils.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 load = async (link) => { +const loadContent = async (link) => { const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 解析日期 const pubDate = timezone(parseDate($('time').attr('datetime')), +8); // 去除样式 @@ -33,14 +33,14 @@ const ProcessFeed = (list, caches) => { return Promise.all( list.map((item) => { - const $ = cheerio.load(item); + const $ = load(item); const $title = $('.title'); // 还原相对链接为绝对链接 const itemUrl = new URL($title.attr('href'), host).toString(); // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容 return caches.tryGet(itemUrl, async () => { - const other = await load(itemUrl); + const other = await loadContent(itemUrl); // 合并解析后的结果集作为该篇文章最终的输出结果 return { title: $title.text(), diff --git a/lib/v2/jiaoliudao/index.js b/lib/v2/jiaoliudao/index.js index bf2ca8d49..f26663990 100644 --- a/lib/v2/jiaoliudao/index.js +++ b/lib/v2/jiaoliudao/index.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.jiaoliudao.com'; const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30, + per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30, }, }); @@ -17,10 +17,10 @@ module.exports = async (ctx) => { link: item.link, })); - ctx.state.data = { + ctx.set('data', { title: '交流岛资源网-专注网络资源收集', image: `${baseUrl}/favicon.ico`, link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/jiemian/lists.js b/lib/v2/jiemian/lists.js index 1435d9bfa..b9372de32 100644 --- a/lib/v2/jiemian/lists.js +++ b/lib/v2/jiemian/lists.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.jiemian.com'; const currentUrl = new URL(category ? `${category}.html` : '', rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a') .toArray() @@ -39,7 +39,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 image = content('div.article-img img').first(); const video = content('#video-player').first(); @@ -85,7 +85,7 @@ module.exports = async (ctx) => { const image = $('div.logo img').prop('src'); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -96,5 +96,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: titleSplits[0], author: titleSplits.pop(), - }; + }); }; diff --git a/lib/v2/jike/topic-text.js b/lib/v2/jike/topic-text.js index 06ee45a09..f243428f3 100644 --- a/lib/v2/jike/topic-text.js +++ b/lib/v2/jike/topic-text.js @@ -2,7 +2,7 @@ const dayjs = require('dayjs'); const { constructTopicEntry } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const topicUrl = `https://m.okjike.com/topics/${id}`; const data = await constructTopicEntry(ctx, topicUrl); diff --git a/lib/v2/jike/topic.js b/lib/v2/jike/topic.js index 370151665..4a14b564c 100644 --- a/lib/v2/jike/topic.js +++ b/lib/v2/jike/topic.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { topicDataHanding } = require('./utils'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const dayjs = require('dayjs'); const { constructTopicEntry } = require('@/v2/jike/utils'); const urlRegex = /(https?:\/\/[^\s"'<>]+)/g; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const topicUrl = `https://m.okjike.com/topics/${id}`; const data = await constructTopicEntry(ctx, topicUrl); @@ -23,7 +23,7 @@ module.exports = async (ctx) => { const newsUrl = regResult[0]; item.description = await ctx.cache.tryGet(newsUrl, async () => { const { data } = await got(newsUrl); - const $ = cheerio.load(data); + const $ = load(data); const upper = $('ul.main > li.item'); const links = upper.find('a').map((_, ele) => $(ele).attr('href')); const texts = upper.find('span.text').map((_, ele) => $(ele).text()); diff --git a/lib/v2/jike/user.js b/lib/v2/jike/user.js index 87e4c56a4..4e3e6a852 100644 --- a/lib/v2/jike/user.js +++ b/lib/v2/jike/user.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 response = await got({ method: 'get', @@ -14,7 +14,7 @@ module.exports = async (ctx) => { }); const html = response.data; - const $ = cheerio.load(html); + const $ = load(html); const raw = $('[type = "application/json"]').html(); const data = JSON.parse(raw).props.pageProps; @@ -130,7 +130,7 @@ module.exports = async (ctx) => { Referer: `https://m.okjike.com/users/${id}`, }, }); - const $$ = cheerio.load(data); + const $$ = load(data); $$('span.num,span.arrow').remove(); single.title = `一觉醒来世界发生了什么 ${$$('title').text()}`; @@ -148,11 +148,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${data.user.screenName}的即刻动态`, description: data.user.bio, link: `https://m.okjike.com/users/${id}`, image: data.user.avatarImage.picUrl, item: items, - }; + }); }; diff --git a/lib/v2/jike/utils.js b/lib/v2/jike/utils.js index 70bf1e863..663b8bda0 100644 --- a/lib/v2/jike/utils.js +++ b/lib/v2/jike/utils.js @@ -1,7 +1,7 @@ -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; const videoAPI = 'https://api.ruguoapp.com/1.0/mediaMeta/play?type=ORIGINAL_POST'; @@ -39,7 +39,7 @@ module.exports = { // 添加内容作者信息 if (item.user) { author = item.user.screenName; - if (ctx.params.showUid) { + if (ctx.req.param('showUid')) { description += `用户昵称:${author}
Username:${item.user.username}

`; } } @@ -152,7 +152,7 @@ module.exports = { async () => { const resp = await got(url); const html = resp.data; - const $ = cheerio.load(html); + const $ = load(html); const raw = $('[type = "application/json"]').html(); const data = JSON.parse(raw).props.pageProps; data.posts = await Promise.all( diff --git a/lib/v2/jin10/index.js b/lib/v2/jin10/index.js index 4e5833750..7a0bb4418 100644 --- a/lib/v2/jin10/index.js +++ b/lib/v2/jin10/index.js @@ -1,9 +1,9 @@ -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'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { const { important = false } = ctx.params; @@ -50,9 +50,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: '金十数据', link: 'https://www.jin10.com/', item: important ? item.filter((item) => item.important) : item, - }; + }); }; diff --git a/lib/v2/jin10/topic.js b/lib/v2/jin10/topic.js index 5b5252ffb..f377d5a83 100644 --- a/lib/v2/jin10/topic.js +++ b/lib/v2/jin10/topic.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { config } from '@/config'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const data = await ctx.cache.tryGet( `jin10:topic:${id}`, async () => { @@ -41,10 +41,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: data.title, link: `https://xnews.jin10.com/topic/${id}`, description: data.introduction, item: items, - }; + }); }; diff --git a/lib/v2/jinse/catalogue.js b/lib/v2/jinse/catalogue.js index 0ec43bc27..cb2f1d531 100644 --- a/lib/v2/jinse/catalogue.js +++ b/lib/v2/jinse/catalogue.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 = { @@ -19,7 +19,7 @@ const categories = { module.exports = async (ctx) => { const { category = 'zhengce' } = 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.jinse.cn'; const rootApiUrl = 'https://api.jinse.cn'; @@ -63,7 +63,7 @@ module.exports = async (ctx) => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description += art(path.join(__dirname, 'templates/description.art'), { description: content('section.js-article-content').html() || content('div.js-article').html(), @@ -79,13 +79,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[name="author"]').prop('content'); const image = $('a.js-logoBox img').prop('src'); const icon = new URL($('link[rel="favicon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${Object.hasOwn(categories, category) ? categories[category] : category}`, link: currentUrl, @@ -97,5 +97,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/jinse/lives.js b/lib/v2/jinse/lives.js index 94de36503..a89908a2b 100644 --- a/lib/v2/jinse/lives.js +++ b/lib/v2/jinse/lives.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 = { @@ -15,7 +15,7 @@ const categories = { module.exports = async (ctx) => { const { category = '0' } = 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://jinse.cn'; const rootApiUrl = 'https://api.jinse.cn'; @@ -65,13 +65,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[name="author"]').prop('content'); const image = $('a.js-logoBox img').prop('src'); const icon = new URL($('link[rel="favicon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${Object.hasOwn(categories, category) ? categories[category] : category}`, link: currentUrl, @@ -83,5 +83,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/jinse/timeline.js b/lib/v2/jinse/timeline.js index 7bc6e902a..5732eb908 100644 --- a/lib/v2/jinse/timeline.js +++ b/lib/v2/jinse/timeline.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 = '头条' } = 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.jinse.cn'; const rootApiUrl = 'https://api.jinse.cn'; @@ -58,7 +58,7 @@ module.exports = async (ctx) => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description += art(path.join(__dirname, 'templates/description.art'), { description: content('section.js-article-content').html() || content('div.js-article').html(), @@ -74,13 +74,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[name="author"]').prop('content'); const image = $('a.js-logoBox img').prop('src'); const icon = new URL($('link[rel="favicon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${category}`, link: currentUrl, @@ -92,5 +92,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/jisilu/index.js b/lib/v2/jisilu/index.js index df3016943..e7503aabb 100644 --- a/lib/v2/jisilu/index.js +++ b/lib/v2/jisilu/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'); +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 sort = ctx.params.sort ?? ''; - const day = ctx.params.day ?? ''; + const category = ctx.req.param('category') ?? ''; + const sort = ctx.req.param('sort') ?? ''; + const day = ctx.req.param('day') ?? ''; const rootUrl = 'https://www.jisilu.cn'; let currentUrl = '', @@ -36,12 +36,12 @@ module.exports = async (ctx) => { }); } - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.nav').prevAll('.aw-item').remove(); let items = $('.aw-item') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -71,7 +71,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.aw-dynamic-topic-more-operate').remove(); @@ -82,9 +82,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${name ? `${name}的${category === 'topic' ? '主题' : '回复'}` : '广场'} - 集思录`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/jjwxc/author.js b/lib/v2/jjwxc/author.js index 84e7cfee3..d659fb00b 100644 --- a/lib/v2/jjwxc/author.js +++ b/lib/v2/jjwxc/author.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 timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -16,7 +16,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response, 'gbk')); + const $ = load(iconv.decode(response, 'gbk')); const bookEl = $('font a').first(); const bookInfoEl = bookEl.parent(); @@ -53,7 +53,7 @@ module.exports = async (ctx) => { const image = `https:${logoEl.prop('src')}`; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${logoEl.prop('alt').replace(/logo/, '')} | ${author} - 最近更新`, link: currentUrl, @@ -64,5 +64,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="Description"]').prop('content'), author, - }; + }); }; diff --git a/lib/v2/jjwxc/book.js b/lib/v2/jjwxc/book.js index f469ca6c8..26b05140b 100644 --- a/lib/v2/jjwxc/book.js +++ b/lib/v2/jjwxc/book.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id } = 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.jjwxc.net'; const currentUrl = new URL(`onebook.php?novelid=${id}`, rootUrl).href; @@ -17,7 +17,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response, 'gbk')); + const $ = load(iconv.decode(response, 'gbk')); const author = $('meta[name="Author"]').prop('content'); const keywords = $('meta[name="Keywords"]').prop('content').split(/,/); @@ -71,7 +71,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse, 'gbk')); + const content = load(iconv.decode(detailResponse, 'gbk')); content('span.favorite_novel').parent().remove(); @@ -91,7 +91,7 @@ module.exports = async (ctx) => { const image = `https:${logoEl.prop('src')}`; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${logoEl.prop('alt').replace(/logo/, '')} | ${author}${keywords[0]}`, link: currentUrl, @@ -102,5 +102,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="Description"]').prop('content'), author: $('meta[name="Author"]').prop('content'), - }; + }); }; diff --git a/lib/v2/jornada/index.js b/lib/v2/jornada/index.js index c53dd7d46..6d85e714f 100644 --- a/lib/v2/jornada/index.js +++ b/lib/v2/jornada/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 rootUrl = 'https://www.jornada.com.mx'; @@ -24,8 +24,8 @@ const getDateForToday = () => { }; module.exports = async (ctx) => { - const date = ctx.params.date === 'today' || ctx.params.date === undefined ? getDateForToday() : ctx.params.date; - const category = ctx.params.category; + const date = ctx.req.param('date') === 'today' || ctx.req.param('date') === undefined ? getDateForToday() : ctx.req.param('date'); + const category = ctx.req.param('category'); const url = `${rootUrl}/jsonstorage/articles_${date}_.json`; const response = await got(url); @@ -51,9 +51,9 @@ module.exports = async (ctx) => { })); } - ctx.state.data = { + ctx.set('data', { title: 'La Jornada', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/jou/home.js b/lib/v2/jou/home.js index 5a88b9379..950d6cf1b 100644 --- a/lib/v2/jou/home.js +++ b/lib/v2/jou/home.js @@ -7,12 +7,12 @@ module.exports = async (ctx) => { const out = await getItems(ctx, url, host, 'winstyle106390', 'timestyle106390', 'titlestyle106402', 'timestyle106402'); // 生成RSS源 - ctx.state.data = { + ctx.set('data', { // 项目标题 title: '江苏海洋大学 -- 通知公告', // 项目链接 link: url, // items的内容 item: out, - }; + }); }; diff --git a/lib/v2/jou/utils/index.js b/lib/v2/jou/utils/index.js index e072a34e7..85e14b477 100644 --- a/lib/v2/jou/utils/index.js +++ b/lib/v2/jou/utils/index.js @@ -1,17 +1,17 @@ // 导入got库,该库用来请求网页数据 -const got = require('@/utils/got'); +import got from '@/utils/got'; // 导入cheerio库,该库用来解析网页数据 -const cheerio = require('cheerio'); +import { load } from 'cheerio'; // 导入parseDate函数,该函数用于日期处理 -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; // 导入timezone库,该库用于时区处理 -const timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; async function getItems(ctx, url, host, tableClass, timeStyleClass1, titleStyleClass, timeStyleClass2) { // 发起Http请求,获取网页数据 const response = await got({ url, https: { rejectUnauthorized: false } }); // 解析网页数据 - const $ = cheerio.load(response.data); + const $ = load(response.data); // 通知公告的items的标题、url链接、发布日期 const list = $(`table.${tableClass} > tbody > tr[height=20]`) @@ -38,7 +38,7 @@ async function getItems(ctx, url, host, tableClass, timeStyleClass1, titleStyleC item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $(`.${titleStyleClass}`).text(); item.description = $('.v_news_content') .html() diff --git a/lib/v2/jou/yz.js b/lib/v2/jou/yz.js index 94ce27621..944c0ba37 100644 --- a/lib/v2/jou/yz.js +++ b/lib/v2/jou/yz.js @@ -7,12 +7,12 @@ module.exports = async (ctx) => { const out = await getItems(ctx, url, host, 'winstyle207638', 'timestyle207638', 'titlestyle207543', 'timestyle207543'); // 生成RSS源 - ctx.state.data = { + ctx.set('data', { // 项目标题 title: '江苏海洋大学 -- 研招通知公告', // 项目链接 link: url, // items的内容 item: out, - }; + }); }; diff --git a/lib/v2/jseea/news.js b/lib/v2/jseea/news.js index 2f589796c..c5c7b46a6 100644 --- a/lib/v2/jseea/news.js +++ b/lib/v2/jseea/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'; // 参考 bit/jwc 北京理工大学的的页面写成 @@ -9,11 +9,11 @@ const baseUrl = 'https://www.jseea.cn'; const siteTitle = ' - 江苏省教育考试院'; // 专门定义一个function用于加载文章内容 -async function load(link) { +async function loadContent(link) { // 异步请求文章 const { data: response } = await got(link); // 加载文章内容 - const $ = cheerio.load(response); + const $ = load(response); // 提取文章内容 $('strong').remove(); const description = $('#content').html(); @@ -23,10 +23,10 @@ async function load(link) { module.exports = async (ctx) => { // 默认 正常规定 然后获取列表页面 - const type = ctx.params.type ?? 'zkyw'; + const type = ctx.req.param('type') ?? 'zkyw'; const listPageUrl = `${baseUrl}/webfile/news/${type}/`; const { data: response } = await got(listPageUrl); - const $ = cheerio.load(response); + const $ = load(response); // console.log(type+":"+listPageUrl); // 获取当前页面的 list @@ -49,16 +49,16 @@ module.exports = async (ctx) => { // 遍历每一篇文章 list.map((item) => ctx.cache.tryGet(item.link, async () => { - item.description = await load(item.link); + item.description = await loadContent(item.link); // 合并解析后的结果集作为该篇文章最终的输出结果 return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text() + siteTitle, link: listPageUrl, item: result, - }; + }); }; diff --git a/lib/v2/jsu/cxzx.js b/lib/v2/jsu/cxzx.js index 2aad79f5a..6a3b78415 100644 --- a/lib/v2/jsu/cxzx.js +++ b/lib/v2/jsu/cxzx.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; const { getPageItemAndDate } = require('./utils/index'); module.exports = async (ctx) => { @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: urls[types].url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('tr[height="20"]').toArray(); const out = await Promise.all( @@ -65,11 +65,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: `吉首大学创新中心 - ${urls[types].title}`, link: urls[types].url, description: '吉首大学创新中心', item: out, - }; + }); }; diff --git a/lib/v2/jsu/jwc.js b/lib/v2/jsu/jwc.js index eacd448da..8983c7bff 100644 --- a/lib/v2/jsu/jwc.js +++ b/lib/v2/jsu/jwc.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; const { getPageItemAndDate } = require('@/v2/jsu/utils'); module.exports = async (ctx) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { url: selectors[types].url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a.c135042').toArray(); const out = await Promise.all( list.map((item) => { @@ -49,11 +49,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: `吉首大学教务处 - ${selectors[types].category}`, link: selectors[types].url, description: `吉首大学教务处 - ${selectors[types].category}`, item: out, - }; + }); }; diff --git a/lib/v2/jsu/math.js b/lib/v2/jsu/math.js index 72f37eadf..da11fc1b6 100644 --- a/lib/v2/jsu/math.js +++ b/lib/v2/jsu/math.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; const { getPageItemAndDate } = require('@/v2/jsu/utils'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: 'https://stxy.jsu.edu.cn/index/tzgg1.htm', }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.art_list').toArray(); const out = await Promise.all( list.map((item) => { @@ -32,10 +32,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '吉首大学数学与统计学院 - 通知公告', link: 'https://stxy.jsu.edu.cn/index/tzgg1.htm', description: '吉首大学数学与统计学院 - 通知公告', item: out, - }; + }); }; diff --git a/lib/v2/jsu/rjxy.js b/lib/v2/jsu/rjxy.js index aa5d5c71b..5d2631851 100644 --- a/lib/v2/jsu/rjxy.js +++ b/lib/v2/jsu/rjxy.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; const { getPageItemAndDate } = require('@/v2/jsu/utils'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: 'https://rjxy.jsu.edu.cn/index/tzgg1.htm', }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > div.list-box > div > ul > li').toArray(); const out = await Promise.all( list.map((item) => { @@ -33,11 +33,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: '吉首大学计算机科学与工程学院 - 通知公告', link: 'https://rjxy.jsu.edu.cn/index/tzgg1.htm', description: '吉首大学计算机科学与工程学院 - 通知公告', item: out, - }; + }); }; diff --git a/lib/v2/jsu/universityindex.js b/lib/v2/jsu/universityindex.js index 51e1b823f..d08c7155f 100644 --- a/lib/v2/jsu/universityindex.js +++ b/lib/v2/jsu/universityindex.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; const { getPageItemAndDate } = require('./utils'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: 'https://www.jsu.edu.cn/index/tzgg.htm', }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > div.container.container-fluid.dynava.no-padding.cleafix > div.con_wz_fr.fr.cleafix > div:nth-child(2) > ul > li').toArray(); const out = await Promise.all( list.map((item) => { @@ -38,11 +38,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: '吉首大学 - 通知公告', link: 'https://www.jsu.edu.cn/index/tzgg.htm', description: '吉首大学 - 通知公告', item: out, - }; + }); }; diff --git a/lib/v2/jsu/utils/index.js b/lib/v2/jsu/utils/index.js index 1a41053d0..9ec764788 100644 --- a/lib/v2/jsu/utils/index.js +++ b/lib/v2/jsu/utils/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 /** * 获取页面内容 @@ -13,7 +13,7 @@ async function getPageItem(selector, pageUrl) { url: pageUrl, https: { rejectUnauthorized: false }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const page = $(selector); return page ? page.html() : '无法获取内容'; } @@ -33,7 +33,7 @@ async function getPageDetails(selector, pageUrl, titleSelector, dateSelector, da url: pageUrl, https: { rejectUnauthorized: false }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const page = $(selector); const date = dateHander($(dateSelector).text()); const title = $(titleSelector).text(); diff --git a/lib/v2/juejin/books.js b/lib/v2/juejin/books.js index 29120e0eb..ba8a42e6a 100644 --- a/lib/v2/juejin/books.js +++ b/lib/v2/juejin/books.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 response = await got({ @@ -22,9 +22,9 @@ module.exports = async (ctx) => { guid: base_info.booklet_id, })); - ctx.state.data = { + ctx.set('data', { title: '掘金小册', link: 'https://juejin.cn/books', item: items, - }; + }); }; diff --git a/lib/v2/juejin/category.js b/lib/v2/juejin/category.js index f3d3b6be3..cc26e756f 100644 --- a/lib/v2/juejin/category.js +++ b/lib/v2/juejin/category.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -30,10 +30,10 @@ module.exports = async (ctx) => { } const resultItems = await util.ProcessFeed(originalData, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `掘金 ${cat.category_name}`, link: `https://juejin.cn/${category}`, description: `掘金 ${cat.category_name}`, item: resultItems, - }; + }); }; diff --git a/lib/v2/juejin/collection.js b/lib/v2/juejin/collection.js index 99d7160af..462fea397 100644 --- a/lib/v2/juejin/collection.js +++ b/lib/v2/juejin/collection.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -16,11 +16,11 @@ module.exports = async (ctx) => { const result = await util.ProcessFeed(items, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '掘金 - 单个收藏夹', link: `https://juejin.cn/collection/${collectionId}`, description: '掘金,用户单个收藏夹', item: result, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/juejin/column.js b/lib/v2/juejin/column.js index 9fe3f16ac..80a2c6d74 100644 --- a/lib/v2/juejin/column.js +++ b/lib/v2/juejin/column.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -22,10 +22,10 @@ module.exports = async (ctx) => { const columnName = detailData && detailData.column_version && detailData.column_version.title; const resultItems = await util.ProcessFeed(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `掘金专栏-${columnName}`, link: `https://juejin.cn/column/${id}`, description: `掘金专栏-${columnName}`, item: resultItems, - }; + }); }; diff --git a/lib/v2/juejin/favorites.js b/lib/v2/juejin/favorites.js index f267d623f..5f5da8d7b 100644 --- a/lib/v2/juejin/favorites.js +++ b/lib/v2/juejin/favorites.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -29,11 +29,11 @@ module.exports = async (ctx) => { const result = await util.ProcessFeed(posts, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '掘金 - 收藏集', link: `https://juejin.im/user/${userId}/collections`, description: '掘金,指定用户整个收藏集', item: result, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/juejin/pins.js b/lib/v2/juejin/pins.js index 330503767..b216c24f6 100644 --- a/lib/v2/juejin/pins.js +++ b/lib/v2/juejin/pins.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 type = ctx.params.type ?? 'recommend'; + const type = ctx.req.param('type') ?? 'recommend'; const title = { recommend: '推荐', hot: '热门', @@ -59,9 +59,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `沸点 - ${title[type]}`, link: 'https://juejin.cn/pins/recommended', item: items, - }; + }); }; diff --git a/lib/v2/juejin/posts.js b/lib/v2/juejin/posts.js index 8c9b4f75d..8791afb40 100644 --- a/lib/v2/juejin/posts.js +++ b/lib/v2/juejin/posts.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -16,10 +16,10 @@ module.exports = async (ctx) => { const username = data[0] && data[0].author_user_info && data[0].author_user_info.user_name; const resultItems = await util.ProcessFeed(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `掘金专栏-${username}`, link: `https://juejin.cn/user/${id}/posts`, description: `掘金专栏-${username}`, item: resultItems, - }; + }); }; diff --git a/lib/v2/juejin/tag.js b/lib/v2/juejin/tag.js index fe46d258c..8563b2c8a 100644 --- a/lib/v2/juejin/tag.js +++ b/lib/v2/juejin/tag.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -31,10 +31,10 @@ module.exports = async (ctx) => { } const resultItems = await util.ProcessFeed(originalData, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `掘金 ${tag}`, link: `https://juejin.cn/tag/${encodeURIComponent(tag)}`, description: `掘金 ${tag}`, item: resultItems, - }; + }); }; diff --git a/lib/v2/juejin/trending.js b/lib/v2/juejin/trending.js index 240f02797..d102e3022 100644 --- a/lib/v2/juejin/trending.js +++ b/lib/v2/juejin/trending.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); module.exports = async (ctx) => { @@ -71,9 +71,9 @@ module.exports = async (ctx) => { const resultItems = await util.ProcessFeed(entrylist, ctx.cache); - ctx.state.data = { + ctx.set('data', { title, link, item: resultItems, - }; + }); }; diff --git a/lib/v2/juejin/utils.js b/lib/v2/juejin/utils.js index 587392cf3..ad5e9ee69 100644 --- a/lib/v2/juejin/utils.js +++ b/lib/v2/juejin/utils.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 md = require('markdown-it')({ html: true, }); // 加载文章页 -async function load(id) { +async function loadContent(id) { const response = await got({ method: 'post', url: 'https://api.juejin.cn/content_api/v1/article/detail', @@ -23,7 +23,7 @@ async function load(id) { const loadNews = async (link) => { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('h1.title, .main-box .message').remove(); return { description: $('.main-box .article').html() }; }; @@ -45,7 +45,7 @@ const ProcessFeed = (list, caches) => // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(link, () => (isArticle ? load(item.article_id) : loadNews(link))); + const other = await caches.tryGet(link, () => (isArticle ? loadContent(item.article_id) : loadNews(link))); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; }) diff --git a/lib/v2/jump/discount.js b/lib/v2/jump/discount.js index 518b86ea9..9481071cb 100644 --- a/lib/v2/jump/discount.js +++ b/lib/v2/jump/discount.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 discountUrl = 'https://switch.jumpvg.com/jump/discount/find4Discount/5/v2'; @@ -94,9 +94,9 @@ const getAllPageDiscountItem = async (countries, platform, termsId, totalNum) => // }; module.exports = async (ctx) => { - const platform = ctx.params.platform; - const filter = ctx.params.filter || 'all'; - const countries = ctx.params.countries || ''; + const platform = ctx.req.param('platform'); + const filter = ctx.req.param('filter') || 'all'; + const countries = ctx.req.param('countries') || ''; const discountNum = await getDiscountNum(platform); const allDiscountItem = await getAllPageDiscountItem(countries, platformObject[platform.toLocaleLowerCase()], filterObject[platform.toLocaleLowerCase()][filter], discountNum); @@ -106,7 +106,7 @@ module.exports = async (ctx) => { // await seqGetGameDetail(allDiscountItem, ctx); // } - ctx.state.data = { + ctx.set('data', { title: `jump 折扣-${platform}-${filterName[filter]}${countries ? `-${countries}` : ''}`, link: 'https://jumpvg.com/', description: 'jump 发现游戏', @@ -116,5 +116,5 @@ module.exports = async (ctx) => { link: item.banner, guid: `${platform}-${item.oldGameId}-${item.cutOff}`, // 平台-打折id-打折率 })), - }; + }); }; diff --git a/lib/v2/kamen-rider-official/news.js b/lib/v2/kamen-rider-official/news.js index d31c38cfb..0a84cee6e 100644 --- a/lib/v2/kamen-rider-official/news.js +++ b/lib/v2/kamen-rider-official/news.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 } = 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.kamen-rider-official.com'; const apiUrl = new URL('api/v1/news_articles', rootUrl).href; @@ -52,7 +52,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('a.c-button').each(function () { content(this).parent().remove(); @@ -90,11 +90,11 @@ module.exports = async (ctx) => { ) ); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${$('title').text().split(/ー/)[0]}${category ? ` - ${category}` : ''}`, link: currentUrl, @@ -106,5 +106,5 @@ module.exports = async (ctx) => { subtitle: $('meta[property="keywords"]').prop('content'), author: $('meta[property="og:site_name"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/kantarworldpanel/index.js b/lib/v2/kantarworldpanel/index.js index 6cbc25982..6774f19aa 100644 --- a/lib/v2/kantarworldpanel/index.js +++ b/lib/v2/kantarworldpanel/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 { region = 'cn-en', category = 'news' } = 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://www.kantarworldpanel.com/'; const currentUrl = new URL(`${region}/${category}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('ul.slide, #newssource') .find('li') @@ -67,7 +67,7 @@ module.exports = async (ctx) => { return item; } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('h1.newshead').text(); item.description = content('div.center-content div.left-layout-col').html(); @@ -81,7 +81,7 @@ module.exports = async (ctx) => { const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -92,5 +92,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="keywords"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/kbs/news.js b/lib/v2/kbs/news.js index 866ca6324..5663e488d 100644 --- a/lib/v2/kbs/news.js +++ b/lib/v2/kbs/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'; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'all'; - const language = ctx.params.language ?? 'e'; + const category = ctx.req.param('category') ?? 'all'; + const language = ctx.req.param('language') ?? 'e'; const rootUrl = 'http://world.kbs.co.kr'; const currentUrl = `${rootUrl}/service/news_list.htm?lang=${language}${category === 'all' ? '' : `&id=${category}`}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.comp_pagination').remove(); @@ -50,7 +50,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.body_txt').html(); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.active').text() || list[0].category} - KBS WORLD`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/kbs/today.js b/lib/v2/kbs/today.js index b09f73389..e57985b9a 100644 --- a/lib/v2/kbs/today.js +++ b/lib/v2/kbs/today.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 language = ctx.params.language ?? 'e'; + const language = ctx.req.param('language') ?? 'e'; const rootUrl = 'http://world.kbs.co.kr'; const currentUrl = `${rootUrl}/service/news_today.htm?lang=${language}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.comp_text_1x article') .map((_, item) => { @@ -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('.body_txt').html(); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Latest News | KBS WORLD`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/kcna/news.js b/lib/v2/kcna/news.js index ab3e0a026..cb148eddd 100644 --- a/lib/v2/kcna/news.js +++ b/lib/v2/kcna/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 asyncPool = require('tiny-async-pool'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const { parseJucheDate, fixDesc, fetchPhoto, fetchVideo } = require('./utils'); const path = require('path'); const sanitizeHtml = require('sanitize-html'); @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const pageUrl = `${rootUrl}/${lang}/category/articles/q/${category}.kcmsf`; const response = await got(pageUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); // fix ??? const title = sanitizeHtml($('head > title').text(), { allowedTags: [], allowedAttributes: {} }); @@ -39,7 +39,7 @@ module.exports = async (ctx) => { for await (const item of asyncPool(3, list, (item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('article-main-title').text() || item.title; const dateElem = $('.publish-time'); @@ -72,9 +72,9 @@ module.exports = async (ctx) => { items.push(item); } - ctx.state.data = { + ctx.set('data', { title, link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/kcna/utils.js b/lib/v2/kcna/utils.js index 7725cd7ed..786b99523 100644 --- a/lib/v2/kcna/utils.js +++ b/lib/v2/kcna/utils.js @@ -1,6 +1,6 @@ -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; const rootUrl = 'http://www.kcna.kp'; @@ -35,7 +35,7 @@ const fixDesc = ($, elem) => { const fetchPhoto = (ctx, url) => ctx.cache.tryGet(url, async () => { const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); let html = ''; $('.content img').each((_, item) => { const src = item.attribs.src; @@ -49,7 +49,7 @@ const fetchPhoto = (ctx, url) => const fetchVideo = (ctx, url) => ctx.cache.tryGet(url, async () => { const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const js = $('script[type="text/javascript"]:not([src])').html(); let sources = js.match(/<[^>]*source[^>]+src[^>]+>/g); sources = sources && sources.map((item) => item.replaceAll("'", '"').replaceAll(/src="([^"]+)"/g, `src="${rootUrl}$1"`)); diff --git a/lib/v2/ke/results.js b/lib/v2/ke/results.js index 642287bc1..4a28b6460 100644 --- a/lib/v2/ke/results.js +++ b/lib/v2/ke/results.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 response = await got({ @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const { list } = data.data; - ctx.state.data = { + ctx.set('data', { title: '房地产行业研究报告', link: 'https://research.ke.com/ResearchResults', description: '研究成果', @@ -32,5 +32,5 @@ module.exports = async (ctx) => { description: item.guideReading, pubDate: parseDate(item.publishTime), })), - }; + }); }; diff --git a/lib/v2/keep/user.js b/lib/v2/keep/user.js index 5d54ec80b..448f8e9e0 100644 --- a/lib/v2/keep/user.js +++ b/lib/v2/keep/user.js @@ -1,9 +1,9 @@ -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) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got({ method: 'get', @@ -21,7 +21,7 @@ module.exports = async (ctx) => { response.data.data.entries[0] = response.data.data.entries[0].entries; const data = response.data.data.entries.reduce((all, current) => [...all, ...current.entries]); - ctx.state.data = { + ctx.set('data', { title: `${data[0].author.username} 的 Keep 动态`, link: `https://show.gotokeep.com/users/${id}`, language: 'zh-cn', @@ -53,5 +53,5 @@ module.exports = async (ctx) => { }), }; }), - }; + }); }; diff --git a/lib/v2/keepass/news.js b/lib/v2/keepass/news.js index b22e8a10e..ddbd20a9b 100644 --- a/lib/v2/keepass/news.js +++ b/lib/v2/keepass/news.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://keepass.info/news/news_all.html'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = $('p > a') .toArray() @@ -17,7 +17,7 @@ module.exports = async (ctx) => { pubDate: parseDate(elem.next().next('small').text().split('.')[0]), }; }) - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 10); + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10); const items = await Promise.all( list.map((item) => @@ -27,7 +27,7 @@ module.exports = async (ctx) => { } const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); $('.sectionheader').remove(); $('.laytablews > tbody> tr:nth-child(1) > td:nth-child(2) > p').first().remove(); @@ -38,9 +38,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').attr('content'), link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/kemono/index.js b/lib/v2/kemono/index.js index bc7215aac..9b2a06d9e 100644 --- a/lib/v2/kemono/index.js +++ b/lib/v2/kemono/index.js @@ -1,13 +1,13 @@ -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 limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25; - const source = ctx.params.source ?? ''; - const id = ctx.params.id; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25; + const source = ctx.req.param('source') ?? ''; + const id = ctx.req.param('id'); const rootUrl = 'https://kemono.su'; const apiUrl = `${rootUrl}/api/v1/discord/channel/lookup/${id}`; @@ -56,7 +56,7 @@ module.exports = async (ctx) => { ); items = items.flat(); } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); title = $('title').text(); image = $('.user-header__avatar img[src]').attr('src'); @@ -81,7 +81,7 @@ module.exports = async (ctx) => { headers, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.post__thumbnail').each(function () { const href = content(this).find('.fileThumb').attr('href'); @@ -120,10 +120,10 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title, image, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/kepu/live.js b/lib/v2/kepu/live.js index 32f77f0bc..c4ef2cc41 100644 --- a/lib/v2/kepu/live.js +++ b/lib/v2/kepu/live.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 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://live.kepu.net.cn'; const apiRootUrl = 'https://live.kepu.net.cn:8089'; @@ -72,7 +72,7 @@ module.exports = async (ctx) => { const author = '中国科普博览'; const subtitle = '直播回看'; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -85,5 +85,5 @@ module.exports = async (ctx) => { itunes_author: author, itunes_category: 'Science', allowEmpty: true, - }; + }); }; diff --git a/lib/v2/keylol/index.js b/lib/v2/keylol/index.js index 1f55d5271..5ab2aa182 100644 --- a/lib/v2/keylol/index.js +++ b/lib/v2/keylol/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'; module.exports = async (ctx) => { let thePath = ctx.path.replace(/^\//, ''); @@ -10,14 +10,14 @@ module.exports = async (ctx) => { thePath = `fid=${thePath.match(/^f(\d+)-\d+/)[1]}`; } - 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://keylol.com'; const currentUrl = new URL(`forum.php?mod=forumdisplay&${thePath.replaceAll(/mod=\w+&/g, '')}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a.xst') .slice(0, limit) @@ -36,7 +36,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.description = content('td.t_f').html(); item.author = content('a.xw1').first().text(); @@ -68,7 +68,7 @@ module.exports = async (ctx) => { const icon = $('link[rel="apple-touch-icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -78,5 +78,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="application-name"]').prop('content'), author: $('meta[name="author"]').prop('content'), - }; + }); }; diff --git a/lib/v2/kimlaw/thesis.js b/lib/v2/kimlaw/thesis.js index d4facb381..eec5efd6d 100644 --- a/lib/v2/kimlaw/thesis.js +++ b/lib/v2/kimlaw/thesis.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.kimlaw.or.kr'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/67`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.li_body') .toArray() .map((item) => { @@ -27,7 +27,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 = $('.board_txt_area').html(); return item; @@ -35,10 +35,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.widget_menu_title').text()} - ${$('head title').text()}`, link, image: 'https://cdn.imweb.me/upload/S20210819f9dd86d20e7d7/9aec17c4e98a5.ico', item: items, - }; + }); }; diff --git a/lib/v2/konghq/blog-posts.js b/lib/v2/konghq/blog-posts.js index 9fac6d334..08f1f4275 100644 --- a/lib/v2/konghq/blog-posts.js +++ b/lib/v2/konghq/blog-posts.js @@ -1,7 +1,7 @@ // Get the lastest blog posts of https://konghq.com/ -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_URL = 'https://konghq.com'; const BLOG_POSTS_URL = `${BASE_URL}/blog`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { // Request and parse the index page to get the posts const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const posts = nextData.props.pageProps.cardsPaged.cards.map((item) => { const title = item.title; @@ -35,7 +35,7 @@ module.exports = async (ctx) => { posts.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); // Update the description to post's main content item.description = $('section[class^="blog_sections"]').first().html(); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Kong Inc(konghq.com) blog posts`, link: BLOG_POSTS_URL, item: items, - }; + }); }; diff --git a/lib/v2/kuaidi100/index.js b/lib/v2/kuaidi100/index.js index 23176d9b8..01c653c60 100644 --- a/lib/v2/kuaidi100/index.js +++ b/lib/v2/kuaidi100/index.js @@ -31,7 +31,7 @@ module.exports = async (ctx) => { // Maybe we can look into isCheck, condition, and state :) // But I just want to make it work for now. - ctx.state.data = { + ctx.set('data', { title: `快递 ${company.name}-${id}`, link: 'https://www.kuaidi100.com', description: `快递 ${company.name}-${id}`, @@ -42,5 +42,5 @@ module.exports = async (ctx) => { pubDate: new Date(item.time || item.ftime).toUTCString(), link: 'https://www.kuaidi100.com', })), - }; + }); }; diff --git a/lib/v2/kuaidi100/supported-company.js b/lib/v2/kuaidi100/supported-company.js index 8553d235b..247ebe150 100644 --- a/lib/v2/kuaidi100/supported-company.js +++ b/lib/v2/kuaidi100/supported-company.js @@ -2,7 +2,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { const ls = await utils.company(ctx); - ctx.state.data = { + ctx.set('data', { title: `快递100 快递列表`, link: 'https://www.kuaidi100.com', description: `快递100 所支持的快递列表及其查询名称`, @@ -12,5 +12,5 @@ module.exports = async (ctx) => { category: item.comTypeName, link: item.siteUrl, })), - }; + }); }; diff --git a/lib/v2/kuaidi100/utils.js b/lib/v2/kuaidi100/utils.js index cf8355134..631541915 100644 --- a/lib/v2/kuaidi100/utils.js +++ b/lib/v2/kuaidi100/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const wwwid_key = 'kuaidi100-wwwid'; const csrf_key = 'kuaidi100-csrf'; const globacsrftoken_key = 'kuaidi100-globacsrftoken'; diff --git a/lib/v2/kunchengblog/essay.js b/lib/v2/kunchengblog/essay.js index 61a829045..42f203456 100644 --- a/lib/v2/kunchengblog/essay.js +++ b/lib/v2/kunchengblog/essay.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { SourceMapConsumer } = require('source-map'); module.exports = async (ctx) => { - 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.kunchengblog.com'; const currentUrl = new URL('essay', rootUrl).href; const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const title = $('title').text(); @@ -32,7 +32,7 @@ module.exports = async (ctx) => { return `${key}="${processedValue}"`; }); - const content = cheerio.load(processedSource); + const content = load(processedSource); return { title: content('title').text(), @@ -50,7 +50,7 @@ module.exports = async (ctx) => { const description = $('meta[name="description"]').prop('content'); const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${title} - Essay`, link: currentUrl, @@ -62,5 +62,5 @@ module.exports = async (ctx) => { subtitle: description, author: title, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/kuwaitlocal/index.js b/lib/v2/kuwaitlocal/index.js index ad7fcbb68..2697c7060 100644 --- a/lib/v2/kuwaitlocal/index.js +++ b/lib/v2/kuwaitlocal/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 baseUrl = 'https://kuwaitlocal.com'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${baseUrl}/news/${category === 'latest' ? category : `categories/${category}`}`; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('a.ggrid') .toArray() .map((item) => { @@ -23,7 +23,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.pubDate = parseDate($('.single_news_meta span').eq(0).text().trim()); item.category = $('.tags .tag') @@ -38,11 +38,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text().trim(), description: $('head meta[name="description"]').attr('content').trim(), link: url, item: items, language: 'en', - }; + }); }; diff --git a/lib/v2/kyodonews/index.js b/lib/v2/kyodonews/index.js index 600bb9bd1..0c209651a 100644 --- a/lib/v2/kyodonews/index.js +++ b/lib/v2/kyodonews/index.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -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 resolveRelativeLink = (link, baseUrl) => (link.startsWith('http') ? link : `${baseUrl}${link}`); module.exports = async (ctx) => { - const language = ctx.params.language ?? 'china'; - const keyword = ctx.params.keyword === 'RSS' ? 'rss' : ctx.params.keyword ?? ''; + const language = ctx.req.param('language') ?? 'china'; + const keyword = ctx.req.param('keyword') === 'RSS' ? 'rss' : ctx.req.param('keyword') ?? ''; // raise error for invalid languages if (!['china', 'tchina'].includes(language)) { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { throw error.response && error.response.statusCode === 404 ? new Error('Invalid keyword') : error; } - const $ = cheerio.load(response.data, { xmlMode: keyword === 'rss' }); + const $ = load(response.data, { xmlMode: keyword === 'rss' }); let title, description, image, items; image = `${rootUrl}/apple-touch-icon-180x180.png`; @@ -65,7 +65,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); item.title = $('head > title').text(); item.author = $('meta[name="author"]').attr('content'); @@ -113,11 +113,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, description, link: currentUrl, item: items, image, - }; + }); }; diff --git a/lib/v2/laimanhua/index.js b/lib/v2/laimanhua/index.js index 98440a2b7..d52d73f61 100644 --- a/lib/v2/laimanhua/index.js +++ b/lib/v2/laimanhua/index.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const iconv = require('iconv-lite'); -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; @@ -11,12 +11,12 @@ module.exports = async (ctx) => { const { data: response } = await got(link, { responseType: 'buffer', }); - let $ = cheerio.load(iconv.decode(response, 'utf-8')); + let $ = load(iconv.decode(response, 'utf-8')); const charset = $('meta[http-equiv="Content-Type"]') .attr('content') ?.match(/charset=(.*)/)?.[1]; if (charset?.toLowerCase() !== 'utf-8') { - $ = cheerio.load(iconv.decode(response, charset ?? 'utf-8')); + $ = load(iconv.decode(response, charset ?? 'utf-8')); } const items = $('.plist a') @@ -31,11 +31,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${$('head meta[property="og:novel:book_name"]').attr('content')} - 来漫画`, description: $('.introduction').text(), image: $('head meta[property="og:image"]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/lala/rss.js b/lib/v2/lala/rss.js index 82eba69a7..3f0c63123 100644 --- a/lib/v2/lala/rss.js +++ b/lib/v2/lala/rss.js @@ -1,10 +1,10 @@ -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://lala.im'; const response = await got(`${currentUrl}/feed`); - const $ = cheerio.load(response.data, { xmlMode: true }); + const $ = load(response.data, { xmlMode: true }); const titleMain = $('channel > title').text(); const descriptionMain = $('channel > description').text(); const items = $('channel > item') @@ -23,10 +23,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: titleMain, description: descriptionMain, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/lang/room.js b/lib/v2/lang/room.js index 8a6471932..bd7a77430 100644 --- a/lib/v2/lang/room.js +++ b/lib/v2/lang/room.js @@ -1,9 +1,9 @@ -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) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const url = `https://www.lang.live/room/${id}`; const api = 'https://api.lang.live/langweb/v1/room/liveinfo'; @@ -30,11 +30,11 @@ module.exports = async (ctx) => { ]; } - ctx.state.data = { + ctx.set('data', { title: `${name} 的浪 Play 直播`, description: data.live_info.sign, link: url, item, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/lanqiao/author.js b/lib/v2/lanqiao/author.js index 6c802929c..d613e54d0 100644 --- a/lib/v2/lanqiao/author.js +++ b/lib/v2/lanqiao/author.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); const MarkdownIt = require('markdown-it'); @@ -16,7 +16,7 @@ async function getUserName(uid) { } module.exports = async (ctx) => { - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const userName = await getUserName(uid); // 发起 HTTP GET 请求 const response = await got({ @@ -48,7 +48,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { // 源标题 title: `${userName} 发布的课程`, // 源链接 @@ -57,5 +57,5 @@ module.exports = async (ctx) => { description: `${userName} 发布的课程`, // 遍历此前获取的数据 item: items, - }; + }); }; diff --git a/lib/v2/lanqiao/courses.js b/lib/v2/lanqiao/courses.js index 6003a5b07..44e1fa907 100644 --- a/lib/v2/lanqiao/courses.js +++ b/lib/v2/lanqiao/courses.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); const MarkdownIt = require('markdown-it'); module.exports = async (ctx) => { - const sort = ctx.params.sort; - const tag = ctx.params.tag; + const sort = ctx.req.param('sort'); + const tag = ctx.req.param('tag'); // 发起 HTTP GET 请求 const response = await got({ method: 'get', @@ -49,7 +49,7 @@ module.exports = async (ctx) => { default: '默认', }; - ctx.state.data = { + ctx.set('data', { // 源标题 title: `蓝桥云课${sortType[sort]}课程列表【${tag}】`, // 源链接 @@ -58,5 +58,5 @@ module.exports = async (ctx) => { description: `蓝桥云课【${tag}】标签下${sortType[sort]}课程列表`, // 遍历此前获取的数据 item: items, - }; + }); }; diff --git a/lib/v2/lanqiao/questions.js b/lib/v2/lanqiao/questions.js index 1efdfdfbb..bd9b8adf3 100644 --- a/lib/v2/lanqiao/questions.js +++ b/lib/v2/lanqiao/questions.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 MarkdownIt = require('markdown-it'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); // 发起 HTTP GET 请求 const response = await got({ method: 'get', @@ -41,7 +41,7 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { // 源标题 title: `蓝桥云课技术社区【${topic_name}】`, // 源链接 @@ -50,5 +50,5 @@ module.exports = async (ctx) => { description: `蓝桥云课技术社区【${topic_name}】`, // 遍历此前获取的数据 item: items, - }; + }); }; diff --git a/lib/v2/lanqiao/utils.js b/lib/v2/lanqiao/utils.js index e43ff4826..9ca3d6ed2 100644 --- a/lib/v2/lanqiao/utils.js +++ b/lib/v2/lanqiao/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const courseDesc = (picurl, desc) => diff --git a/lib/v2/laohu8/personal.js b/lib/v2/laohu8/personal.js index 1b4ae1a1e..e67334a95 100644 --- a/lib/v2/laohu8/personal.js +++ b/lib/v2/laohu8/personal.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 rootUrl = 'https://www.laohu8.com'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const url = `${rootUrl}/personal/${id}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const author = $('h2.personal-name').text(); const data = JSON.parse($('#__APP_DATA__').text()).tweetList; @@ -24,9 +24,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `老虎社区 - ${author} 个人社区`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/latepost/index.js b/lib/v2/latepost/index.js index 076d530e6..ea601667a 100644 --- a/lib/v2/latepost/index.js +++ b/lib/v2/latepost/index.js @@ -1,6 +1,6 @@ -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'); /** @@ -22,7 +22,7 @@ const arrayToDictionary = (arr) => module.exports = async (ctx) => { const { proma } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 5; const title = '晚点'; const defaultTitle = '最新报道'; @@ -67,7 +67,7 @@ module.exports = async (ctx) => { delete_num: 0, }); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.title = item.title ?? content('div.article-header-title').text(); item.description = content('#select-main').html().replaceAll('


', ''); @@ -93,9 +93,9 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); - ctx.state.data = { + ctx.set('data', { item: items, title: `${title} - ${proma ? columns[proma].title : defaultTitle}`, link: currentUrl, @@ -105,5 +105,5 @@ module.exports = async (ctx) => { icon, logo: icon, author: title, - }; + }); }; diff --git a/lib/v2/layoffs/index.js b/lib/v2/layoffs/index.js index 94d874ab7..e751a1447 100644 --- a/lib/v2/layoffs/index.js +++ b/lib/v2/layoffs/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 ROW_COUNT = 100; @@ -73,7 +73,7 @@ module.exports = async (ctx) => { method: 'get', url: ENTRY_URL, }); - const $ = cheerio.load(sourcePage.data); + const $ = load(sourcePage.data); dataSourceUrl = AIRTABLE_HOST + $('script') @@ -107,7 +107,7 @@ module.exports = async (ctx) => { const countryMapping = getMappings(table.columns.find((col) => col.name === 'Country').typeOptions.choices)[0]; const rows = table.rows.slice(0, ROW_COUNT); - ctx.state.data = { + ctx.set('data', { title: 'Tech layoff data feed from layoffs.fyi', link: WEBSITE_URL, description: 'This feed gets tech layoff data from layoffs.fyi and display them in a user friendly way', @@ -130,5 +130,5 @@ module.exports = async (ctx) => { link: source, // Laid off source link }; }), - }; + }); }; diff --git a/lib/v2/learnblockchain/posts.js b/lib/v2/learnblockchain/posts.js index 29cef50c8..52bece7da 100644 --- a/lib/v2/learnblockchain/posts.js +++ b/lib/v2/learnblockchain/posts.js @@ -1,10 +1,10 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseRelativeDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseRelativeDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const cid = ctx.params.cid || 'all'; - const sort = ctx.params.sort; + const cid = ctx.req.param('cid') || 'all'; + const sort = ctx.req.param('sort'); let url = 'https://learnblockchain.cn/categories/'; url += cid + '/'; @@ -16,10 +16,10 @@ module.exports = async (ctx) => { const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('div.stream-list section.stream-list-item'); - ctx.state.data = { + ctx.set('data', { title: `登链社区--${cid}`, link: url, description: `登链社区`, @@ -39,5 +39,5 @@ module.exports = async (ctx) => { return json; }) .get(), - }; + }); }; diff --git a/lib/v2/learnku/topic.js b/lib/v2/learnku/topic.js index d41006001..f322f5c65 100644 --- a/lib/v2/learnku/topic.js +++ b/lib/v2/learnku/topic.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'; module.exports = async (ctx) => { - const community = ctx.params.community; - const category = ctx.params.category || ''; + const community = ctx.req.param('community'); + const category = ctx.req.param('category') || ''; let url = `https://learnku.com/${community}`; if (category !== '') { @@ -19,11 +19,11 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.simple-topic').get(); const item = await Promise.all( list.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const categoryName = $('.category-name span').text().trim(); if (['置顶', '广告'].includes(categoryName)) { return ''; @@ -35,7 +35,7 @@ module.exports = async (ctx) => { const content = await ctx.cache.tryGet(itemLink, async () => { const result = await got.get(itemLink); - return cheerio.load(result.data); + return load(result.data); }); const article = content('.article-content .content-body').html(); const comment = content('#all-comments').html(); @@ -63,10 +63,10 @@ module.exports = async (ctx) => { ['links', { name: '链接' }], ['', { name: '最新' }], ]); - ctx.state.data = { + ctx.set('data', { title: `LearnKu - ${title} - ${categoryTitle.get(category).name}`, link: url, description, item: item.filter((item) => item !== ''), - }; + }); }; diff --git a/lib/v2/leetcode/articles.js b/lib/v2/leetcode/articles.js index 12ff1f8f8..814c5054a 100644 --- a/lib/v2/leetcode/articles.js +++ b/lib/v2/leetcode/articles.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')({ html: true, breaks: true, @@ -12,7 +12,7 @@ const gqlEndpoint = `${host}/graphql`; module.exports = async (ctx) => { const link = new URL('/articles/', host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a.list-group-item') .filter((i, e) => $(e).find('h4.media-heading i').length === 0) @@ -74,11 +74,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[property="og:description"]').attr('content'), image: 'https://assets.leetcode.com/static_assets/public/icons/favicon-192x192.png', link, item: out, - }; + }); }; diff --git a/lib/v2/leetcode/dailyquestion-cn.js b/lib/v2/leetcode/dailyquestion-cn.js index 67c83df41..d6904873d 100644 --- a/lib/v2/leetcode/dailyquestion-cn.js +++ b/lib/v2/leetcode/dailyquestion-cn.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 host = 'https://leetcode.cn'; @@ -100,7 +100,7 @@ module.exports = async (ctx) => { link: question.link, }; - ctx.state.data = { + ctx.set('data', { title: 'LeetCode 每日一题', link: 'https://leetcode.cn', description: 'Leetcode 每日一题', @@ -111,5 +111,5 @@ module.exports = async (ctx) => { link: rssData.link, }, ], - }; + }); }; diff --git a/lib/v2/leetcode/dailyquestion-en.js b/lib/v2/leetcode/dailyquestion-en.js index b6b81ef43..cbfd28fcb 100644 --- a/lib/v2/leetcode/dailyquestion-en.js +++ b/lib/v2/leetcode/dailyquestion-en.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 host = 'https://leetcode.com'; @@ -101,7 +101,7 @@ module.exports = async (ctx) => { link: question.link, }; - ctx.state.data = { + ctx.set('data', { title: 'LeetCode Daily Question', link: 'https://leetcode.com', description: 'Leetcode Daily Question', @@ -112,5 +112,5 @@ module.exports = async (ctx) => { link: rssData.link, }, ], - }; + }); }; diff --git a/lib/v2/leetcode/dailyquestion-solution-cn.js b/lib/v2/leetcode/dailyquestion-solution-cn.js index 268b91daa..67e163602 100644 --- a/lib/v2/leetcode/dailyquestion-solution-cn.js +++ b/lib/v2/leetcode/dailyquestion-solution-cn.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, breaks: true, }); -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 baseurl = `https://leetcode.cn`; const url = `${baseurl}/graphql/`; @@ -163,7 +163,7 @@ module.exports = async (ctx) => { s = s.replaceAll(/(```)([\d#+A-Za-z-]+)\s*?(\[.*?])?\n/g, '\r\n###$2\r\n$1$2\r\n'); return s; }; - ctx.state.data = { + ctx.set('data', { title: 'LeetCode 每日一题题解', description: 'LeetCode 每日一题题解', link: questionUrl, @@ -182,5 +182,5 @@ module.exports = async (ctx) => { author: art.author.username, })), ], - }; + }); }; diff --git a/lib/v2/leetcode/dailyquestion-solution-en.js b/lib/v2/leetcode/dailyquestion-solution-en.js index 9fcaebbe8..1795bdf9a 100644 --- a/lib/v2/leetcode/dailyquestion-solution-en.js +++ b/lib/v2/leetcode/dailyquestion-solution-en.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, breaks: true, }); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const path = require('path'); module.exports = async (ctx) => { const baseurl = `https://leetcode.com`; @@ -193,7 +193,7 @@ module.exports = async (ctx) => { return s; }; article.content = await handleText(article.content); - ctx.state.data = { + ctx.set('data', { title: 'LeetCode DailyQuestion Solution', description: 'LeetCode DailyQuestion Solution', link: questionUrl, @@ -212,5 +212,5 @@ module.exports = async (ctx) => { author: 'leetcode', }, ], - }; + }); }; diff --git a/lib/v2/leiphone/index.js b/lib/v2/leiphone/index.js index 627c37b0b..5064cb051 100644 --- a/lib/v2/leiphone/index.js +++ b/lib/v2/leiphone/index.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); module.exports = async (ctx) => { - const todo = ctx.params.do ?? ''; - const keyword = ctx.params.keyword ?? ''; + const todo = ctx.req.param('do') ?? ''; + const keyword = ctx.req.param('keyword') ?? ''; const rootUrl = 'https://www.leiphone.com'; const url = `${rootUrl}/${todo}/${keyword}`; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.word > h3 > a') .slice(0, 10) @@ -16,10 +16,10 @@ module.exports = async (ctx) => { .map((e) => $(e).attr('href')); const items = await utils.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `雷峰网${todo === 'category' ? ` ${keyword}` : ''}`, description: '雷峰网 - 读懂智能&未来', link: url, item: items, - }; + }); }; diff --git a/lib/v2/leiphone/newsflash.js b/lib/v2/leiphone/newsflash.js index 340b2df97..fb8b9b5ea 100644 --- a/lib/v2/leiphone/newsflash.js +++ b/lib/v2/leiphone/newsflash.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -// const cheerio = require('cheerio'); +// import { load } from 'cheerio'; module.exports = async (ctx) => { const url = 'https://www.leiphone.com/site/YejieKuaixun'; @@ -10,10 +10,10 @@ module.exports = async (ctx) => { const list = article.map((item) => item.url); const items = await utils.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '雷峰网 业界资讯', description: '雷峰网 - 读懂智能&未来', link: url, item: items, - }; + }); }; diff --git a/lib/v2/leiphone/utils.js b/lib/v2/leiphone/utils.js index a82b0a18b..a75389ac7 100644 --- a/lib/v2/leiphone/utils.js +++ b/lib/v2/leiphone/utils.js @@ -1,6 +1,6 @@ -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'; const url = require('url'); const ProcessFeed = async (list, cache) => { @@ -13,7 +13,7 @@ const ProcessFeed = async (list, cache) => { const single = await cache.tryGet(link, async () => { const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let description = ''; if ($('.top-img').html() !== null) { diff --git a/lib/v2/lemmy/index.js b/lib/v2/lemmy/index.js index 3657ad82b..33345e9a1 100644 --- a/lib/v2/lemmy/index.js +++ b/lib/v2/lemmy/index.js @@ -1,19 +1,19 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const md = require('markdown-it')({ html: true }); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const sort = ctx.params.sort ?? 'Active'; - const community = ctx.params.community; + const sort = ctx.req.param('sort') ?? 'Active'; + const community = ctx.req.param('community'); const communitySlices = community.split('@'); if (communitySlices.length !== 2) { - ctx.throw(400, `Invalid community: ${community}`); + throw new Error(`Invalid community: ${community}`); } const instance = community.split('@')[1]; const allowedDomain = ['lemmy.world', 'lemm.ee', 'lemmy.ml', 'sh.itjust.works', 'feddit.de', 'hexbear.net', 'beehaw.org', 'lemmynsfw.com', 'lemmy.ca', 'programming.dev']; if (!config.feature.allow_user_supply_unsafe_domain && !allowedDomain.includes(new URL(`http://${instance}/`).hostname)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const communityUrl = `https://${instance}/api/v3/community?name=${community}`; @@ -52,10 +52,10 @@ module.exports = async (ctx) => { return item; }); - ctx.state.data = { + ctx.set('data', { title: `${community} - ${sort} posts`, description: communityData.description, link: communityData.actor_id, item: items, - }; + }); }; diff --git a/lib/v2/lfsyd/home.js b/lib/v2/lfsyd/home.js index 703444adc..0721095f5 100644 --- a/lib/v2/lfsyd/home.js +++ b/lib/v2/lfsyd/home.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 { ProcessForm, ProcessFeed } = require('./utils'); module.exports = async (ctx) => { @@ -34,9 +34,9 @@ module.exports = async (ctx) => { })); const items = await ProcessFeed(ctx.cache, articleList); - ctx.state.data = { + ctx.set('data', { title: '首页 - 旅法师营地', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/lfsyd/old-home.js b/lib/v2/lfsyd/old-home.js index e81cd1dfd..43cd9648b 100644 --- a/lib/v2/lfsyd/old-home.js +++ b/lib/v2/lfsyd/old-home.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 { ProcessFeed } = require('./utils'); module.exports = async (ctx) => { - const limit = ctx.query.limit ?? 10; + const limit = ctx.req.query('limit') ?? 10; const rootUrl = 'https://www.iyingdi.com'; const url = `${rootUrl}/feed/list/user/v3?feedIdUp=0&feedIdDown=0&hotfeed=1&system=web`; const { data } = await got(url); @@ -21,9 +21,9 @@ module.exports = async (ctx) => { const items = await ProcessFeed(ctx.cache, articleList); - ctx.state.data = { + ctx.set('data', { title: '旅法师营地 - 首页资讯(旧版)', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/lfsyd/tag.js b/lib/v2/lfsyd/tag.js index ee8e1a720..4a3afc3aa 100644 --- a/lib/v2/lfsyd/tag.js +++ b/lib/v2/lfsyd/tag.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 { ProcessForm, ProcessFeed } = require('./utils'); module.exports = async (ctx) => { @@ -56,9 +56,9 @@ module.exports = async (ctx) => { const items = await ProcessFeed(ctx.cache, articleList); - ctx.state.data = { + ctx.set('data', { title: `${tagName || tagJson[0].tag} - 旅法师营地 `, link: `${rootUrl}/tz/tag/${tagId}`, item: items, - }; + }); }; diff --git a/lib/v2/lfsyd/user.js b/lib/v2/lfsyd/user.js index 023789937..6df113735 100644 --- a/lib/v2/lfsyd/user.js +++ b/lib/v2/lfsyd/user.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 { ProcessForm, ProcessFeed } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://www.iyingdi.com'; const listUrl = 'https://api.iyingdi.com/web/user/event-list'; const form = { @@ -40,9 +40,9 @@ module.exports = async (ctx) => { const items = await ProcessFeed(ctx.cache, articleList); - ctx.state.data = { + ctx.set('data', { title: `${nickname} - 旅法师营地 `, link: `${rootUrl}/tz/people/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/lfsyd/utils.js b/lib/v2/lfsyd/utils.js index 8132f02a7..2558870eb 100644 --- a/lib/v2/lfsyd/utils.js +++ b/lib/v2/lfsyd/utils.js @@ -1,8 +1,8 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const md5 = require('@/utils/md5'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import md5 from '@/utils/md5'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const rootUrl = 'https://www.iyingdi.com'; const infoUrL = 'https://api.iyingdi.com/web/post/info'; @@ -47,7 +47,7 @@ const ProcessForm = (form, type) => { const cleanHtml = (htmlString) => { const regex = /(

|

)(.*?)?(标准|狂野)日报投稿.*?<\/strong>(.*?)?(<\/p>|<\/div>)(.|\n)*$/; - const $ = cheerio.load(htmlString.replace(regex, '')); + const $ = load(htmlString.replace(regex, '')); $('.yingdi-car,.bbspost,.deck-set').each((i, e) => { const className = $(e).attr('class'); diff --git a/lib/v2/lifeweek/channel.js b/lib/v2/lifeweek/channel.js index 8ae9168e2..c4cd90c8b 100644 --- a/lib/v2/lifeweek/channel.js +++ b/lib/v2/lifeweek/channel.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const getRssItem = require('./utils'); const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=3&sort=2&tagId'; @@ -6,7 +6,7 @@ const rootUrl = 'https://www.lifeweek.com.cn/column'; const articleRootUrl = 'https://www.lifeweek.com.cn/article'; module.exports = async (ctx) => { - const channel = ctx.params.id; + const channel = ctx.req.param('id'); const url = `${rootApiUrl}=${channel}`; const { data } = await got(url); const result = data.model.articleResponseList; @@ -17,9 +17,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: data.model.tagName, link: `${rootUrl}/${channel}`, item: items, - }; + }); }; diff --git a/lib/v2/lifeweek/tag.js b/lib/v2/lifeweek/tag.js index 51a20bddd..e937c4a70 100644 --- a/lib/v2/lifeweek/tag.js +++ b/lib/v2/lifeweek/tag.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const getRssItem = require('./utils'); const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=4&sort=2&tagId'; const rootUrl = 'https://www.lifeweek.com.cn/articleList'; const articleRootUrl = 'https://www.lifeweek.com.cn/article'; module.exports = async (ctx) => { - const tag = ctx.params.id; + const tag = ctx.req.param('id'); const url = `${rootApiUrl}=${tag}`; const { data } = await got(url); const result = data.model.articleResponseList; @@ -16,9 +16,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: data.model.tagName, link: `${rootUrl}/${tag}`, item: items, - }; + }); }; diff --git a/lib/v2/lifeweek/utils.js b/lib/v2/lifeweek/utils.js index 67b29ae7b..4660cef07 100644 --- a/lib/v2/lifeweek/utils.js +++ b/lib/v2/lifeweek/utils.js @@ -1,6 +1,6 @@ -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 articleApiRootUrl = 'https://www.lifeweek.com.cn/api/article'; async function getRssItem(item, articleLink) { diff --git a/lib/v2/lightnovel/light-novel.js b/lib/v2/lightnovel/light-novel.js index 02e4c097c..ce34ecf9b 100644 --- a/lib/v2/lightnovel/light-novel.js +++ b/lib/v2/lightnovel/light-novel.js @@ -1,7 +1,7 @@ -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; module.exports = async (ctx) => { const baseUrl = 'https://www.lightnovel.us'; @@ -34,7 +34,7 @@ module.exports = async (ctx) => { pubDate: parseDate(item.time), author: item.author, })) - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 5); + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 5); const items = await Promise.all( list.map((item) => @@ -47,16 +47,16 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('#article-main-contents').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: `轻之国度-追踪${keywords}更新-${type} `, link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/line/publisher.js b/lib/v2/line/publisher.js index 4b9df8c2b..f493679a9 100644 --- a/lib/v2/line/publisher.js +++ b/lib/v2/line/publisher.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -43,11 +43,11 @@ module.exports = async (ctx) => { const items = await parseItems(list, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${publisherInfo.data.name} - Line Today`, description: publisherInfo.data.introduction, image: publisherInfo.data.icon ? `https://obs.line-scdn.net/${publisherInfo.data.icon.hash}` : undefined, link: `${baseUrl}/${edition}/v2/publisher/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/line/today.js b/lib/v2/line/today.js index 92ac773e8..d739af5c7 100644 --- a/lib/v2/line/today.js +++ b/lib/v2/line/today.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl: rootUrl, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { - const edition = ctx.params.edition || 'tw'; - const tab = ctx.params.tab || 'top'; + const edition = ctx.req.param('edition') || 'tw'; + const tab = ctx.req.param('tab') || 'top'; const tabUrl = `${rootUrl}/webapi/portal/page/${tab}?country=${edition}`; const recommendationUrl = `${rootUrl}/webapi/api/v6/recommendation/articles/listings/mytoday_rec:id?offset=0&length=50&country=${edition}&gender=&age=&excludeNoThumbnail=0&containMainSnapshot=0`; @@ -36,9 +36,9 @@ module.exports = async (ctx) => { const items = await parseItems(list, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: `${title} - Line Today`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/line/utils.js b/lib/v2/line/utils.js index 206d09cc8..343dcc00f 100644 --- a/lib/v2/line/utils.js +++ b/lib/v2/line/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 logger = require('@/utils/logger'); const baseUrl = 'https://today.line.me'; @@ -36,7 +36,7 @@ const parseItems = (list, tryGet) => throw error; } - const $ = cheerio.load(data.data.content, null, false); + const $ = load(data.data.content, null, false); $('img').each((_, img) => { delete img.attribs['data-hashid']; diff --git a/lib/v2/linkedin/cn/index.js b/lib/v2/linkedin/cn/index.js index 2958a1472..077797fca 100644 --- a/lib/v2/linkedin/cn/index.js +++ b/lib/v2/linkedin/cn/index.js @@ -5,9 +5,9 @@ const siteUrl = 'https://www.linkedin.cn/incareer/jobs/search'; module.exports = async (ctx) => { const { title, jobs } = await parseSearchHit(ctx); const items = await Promise.all(jobs.map((job) => parseJobPosting(ctx, job))); - ctx.state.data = { + ctx.set('data', { title: `领英 - ${title}`, link: siteUrl, item: items, - }; + }); }; diff --git a/lib/v2/linkedin/cn/utils.js b/lib/v2/linkedin/cn/utils.js index 95f48c955..20e09ff81 100644 --- a/lib/v2/linkedin/cn/utils.js +++ b/lib/v2/linkedin/cn/utils.js @@ -1,7 +1,7 @@ const crypto = require('crypto'); const path = require('path'); -const { art } = require('@/utils/render'); -const got = require('@/utils/got'); +import { art } from '@/utils/render'; +import got from '@/utils/got'; const { parseAttr } = require('./renderer'); const apiUrl = 'https://www.linkedin.cn/karpos/api/graphql'; @@ -66,14 +66,14 @@ const ctxToTitle = (ctx) => { const parseSearchHit = async (ctx) => { const variables = { origin: 'jserp', - isForRemoteJobsPage: !!ctx.query.remote, + isForRemoteJobsPage: !!ctx.req.query('remote'), isChinaMultiNationalCorporation: false, - count: ctx.query.limit || 20, + count: ctx.req.query('limit') || 20, start: '0', - geoUrn: `urn:li:ks_geo:${location[ctx.query.location] || ctx.query.geo || location.china}`, - keywords: decodeURIComponent(ctx.params.keywords || ''), - f_TPR: period[ctx.query.period] || '', - sortType: ctx.query.relevant ? '' : 'DATE_DESCENDING', + geoUrn: `urn:li:ks_geo:${location[ctx.req.query('location')] || ctx.req.query('geo') || location.china}`, + keywords: decodeURIComponent(ctx.req.param('keywords') || ''), + f_TPR: period[ctx.req.query('period')] || '', + sortType: ctx.req.query('relevant') ? '' : 'DATE_DESCENDING', }; const resp = await got.post(apiUrl, { diff --git a/lib/v2/linkedin/jobs.js b/lib/v2/linkedin/jobs.js index 268ad5349..cf1594052 100644 --- a/lib/v2/linkedin/jobs.js +++ b/lib/v2/linkedin/jobs.js @@ -1,16 +1,16 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const { parseJobSearch, KEYWORDS_QUERY_KEY, JOB_TYPES, JOB_TYPES_QUERY_KEY, EXP_LEVELS_QUERY_KEY, parseParamsToSearchParams, EXP_LEVELS, parseParamsToString } = require('./utils'); const BASE_URL = 'https://www.linkedin.com/'; const JOB_SEARCH_PATH = '/jobs-guest/jobs/api/seeMoreJobPostings/search'; module.exports = async (ctx) => { - const jobTypesParam = parseParamsToSearchParams(ctx.params.job_types, JOB_TYPES); - const expLevelsParam = parseParamsToSearchParams(ctx.params.exp_levels, EXP_LEVELS); + const jobTypesParam = parseParamsToSearchParams(ctx.req.param('job_types'), JOB_TYPES); + const expLevelsParam = parseParamsToSearchParams(ctx.req.param('exp_levels'), EXP_LEVELS); let url = new URL(JOB_SEARCH_PATH, BASE_URL); - url.searchParams.append(KEYWORDS_QUERY_KEY, ctx.params.keywords || ''); + url.searchParams.append(KEYWORDS_QUERY_KEY, ctx.req.param('keywords') || ''); url.searchParams.append(JOB_TYPES_QUERY_KEY, jobTypesParam); // see JOB_TYPES in utils.js url.searchParams.append(EXP_LEVELS_QUERY_KEY, expLevelsParam); // see EXPERIENCE_LEVELS in utils.js url = url.toString(); @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }); const jobs = parseJobSearch(response.data); - const jobTypes = parseParamsToString(ctx.params.job_types, JOB_TYPES); - const expLevels = parseParamsToString(ctx.params.exp_levels, EXP_LEVELS); - const feedTitle = 'LinkedIn Job Listing' + (jobTypes ? ` | Job Types: ${jobTypes}` : '') + (expLevels ? ` | Experience Levels: ${expLevels}` : '') + (ctx.params.keywords ? ` | Keywords: ${ctx.params.keywords}` : ''); - ctx.state.data = { + const jobTypes = parseParamsToString(ctx.req.param('job_types'), JOB_TYPES); + const expLevels = parseParamsToString(ctx.req.param('exp_levels'), EXP_LEVELS); + const feedTitle = 'LinkedIn Job Listing' + (jobTypes ? ` | Job Types: ${jobTypes}` : '') + (expLevels ? ` | Experience Levels: ${expLevels}` : '') + (ctx.req.param('keywords') ? ` | Keywords: ${ctx.req.param('keywords')}` : ''); + ctx.set('data', { title: feedTitle, link: url, description: 'This feed gets LinkedIn job posts', @@ -40,5 +40,5 @@ module.exports = async (ctx) => { link: job.link, // job source link }; }), - }; + }); }; diff --git a/lib/v2/linkedin/utils.js b/lib/v2/linkedin/utils.js index 407333bf7..6e11a64d6 100644 --- a/lib/v2/linkedin/utils.js +++ b/lib/v2/linkedin/utils.js @@ -1,4 +1,4 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const { Job } = require('./models'); /** @@ -73,7 +73,7 @@ function parseParamsToString(params, map) { * @returns {Job[]} Array of jobs with data filled */ function parseJobSearch(data) { - const $ = cheerio.load(data); + const $ = load(data); // Parse data const jobs = $('li') @@ -100,7 +100,7 @@ function parseJobSearch(data) { */ function parseJobDetail(data) { const job = new Job(); - const $ = cheerio.load(data); + const $ = load(data); job.recruiter = $('a.message-the-recruiter__cta').attr(`href`); job.description = $('div.description__text description__text--rich').text(); diff --git a/lib/v2/linkresearcher/index.js b/lib/v2/linkresearcher/index.js index ff8ccb883..f3bbf3527 100644 --- a/lib/v2/linkresearcher/index.js +++ b/lib/v2/linkresearcher/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const qs = require('query-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const baseURL = 'https://www.linkresearcher.com'; @@ -57,12 +57,12 @@ module.exports = async (ctx) => { author: item.authors === undefined ? '' : item.authors.join(', '), })); - ctx.state.data = { + ctx.set('data', { title: `领研 | ${title}`, description: '领研是链接华人学者的人才及成果平台。领研为国内外高校、科研机构及科技企业提供科研人才招聘服务,也是青年研究者的职业发展指导及线上培训平台;研究者还可将自己的研究论文上传至领研,与超过五十万华人学者分享工作的最新进展。', image: 'https://www.linkresearcher.com/assets/images/logo-app.png', link: baseURL, item: out, - }; + }); }; diff --git a/lib/v2/linovelib/novel.js b/lib/v2/linovelib/novel.js index da6ad781d..a3b3eba39 100644 --- a/lib/v2/linovelib/novel.js +++ b/lib/v2/linovelib/novel.js @@ -1,9 +1,9 @@ -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://www.linovelib.com/novel/${ctx.params.id}/catalog`); - const $ = cheerio.load(response.data); + const response = await got(`https://www.linovelib.com/novel/${ctx.req.param('id')}/catalog`); + const $ = load(response.data); const meta = $('.book-meta'); const title = meta.children().first().text(); @@ -23,11 +23,11 @@ module.exports = async (ctx) => { .get(); items.reverse(); - ctx.state.data = { + ctx.set('data', { title: `哩哔轻小说 - ${title}`, - link: `https://www.linovelib.com/novel/${ctx.params.id}/catalog`, + link: `https://www.linovelib.com/novel/${ctx.req.param('id')}/catalog`, description: title, language: 'zh', item: items, - }; + }); }; diff --git a/lib/v2/liquipedia/cs-matches.js b/lib/v2/liquipedia/cs-matches.js index 2abc637c8..ba8b16c5a 100644 --- a/lib/v2/liquipedia/cs-matches.js +++ b/lib/v2/liquipedia/cs-matches.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 team = ctx.params.team; + const team = ctx.req.param('team'); const rootUrl = 'https://liquipedia.net'; const currentUrl = `${rootUrl}/counterstrike/${team}/Matches`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.recent-matches-bg-lose, .recent-matches-bg-win'); const matches = list @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: `[Counter-Strike] ${team} Match Results From Liquipedia`, link: currentUrl, item: matches, - }; + }); }; diff --git a/lib/v2/liquipedia/dota2-matches.js b/lib/v2/liquipedia/dota2-matches.js index aaed4abf3..37d5a09c2 100644 --- a/lib/v2/liquipedia/dota2-matches.js +++ b/lib/v2/liquipedia/dota2-matches.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.id; + const team = ctx.req.param('id'); const url = `https://liquipedia.net/dota2/${team}`; const response = await got({ method: 'get', @@ -12,10 +12,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('div.recent-matches > table > tbody > tr[style]'); - ctx.state.data = { + ctx.set('data', { title: `Liquipedia Dota2 ${team} Matches`, link: url, item: list?.toArray().map((item) => { @@ -43,5 +43,5 @@ module.exports = async (ctx) => { guid: url + dateTime, }; }), - }; + }); }; diff --git a/lib/v2/literotica/category.js b/lib/v2/literotica/category.js index 839ffaa62..34b07f3ea 100644 --- a/lib/v2/literotica/category.js +++ b/lib/v2/literotica/category.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.literotica.com'; const currentUrl = `${rootUrl}/c/${category}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.b-slb-item') .map((_, item) => { @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.aa_ht').html(); @@ -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/literotica/new.js b/lib/v2/literotica/new.js index d6f45a5fa..b3cc98033 100644 --- a/lib/v2/literotica/new.js +++ b/lib/v2/literotica/new.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.literotica.com'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.b-46t') .map((_, item) => { @@ -42,7 +42,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.aa_ht').html(); @@ -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/liulinblog/index.js b/lib/v2/liulinblog/index.js index 9c75f614a..80a965485 100644 --- a/lib/v2/liulinblog/index.js +++ b/lib/v2/liulinblog/index.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 { params } = ctx.params; - 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 rootUrl = 'https://www.liulinblog.com'; const currentUrl = params ? new URL(params, rootUrl).href : rootUrl; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.scroll') .first() @@ -47,7 +47,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[role="alert"]').remove(); @@ -83,7 +83,7 @@ module.exports = async (ctx) => { const icon = $('link[rel="icon"]').prop('href'); const title = $('img.logo').prop('alt'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${title} - ${params ? $('h1.term-title').text().split('搜索到')[0] : '最新'}`, link: currentUrl, @@ -94,5 +94,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('p.term-description').text(), author: title, - }; + }); }; diff --git a/lib/v2/liveuamap/index.js b/lib/v2/liveuamap/index.js index 3f7859454..acfe8cf1b 100644 --- a/lib/v2/liveuamap/index.js +++ b/lib/v2/liveuamap/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - let region = ctx.params.region ?? 'ukraine'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50; + let region = ctx.req.param('region') ?? 'ukraine'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; if (!isValidHost(region)) { throw new Error('Invalid region'); } @@ -19,7 +19,7 @@ module.exports = async (ctx) => { method: 'get', url, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('div#feedler > div') .slice(0, limit) @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Liveuamap - ${region}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/lkong/forum.js b/lib/v2/lkong/forum.js index 169decc9b..99d419281 100644 --- a/lib/v2/lkong/forum.js +++ b/lib/v2/lkong/forum.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 { viewForum, viewThread } = require('./query'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '8'; - const digest = ctx.params.digest; + const id = ctx.req.param('id') ?? '8'; + const digest = ctx.req.param('digest'); const rootUrl = 'https://www.lkong.com'; const apiUrl = 'https://api.lkong.com/api'; @@ -46,10 +46,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${response.data.data.forum.name} - 龙空`, link: currentUrl, item: items, description: response.data.data.forumCount.info, - }; + }); }; diff --git a/lib/v2/lkong/thread.js b/lib/v2/lkong/thread.js index bd62125be..fd90fd21a 100644 --- a/lib/v2/lkong/thread.js +++ b/lib/v2/lkong/thread.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'); const { viewThread, countReplies } = require('./query'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://www.lkong.com'; const apiUrl = 'https://api.lkong.com/api'; @@ -49,9 +49,9 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: `${response.data.data.thread.title} - 龙空`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/lofter/tag.js b/lib/v2/lofter/tag.js index efff0bdb4..9a8584a4f 100644 --- a/lib/v2/lofter/tag.js +++ b/lib/v2/lofter/tag.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 { JSDOM } = require('jsdom'); module.exports = async (ctx) => { - const name = ctx.params.name ?? '摄影'; - const type = ctx.params.type ?? 'new'; + const name = ctx.req.param('name') ?? '摄影'; + const type = ctx.req.param('type') ?? 'new'; const pageSize = 20; const startingIndex = 0; @@ -73,7 +73,7 @@ module.exports = async (ctx) => { ? JSON.parse(post.photoLinks).reduce((accumulator, currentValue) => accumulator + ``, '') // small | middle | orign : ''; - const digest = cheerio.load(post.digest); + const digest = load(post.digest); const description = digest.text(); return { @@ -86,9 +86,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${name} - ${title} | LOFTER`, link: linkUrl, item: items, - }; + }); }; diff --git a/lib/v2/lofter/user.js b/lib/v2/lofter/user.js index fbd95c851..8140ec9a1 100644 --- a/lib/v2/lofter/user.js +++ b/lib/v2/lofter/user.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 name = ctx.params.name ?? 'i'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : '50'; + const name = ctx.req.param('name') ?? 'i'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : '50'; if (!isValidHost(name)) { throw new Error('Invalid name'); } @@ -52,10 +52,10 @@ module.exports = async (ctx) => { category: item.post.tag.split(','), })); - ctx.state.data = { + ctx.set('data', { title: `${items[0].author} | LOFTER`, link: rootUrl, item: items, description: response.data.response.posts[0].post.blogInfo.selfIntro, - }; + }); }; diff --git a/lib/v2/logclub/index.js b/lib/v2/logclub/index.js index e1fffcb88..0dc7eb971 100644 --- a/lib/v2/logclub/index.js +++ b/lib/v2/logclub/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 = 'news' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 11; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11; const rootUrl = 'https://www.logclub.com'; const currentUrl = new URL(category, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('li.layui-row, li.layui-timeline-item') .slice(0, limit) @@ -43,7 +43,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('a.dl_file').each((_, el) => { el = content(el); @@ -116,7 +116,7 @@ module.exports = async (ctx) => { const subtitle = $('meta[name="keywords"]').prop('content'); const author = subtitle.split(/,/)[0]; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text().split(/-/)[0].trim(), link: currentUrl, @@ -129,5 +129,5 @@ module.exports = async (ctx) => { author, itunes_author: author, itunes_category: 'News', - }; + }); }; diff --git a/lib/v2/logclub/report.js b/lib/v2/logclub/report.js index 0375a7835..5ac384280 100644 --- a/lib/v2/logclub/report.js +++ b/lib/v2/logclub/report.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id = 'Report' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 11; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11; const rootUrl = 'https://www.logclub.com'; const currentUrl = new URL('lc_report', rootUrl).href; @@ -39,7 +39,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('img').each((_, el) => { el = content(el); @@ -77,13 +77,13 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const title = $('div.this_nav').text().trim(); const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; const subtitle = $('meta[name="keywords"]').prop('content'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${$('title').text()}${title}`, link: currentUrl, @@ -94,5 +94,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: subtitle.replaceAll(',', ''), author: subtitle.split(/,/)[0], - }; + }); }; diff --git a/lib/v2/logonews/index.js b/lib/v2/logonews/index.js index be80e9c62..f2a5d40ce 100644 --- a/lib/v2/logonews/index.js +++ b/lib/v2/logonews/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) => { @@ -16,10 +16,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $(isWork ? 'h2 a' : 'a.article-link') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.iconfont').remove(); @@ -68,9 +68,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/loltw/news.js b/lib/v2/loltw/news.js index 00c54d79e..e186a0c01 100644 --- a/lib/v2/loltw/news.js +++ b/lib/v2/loltw/news.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 baseUrl = 'https://lol.garena.tw'; @@ -28,9 +28,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '英雄联盟 - 台服新闻', link: category ? `${baseUrl}/news/${category}` : `${baseUrl}/news`, item: items, - }; + }); }; diff --git a/lib/v2/lovelive-anime/news.js b/lib/v2/lovelive-anime/news.js index ec9c987e3..e01139004 100644 --- a/lib/v2/lovelive-anime/news.js +++ b/lib/v2/lovelive-anime/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 path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const renderDescription = (desc) => art(path.join(__dirname, 'templates/description.art'), desc); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const response = await got(rootUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const pageFace = $('div.c-card.p-colum__box') .map((_, item) => { @@ -30,12 +30,12 @@ module.exports = async (ctx) => { let items = pageFace; - if (ctx.params.option === 'detail') { + if (ctx.req.param('option') === 'detail') { items = await Promise.all( pageFace.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResp = await got(item.link); - const $ = cheerio.load(detailResp.data); + const $ = load(detailResp.data); const content = $('div.p-page__detail.p-article'); for (const v of content.find('img')) { @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: 'lovelive official website news', link: 'https://www.lovelive-anime.jp/news/', item: items, - }; + }); }; diff --git a/lib/v2/lovelive-anime/schedules.js b/lib/v2/lovelive-anime/schedules.js index 93193958a..3bc79cc85 100644 --- a/lib/v2/lovelive-anime/schedules.js +++ b/lib/v2/lovelive-anime/schedules.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const renderDescription = (desc) => art(path.join(__dirname, 'templates/scheduleDesc.art'), desc); const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); @@ -9,8 +9,8 @@ const timezone = require('dayjs/plugin/timezone'); module.exports = async (ctx) => { dayjs.extend(utc); dayjs.extend(timezone); - const serie = ctx.params.serie; - const category = ctx.params.category; + const serie = ctx.req.param('serie'); + const category = ctx.req.param('category'); const rootUrl = `https://www.lovelive-anime.jp/common/api/calendar_list.php`; const nowTime = dayjs(); const dataPara = { @@ -46,11 +46,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${category} - ${serie} - Love Live Official Website Schedule`, link: 'https://www.lovelive-anime.jp/schedule/', item: items, description: 'The schedule date and other information shall be subject to the announcement on the official website. The RSS route has not been strictly tested, and the captured information cannot be guaranteed to be correct.', - }; + }); }; diff --git a/lib/v2/lovelive-anime/topics.js b/lib/v2/lovelive-anime/topics.js index 2feb9dca5..11208f933 100644 --- a/lib/v2/lovelive-anime/topics.js +++ b/lib/v2/lovelive-anime/topics.js @@ -1,12 +1,12 @@ -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'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; const renderDescription = (desc) => art(path.join(__dirname, 'templates/description.art'), desc); module.exports = async (ctx) => { - const abbr = ctx.params.abbr; + const abbr = ctx.req.param('abbr'); const rootUrl = `https://www.lovelive-anime.jp/${abbr}`; const topicsUrlPart = 'yuigaoka' === abbr ? 'topics/' : 'topics.php'; const baseUrl = `${rootUrl}/${'yuigaoka' === abbr ? 'topics/' : ''}`; @@ -17,11 +17,11 @@ module.exports = async (ctx) => { yuigaoka: 'スーパースター!!', }; - const url = Object.hasOwn(ctx.params, 'category') && ctx.params.category !== 'detail' ? `${rootUrl}/${topicsUrlPart}?cat=${ctx.params.category}` : `${rootUrl}/${topicsUrlPart}`; + const url = Object.hasOwn(ctx.params, 'category') && ctx.req.param('category') !== 'detail' ? `${rootUrl}/${topicsUrlPart}?cat=${ctx.req.param('category')}` : `${rootUrl}/${topicsUrlPart}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const categoryName = 'uranohoshi' === abbr ? $('div.llbox > p').text() : $('div.category_title > h2').text(); @@ -53,12 +53,12 @@ module.exports = async (ctx) => { }) .get(); - if (ctx.params.option === 'detail' || ctx.params.category === 'detail') { + if (ctx.req.param('option') === 'detail' || ctx.req.param('category') === 'detail') { items = await Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResp = await got(item.link); - const $ = cheerio.load(detailResp.data); + const $ = load(detailResp.data); const content = $('div.p-page__detail.p-article'); for (const v of content.find('img')) { @@ -71,9 +71,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `${categoryName} - ${abbrDetail[abbr]} - Love Live Official Website Topics`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/lsnu/jiaowc/tzgg.js b/lib/v2/lsnu/jiaowc/tzgg.js index ce0b59d00..42cfc7f4a 100644 --- a/lib/v2/lsnu/jiaowc/tzgg.js +++ b/lib/v2/lsnu/jiaowc/tzgg.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 category = ctx.params.category; + const category = ctx.req.param('category'); const url = category ? `https://jiaowc.lsnu.edu.cn/tzgg/${category}.htm` : 'https://jiaowc.lsnu.edu.cn/tzgg.htm'; const response = await got({ @@ -12,12 +12,12 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('tr[id^="line_u5_"]').get(); const out = await Promise.all( list.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const title = $('a').attr('title'); const link = `https://jiaowc.lsnu.edu.cn/${$('a').attr('href')}`; const date = $('td[width="80"]').text(); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { }); const articleData = response.data; - const article$ = cheerio.load(articleData); + const article$ = load(articleData); const description = article$('.v_news_content').html(); return { @@ -44,9 +44,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '乐山师范学院教学部通知公告', link: 'https://jiaowc.lsnu.edu.cn/tzgg.htm', item: out, - }; + }); }; diff --git a/lib/v2/luogu/contest.js b/lib/v2/luogu/contest.js index 86ba719af..48793aedc 100644 --- a/lib/v2/luogu/contest.js +++ b/lib/v2/luogu/contest.js @@ -1,7 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const md = require('markdown-it')(); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import MarkdownIt from 'markdown-it'; +const md = MarkdownIt(); const asyncPool = require('tiny-async-pool'); const baseUrl = 'https://www.luogu.com.cn'; @@ -27,7 +28,7 @@ const typeMap = { module.exports = async (ctx) => { const link = `${baseUrl}/contest/list`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const data = JSON.parse( decodeURIComponent( @@ -41,7 +42,7 @@ module.exports = async (ctx) => { for await (const item of asyncPool(4, data.currentData.contests.result, (item) => ctx.cache.tryGet(`${baseUrl}/contest/${item.id}`, async () => { const { data: response } = await got(`${baseUrl}/contest/${item.id}`); - const $ = cheerio.load(response); + const $ = load(response); const data = JSON.parse( decodeURIComponent( $('script') @@ -63,10 +64,10 @@ module.exports = async (ctx) => { result.push(item); } - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, image: 'https://www.luogu.com.cn/favicon.ico', item: result, - }; + }); }; diff --git a/lib/v2/luogu/daily.js b/lib/v2/luogu/daily.js index 4e8afb5a3..2cf26bb0d 100644 --- a/lib/v2/luogu/daily.js +++ b/lib/v2/luogu/daily.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 id = ctx.params.id ?? 47327; + const id = ctx.req.param('id') ?? 47327; const link = `https://www.luogu.com.cn/discuss/${id}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('head title').text(); const injectionScript = $('head script:contains("window._feInjection")').text(); @@ -17,7 +17,7 @@ module.exports = async (ctx) => { const dailyLink = mdRaw.match(/<([^>]*)>/)[1]; const { data: dailyResponse } = await got(dailyLink); - const $daily = cheerio.load(dailyResponse); + const $daily = load(dailyResponse); const issueHeading = $daily('.am-article-title').first().text().trim(); const item = [ { @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: '洛谷日报', link, item, - }; + }); }; diff --git a/lib/v2/luogu/user-blog.js b/lib/v2/luogu/user-blog.js index b488d4a31..bdd828da7 100644 --- a/lib/v2/luogu/user-blog.js +++ b/lib/v2/luogu/user-blog.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const name = ctx.params.name; + const name = ctx.req.param('name'); const blogBaseUrl = `https://www.luogu.com.cn/blog/${name}/`; // Fetch the uid & title const { uid: blogUid, title: blogTitle } = await ctx.cache.tryGet(blogBaseUrl, async () => { const rsp = await got(blogBaseUrl); - const $ = cheerio.load(rsp.data); + const $ = load(rsp.data); const uid = $("meta[name='blog-uid']").attr('content'); const name = $("meta[name='blog-name']").attr('content'); return { @@ -29,7 +29,7 @@ module.exports = async (ctx) => { posts.map((post) => ctx.cache.tryGet(post.link, async () => { const rsp = await got(post.link); - const $ = cheerio.load(rsp.data); + const $ = load(rsp.data); return { title: post.title, link: post.link, @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: blogTitle, link: blogBaseUrl, item, - }; + }); }; diff --git a/lib/v2/luogu/user-feed.js b/lib/v2/luogu/user-feed.js index 5a7f19cfb..c999d8526 100644 --- a/lib/v2/luogu/user-feed.js +++ b/lib/v2/luogu/user-feed.js @@ -1,6 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const md = require('markdown-it')(); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import MarkdownIt from 'markdown-it'; +const md = MarkdownIt(); module.exports = async (ctx) => { const getUsernameFromUID = (uid) => @@ -9,13 +10,13 @@ module.exports = async (ctx) => { return data.currentData.user.name; }); - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const name = await getUsernameFromUID(uid); const { data: response } = await got(`https://www.luogu.com.cn/api/feed/list?user=${uid}`); const data = response.feeds.result; - ctx.state.data = { + ctx.set('data', { title: `${name} 的洛谷动态`, link: `https://www.luogu.com.cn/user/${uid}#activity`, allowEmpty: true, @@ -27,5 +28,5 @@ module.exports = async (ctx) => { link: `https://www.luogu.com.cn/user/${uid}#activity`, guid: item.id, })), - }; + }); }; diff --git a/lib/v2/luxiangdong/archive.js b/lib/v2/luxiangdong/archive.js index b0996d711..b05c7ce78 100644 --- a/lib/v2/luxiangdong/archive.js +++ b/lib/v2/luxiangdong/archive.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got(`https://www.luxiangdong.com/content.json?t=${Date.now()}`); @@ -17,12 +17,12 @@ module.exports = async (ctx) => { category: item.tags.map((tag) => tag.name), })); - ctx.state.data = { + ctx.set('data', { // 源标题 title: '土猛的员外', // 源链接 link: 'https://www.luxiangdong.com/', // 源文章 item: items, - }; + }); }; diff --git a/lib/v2/lvv2/news.js b/lib/v2/lvv2/news.js index 0fb5a5721..1e0cea5e3 100644 --- a/lib/v2/lvv2/news.js +++ b/lib/v2/lvv2/news.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 rootUrl = 'https://lvv2.com'; @@ -25,12 +25,12 @@ const titleMap = { }; module.exports = async (ctx) => { - const channel = ctx.params.channel; - const sort = (channel === 'sort-realtime' || channel === 'sort-score') && !ctx.params.sort ? 't-week' : ctx.params.sort; + const channel = ctx.req.param('channel'); + const sort = (channel === 'sort-realtime' || channel === 'sort-score') && !ctx.req.param('sort') ? 't-week' : ctx.req.param('sort'); const url = `${rootUrl}/${channel}/${sort}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.spacer > div') .map((_, item) => ({ title: $(item).find('h3 > a.title').text().trim(), @@ -48,7 +48,7 @@ module.exports = async (ctx) => { new URL(item.link).hostname === 'instant.lvv2.com' ? await ctx.cache.tryGet(item.link, async () => { const articleResponse = await got(item.link); - const article = cheerio.load(articleResponse.data); + const article = load(articleResponse.data); const description = article('#_tl_editor') .html() @@ -66,9 +66,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `lvv2 - ${sort ? titleMap[channel][sort] : titleMap[channel]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/lvv2/top.js b/lib/v2/lvv2/top.js index 416bab161..f664f01e1 100644 --- a/lib/v2/lvv2/top.js +++ b/lib/v2/lvv2/top.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 rootUrl = 'https://lvv2.com'; @@ -25,12 +25,12 @@ const titleMap = { }; module.exports = async (ctx) => { - const channel = ctx.params.channel; - const sort = (channel === 'sort-realtime' || channel === 'sort-score') && !ctx.params.sort ? 't-week' : ctx.params.sort; + const channel = ctx.req.param('channel'); + const sort = (channel === 'sort-realtime' || channel === 'sort-score') && !ctx.req.param('sort') ? 't-week' : ctx.req.param('sort'); const url = `${rootUrl}/${channel}/${sort}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#top-content-news > div') .map((_, item) => ({ title: $(item).find('div.md > a').text(), @@ -42,7 +42,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = timezone(parseDate(content('time').attr('datetime')), +8); item.author = content('a.author').text(); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { new URL(link, item.link).hostname === 'instant.lvv2.com' ? await ctx.cache.tryGet(link, async () => { const articleResponse = await got(link); - const article = cheerio.load(articleResponse.data); + const article = load(articleResponse.data); const description = article('#_tl_editor') .html() @@ -68,9 +68,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `lvv2 - ${sort ? titleMap[channel][sort] : titleMap[channel]} 24小时点击 Top 10`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/lxixsxa/discography.js b/lib/v2/lxixsxa/discography.js index 34f94eedf..aa2ed23dd 100644 --- a/lib/v2/lxixsxa/discography.js +++ b/lib/v2/lxixsxa/discography.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 { parseJSONP } = require('./jsonp-helper'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { comment: item.catch_copy === '' ? '今日もいい日だ!' : item.catch_copy, })); - ctx.state.data = { + ctx.set('data', { // the source title title, // the source url @@ -50,5 +50,5 @@ module.exports = async (ctx) => { // the article link link: `${url}/${item.referID}`, })), - }; + }); }; diff --git a/lib/v2/lxixsxa/information.js b/lib/v2/lxixsxa/information.js index bb80dee64..9d1e5d0b8 100644 --- a/lib/v2/lxixsxa/information.js +++ b/lib/v2/lxixsxa/information.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 { parseJSONP } = require('./jsonp-helper'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { description: item.article, })); - ctx.state.data = { + ctx.set('data', { // the source title title, // the source url @@ -44,5 +44,5 @@ module.exports = async (ctx) => { // the article link link: `${url}/${item.id}`, })), - }; + }); }; diff --git a/lib/v2/m4/index.js b/lib/v2/m4/index.js index ec63c6946..b5da74ed1 100644 --- a/lib/v2/m4/index.js +++ b/lib/v2/m4/index.js @@ -1,20 +1,20 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id = 'news', category = 'china' } = 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 = `http://${id}.m4.cn`; const currentUrl = new URL(category ? `/${category.replace(/\/$/, '')}/` : '/', rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('div.articleitem0 div.aheader0') .slice(0, limit) @@ -48,7 +48,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('h1').first().text(); item.description = art(path.join(__dirname, 'templates/description.art'), { @@ -68,7 +68,7 @@ module.exports = async (ctx) => { const image = $('a.logo0_b img').prop('src'); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -78,5 +78,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author: $('meta[name="author"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/macfilos/blog.js b/lib/v2/macfilos/blog.js index 2d20bf5ba..37175906c 100644 --- a/lib/v2/macfilos/blog.js +++ b/lib/v2/macfilos/blog.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.macfilos.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.entry-title a') - .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); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('hr').nextAll().remove(); content('hr').remove(); @@ -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/macmenubar/recently.js b/lib/v2/macmenubar/recently.js index 15b6d4123..1a184da05 100644 --- a/lib/v2/macmenubar/recently.js +++ b/lib/v2/macmenubar/recently.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; async function getCategoryId(categories) { const baseUrl = `https://macmenubar.com/wp-json/wp/v2/categories`; @@ -13,7 +13,7 @@ async function getCategoryId(categories) { module.exports = async (ctx) => { const baseUrl = 'https://macmenubar.com/wp-json/wp/v2/posts'; - const categories = ctx.params.category; + const categories = ctx.req.param('category'); const searchParams = { per_page: 100, }; @@ -39,9 +39,9 @@ module.exports = async (ctx) => { category: [...tags, ...categories], }; }); - ctx.state.data = { + ctx.set('data', { title: 'Recent Posts | MacMenuBar.com', link: 'https://macmenubar.com/recently-added/', item: items, - }; + }); }; diff --git a/lib/v2/macupdate/app.js b/lib/v2/macupdate/app.js index 9260f4b11..58d4a5011 100644 --- a/lib/v2/macupdate/app.js +++ b/lib/v2/macupdate/app.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 { appId, appSlug } = ctx.params; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/app/mac/${appId}${appSlug ? `/${appSlug}` : ''}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('#__NEXT_DATA__').text()); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { author: appData.developer.name, }; - ctx.state.data = { + ctx.set('data', { title: appData.title, description: appData.description, link: `${baseUrl}${asPath}`, @@ -35,9 +35,9 @@ module.exports = async (ctx) => { icon: appData.logo.source, item: [item], language: 'en', - }; + }); - ctx.state.json = { + ctx.set('json', { pageProps: nextData.props.initialProps.pageProps, - }; + }); }; diff --git a/lib/v2/magazinelib/latest-magazine.js b/lib/v2/magazinelib/latest-magazine.js index cbf26df4e..5372286fa 100644 --- a/lib/v2/magazinelib/latest-magazine.js +++ b/lib/v2/magazinelib/latest-magazine.js @@ -1,11 +1,11 @@ -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://magazinelib.com'; module.exports = async (ctx) => { - const query = ctx.params.query; + const query = ctx.req.param('query'); const url = `${host}/wp-json/wp/v2/posts/`; const response = await got({ method: 'get', @@ -30,7 +30,7 @@ module.exports = async (ctx) => { data.link = obj.link; data.featuredMediaLink = obj._links['wp:featuredmedia'][0].href; data.title = obj.title.rendered; - const $ = cheerio.load(obj.content.rendered); + const $ = load(obj.content.rendered); const content = $('.vk-att'); content.find('img[src="https://magazinelib.com/wp-includes/images/media/default.png"]').remove(); data.content = content.html(); @@ -40,7 +40,7 @@ module.exports = async (ctx) => { return data; }); - ctx.state.data = { + ctx.set('data', { title: `MagazineLib - Latest Magazines${subTitle}`, link: `{host}/?s=${query}`, description: `MagazineLib - Latest Magazines${subTitle}`, @@ -51,5 +51,5 @@ module.exports = async (ctx) => { pubDate: new Date(item.pubDate).toUTCString(), description: item.description, })), - }; + }); }; diff --git a/lib/v2/mail/imap.js b/lib/v2/mail/imap.js index 433c6b7c9..55ffe9ad7 100644 --- a/lib/v2/mail/imap.js +++ b/lib/v2/mail/imap.js @@ -1,8 +1,8 @@ const { ImapFlow } = require('imapflow'); -const config = require('@/config').value; +import { config } from '@/config'; const { simpleParser } = require('mailparser'); const logger = require('@/utils/logger'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { email, folder = 'INBOX' } = ctx.params; @@ -90,10 +90,10 @@ module.exports = async (ctx) => { await client.logout(); - ctx.state.data = { + ctx.set('data', { title: `${email}'s Inbox${folder === 'INBOX' ? '' : ` - ${folder}`}`, link: `https://${email.split('@')[1]}`, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/mangadex/index.js b/lib/v2/mangadex/index.js index 0791296e5..db5c970ea 100644 --- a/lib/v2/mangadex/index.js +++ b/lib/v2/mangadex/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 { RequestInProgressError } = require('@/errors'); module.exports = async (ctx) => { @@ -44,7 +44,7 @@ module.exports = async (ctx) => { if (data.result === 'error') { throw new RequestInProgressError(data.errors[0].detail); } - ctx.state.data = { + ctx.set('data', { title: `${title} - MangaDex`, link: `https://mangadex.org/title/${id}`, description, @@ -66,7 +66,7 @@ module.exports = async (ctx) => { pubDate: parseDate(chapter.attributes.publishAt), }; }), - }; + }); if (lang) { ctx.state.data.language = lang; } diff --git a/lib/v2/manhuagui/comic.js b/lib/v2/manhuagui/comic.js index 9492a767f..2058595e9 100644 --- a/lib/v2/manhuagui/comic.js +++ b/lib/v2/manhuagui/comic.js @@ -1,7 +1,7 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const LZString = require('lz-string'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; let baseUrl = ''; @@ -53,9 +53,9 @@ module.exports = async (ctx) => { baseUrl = 'https://www.manhuagui.com'; } - const chapterCnt = Number(ctx.params.chapterCnt || 0); + const chapterCnt = Number(ctx.req.param('chapterCnt') || 0); const { data } = await got(`${baseUrl}/comic/${id}/`); - const $ = cheerio.load(data); + const $ = load(data); if ($('#__VIEWSTATE').length > 0) { const n = LZString.decompressFromBase64($('#__VIEWSTATE').val()); diff --git a/lib/v2/manhuagui/subscribe.js b/lib/v2/manhuagui/subscribe.js index 2671650c7..420b9ead9 100644 --- a/lib/v2/manhuagui/subscribe.js +++ b/lib/v2/manhuagui/subscribe.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseRelativeDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseRelativeDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; const web_url = 'https://www.manhuagui.com/user/book/shelf/1'; module.exports = async (ctx) => { @@ -18,7 +18,7 @@ module.exports = async (ctx) => { Cookie: cookie, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const user_name = $('.avatar-box').find('h3').text(); const title = `${user_name} 的 漫画订阅`; const link = web_url; @@ -45,10 +45,10 @@ module.exports = async (ctx) => { return single; }) .get(); // 这里获取数组= = - ctx.state.data = { + ctx.set('data', { title, link, description, item, - }; + }); }; diff --git a/lib/v2/mastodon/account-id.js b/lib/v2/mastodon/account-id.js index 5c197b870..b7f998ea6 100644 --- a/lib/v2/mastodon/account-id.js +++ b/lib/v2/mastodon/account-id.js @@ -1,21 +1,21 @@ const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const site = ctx.params.site; - const account_id = ctx.params.account_id; - const only_media = ctx.params.only_media ? 'true' : 'false'; + const site = ctx.req.param('site'); + const account_id = ctx.req.param('account_id'); + const only_media = ctx.req.param('only_media') ? 'true' : 'false'; if (!config.feature.allow_user_supply_unsafe_domain && !utils.allowSiteList.includes(site)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { account_data, data } = await utils.getAccountStatuses(site, account_id, only_media); - ctx.state.data = { + ctx.set('data', { title: `${account_data.display_name} (@${account_data.acct})`, link: account_data.url, description: account_data.note, item: utils.parseStatuses(data), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/mastodon/acct.js b/lib/v2/mastodon/acct.js index 660ae0687..2f6ff7070 100644 --- a/lib/v2/mastodon/acct.js +++ b/lib/v2/mastodon/acct.js @@ -1,18 +1,18 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const acct = ctx.params.acct; - const only_media = ctx.params.only_media ? 'true' : 'false'; + const acct = ctx.req.param('acct'); + const only_media = ctx.req.param('only_media') ? 'true' : 'false'; const { site, account_id } = await utils.getAccountIdByAcct(acct, ctx); const { account_data, data } = await utils.getAccountStatuses(site, account_id, only_media); - ctx.state.data = { + ctx.set('data', { title: `${account_data.display_name} (@${account_data.acct})`, link: account_data.url, description: account_data.note, item: utils.parseStatuses(data), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/mastodon/timeline-local.js b/lib/v2/mastodon/timeline-local.js index abbdd458b..d7adb1991 100644 --- a/lib/v2/mastodon/timeline-local.js +++ b/lib/v2/mastodon/timeline-local.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const site = ctx.params.site; - const only_media = ctx.params.only_media ? 'true' : 'false'; + const site = ctx.req.param('site'); + const only_media = ctx.req.param('only_media') ? 'true' : 'false'; if (!config.feature.allow_user_supply_unsafe_domain && !utils.allowSiteList.includes(site)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const url = `http://${site}/api/v1/timelines/public?local=true&only_media=${only_media}`; @@ -14,9 +14,9 @@ module.exports = async (ctx) => { const response = await got.get(url); const list = response.data; - ctx.state.data = { - title: `Local Public${ctx.params.only_media ? ' Media' : ''} Timeline on ${site}`, + ctx.set('data', { + title: `Local Public${ctx.req.param('only_media') ? ' Media' : ''} Timeline on ${site}`, link: `https://${site}`, item: utils.parseStatuses(list), - }; + }); }; diff --git a/lib/v2/mastodon/timeline-remote.js b/lib/v2/mastodon/timeline-remote.js index 67ae65543..cb1deeb9f 100644 --- a/lib/v2/mastodon/timeline-remote.js +++ b/lib/v2/mastodon/timeline-remote.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const site = ctx.params.site; - const only_media = ctx.params.only_media ? 'true' : 'false'; + const site = ctx.req.param('site'); + const only_media = ctx.req.param('only_media') ? 'true' : 'false'; if (!config.feature.allow_user_supply_unsafe_domain && !utils.allowSiteList.includes(site)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const url = `http://${site}/api/v1/timelines/public?remote=true&only_media=${only_media}`; @@ -14,9 +14,9 @@ module.exports = async (ctx) => { const response = await got.get(url); const list = response.data; - ctx.state.data = { - title: `Federated Public${ctx.params.only_media ? ' Media' : ''} Timeline on ${site}`, + ctx.set('data', { + title: `Federated Public${ctx.req.param('only_media') ? ' Media' : ''} Timeline on ${site}`, link: `https://${site}`, item: utils.parseStatuses(list), - }; + }); }; diff --git a/lib/v2/mastodon/utils.js b/lib/v2/mastodon/utils.js index 692a1abb3..6d8b42316 100644 --- a/lib/v2/mastodon/utils.js +++ b/lib/v2/mastodon/utils.js @@ -1,5 +1,6 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const allowSiteList = ['mastodon.social', 'pawoo.net']; @@ -76,7 +77,6 @@ async function getAccountStatuses(site, account_id, only_media) { } async function getAccountIdByAcct(acct, ctx) { - const config = require('@/config').value; const mastodonConfig = config.mastodon; // acctHost is from the acct param of the request, and acctDomain is from either acctHost or the config diff --git a/lib/v2/mckinsey/cn/index.js b/lib/v2/mckinsey/cn/index.js index ce0862927..0f6e24dcb 100644 --- a/lib/v2/mckinsey/cn/index.js +++ b/lib/v2/mckinsey/cn/index.js @@ -2,7 +2,7 @@ // https://github.com/DIYgod/RSSHub/issues/8239 // https://github.com/DIYgod/RSSHub/pull/8288 const got = require('got'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const { categories } = require('./category-map'); const baseUrl = 'https://www.mckinsey.com.cn'; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const posts = await got(`${endpoint}/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ? Number(ctx.query.limit) : 50, + per_page: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 50, categories: category, }, }).json(); @@ -29,9 +29,9 @@ module.exports = async (ctx) => { pubDate: parseDate(item.date_gmt), })); - ctx.state.data = { + ctx.set('data', { title: category ? `McKinsey Greater China - ${categories[category].name}` : `McKinsey Greater China`, link: `${baseUrl}/${category === '25' ? categories[category].slug : `${categories[25].slug}/${categories[category].slug}`}/`, item: items, - }; + }); }; diff --git a/lib/v2/mdpi/journal.js b/lib/v2/mdpi/journal.js index c3177e57f..8438a56b1 100644 --- a/lib/v2/mdpi/journal.js +++ b/lib/v2/mdpi/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 journal = ctx.params.journal; + const journal = ctx.req.param('journal'); const host = 'https://www.mdpi.com'; const jrnlUrl = `${host}/journal/${journal}`; const response = await got(jrnlUrl, { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const jrnlName = $('.journal__description').find('h1').text(); const issueUrl = `${host}${$('.side-menu-ul').find('a').eq(1).attr('href')}`; const response2 = await got(issueUrl, { cookieJar, }); - const $2 = cheerio.load(response2.data); + const $2 = load(response2.data); const issue = $2('.content__container').find('h1').text().trim(); const list = $2('.article-item') .map((_, item) => { @@ -57,9 +57,9 @@ module.exports = async (ctx) => { return item; }); - ctx.state.data = { + ctx.set('data', { title: jrnlName, link: jrnlUrl, item: items, - }; + }); }; diff --git a/lib/v2/medieval-china/post.js b/lib/v2/medieval-china/post.js index 3e8e59bb0..1e0257a31 100644 --- a/lib/v2/medieval-china/post.js +++ b/lib/v2/medieval-china/post.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { const baseUrl = 'https://medieval-china.club'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const posts = JSON.parse( $('script:contains("window.localPosts")') .text() .match(/window\.localPosts = JSON\.parse\('(.*)'\);/)[1] ) - .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((item) => ({ title: item.title, link: `${baseUrl}${item.path}`, @@ -22,7 +22,7 @@ module.exports = async (ctx) => { posts.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); const imgSrc = $('img').attr('data-original'); $('img').attr('src', `${baseUrl}${imgSrc}`); $('.head-mask').remove(); @@ -33,12 +33,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '中国的中古', link: baseUrl, item: items, image: 'https://medieval-china.club/images/icons/favicon-144x144.png', description: '世界那么大,你无法去到每一个地方,感受每一处风景;时间那么长,那些逝去的人你也终将无法与之谋面。而通过古人之文字,今人之分享,你可以领略以前风光之奇绝瑰玮,感受逝人之人情冷暖。中古就是这么一个地方,大家来自全球各地,不同时区,不同性别,不同身份,不同职业,但是大家都被中古的绚烂华章聚集在一起,哀其所哀,乐其所乐。这是一个虚拟的世界,但是我们仿佛跨越千里而来,谈一场绝世爱恋,今夕何夕!仅以此网站献给中古club的每一位成员,契阔谈宴,西园不芜!', - }; + }); }; diff --git a/lib/v2/medium/following.js b/lib/v2/medium/following.js index ac55a92b4..48d348417 100644 --- a/lib/v2/medium/following.js +++ b/lib/v2/medium/following.js @@ -1,10 +1,10 @@ -const config = require('@/config').value; +import { config } from '@/config'; const parseArticle = require('./parse-article.js'); const { getFollowingFeedQuery } = require('./graphql.js'); module.exports = async (ctx) => { - const user = ctx.params.user; + const user = ctx.req.param('user'); const cookie = config.medium.cookies[user]; if (cookie === undefined) { @@ -23,9 +23,9 @@ module.exports = async (ctx) => { const parsedArticles = await Promise.all(urls.map((url) => parseArticle(ctx, url))); - ctx.state.data = { + ctx.set('data', { title: `${user} Medium Following`, link: 'https://medium.com/?feed=following', item: parsedArticles, - }; + }); }; diff --git a/lib/v2/medium/for-you.js b/lib/v2/medium/for-you.js index ab86b2361..77346070a 100644 --- a/lib/v2/medium/for-you.js +++ b/lib/v2/medium/for-you.js @@ -1,10 +1,10 @@ -const config = require('@/config').value; +import { config } from '@/config'; const parseArticle = require('./parse-article.js'); const { getWebInlineRecommendedFeedQuery } = require('./graphql.js'); module.exports = async (ctx) => { - const user = ctx.params.user; + const user = ctx.req.param('user'); const cookie = config.medium.cookies[user]; if (cookie === undefined) { @@ -23,9 +23,9 @@ module.exports = async (ctx) => { const parsedArticles = await Promise.all(urls.map((url) => parseArticle(ctx, url))); - ctx.state.data = { + ctx.set('data', { title: `${user} Medium For You`, link: 'https://medium.com/', item: parsedArticles, - }; + }); }; diff --git a/lib/v2/medium/graphql.js b/lib/v2/medium/graphql.js index 75b9fcc7e..4f5d2e791 100644 --- a/lib/v2/medium/graphql.js +++ b/lib/v2/medium/graphql.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; async function graphqlRequest(body, cookie) { const { data } = await got('https://medium.com/_/graphql', { diff --git a/lib/v2/medium/list.js b/lib/v2/medium/list.js index 0c5202148..b5d13cfa8 100644 --- a/lib/v2/medium/list.js +++ b/lib/v2/medium/list.js @@ -1,11 +1,11 @@ -const config = require('@/config').value; +import { config } from '@/config'; const parseArticle = require('./parse-article.js'); const { getUserCatalogMainContentQuery } = require('./graphql.js'); module.exports = async (ctx) => { - const user = ctx.params.user; - const catalogId = ctx.params.catalogId; + const user = ctx.req.param('user'); + const catalogId = ctx.req.param('catalogId'); const cookie = config.medium.cookies[user]; @@ -24,9 +24,9 @@ module.exports = async (ctx) => { const parsedArticles = await Promise.all(urls.map((url) => parseArticle(ctx, url))); - ctx.state.data = { + ctx.set('data', { title: `List: ${name}`, link: `https://medium.com/@${user}/list/${catalogId}`, item: parsedArticles, - }; + }); }; diff --git a/lib/v2/medium/parse-article.js b/lib/v2/medium/parse-article.js index aad3bb386..6eb46a634 100644 --- a/lib/v2/medium/parse-article.js +++ b/lib/v2/medium/parse-article.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; -const config = require('@/config').value; +import { config } from '@/config'; async function parse(url, cookie = '') { const { data } = await got(url, { @@ -9,7 +9,7 @@ async function parse(url, cookie = '') { cookie, }, }); - const $ = cheerio.load(data); + const $ = load(data); const publishedTime = $('meta[property="article:published_time"]').attr('content'); const author = $('meta[name="author"]').attr('content'); diff --git a/lib/v2/medium/tag.js b/lib/v2/medium/tag.js index 7bdfd047a..c8883cd75 100644 --- a/lib/v2/medium/tag.js +++ b/lib/v2/medium/tag.js @@ -1,11 +1,11 @@ -const config = require('@/config').value; +import { config } from '@/config'; const parseArticle = require('./parse-article.js'); const { getWebInlineTopicFeedQuery } = require('./graphql.js'); module.exports = async (ctx) => { - const user = ctx.params.user; - const tag = ctx.params.tag; + const user = ctx.req.param('user'); + const tag = ctx.req.param('tag'); const cookie = config.medium.cookies[user]; if (cookie === undefined) { @@ -24,9 +24,9 @@ module.exports = async (ctx) => { const parsedArticles = await Promise.all(urls.map((url) => parseArticle(ctx, url))); - ctx.state.data = { + ctx.set('data', { title: `${user} Medium Following Tag ${tag}`, link: `https://medium.com/?tag=${tag}`, item: parsedArticles, - }; + }); }; diff --git a/lib/v2/medsci/index.js b/lib/v2/medsci/index.js index 21587e56c..b69c4e88b 100644 --- a/lib/v2/medsci/index.js +++ b/lib/v2/medsci/index.js @@ -1,10 +1,10 @@ -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) => { - let sid = ctx.params.sid ?? ''; - const tid = ctx.params.tid ?? ''; + let sid = ctx.req.param('sid') ?? ''; + const tid = ctx.req.param('tid') ?? ''; sid = sid === 'recommend' ? '' : sid; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('#articleList') .find('.ms-link') @@ -41,7 +41,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const pubDateMatches = detailResponse.data.match(/"publishedTime":"(.*)","publishedTimeString"/); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${sid ? $('.department-header-active').text() : '推荐'} -${tid ? ` ${$('.department-keywords-ul .active').text()} -` : ''} MedSci.cn`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/metacritic/index.js b/lib/v2/metacritic/index.js index 208ceafaa..7a088a151 100644 --- a/lib/v2/metacritic/index.js +++ b/lib/v2/metacritic/index.js @@ -1,14 +1,14 @@ -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 { sorts, types } = require('./util'); module.exports = async (ctx) => { const { type = 'game', sort = 'new', filter } = 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.metacritic.com'; const rootApiUrl = 'https://internal-prod.apigee.fandom.net'; @@ -101,11 +101,11 @@ module.exports = async (ctx) => { comments: item.criticScoreSummary?.reviewCount ? Number.parseInt(item.criticScoreSummary?.reviewCount, 10) : 0, })); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const icon = new URL($('meta[data-hid="msapplication-task-metacritic"]').prop('content').split('icon-uri=').pop(), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -117,5 +117,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="msapplication-tooltip"]').prop('content'), author: $('meta[name="twitter:site"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/metacritic/release.js b/lib/v2/metacritic/release.js index a8231c429..2e354876a 100644 --- a/lib/v2/metacritic/release.js +++ b/lib/v2/metacritic/release.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { toTitleCase } = require('@/utils/common-utils'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; module.exports = async (ctx) => { let type = 'new-releases'; let title = 'New Releases'; - const sort = ctx.params.sort || 'date'; + const sort = ctx.req.param('sort') || 'date'; - switch (ctx.params.type) { + switch (ctx.req.param('type')) { case 'coming': type = 'coming-soon'; title = 'Coming Soon'; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { break; } - const url = `https://www.metacritic.com/browse/games/release-date/${type}/${ctx.params.platform}/${sort}`; + const url = `https://www.metacritic.com/browse/games/release-date/${type}/${ctx.req.param('platform')}/${sort}`; const response = await got({ method: 'get', @@ -27,11 +27,11 @@ module.exports = async (ctx) => { }); const data = response.body; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.list_products > li').get().slice(0, 10); const result = list.map((item) => { - const $ = cheerio.load(item); + const $ = load(item); return { title: $('.product_title').text().trim(), url: 'https://www.metacritic.com' + $('.product_title > a').attr('href'), @@ -41,13 +41,13 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { - title: toTitleCase(`Metacritic ${ctx.params.platform} games ${title}`), + ctx.set('data', { + title: toTitleCase(`Metacritic ${ctx.req.param('platform')} games ${title}`), link: url, item: result.map((item) => ({ title: `${item.metascore === 'tbd' ? '' : '[' + item.metascore + ']'} ${item.title}`, description: `Release Date: ${item.date}
Metacritic Score: ${item.metascore}
User Score: ${item.userscore}
`, link: item.url, })), - }; + }); }; diff --git a/lib/v2/meteor/boards.js b/lib/v2/meteor/boards.js index bcd2a74c7..204c1d96a 100644 --- a/lib/v2/meteor/boards.js +++ b/lib/v2/meteor/boards.js @@ -3,9 +3,9 @@ const { baseUrl, getBoards } = require('./utils'); module.exports = async (ctx) => { const items = await getBoards(ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { title: '看板列表', link: `${baseUrl}/board/all`, item: items, - }; + }); }; diff --git a/lib/v2/meteor/index.js b/lib/v2/meteor/index.js index d32393b2e..baf5ca0f0 100644 --- a/lib/v2/meteor/index.js +++ b/lib/v2/meteor/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 { baseUrl, getBoards, renderDesc } = require('./utils'); module.exports = async (ctx) => { @@ -17,7 +17,7 @@ module.exports = async (ctx) => { boardId: board, isCollege: false, page: 0, - pageSize: ctx.query.limit ? Number(ctx.query.limit) : 30, + pageSize: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30, }, }); @@ -35,11 +35,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${board === 'all' ? '全部看板' : boardInfo.title} | Meteor 學生社群`, description: board === 'all' ? null : boardInfo.feedDescription, image: board === 'all' ? null : boardInfo.imgUrl === 'not_set' ? null : boardInfo.imgUrl, link: `${board === 'all' ? `${baseUrl}/board/all` : boardInfo.link}/new`, item: items, - }; + }); }; diff --git a/lib/v2/meteor/utils.js b/lib/v2/meteor/utils.js index fb3a54bbe..a8711d0eb 100644 --- a/lib/v2/meteor/utils.js +++ b/lib/v2/meteor/utils.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 baseUrl = 'https://meteor.today'; diff --git a/lib/v2/metmuseum/exhibitions.js b/lib/v2/metmuseum/exhibitions.js index 4bb01e156..c256c419c 100644 --- a/lib/v2/metmuseum/exhibitions.js +++ b/lib/v2/metmuseum/exhibitions.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'; function generateExhibitionItem(result) { return { @@ -12,7 +12,7 @@ function generateExhibitionItem(result) { } module.exports = async (ctx) => { - const searchType = ctx.params.state ?? 'current'; + const searchType = ctx.req.param('state') ?? 'current'; const url = `https://www.metmuseum.org/ghidorah/ExhibitionListing/Search?searchType=${searchType}`; @@ -23,9 +23,9 @@ module.exports = async (ctx) => { const data = response.data.data; - ctx.state.data = { + ctx.set('data', { title: 'The Metropolitan Museum of Art - Exhibitions', link: 'https://www.metmuseum.org/exhibitions', item: data.results.map((element) => generateExhibitionItem(element)), - }; + }); }; diff --git a/lib/v2/mihoyo/bbs/cache.js b/lib/v2/mihoyo/bbs/cache.js index 6ed3647b3..69b1ffbfc 100644 --- a/lib/v2/mihoyo/bbs/cache.js +++ b/lib/v2/mihoyo/bbs/cache.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { config } from '@/config'; module.exports = { getUserFullInfo: (ctx, uid) => { diff --git a/lib/v2/mihoyo/bbs/follow-list.js b/lib/v2/mihoyo/bbs/follow-list.js index 8acbf2588..a314fc2b9 100644 --- a/lib/v2/mihoyo/bbs/follow-list.js +++ b/lib/v2/mihoyo/bbs/follow-list.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 cache = require('./cache'); @@ -7,7 +7,7 @@ const renderDescription = (description, images) => art(path.join(__dirname, '../ module.exports = async (ctx) => { const { uid } = ctx.params; - const page_size = ctx.query.limit || '20'; + const page_size = ctx.req.query('limit') || '20'; const searchParams = { gids: 2, uid, diff --git a/lib/v2/mihoyo/bbs/img-ranking.js b/lib/v2/mihoyo/bbs/img-ranking.js index e2a3dd51a..1e2c1b64e 100644 --- a/lib/v2/mihoyo/bbs/img-ranking.js +++ b/lib/v2/mihoyo/bbs/img-ranking.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { DATA_MAP, RANKING_TYPE_MAP } = require('./static-data'); const { post2item } = require('./utils'); @@ -40,9 +40,9 @@ const getRankingTypeInfo = (game, ranking_type) => { module.exports = async (ctx) => { const { game } = ctx.params; - const routeParams = Object.fromEntries(new URLSearchParams(ctx.params.routeParams)); + const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams'))); const { forumType: forum_type = 'tongren', cateType: cate_type, rankingType: ranking_type, lastId: last_id = '' } = routeParams; - const page_size = ctx.query.limit || '20'; + const page_size = ctx.req.query('limit') || '20'; const { gids, title: game_title } = getGameInfo(game); if (!gids) { throw new Error('未知的游戏!'); diff --git a/lib/v2/mihoyo/bbs/official.js b/lib/v2/mihoyo/bbs/official.js index 9e38ea88b..2131b8c47 100644 --- a/lib/v2/mihoyo/bbs/official.js +++ b/lib/v2/mihoyo/bbs/official.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { post2item } = require('./utils'); // 游戏id const GITS_MAP = { diff --git a/lib/v2/mihoyo/bbs/timeline.js b/lib/v2/mihoyo/bbs/timeline.js index 5e580ff6f..e9c64acbc 100644 --- a/lib/v2/mihoyo/bbs/timeline.js +++ b/lib/v2/mihoyo/bbs/timeline.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const cache = require('./cache'); -const config = require('@/config').value; +import { config } from '@/config'; const { post2item } = require('./utils'); module.exports = async (ctx) => { @@ -8,7 +8,7 @@ module.exports = async (ctx) => { throw new Error('Miyoushe Timeline is not available due to the absense of [Miyoushe Cookie]. Check relevant config tutorial'); } - const page_size = ctx.query.limit || '20'; + const page_size = ctx.req.query('limit') || '20'; const searchParams = { gids: 2, page_size, diff --git a/lib/v2/mihoyo/bbs/user-post.js b/lib/v2/mihoyo/bbs/user-post.js index 547ff0fa3..b9adf4d76 100644 --- a/lib/v2/mihoyo/bbs/user-post.js +++ b/lib/v2/mihoyo/bbs/user-post.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { post2item } = require('./utils'); module.exports = async (ctx) => { const { uid } = ctx.params; - const size = ctx.query.limit || '20'; + const size = ctx.req.query('limit') || '20'; const searchParams = { uid, size, diff --git a/lib/v2/mihoyo/bbs/utils.js b/lib/v2/mihoyo/bbs/utils.js index 165d8fdd0..1cad74e01 100644 --- a/lib/v2/mihoyo/bbs/utils.js +++ b/lib/v2/mihoyo/bbs/utils.js @@ -1,6 +1,6 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images }); diff --git a/lib/v2/mihoyo/sr/news.js b/lib/v2/mihoyo/sr/news.js index a48c48537..6d860c45d 100644 --- a/lib/v2/mihoyo/sr/news.js +++ b/lib/v2/mihoyo/sr/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 categories = { 'zh-cn': { @@ -45,7 +45,7 @@ const categories = { module.exports = async (ctx) => { // location 地区 category 类型 const { location = 'zh-cn', category = 'news-all' } = ctx.params; - 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 url = location === 'zh-cn' ? `https://api-takumi-static.mihoyo.com/content_v2_user/app/1963de8dc19e461c/getContentList?iPage=1&iPageSize=${limit}&sLangKey=zh-cn&isPreview=0&iChanId=${categories[location][category].id}` @@ -61,9 +61,9 @@ module.exports = async (ctx) => { category: item.sCategoryName, })); - ctx.state.data = { + ctx.set('data', { title: `${categories[location][category].title}-崩坏:星穹铁道`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/mihoyo/ys/news.js b/lib/v2/mihoyo/ys/news.js index f9b7251ea..ce16279ca 100644 --- a/lib/v2/mihoyo/ys/news.js +++ b/lib/v2/mihoyo/ys/news.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'); const categories = { @@ -76,9 +76,9 @@ const apiUrls = { }; module.exports = async (ctx) => { - const location = ctx.params.location ?? 'main'; - const category = ctx.params.category ?? 'latest'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50; + const location = ctx.req.param('location') ?? 'main'; + const category = ctx.req.param('category') ?? 'latest'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; const params = { main: `pageNum=1&channelId=${categories[category][location].id}&pageSize=${limit}`, @@ -153,9 +153,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `原神 - ${categories[category][location].title}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/mindmeister/example.js b/lib/v2/mindmeister/example.js index 764ef3f66..15ef4994b 100644 --- a/lib/v2/mindmeister/example.js +++ b/lib/v2/mindmeister/example.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 baseUrl = 'https://www.mindmeister.com'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}${language === 'en' || language === 'other' ? '' : `/${language}`}/${category === 'mind-map-examples' ? category : `mind-maps/${category}?language=${language}`}`; const respsonse = await got(link); - const $ = cheerio.load(respsonse.data); + const $ = load(respsonse.data); const items = $('#public-listing .map-tile-wrapper') .toArray() @@ -34,11 +34,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name=description]').text(), link, item: items, language, - }; + }); }; diff --git a/lib/v2/minecraft/version.js b/lib/v2/minecraft/version.js index 81ce23881..bb482dd58 100644 --- a/lib/v2/minecraft/version.js +++ b/lib/v2/minecraft/version.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const url = 'https://launchermeta.mojang.com/mc/game/version_manifest.json'; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const title = `Minecraft Java版游戏更新`; - ctx.state.data = { + ctx.set('data', { title, link: `https://www.minecraft.net/`, description: title, @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: `https://www.minecraft.net`, guid: item.id + item.type, })), - }; + }); }; diff --git a/lib/v2/mingpao/index.js b/lib/v2/mingpao/index.js index 1dbe50a8e..35dc86172 100644 --- a/lib/v2/mingpao/index.js +++ b/lib/v2/mingpao/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const parser = require('@/utils/rss-parser'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const logger = require('@/utils/logger'); @@ -18,8 +18,8 @@ const renderDesc = (media, desc) => }); module.exports = async (ctx) => { - const type = ctx.params.type ?? 'ins'; - const category = ctx.params.category ?? (type === 'ins' ? 'all' : 's00001'); + const type = ctx.req.param('type') ?? 'ins'; + const category = ctx.req.param('category') ?? (type === 'ins' ? 'all' : 's00001'); const link = `https://news.mingpao.com/rss/${type}/${category}.xml`; const feed = await parser.parseURL(link); @@ -42,7 +42,7 @@ module.exports = async (ctx) => { throw error; } - const $ = cheerio.load(response.data); + const $ = load(response.data); const fancyboxImg = $('a.fancybox').length ? $('a.fancybox') : $('a.fancybox-buttons'); // remove unwanted elements @@ -88,12 +88,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.description, item: items, image: feed.image.url, language: feed.language, - }; + }); }; diff --git a/lib/v2/mirror/index.js b/lib/v2/mirror/index.js index 5caa18d04..c0c504b6e 100644 --- a/lib/v2/mirror/index.js +++ b/lib/v2/mirror/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 md = require('markdown-it')({ html: true, linkify: true, @@ -7,7 +7,7 @@ const md = require('markdown-it')({ const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); if (!id.endsWith('.eth') && !isValidHost(id)) { throw new Error('Invalid id'); } @@ -31,11 +31,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${data.props.pageProps.publicationLayoutProject.displayName} - Mirror`, description: data.props.pageProps.publicationLayoutProject.description, image: data.props.pageProps.publicationLayoutProject.avatarURL, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/missav/new.js b/lib/v2/missav/new.js index 2a4858b82..c8cdc100a 100644 --- a/lib/v2/missav/new.js +++ b/lib/v2/missav/new.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'); module.exports = async (ctx) => { const baseUrl = 'https://missav.com'; const { data: response } = await got(`${baseUrl}/dm397/new`); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.grid .group') .toArray() @@ -27,10 +27,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/misskey/featured-notes.js b/lib/v2/misskey/featured-notes.js index 3830d4356..e5dd4a1a8 100644 --- a/lib/v2/misskey/featured-notes.js +++ b/lib/v2/misskey/featured-notes.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const site = ctx.params.site; + const site = ctx.req.param('site'); if (!config.feature.allow_user_supply_unsafe_domain && !utils.allowSiteList.includes(site)) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } // docs on: https://misskey-hub.net/docs/api/endpoints/notes/featured.html @@ -21,9 +21,9 @@ module.exports = async (ctx) => { const list = response.data; - ctx.state.data = { + ctx.set('data', { title: `Featured Notes on ${site}`, link: `https://${site}/explore`, item: utils.parseNotes(list, site), - }; + }); }; diff --git a/lib/v2/misskey/utils.js b/lib/v2/misskey/utils.js index 4f6463348..546febb03 100644 --- a/lib/v2/misskey/utils.js +++ b/lib/v2/misskey/utils.js @@ -1,5 +1,5 @@ -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); const allowSiteList = ['misskey.io', 'madost.one', 'mk.nixnet.social']; diff --git a/lib/v2/mittrchina/index.js b/lib/v2/mittrchina/index.js index 3cef7e45e..53cc349ed 100644 --- a/lib/v2/mittrchina/index.js +++ b/lib/v2/mittrchina/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) => { @@ -24,7 +24,7 @@ module.exports = async (ctx) => { }; const { type = 'index' } = 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 link = `https://apii.mittrchina.com${typeMap[type].apiPath}`; const { data: response } = @@ -91,9 +91,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `MIT 科技评论 - ${typeMap[type].title}`, link: `https://www.mittrchina.com/${type}`, item: items, - }; + }); }; diff --git a/lib/v2/mixcloud/index.js b/lib/v2/mixcloud/index.js index 9f2f7d3d2..d690e89e0 100644 --- a/lib/v2/mixcloud/index.js +++ b/lib/v2/mixcloud/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const CryptoJS = require('crypto-js'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const { queries } = require('./queries'); module.exports = async (ctx) => { @@ -13,11 +13,11 @@ module.exports = async (ctx) => { 'X-Requested-With': 'XMLHttpRequest', }; - const type = ctx.params.type ?? 'uploads'; + const type = ctx.req.param('type') ?? 'uploads'; if (!['stream', 'uploads', 'favorites', 'listens'].includes(type)) { throw new Error(`Invalid type: ${type}`); } - const username = ctx.params.username; + const username = ctx.req.param('username'); const config = { stream: { name: 'Stream', node: 'stream' }, @@ -30,7 +30,7 @@ module.exports = async (ctx) => { query: queries.stream.query, variables: { lookup: { - username: ctx.params.username, + username: ctx.req.param('username'), }, }, }, @@ -38,7 +38,7 @@ module.exports = async (ctx) => { query: queries.uploads.query, variables: { lookup: { - username: ctx.params.username, + username: ctx.req.param('username'), }, orderBy: 'LATEST', }, @@ -47,7 +47,7 @@ module.exports = async (ctx) => { query: queries.favorites.query, variables: { lookup: { - username: ctx.params.username, + username: ctx.req.param('username'), }, }, }, @@ -55,7 +55,7 @@ module.exports = async (ctx) => { query: queries.listens.query, variables: { lookup: { - username: ctx.params.username, + username: ctx.req.param('username'), }, }, }, @@ -102,12 +102,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Mixcloud - ${data.user.displayName}'s ${config[type].name}`, description: biog.replaceAll('\n', '
'), itunes_author: data.user.displayName, image, link: `${host}/${username}/${type}/`, item: items, - }; + }); }; diff --git a/lib/v2/modb/topic.js b/lib/v2/modb/topic.js index 7c7bd684e..572f8c9c4 100644 --- a/lib/v2/modb/topic.js +++ b/lib/v2/modb/topic.js @@ -1,12 +1,12 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const logger = require('@/utils/logger'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://www.modb.pro'; - const topicId = ctx.params.id; + const topicId = ctx.req.param('id'); const response = await got({ url: `${baseUrl}/api/columns/getKnowledge`, searchParams: { @@ -44,16 +44,16 @@ 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.editor-content-styl.article-style').first().html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: '墨天轮合辑', link: `${baseUrl}/topic/${topicId}`, item: items, - }; + }); }; diff --git a/lib/v2/modelscope/community.js b/lib/v2/modelscope/community.js index 18f644736..6cda3f07f 100644 --- a/lib/v2/modelscope/community.js +++ b/lib/v2/modelscope/community.js @@ -1,15 +1,15 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const path = require('path'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://community.modelscope.cn'; const { data } = await got.post(`${baseUrl}/v1/namespace_page/article`, { - json: { id: 142373, notInMediaAidList: [], pageNum: 1, pageSize: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30 }, + json: { id: 142373, notInMediaAidList: [], pageNum: 1, pageSize: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30 }, }); const articles = data.data.content.map((c) => ({ @@ -27,7 +27,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const initialData = JSON.parse( $('script') .text() @@ -45,11 +45,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'ModelScope魔搭社区-DevPress官方社区', description: 'ModelScope魔搭社区 DevPress官方社区-ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单。', image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico', link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/modelscope/datasets.js b/lib/v2/modelscope/datasets.js index 0671c278e..a3f68de09 100644 --- a/lib/v2/modelscope/datasets.js +++ b/lib/v2/modelscope/datasets.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, linkify: true, }); 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://modelscope.cn'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const { data } = await got(`${baseUrl}/api/v1/dolphin/datasets`, { searchParams: { - PageSize: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 36, + PageSize: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 36, PageNumber: 1, Target: '', Sort: 'gmt_modified', @@ -45,11 +45,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '数据集首页 · 魔搭社区', description: 'ModelScope——汇聚各领域先进的机器学习模型,提供模型探索体验、推理、训练、部署和应用的一站式服务。在这里,共建模型开源社区,发现、学习、定制和分享心仪的模型。', image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico', link, item: items, - }; + }); }; diff --git a/lib/v2/modelscope/models.js b/lib/v2/modelscope/models.js index 841c15896..3c71a33f4 100644 --- a/lib/v2/modelscope/models.js +++ b/lib/v2/modelscope/models.js @@ -1,16 +1,16 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, linkify: true, }); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://modelscope.cn'; const link = `${baseUrl}/models`; const { data } = await got.put(`${baseUrl}/api/v1/dolphin/models`, { - json: { PageSize: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 36, PageNumber: 1, SortBy: 'GmtModified', Target: '', SingleCriterion: [] }, + json: { PageSize: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 36, PageNumber: 1, SortBy: 'GmtModified', Target: '', SingleCriterion: [] }, }); const models = data.Data.Model.Models.map((model) => ({ @@ -35,11 +35,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '模型库首页 · 魔搭社区', description: 'ModelScope——汇聚各领域先进的机器学习模型,提供模型探索体验、推理、训练、部署和应用的一站式服务。在这里,共建模型开源社区,发现、学习、定制和分享心仪的模型。', image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico', link, item: items, - }; + }); }; diff --git a/lib/v2/modelscope/studios.js b/lib/v2/modelscope/studios.js index 5a4444691..4fae2f9fd 100644 --- a/lib/v2/modelscope/studios.js +++ b/lib/v2/modelscope/studios.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, linkify: true, }); 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://modelscope.cn'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const { data } = await got.put(`${baseUrl}/api/v1/studios`, { json: { - PageSize: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 36, + PageSize: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 36, PageNumber: 1, SortBy: 'gmt_modified', }, @@ -47,11 +47,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '创空间首页 · 魔搭社区', description: 'ModelScope——汇聚各领域先进的机器学习模型,提供模型探索体验、推理、训练、部署和应用的一站式服务。在这里,共建模型开源社区,发现、学习、定制和分享心仪的模型。', image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico', link, item: items, - }; + }); }; diff --git a/lib/v2/modrinth/versions.js b/lib/v2/modrinth/versions.js index 3dca9eb7b..385fa9f14 100644 --- a/lib/v2/modrinth/versions.js +++ b/lib/v2/modrinth/versions.js @@ -1,9 +1,10 @@ -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'); -const { value: config } = require('@/config'); +import { config } from '@/config'; +import got from '@/utils/got'; -const got = require('@/utils/got').extend({ +const customGot = got.extend({ headers: { // https://docs.modrinth.com/#section/User-Agents 'user-agent': config.trueUA, @@ -38,13 +39,13 @@ module.exports = async ( try { /** @type {import('./api').Project} */ - const project = await got(`https://api.modrinth.com/v2/project/${id}`).json(); + const project = await customGot(`https://api.modrinth.com/v2/project/${id}`).json(); /** @type {import('./api').Version[]} */ - const versions = await got(`https://api.modrinth.com/v2/project/${id}/version`, { + const versions = await customGot(`https://api.modrinth.com/v2/project/${id}/version`, { searchParams: parsedQuery, }).json(); /** @type {import('./api').Author[]} */ - const authors = await got(`https://api.modrinth.com/v2/users`, { + const authors = await customGot(`https://api.modrinth.com/v2/users`, { searchParams: { ids: JSON.stringify(versions.map((it) => it.author_id)), }, diff --git a/lib/v2/mohw/clarification.js b/lib/v2/mohw/clarification.js index 354f59bc0..22b848073 100644 --- a/lib/v2/mohw/clarification.js +++ b/lib/v2/mohw/clarification.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.mohw.gov.tw'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.list01 a[title]') .toArray() @@ -32,7 +32,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('article').html(); item.pubDate = parseDate(content('meta[name="DC.Date"]').attr('datetime')); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '即時新聞澄清 - 台灣衛生福利部', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/mox/index.js b/lib/v2/mox/index.js index 1a6bb5e82..481c5840a 100644 --- a/lib/v2/mox/index.js +++ b/lib/v2/mox/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://mox.moe'; const currentUrl = `${rootUrl}${category ? `/l/${category}` : ''}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.listbg td') .toArray() @@ -39,7 +39,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('.status font a').first().text(); item.description = `
${content('.author').html()}
${content('#desc_text').html()}`; @@ -49,9 +49,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Mox.moe', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/mpaypass/main.js b/lib/v2/mpaypass/main.js index 6c74d08d2..d1ff3a47c 100644 --- a/lib/v2/mpaypass/main.js +++ b/lib/v2/mpaypass/main.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 { type = '' } = ctx.params; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const title_cn = type ? $(`a[href="http://www.mpaypass.com.cn/${type}.html"]`).text() : '最新文章'; const list = $('.newslist') @@ -37,7 +37,7 @@ module.exports = async (ctx) => { list.map((info) => ctx.cache.tryGet(info.link, async () => { const response = await got(info.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const newsbody = $('div.newsbody').html(); return { @@ -51,9 +51,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `移动支付网-${title_cn}`, link: title_url, item: out, - }; + }); }; diff --git a/lib/v2/mpaypass/news.js b/lib/v2/mpaypass/news.js index 5dbb471c8..e8d81f973 100644 --- a/lib/v2/mpaypass/news.js +++ b/lib/v2/mpaypass/news.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 = 'http://m.mpaypass.com.cn'; const listData = await got(link); - const $list = cheerio.load(listData.data); - ctx.state.data = { + const $list = load(listData.data); + ctx.set('data', { title: '新闻 - 移动支付网', link, language: 'zh-CN', @@ -22,7 +22,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(href, async () => { const contentData = await got.get(href); - const $content = cheerio.load(contentData.data); + const $content = load(contentData.data); const description = $content('.newslist-body').html(); return { @@ -35,5 +35,5 @@ module.exports = async (ctx) => { }) .get() ), - }; + }); }; diff --git a/lib/v2/mrdx/daily.js b/lib/v2/mrdx/daily.js index b2dfa999c..0d4bcd4c5 100644 --- a/lib/v2/mrdx/daily.js +++ b/lib/v2/mrdx/daily.js @@ -1,11 +1,11 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { getElementChildrenInnerText } = require('./utils'); const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); dayjs.extend(utc); -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const dateFormatted = dayjs().utcOffset(8).format('YYYYMMDD'); @@ -17,7 +17,7 @@ module.exports = async (ctx) => { url: link, method: 'get', }); - const $ = cheerio.load(indexPageResponse.data); + const $ = load(indexPageResponse.data); // 当日所有文章Url在的`daoxiang` attribute中 // 其站点使用**非标准**的HTML语法 @@ -36,7 +36,7 @@ module.exports = async (ctx) => { method: 'get', }); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 标题在`h2`,`h3`,`h4`,`h5`中,有多余空格和换行符 // 但是Middleware会处理 @@ -69,11 +69,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '新华每日电讯', link, item: passages, description: '中国报纸发行前三强。位列《人民日报》,《参考消息》之后。《新华每日电讯》是新华社出版的一份新闻电讯报,1993年创办,具有很高的权威性和准确性,有“一报在手,便知天下”之美誉。《新华每日电讯》为对开八版日报,集中刊登[新华社]每天向国内播发的电讯稿及图片稿。打开《新华每日电讯》,中国和全世界每天发生的重大事件便将一目了然。在人类生活节奏日益加快的当今世界,《新华每日电讯》以最便捷、最醒目的方式为公众提供最重要的新闻报道,受到公众的喜爱和拥护。', - }; + }); }; diff --git a/lib/v2/mrm/index.js b/lib/v2/mrm/index.js index eef354741..d47cdbe33 100644 --- a/lib/v2/mrm/index.js +++ b/lib/v2/mrm/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 { category = 'zonghezixun3' } = ctx.params; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/${category}.html`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#datalist_wap .li') .toArray() @@ -26,7 +26,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.description = $('.article-cont').html(); return item; @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, item: items, - }; + }); }; diff --git a/lib/v2/mvm/index.js b/lib/v2/mvm/index.js index 79fe7183b..5a6e2fa4d 100644 --- a/lib/v2/mvm/index.js +++ b/lib/v2/mvm/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'; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'bqym'; + const category = ctx.req.param('category') ?? 'bqym'; const rootUrl = 'http://www.mwm.net.cn'; - const currentUrl = `${rootUrl}/web/${category === 'bqym' ? `bqym?pagesize=${ctx.query.limit ?? 100}` : category}`; + const currentUrl = `${rootUrl}/web/${category === 'bqym' ? `bqym?pagesize=${ctx.req.query('limit') ?? 100}` : category}`; const response = await got({ method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.n_date').remove(); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.mrt20').html(); item.author = content('.mrl20') @@ -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/mydrivers/cid.js b/lib/v2/mydrivers/cid.js index 3b568aa97..05d956603 100644 --- a/lib/v2/mydrivers/cid.js +++ b/lib/v2/mydrivers/cid.js @@ -1,11 +1,11 @@ -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const parser = require('@/utils/rss-parser'); const { rootUrl, rootRSSUrl, title, categories, getInfo, processItems } = require('./util'); module.exports = async (ctx) => { const { id } = 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 queryString = id ? `?cid=${id}` : ''; const currentUrl = new URL(id ? `newsclass.aspx${queryString}` : '', rootUrl).href; @@ -28,10 +28,10 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); } - ctx.state.data = { + ctx.set('data', { ...(await getInfo(currentUrl, ctx.cache.tryGet)), item: items, title: `${title} - ${feed.title.split(/_/).pop() || categories.zhibo}`, - }; + }); }; diff --git a/lib/v2/mydrivers/index.js b/lib/v2/mydrivers/index.js index c537c1cae..973362351 100644 --- a/lib/v2/mydrivers/index.js +++ b/lib/v2/mydrivers/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'); const { rootUrl, title, categories, convertToQueryString, getInfo, processItems } = require('./util'); @@ -17,7 +17,7 @@ module.exports = async (ctx) => { category = `ac/${category}`; } - 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 queryString = convertToQueryString(category); const currentUrl = new URL(`newsclass.aspx${queryString}`, rootUrl).href; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { const { data: response } = await got(apiUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('li[data-id]') .slice(0, limit) @@ -49,7 +49,7 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { ...(await getInfo(currentUrl, ctx.cache.tryGet)), ...Object.fromEntries( Object.entries({ @@ -57,5 +57,5 @@ module.exports = async (ctx) => { title: newTitle, }).filter(([value]) => value) ), - }; + }); }; diff --git a/lib/v2/mydrivers/rank.js b/lib/v2/mydrivers/rank.js index 74eeb9907..9fa21d603 100644 --- a/lib/v2/mydrivers/rank.js +++ b/lib/v2/mydrivers/rank.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, getInfo, processItems } = require('./util'); module.exports = async (ctx) => { const { range = '0' } = 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 currentUrl = new URL('newsclass.aspx?tid=1001', rootUrl).href; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const { data: response } = await got(apiUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('a') .toArray() @@ -33,8 +33,8 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - ctx.state.data = { + ctx.set('data', { item: items, ...(await getInfo(currentUrl, ctx.cache.tryGet, Number.parseInt(range, 10))), - }; + }); }; diff --git a/lib/v2/mydrivers/util.js b/lib/v2/mydrivers/util.js index 1b0581c3b..f2bebbe2f 100644 --- a/lib/v2/mydrivers/util.js +++ b/lib/v2/mydrivers/util.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 domain = 'mydrivers.com'; const rootUrl = `https://m.${domain}`; @@ -50,7 +50,7 @@ const getInfo = (url, tryGet, range) => tryGet(url, async () => { const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const icon = new URL($('link[rel="apple-touch-icon-precomposed"]').prop('href'), rootUrl).href; const image = `https:${$('div.logo a img').prop('src')}`; @@ -91,7 +91,7 @@ const processItems = async (items, tryGet) => }, }); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.title = content('div.news_t').text() || item.title; item.description = content('#content').html() ?? item.description; diff --git a/lib/v2/myfigurecollection/activity.js b/lib/v2/myfigurecollection/activity.js index db2271430..25fa50779 100644 --- a/lib/v2/myfigurecollection/activity.js +++ b/lib/v2/myfigurecollection/activity.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'); -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 { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const category = ctx.params.category ?? '-1'; - const language = ctx.params.language ?? ''; - const latestAdditions = ctx.params.latestAdditions ?? '1'; - const latestEdits = ctx.params.latestEdits ?? '1'; - const latestAlerts = ctx.params.latestAlerts ?? '1'; - const latestPictures = ctx.params.latestPictures ?? '1'; + const category = ctx.req.param('category') ?? '-1'; + const language = ctx.req.param('language') ?? ''; + const latestAdditions = ctx.req.param('latestAdditions') ?? '1'; + const latestEdits = ctx.req.param('latestEdits') ?? '1'; + const latestAlerts = ctx.req.param('latestAlerts') ?? '1'; + const latestPictures = ctx.req.param('latestPictures') ?? '1'; if (language && !isValidHost(language)) { throw new Error('Invalid language'); @@ -26,7 +26,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.activity-wrapper') .toArray() @@ -53,11 +53,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title') .text() .replace(/ \(.*\)/, ''), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/myfigurecollection/index.js b/lib/v2/myfigurecollection/index.js index b3170bb98..1cee5159b 100644 --- a/lib/v2/myfigurecollection/index.js +++ b/lib/v2/myfigurecollection/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 { isValidHost } = require('@/utils/valid-host'); @@ -11,8 +11,8 @@ const shortcuts = { }; module.exports = async (ctx) => { - const language = ctx.params.language ?? ''; - const category = ctx.params.category ?? 'figure'; + const language = ctx.req.param('language') ?? ''; + const category = ctx.req.param('category') ?? 'figure'; if (language && !isValidHost(language)) { throw new Error('Invalid language'); } @@ -25,10 +25,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.item-icon, .picture-icon') - .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).find('a'); @@ -49,7 +49,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('.headline').text(); item.description = art(path.join(__dirname, 'templates/description.art'), { @@ -72,11 +72,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title') .text() .replace(/ \(.*\)/, ''), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/mygopen/index.js b/lib/v2/mygopen/index.js index 7789bf3de..131b84b6d 100644 --- a/lib/v2/mygopen/index.js +++ b/lib/v2/mygopen/index.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const label = ctx.params.label ?? ''; + const label = ctx.req.param('label') ?? ''; const rootUrl = 'https://www.mygopen.com'; const currentUrl = `${rootUrl}${label ? `/search/label/${label}` : ''}`; - const apiUrl = `${rootUrl}/feeds/posts/default${label ? `/-/${label}` : ''}?alt=json-in-script&max-results=${ctx.query.limit ? Number.parseInt(ctx.query.limit) : 50}`; + const apiUrl = `${rootUrl}/feeds/posts/default${label ? `/-/${label}` : ''}?alt=json-in-script&max-results=${ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50}`; const response = await got({ method: 'get', @@ -20,10 +20,10 @@ module.exports = async (ctx) => { link: item.link.pop().href, })); - ctx.state.data = { + ctx.set('data', { title: `MyGoPen${label ? `: ${label}` : ''}`, link: currentUrl, item: items, description: '詐騙與謠言頻傳的年代,「MyGoPen|這是假消息」提醒網路使用者隨時要用謹慎懷疑的態度面對網路上的消息。', - }; + }); }; diff --git a/lib/v2/mymusicsheet/usersheets.js b/lib/v2/mymusicsheet/usersheets.js index 633f2e3e6..b978258bf 100644 --- a/lib/v2/mymusicsheet/usersheets.js +++ b/lib/v2/mymusicsheet/usersheets.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) => { @@ -112,9 +112,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${username}'s sheets`, link: `https://www.mymusicsheet.com/${username}?viewType=sheet&orderBy=createdAt`, item: items, - }; + }); }; diff --git a/lib/v2/mysql/release.js b/lib/v2/mysql/release.js index b2cffdfc1..57614b505 100644 --- a/lib/v2/mysql/release.js +++ b/lib/v2/mysql/release.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const version = ctx.params.version ?? '8.0'; + const version = ctx.req.param('version') ?? '8.0'; const rootUrl = 'https://dev.mysql.com'; const currentUrl = `${rootUrl}/doc/relnotes/mysql/${version}/en/`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('dt span a') .slice(1, -1) @@ -41,7 +41,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.indexterm').remove(); content('.titlepage').first().remove(); @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nasa/apod-cn.js b/lib/v2/nasa/apod-cn.js index 394d622a8..a4d846fb3 100644 --- a/lib/v2/nasa/apod-cn.js +++ b/lib/v2/nasa/apod-cn.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 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.nasachina.cn/wp-json/wp/v2/posts?categories=2&per_page=${limit}`; const { data } = await got({ method: 'get', @@ -16,9 +16,9 @@ module.exports = async (ctx) => { link: item.link, })); - ctx.state.data = { + ctx.set('data', { title: 'NASA中文 - 天文·每日一图', link: 'https://www.nasachina.cn/nasa-image-of-the-day', item: items, - }; + }); }; diff --git a/lib/v2/nasa/apod-ncku.js b/lib/v2/nasa/apod-ncku.js index 57203c82c..dd1848294 100644 --- a/lib/v2/nasa/apod-ncku.js +++ b/lib/v2/nasa/apod-ncku.js @@ -1,16 +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'; 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 = 'http://sprite.phys.ncku.edu.tw/astrolab/mirrors/apod/archivepix.html'; const response = await got({ method: 'get', url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > b > a') .slice(0, limit) @@ -27,7 +27,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const description = `
${content('body > center').eq(1).html()}
${content('body > p').eq(0).html()}`; const pubDate = parseDate(item.link.slice(-11, -5), 'YYMMDD'); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'NASA 每日一天文圖 (成大物理分站) ', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/nasa/apod.js b/lib/v2/nasa/apod.js index 603668218..af88e76b7 100644 --- a/lib/v2/nasa/apod.js +++ b/lib/v2/nasa/apod.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'; 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://apod.nasa.gov/apod/archivepix.html'; const response = await got({ method: 'get', url: rootUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('body > b > a') .slice(0, limit) @@ -27,7 +27,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const description = `
${content('body > center').eq(1).html()}
${content('body > p').eq(0).html()}`; const pubDate = timezone(parseDate(item.link.slice(-11, -5), 'YYMMDD'), -5); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'NASA Astronomy Picture of the Day', link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/natgeo/dailyphoto.js b/lib/v2/natgeo/dailyphoto.js index 2a5c32848..065dd8176 100644 --- a/lib/v2/natgeo/dailyphoto.js +++ b/lib/v2/natgeo/dailyphoto.js @@ -1,15 +1,15 @@ -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 config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { const rootUrl = 'https://www.nationalgeographic.com'; const apiUrl = `${rootUrl}/photo-of-the-day`; const response = await ctx.cache.tryGet(apiUrl, async () => (await got(apiUrl)).data, config.cache.contentExpire, false); - const $ = cheerio.load(response); + const $ = load(response); const natgeo = JSON.parse($.html().match(/window\['__natgeo__']=(.*);/)[1]); const media = natgeo.page.content.mediaspotlight.frms[0].mods[0].edgs[1].media; @@ -24,9 +24,9 @@ module.exports = async (ctx) => { author: item.img.crdt, })); - ctx.state.data = { + ctx.set('data', { title: 'Nat Geo Photo of the Day', link: apiUrl, item: items, - }; + }); }; diff --git a/lib/v2/natgeo/dailyselection.js b/lib/v2/natgeo/dailyselection.js index d89add8d5..ded9bad7a 100644 --- a/lib/v2/natgeo/dailyselection.js +++ b/lib/v2/natgeo/dailyselection.js @@ -1,6 +1,6 @@ -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'; module.exports = async (ctx) => { const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { const api = 'http://dili.bdatu.com/jiekou/albums/a' + sort + '.html'; const response = await got(api); const items = response.data.picture; - const out = new Array(); + const out = []; items.map((item) => { const info = { @@ -33,9 +33,9 @@ module.exports = async (ctx) => { return info; }); - ctx.state.data = { + ctx.set('data', { title: 'Photo of the Daily Selection', link: api, item: out, - }; + }); }; diff --git a/lib/v2/natgeo/natgeo.js b/lib/v2/natgeo/natgeo.js index fed6fe935..f58b6a21f 100644 --- a/lib/v2/natgeo/natgeo.js +++ b/lib/v2/natgeo/natgeo.js @@ -1,12 +1,12 @@ -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'; // https://www.natgeomedia.com//article/ -async function load(link) { +async function loadContent(link) { const { data } = await got(link); - const $ = cheerio.load(data); + const $ = load(data); const dtStr = $('.content-title-area') .find('h6') .first() @@ -26,10 +26,10 @@ async function load(link) { } module.exports = async (ctx) => { - const type = ctx.params.type ?? ''; - const url = `https://www.natgeomedia.com/${ctx.params.cat}/${type}`; + const type = ctx.req.param('type') ?? ''; + const url = `https://www.natgeomedia.com/${ctx.req.param('cat')}/${type}`; const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const urlList = $('.article-link-w100') .find('.read-btn') @@ -44,13 +44,13 @@ module.exports = async (ctx) => { const single = { link, }; - const other = await ctx.cache.tryGet(link, () => load(link)); + const other = await ctx.cache.tryGet(link, () => loadContent(link)); return { ...single, ...other }; }) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, item: out, - }; + }); }; diff --git a/lib/v2/nationalgeographic/latest-stories.js b/lib/v2/nationalgeographic/latest-stories.js index 33ad9a927..347671123 100644 --- a/lib/v2/nationalgeographic/latest-stories.js +++ b/lib/v2/nationalgeographic/latest-stories.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 findNatgeo = ($) => @@ -14,7 +14,7 @@ const findNatgeo = ($) => module.exports = async (ctx) => { const currentUrl = 'https://www.nationalgeographic.com/pages/topic/latest-stories'; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = await Promise.all( findNatgeo($) .page.content.hub.frms.flatMap((e) => e.mods) @@ -28,7 +28,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); const mods = findNatgeo($).page.content.article.frms.find((f) => f.cmsType === 'ArticleBodyFrame').mods; const bodyTile = mods.find((m) => m.edgs[0].cmsType === 'ArticleBodyTile').edgs[0]; @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('meta[property="og:title"]').attr('content'), link: currentUrl, item: items.filter((item) => item !== null), - }; + }); }; diff --git a/lib/v2/nature/cover.js b/lib/v2/nature/cover.js index 93884bebd..52a015db8 100644 --- a/lib/v2/nature/cover.js +++ b/lib/v2/nature/cover.js @@ -14,9 +14,9 @@ // natastron: Nature Astronomy // nphys Nature Physics -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, journalMap } = require('./utils'); const { CookieJar } = require('tough-cookie'); @@ -44,7 +44,7 @@ module.exports = async (ctx) => { const imageUrl = `https://media.springernature.com/full/springer-static/cover-hires/journal/${id}/${volume}/${issue}?as=webp`; const contents = `
Volume ${volume} Issue ${issue}
`; - const $ = cheerio.load(response.data); + const $ = load(response.data); const date = $('title').text().split(',')[1].trim(); const issueDescription = $('div[data-test=issue-description]').html() ?? ''; @@ -58,10 +58,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Nature Covers Story', description: 'Find out the cover story of some Nature journals.', link: baseUrl, item: out, - }; + }); }; diff --git a/lib/v2/nature/highlight.js b/lib/v2/nature/highlight.js index d8c6a6a8b..57f39c92b 100644 --- a/lib/v2/nature/highlight.js +++ b/lib/v2/nature/highlight.js @@ -1,5 +1,5 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const { baseUrl, cookieJar, getArticleList, getArticle } = require('./utils'); module.exports = async (ctx) => { @@ -7,16 +7,16 @@ module.exports = async (ctx) => { const url = `${baseUrl}/${journal}/articles?type=research-highlight`; const res = await got(url, { cookieJar }); - const $ = cheerio.load(res.data); + const $ = load(res.data); let items = getArticleList($); items = await Promise.all(items.map((item) => getArticle(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: $('title').text().trim(), description: $('meta[name=description]').attr('content'), link: url, item: items, - }; + }); }; diff --git a/lib/v2/nature/news-and-comment.js b/lib/v2/nature/news-and-comment.js index d0c73e534..254e9a15b 100644 --- a/lib/v2/nature/news-and-comment.js +++ b/lib/v2/nature/news-and-comment.js @@ -12,26 +12,26 @@ // nmat: Nature Materials // natmachintell: Nature Machine Intelligence -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const { baseUrl, cookieJar, getArticleList, getArticle } = require('./utils'); module.exports = async (ctx) => { - const journal = ctx.params.journal; + const journal = ctx.req.param('journal'); const pageURL = `${baseUrl}/${journal}/news-and-comment`; const pageResponse = await got(pageURL, { cookieJar }); - const pageCapture = cheerio.load(pageResponse.data); + const pageCapture = load(pageResponse.data); const pageDescription = pageCapture('meta[name=description]').attr('content') || 'Nature, a nature research journal'; let items = getArticleList(pageCapture); items = await Promise.all(items.map((item) => getArticle(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: pageCapture('title').text(), description: pageDescription, link: pageURL, item: items, - }; + }); }; diff --git a/lib/v2/nature/news.js b/lib/v2/nature/news.js index 717695fc5..e1f354a66 100644 --- a/lib/v2/nature/news.js +++ b/lib/v2/nature/news.js @@ -1,12 +1,12 @@ -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'; const { baseUrl, cookieJar, getArticle } = require('./utils'); module.exports = async (ctx) => { const url = `${baseUrl}/latest-news`; const res = await got(url, { cookieJar }); - const $ = cheerio.load(res.data); + const $ = load(res.data); let items = $('.c-article-item__content') .toArray() @@ -21,10 +21,10 @@ module.exports = async (ctx) => { items = await Promise.all(items.map((item) => ctx.cache.tryGet(item.link, () => getArticle(item, ctx)))); - ctx.state.data = { + ctx.set('data', { title: 'Nature | Latest News', description: $('meta[name=description]').attr('content'), link: url, item: items, - }; + }); }; diff --git a/lib/v2/nature/research.js b/lib/v2/nature/research.js index c28a0b108..46ce6a385 100644 --- a/lib/v2/nature/research.js +++ b/lib/v2/nature/research.js @@ -13,16 +13,16 @@ // nmat: Nature Materials // natmachintell: Nature Machine Intelligence -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const { baseUrl, cookieJar, getArticleList, getDataLayer, getArticle } = require('./utils'); module.exports = async (ctx) => { - const journal = ctx.params.journal ?? 'nature'; + const journal = ctx.req.param('journal') ?? 'nature'; const pageURL = `${baseUrl}/${journal}/research-articles`; const pageResponse = await got(pageURL, { cookieJar }); - const pageCapture = cheerio.load(pageResponse.data); + const pageCapture = load(pageResponse.data); const pageTitle = getDataLayer(pageCapture).content.journal.title; @@ -30,10 +30,10 @@ module.exports = async (ctx) => { items = await Promise.all(items.map((item) => getArticle(item, ctx))); - ctx.state.data = { + ctx.set('data', { title: `Nature (${pageTitle}) | Latest Research`, description: pageCapture('meta[name="description"]').attr('content') || `Nature, a nature research journal`, link: pageURL, item: items, - }; + }); }; diff --git a/lib/v2/nature/siteindex.js b/lib/v2/nature/siteindex.js index dbe14a1b6..d4b274338 100644 --- a/lib/v2/nature/siteindex.js +++ b/lib/v2/nature/siteindex.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { baseUrl, cookieJar } = require('./utils'); module.exports = async (ctx) => { const response = await got(`${baseUrl}/siteindex`, { cookieJar }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('li[class^="grid mq640-grid-12"]') .toArray() @@ -21,7 +21,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(`nature:siteindex:${item.title}`, async () => { const response = await got(item.link, { cookieJar }); - const $ = cheerio.load(response.data); + const $ = load(response.data); delete item.link; try { @@ -37,12 +37,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Nature siteindex', link: response.url, item: items, - }; - ctx.state.json = { + }); + ctx.set('json', { items, - }; + }); }; diff --git a/lib/v2/nature/utils.js b/lib/v2/nature/utils.js index 6fb9d4f58..ded7e0638 100644 --- a/lib/v2/nature/utils.js +++ b/lib/v2/nature/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 { CookieJar } = require('tough-cookie'); const baseUrl = 'https://www.nature.com'; @@ -54,7 +54,7 @@ const getArticle = (item, ctx) => const response = await got(item.link, { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const responseUrl = new URL(response.url); if (responseUrl.pathname.startsWith('/immersive/')) { diff --git a/lib/v2/nautil/topics.js b/lib/v2/nautil/topics.js index b8bee1439..546f41cd5 100644 --- a/lib/v2/nautil/topics.js +++ b/lib/v2/nautil/topics.js @@ -1,7 +1,7 @@ -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 baseUrl = 'https://nautil.us'; @@ -21,14 +21,14 @@ module.exports = async (ctx) => { const { data: list } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - categories: categoryIdMap.find((item) => item.slug === ctx.params.tid.toLowerCase()).id, - per_page: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20, + categories: categoryIdMap.find((item) => item.slug === ctx.req.param('tid').toLowerCase()).id, + per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20, }, }); const out = list.map((item) => { const head = item.yoast_head_json; - const $ = cheerio.load(item.content.rendered, null, false); + const $ = load(item.content.rendered, null, false); // lazyload images $('img').each((_, e) => { e = $(e); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { - title: 'Nautilus | ' + categoryIdMap.find((item) => item.slug === ctx.params.tid.toLowerCase()).name, - link: `${baseUrl}/topics/${ctx.params.tid}/`, + ctx.set('data', { + title: 'Nautilus | ' + categoryIdMap.find((item) => item.slug === ctx.req.param('tid').toLowerCase()).name, + link: `${baseUrl}/topics/${ctx.req.param('tid')}/`, item: out, - }; + }); }; diff --git a/lib/v2/nbd/index.js b/lib/v2/nbd/index.js index fd4ac7c2e..1d6e0dbec 100644 --- a/lib/v2/nbd/index.js +++ b/lib/v2/nbd/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 ?? '3'; + const id = ctx.req.param('id') ?? '3'; const rootUrl = 'https://www.nbd.com.cn'; const currentUrl = `${rootUrl}/columns/${id}/`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.u-news-title a') .toArray() @@ -37,7 +37,7 @@ module.exports = async (ctx) => { if (!detailResponse.url.startsWith(`${rootUrl}/`)) { return item; } - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.g-articl-text').html(); item.pubDate = timezone(parseDate(detailResponse.data.match(/"pubDate": "(.*)"/)[1]), +8); @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('h1').text() || $('.u-channelname').text()} - 每经网`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nbd/router.js b/lib/v2/nbd/router.js index b982c3ca5..d9259ca06 100644 --- a/lib/v2/nbd/router.js +++ b/lib/v2/nbd/router.js @@ -1,4 +1,4 @@ module.exports = (router) => { - router.redirect('/daily', '/nbd/332'); + router.get('/daily', (c) => c.redirect('/nbd/332')); router.get('/:id?', require('./index')); }; diff --git a/lib/v2/nber/index.js b/lib/v2/nber/index.js index 5a7ebda39..e5d245785 100644 --- a/lib/v2/nber/index.js +++ b/lib/v2/nber/index.js @@ -1,8 +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'); +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; async function getData(url) { const response = await got(url).json(); @@ -12,7 +13,6 @@ async function getData(url) { module.exports = async (ctx) => { const url = 'https://www.nber.org/api/v1/working_page_listing/contentType/working_paper/_/_/search'; const baseUrl = 'https://www.nber.org'; - const config = require('@/config').value; const data = await ctx.cache.tryGet(url, () => getData(url), config.cache.routeExpire, false); const items = await Promise.all( data @@ -21,7 +21,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}${article.url}`; return ctx.cache.tryGet(link, async () => { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const downloadLink = $('meta[name="citation_pdf_url"]').attr('content'); const fullAbstract = $('.page-header__intro-inner').html(); return { @@ -39,10 +39,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: 'NBER Working Paper', link: 'https://www.nber.org/papers', item: items, description: `National Bureau of Economic Research Working Papers articles`, - }; + }); }; diff --git a/lib/v2/ncc-cma/cmdp.js b/lib/v2/ncc-cma/cmdp.js index 49123a954..d6c6b040f 100644 --- a/lib/v2/ncc-cma/cmdp.js +++ b/lib/v2/ncc-cma/cmdp.js @@ -1,13 +1,13 @@ -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 iconv = require('iconv-lite'); module.exports = async (ctx) => { const { id } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const ids = id?.split(/\//) ?? []; const titles = []; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response, 'gbk')); + const $ = load(iconv.decode(response, 'gbk')); const author = '国家气候中心'; @@ -65,7 +65,7 @@ module.exports = async (ctx) => { const image = $('img.logo').prop('src'); const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}${titles.length === 0 ? '' : ` - ${titles.join('|')}`}`, link: currentUrl, @@ -77,5 +77,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/ncepu/master/masterinfo.js b/lib/v2/ncepu/master/masterinfo.js index 6a6f890c5..9c408b9e6 100644 --- a/lib/v2/ncepu/master/masterinfo.js +++ b/lib/v2/ncepu/master/masterinfo.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 title_map = { tzgg: '通知公告', @@ -20,11 +20,11 @@ const url_map = { }; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const response = await got(`https://yjsy.ncepu.edu.cn/${url_map[type]}/index.htm`); const data = response.data; // 获取页面 html 数据 - const $ = cheerio.load(data); + const $ = load(data); const list = $('.articleList ul li') .map((_, item) => { item = $(item); @@ -48,7 +48,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.map(async (item) => { const itemData = await ctx.cache.tryGet(item.link, async () => (await got(item.link)).data); - const content = cheerio.load(itemData); + const content = load(itemData); const articleAuthor = content('.articleAuthor').html().replace('作者:  ', '').replace('来源:  ', ''); const eDescription = content('.article').html(); @@ -64,10 +64,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${title_map[type]}-华北电力大学研究生院`, link: `http://yjsy.ncepu.edu.cn/${url_map[type]}`, description: `华北电力大学研究生院${description_map[type]}`, item: items, - }; + }); }; diff --git a/lib/v2/ncu/jwc.js b/lib/v2/ncu/jwc.js index 8a02bde5a..f3ad44fc2 100644 --- a/lib/v2/ncu/jwc.js +++ b/lib/v2/ncu/jwc.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://jwc.ncu.edu.cn'; const response = await got(baseUrl); - const $ = cheerio.load(response.body); + const $ = load(response.body); const list = $('.box3 .inner ul.img-list li'); - ctx.state.data = { + ctx.set('data', { title: '南昌大学教务处', link: baseUrl, description: '南昌大学教务处', @@ -29,5 +29,5 @@ module.exports = async (ctx) => { pubDate: parseDate(date, 'MM-DD').setFullYear(month < 6 ? new Date().getFullYear() - 1 : new Date().getFullYear()), }; }), - }; + }); }; diff --git a/lib/v2/ncwu/notice.js b/lib/v2/ncwu/notice.js index 0857d33c3..1bcb74bad 100644 --- a/lib/v2/ncwu/notice.js +++ b/lib/v2/ncwu/notice.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; const baseUrl = 'https://www.ncwu.edu.cn/xxtz.htm'; module.exports = async (ctx) => { const response = await got(baseUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.news-item') .toArray() .map((item) => { @@ -19,9 +19,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: baseUrl, item: list, - }; + }); }; diff --git a/lib/v2/ndss-symposium/ndss.js b/lib/v2/ndss-symposium/ndss.js index f74935ff3..68d7c4f83 100644 --- a/lib/v2/ndss-symposium/ndss.js +++ b/lib/v2/ndss-symposium/ndss.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.ndss-symposium.org'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { // use wordpress api to get data @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const items = await Promise.all( data.map(async (elem) => { - const $ = cheerio.load(elem.content.rendered); + const $ = load(elem.content.rendered); const link = elem.link; const pubDate = parseDate(elem.date); @@ -32,7 +32,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(item.link, async () => { // some titles and authos are not complete const response = await got(item.link); - const $ = cheerio.load(response.body); + const $ = load(response.body); item.description = $('.paper-data').text().trim().replaceAll('\n', ''); item.title = $('h1.entry-title').text().trim().replaceAll('\n', '').replaceAll(/\s+/g, ' '); item.author = $('h1.entry-title').siblings().text().trim().replaceAll('\n', '').replaceAll(/\s+/g, ' '); @@ -70,11 +70,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: 'NDSS', link: url, description: 'The Network and Distributed System Security (NDSS) Symposium Accpeted Papers', allowEmpty: true, item: items.flat(), - }; + }); }; diff --git a/lib/v2/neatdownloadmanager/download.js b/lib/v2/neatdownloadmanager/download.js index 4dacb67fd..ffc587c8c 100644 --- a/lib/v2/neatdownloadmanager/download.js +++ b/lib/v2/neatdownloadmanager/download.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 os = (ctx.params.os ?? '').toLowerCase(); + const os = (ctx.req.param('os') ?? '').toLowerCase(); const rootUrl = 'https://www.neatdownloadmanager.com'; const currentUrl = `${rootUrl}/index.php`; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.p1') .toArray() @@ -38,9 +38,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'Neat Download Manager', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/neea/index.js b/lib/v2/neea/index.js index ee47ab31e..60c30682c 100644 --- a/lib/v2/neea/index.js +++ b/lib/v2/neea/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -function load(link, ctx) { +import got from '@/utils/got'; +import { load } from 'cheerio'; +function loadContent(link, ctx) { return ctx.cache.tryGet(link, async () => { // 开始加载页面 const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 获取标题 const title = $('#Content1 > div > ul > li > h1').text(); // 获取正文内容 @@ -19,7 +19,7 @@ function load(link, ctx) { } module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const host = `http://${type}.neea.edu.cn${typeDic[type].url}`; const response = await got({ method: 'get', @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $(`#ReportIDname > a`).parent().parent().get(); const process = await Promise.all( @@ -43,16 +43,16 @@ module.exports = async (ctx) => { guid: itemUrl, pubDate: new Date(time).toUTCString(), }; - const other = await load(String(itemUrl), ctx); + const other = await loadContent(String(itemUrl), ctx); return Object.assign({}, single, other); }) ); - ctx.state.data = { + ctx.set('data', { title: `${typeDic[String(type)].title}动态`, link: host, description: `${typeDic[String(type)].title}动态 `, item: process, - }; + }); }; const typeDic = { diff --git a/lib/v2/neea/jlpt.js b/lib/v2/neea/jlpt.js index 0865392fd..73608e594 100644 --- a/lib/v2/neea/jlpt.js +++ b/lib/v2/neea/jlpt.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://news.neea.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.dvContent').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/nenu/sohac.js b/lib/v2/nenu/sohac.js index a3b35baea..a013a8c6c 100644 --- a/lib/v2/nenu/sohac.js +++ b/lib/v2/nenu/sohac.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 limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10; const path = ctx.path === '/sohac' ? '/index/tzgg' : ctx.path.replace(/^\/sohac/, ''); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('span.data') .slice(0, limit) @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('.biaoti').text(); item.description = content('.v_news_content').html(); @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nenu/yjsy.js b/lib/v2/nenu/yjsy.js index 93fd02bb6..6a90b985b 100644 --- a/lib/v2/nenu/yjsy.js +++ b/lib/v2/nenu/yjsy.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 limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10; const path = ctx.path === '/yjsy' ? '/tzgg' : ctx.path.replace(/^\/yjsy/, ''); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a.tit') .slice(0, limit) @@ -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('h2').text(); item.description = content('.v_news_content').html(); @@ -56,9 +56,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/netflav/index.js b/lib/v2/netflav/index.js index 52cd727bc..21ff740e1 100644 --- a/lib/v2/netflav/index.js +++ b/lib/v2/netflav/index.js @@ -1,14 +1,14 @@ -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 baseUrl = 'https://netflav.com'; const { data } = await got(baseUrl); - const $ = cheerio.load(data); + const $ = load(data); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const { head, @@ -27,7 +27,7 @@ module.exports = async (ctx) => { category: [...new Set(item.tags?.map((t) => t.replace(/^(\w{2}:)/, '')))], })); - ctx.state.data = { + ctx.set('data', { title: head.find((h) => h[0] === 'title')[1].children, description: head.find((h) => h[0] === 'meta' && h[1].name === 'description')[1].content, logo: `${baseUrl}${head.find((h) => h[0] === 'meta' && h[1].property === 'og:image')[1].content}`, @@ -35,5 +35,5 @@ module.exports = async (ctx) => { link: baseUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/neu/bmie.js b/lib/v2/neu/bmie.js index 4333878c1..dfc2da466 100644 --- a/lib/v2/neu/bmie.js +++ b/lib/v2/neu/bmie.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.bmie.neu.edu.cn'; @@ -23,7 +23,7 @@ const map = { }; module.exports = async (ctx) => { - let type = ctx.params.type; + let type = ctx.req.param('type'); if (map[type] !== undefined) { type = map[type]; } @@ -31,18 +31,18 @@ module.exports = async (ctx) => { const response = await got(newsUrl); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const title = $('title').text(); const items = $('#subIndex > div.main_frame_sub > div.detail_sub > div > div > div > ul > li').slice(0, 7).get(); const results = await Promise.all( items.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const title = $('a').attr('title'); const url = baseUrl + $('a').attr('href'); const data = await ctx.cache.tryGet(url, async () => { const result = await got(url); - const $ = cheerio.load(result.data); + const $ = load(result.data); const info = $($('.ny_con p')[1]).text(); const s = info.search(/\d{4}-\d{2}-\d{2}/); @@ -86,9 +86,9 @@ module.exports = async (ctx) => { return result; }) ); - ctx.state.data = { + ctx.set('data', { title: `东北大学 医学与生物信息工程学院 ${title}`, link: newsUrl, item: results, - }; + }); }; diff --git a/lib/v2/neu/news.js b/lib/v2/neu/news.js index 9545c38b7..7ee5847d0 100644 --- a/lib/v2/neu/news.js +++ b/lib/v2/neu/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 baseUrl = 'https://neunews.neu.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const newsUrl = `${baseUrl}/${type}/list.htm`; const response = await got(newsUrl); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const items = $('.column-news-list > .news_list > .news') .toArray() @@ -26,7 +26,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const result = await got(item.link); - const $ = cheerio.load(result.data); + const $ = load(result.data); item.author = $('.arti-metas').text().split('更新日期')[0]; item.description = $('.article_content').html(); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `东北大学新闻网-${$('head title').text()}`, link: newsUrl, item: results, - }; + }); }; diff --git a/lib/v2/newmuseum/exhibitions.js b/lib/v2/newmuseum/exhibitions.js index 7798526cc..5aaf1486e 100644 --- a/lib/v2/newmuseum/exhibitions.js +++ b/lib/v2/newmuseum/exhibitions.js @@ -2,7 +2,7 @@ const buildData = require('@/utils/common-config'); module.exports = async (ctx) => { let link; - const state = ctx.query.state; + const state = ctx.req.query('state'); switch (state) { case undefined: diff --git a/lib/v2/newrank/douyin.js b/lib/v2/newrank/douyin.js index 05a31f599..74446acf3 100644 --- a/lib/v2/newrank/douyin.js +++ b/lib/v2/newrank/douyin.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.newrank || !config.newrank.cookie) { throw new Error('newrank RSS is disabled due to the lack of
relevant config'); } - const uid = ctx.params.dyid; + const uid = ctx.req.param('dyid'); const nonce = utils.random_nonce(9); const url_detail = 'https://xd.newrank.cn/xdnphb/nr/cloud/douyin/detail/aweme?xyz=' + utils.decrypt_douyin_detail_xyz(nonce) + '&nonce=' + nonce; const cookie = config.newrank.cookie; @@ -54,10 +54,10 @@ module.exports = async (ctx) => { pubDate: item.create_time, })); - ctx.state.data = { + ctx.set('data', { title: name + ' - 抖音', description, link: 'https://xd.newrank.cn/data/d/account/workList/' + uid, item: items, - }; + }); }; diff --git a/lib/v2/newrank/utils.js b/lib/v2/newrank/utils.js index f7c5822db..d677e3fb3 100644 --- a/lib/v2/newrank/utils.js +++ b/lib/v2/newrank/utils.js @@ -1,6 +1,6 @@ -const md5 = require('@/utils/md5'); -const got = require('@/utils/got'); -const config = require('@/config').value; +import md5 from '@/utils/md5'; +import got from '@/utils/got'; +import { config } from '@/config'; const newrank_cookie_token = 'newrank_cookie_token'; const query_count = 'newrank_cookie_count'; const max_query_count = 30; diff --git a/lib/v2/newrank/wechat.js b/lib/v2/newrank/wechat.js index ddb57cd9d..7c73e4b13 100644 --- a/lib/v2/newrank/wechat.js +++ b/lib/v2/newrank/wechat.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { finishArticleItem } = require('@/utils/wechat-mp'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const utils = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.newrank || !config.newrank.cookie) { throw new Error('newrank RSS is disabled due to the lack of relevant config'); } - const uid = ctx.params.wxid; + const uid = ctx.req.param('wxid'); const nonce = utils.random_nonce(9); const { data: summaryHTML } = await got({ method: 'get', @@ -18,7 +18,7 @@ module.exports = async (ctx) => { Cookie: config.newrank.cookie, }, }); - const summary$ = cheerio.load(summaryHTML); + const summary$ = load(summaryHTML); const mainsrc = summary$('script') .toArray() .find((item) => (item.attribs.src || '').startsWith('/new/static/js/main.')).attribs.src; @@ -57,9 +57,9 @@ module.exports = async (ctx) => { })); await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.state.data = { + ctx.set('data', { title: name + ' - 微信公众号', link: `https://www.newrank.cn/new/readDetial?account=${uid}`, item: items, - }; + }); }; diff --git a/lib/v2/news/xhsxw.js b/lib/v2/news/xhsxw.js index cc41e7af3..ddc705570 100644 --- a/lib/v2/news/xhsxw.js +++ b/lib/v2/news/xhsxw.js @@ -1,19 +1,19 @@ -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 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 = 'http://www.news.cn'; const currentUrl = new URL('xhsxw.htm', rootUrl).href; const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const id = $('ul.wz-list') .prop('data') @@ -48,7 +48,7 @@ module.exports = async (ctx) => { try { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.description += art(path.join(__dirname, 'templates/description.art'), { description: content('#detailContent').html(), @@ -66,7 +66,7 @@ module.exports = async (ctx) => { const image = new URL('20141223_xhsxw_logo_v1.png', rootUrl).href; const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title, link: currentUrl, @@ -77,5 +77,5 @@ module.exports = async (ctx) => { logo: icon, author: title.split(/_/).pop(), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/newsmarket/index.js b/lib/v2/newsmarket/index.js index 0c3de57d8..fff65a625 100644 --- a/lib/v2/newsmarket/index.js +++ b/lib/v2/newsmarket/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://www.newsmarket.com.tw'; const currentUrl = `${rootUrl}${category ? `/blog/category/${category}` : ''}`; @@ -13,10 +13,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.title a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20) .map((_, item) => { item = $(item); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('figure img').each(function () { content(this) @@ -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/newzmz/index.js b/lib/v2/newzmz/index.js index 4b7d35c9d..dcfdc672e 100644 --- a/lib/v2/newzmz/index.js +++ b/lib/v2/newzmz/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 { rootUrl, getItems, getItemInfo, processItems } = require('./util'); module.exports = async (ctx) => { const { id = '1', downLinkType = '磁力链' } = 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; // If the id is not composed solely of digits, // then consider it as the id of a movie or TV show; @@ -21,7 +21,7 @@ module.exports = async (ctx) => { return response; }); - const $ = cheerio.load(response); + const $ = load(response); // If a category id is specified, // retrieve all movies and TV shows from that category @@ -50,7 +50,7 @@ module.exports = async (ctx) => { const title = `${$('title').text()}${headerTitle ? ` - ${headerTitle}` : ''}`; const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: isCategory ? items : items.slice(0, limit), title, link: currentUrl, @@ -62,5 +62,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author: title, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/newzmz/util.js b/lib/v2/newzmz/util.js index 748813447..de580ea0e 100644 --- a/lib/v2/newzmz/util.js +++ b/lib/v2/newzmz/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 rootUrl = 'https://nzmz.xyz'; @@ -22,7 +22,7 @@ const getItems = async (tryGet, homeUrl, id, modSelector, itemSelector) => { return response; }); - const $ = cheerio.load(response); + const $ = load(response); return $(modSelector) .eq(Number.parseInt(id, 10)) @@ -47,7 +47,7 @@ const getItemInfo = (tryGet, itemUrl) => tryGet(`newzmz#${itemUrl.match(/details-(.*?)\.html/)[1]}`, async () => { const { data: detailResponse } = await got(itemUrl); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); const nameZh = content('div.chsname').text(); const nameEn = content('div.engname').text(); @@ -107,7 +107,7 @@ const getItemInfo = (tryGet, itemUrl) => const processItems = async (i, downLinkType, itemSelector, categorySelector, downLinkSelector) => { const { data: detailResponse } = await got(i.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); return content(itemSelector) .toArray() diff --git a/lib/v2/nextapple/realtime.js b/lib/v2/nextapple/realtime.js index 7c5b306a8..408d211da 100644 --- a/lib/v2/nextapple/realtime.js +++ b/lib/v2/nextapple/realtime.js @@ -1,19 +1,19 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; const asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'latest'; + const category = ctx.req.param('category') ?? 'latest'; const currentUrl = `https://tw.nextapple.com/realtime/${category}`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = []; for await (const item of asyncPool(5, $('article.infScroll'), (item) => { const link = $(item).find('.post-title').attr('href'); return ctx.cache.tryGet(link, async () => { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const mainContent = $('#main-content'); const titleElement = mainContent.find('header h1'); const title = titleElement.text(); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { items.push(item); } - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nga/forum.js b/lib/v2/nga/forum.js index 16ed64ee3..9a3b7fcd1 100644 --- a/lib/v2/nga/forum.js +++ b/lib/v2/nga/forum.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; const X_UA = 'NGA_skull/6.0.5(iPhone10,3;iOS 12.0.1)'; @@ -62,10 +62,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `NGA-${forumname}${recommend ? '-精华' : ''}`, link: `https://nga.178.com/thread.php?fid=${fid}`, description: 'NGA是国内专业的游戏玩家社区,魔兽世界,英雄联盟,炉石传说,风暴英雄,暗黑破坏神3(D3)游戏攻略讨论,以及其他热门游戏玩家社区', item: resultItem, - }; + }); }; diff --git a/lib/v2/nga/post.js b/lib/v2/nga/post.js index 1c8fbac05..186d2ada9 100644 --- a/lib/v2/nga/post.js +++ b/lib/v2/nga/post.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 { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { config } from '@/config'; module.exports = async (ctx) => { const getPageUrl = (tid, authorId, page = 1, hash = '') => `https://nga.178.com/read.php?tid=${tid}&page=${page}${authorId ? `&authorid=${authorId}` : ''}&rand=${Math.random() * 1000}#${hash}`; @@ -22,7 +22,7 @@ module.exports = async (ctx) => { }); const htmlString = iconv.decode(response.data, 'gbk'); - return cheerio.load(htmlString); + return load(htmlString); }; const getLastPageId = async (tid, authorId) => { @@ -72,8 +72,8 @@ module.exports = async (ctx) => { return str; }; - const tid = ctx.params.tid; - const authorId = ctx.params.authorId || undefined; + const tid = ctx.req.param('tid'); + const authorId = ctx.req.param('authorId') || undefined; const pageId = await getLastPageId(tid, authorId); const $ = await getPage(tid, authorId, pageId); @@ -103,7 +103,7 @@ module.exports = async (ctx) => { const pubDate = timezone(parseDate(post.find('.postInfo > span').first().text(), 'YYYY-MM-DD HH:mm'), +8); return { - title: cheerio.load(description).text(), + title: load(description).text(), author: poster, link, description, @@ -114,9 +114,9 @@ module.exports = async (ctx) => { const rssTitle = authorName ? `NGA ${authorName} ${title}` : `NGA ${title}`; - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: getPageUrl(tid, authorId, pageId), item: items.get(), - }; + }); }; diff --git a/lib/v2/ngocn2/index.js b/lib/v2/ngocn2/index.js index 74a050ba8..fd87b6ee2 100644 --- a/lib/v2/ngocn2/index.js +++ b/lib/v2/ngocn2/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 ?? 'article'; + const category = ctx.req.param('category') ?? 'article'; const rootUrl = 'https://ngocn2.org'; const currentUrl = `${rootUrl}/${category}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.articleroll__article a') .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('.gatsby-resp-image-link').each(function () { content(this).html(``); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.sectitle__content').text()} - NGOCN`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nhentai/other.js b/lib/v2/nhentai/other.js index f59aa429a..8f489b473 100644 --- a/lib/v2/nhentai/other.js +++ b/lib/v2/nhentai/other.js @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const simples = await getSimple(url); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 5; let items = simples; if (mode === 'detail') { items = await getDetails(ctx.cache, simples, limit); @@ -21,10 +21,10 @@ module.exports = async (ctx) => { items = await getTorrents(ctx.cache, simples, limit); } - ctx.state.data = { + ctx.set('data', { title: `nhentai - ${key} - ${keyword}`, link: url, description: 'hentai', item: items, - }; + }); }; diff --git a/lib/v2/nhentai/search.js b/lib/v2/nhentai/search.js index 7712c2c85..f41412275 100644 --- a/lib/v2/nhentai/search.js +++ b/lib/v2/nhentai/search.js @@ -7,7 +7,7 @@ module.exports = async (ctx) => { const simples = await getSimple(url); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 5; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 5; let items = simples; if (mode === 'detail') { items = await getDetails(ctx.cache, simples, limit); @@ -15,9 +15,9 @@ module.exports = async (ctx) => { items = await getTorrents(ctx.cache, simples, limit); } - ctx.state.data = { + ctx.set('data', { title: `nhentai - search - ${keyword}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/nhentai/util.js b/lib/v2/nhentai/util.js index ddc30b4f0..f7befcaa5 100644 --- a/lib/v2/nhentai/util.js +++ b/lib/v2/nhentai/util.js @@ -1,8 +1,8 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +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 baseUrl = 'https://nhentai.net'; @@ -74,7 +74,7 @@ const gotByIp = (url, ...options) => const getSimple = async (url) => { const { data } = await gotByIp(url); - const $ = cheerio.load(data); + const $ = load(data); return $('.gallery a.cover') .toArray() @@ -120,7 +120,7 @@ const getTorrent = async (simple, cookie) => { const getDetail = async (simple) => { const { link } = simple; const { data } = await gotByIp(link); - const $ = cheerio.load(data); + const $ = load(data); const galleryImgs = $('.gallerythumb img') .toArray() diff --git a/lib/v2/nhk/news-web-easy.js b/lib/v2/nhk/news-web-easy.js index 0bd5a7823..5cc876dc3 100644 --- a/lib/v2/nhk/news-web-easy.js +++ b/lib/v2/nhk/news-web-easy.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) => { @@ -27,23 +27,23 @@ module.exports = async (ctx) => { return acc; }, []); - items = items.sort((a, b) => b.pubDate - a.pubDate).slice(0, ctx.query.limit ? Number(ctx.query.limit) : 30); + items = items.sort((a, b) => b.pubDate - a.pubDate).slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30); items = await Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); item.description += $('.article-body').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: 'NEWS WEB EASY', link: 'https://www3.nhk.or.jp/news/easy/', description: 'NEWS WEB EASYは、小学生・中学生の皆さんや、日本に住んでいる外国人のみなさんに、わかりやすいことば でニュースを伝えるウェブサイトです。', item: items, - }; + }); }; diff --git a/lib/v2/nhk/news.js b/lib/v2/nhk/news.js index 455d7ab6e..9f1672fa2 100644 --- a/lib/v2/nhk/news.js +++ b/lib/v2/nhk/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 baseUrl = 'https://www3.nhk.or.jp'; const apiUrl = 'https://nwapi.nhk.jp'; @@ -33,9 +33,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${Object.values(meta.data.config.navigation.header).find((h) => h.keyname === 'topstories')?.name} | NHK WORLD-JAPAN News`, link: `${baseUrl}/nhkworld/${lang}/news/list/`, item: items, - }; + }); }; diff --git a/lib/v2/niaogebiji/cat.js b/lib/v2/niaogebiji/cat.js index d13cc6b55..b3a82b8f9 100644 --- a/lib/v2/niaogebiji/cat.js +++ b/lib/v2/niaogebiji/cat.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 categoryId = ctx.params.cat; + const categoryId = ctx.req.param('cat'); const link = `https://www.niaogebiji.com/cat/${categoryId}`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const catName = $('h1').text(); const articles = $('div.articleBox.clearfix') @@ -34,7 +34,7 @@ module.exports = async (ctx) => { articles.map((element) => ctx.cache.tryGet(element.link, async () => { const response = await got(element.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); element.pubDate = timezone(parseDate($('.writeTime3').text().trim()), 8); element.description = $('.pc_content').html(); @@ -44,10 +44,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/niaogebiji/index.js b/lib/v2/niaogebiji/index.js index 8cfdf89c2..9391f4f36 100644 --- a/lib/v2/niaogebiji/index.js +++ b/lib/v2/niaogebiji/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 baseUrl = 'https://www.niaogebiji.com'; @@ -24,7 +24,7 @@ module.exports = async (ctx) => { postList.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('.pc_content').html(); @@ -33,9 +33,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '鸟哥笔记', link: baseUrl, item: result, - }; + }); }; diff --git a/lib/v2/niaogebiji/today.js b/lib/v2/niaogebiji/today.js index c0323d56b..85081c629 100644 --- a/lib/v2/niaogebiji/today.js +++ b/lib/v2/niaogebiji/today.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 response = await got({ @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const data = response.data.return_data; - ctx.state.data = { + ctx.set('data', { title: '鸟哥笔记-今日事', link: 'https://www.niaogebiji.com/bulletin', item: data.map((item) => ({ @@ -30,5 +30,5 @@ module.exports = async (ctx) => { category: item.seo_keywords.split(','), author: item.user_info.nickname, })), - }; + }); }; diff --git a/lib/v2/nifd/research.js b/lib/v2/nifd/research.js index 47ba267c4..834215e84 100644 --- a/lib/v2/nifd/research.js +++ b/lib/v2/nifd/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.nifd.cn'; @@ -18,11 +18,11 @@ const titleMap = { }; module.exports = async (ctx) => { - const categoryGuid = ctx.params.categoryGuid ?? '7a6a826d-b525-42aa-b550-4236e524227f'; + const categoryGuid = ctx.req.param('categoryGuid') ?? '7a6a826d-b525-42aa-b550-4236e524227f'; const url = `${rootUrl}/Research?categoryGuid=${categoryGuid}`; const response = await got.get(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.qr-main-item') .map((_, item) => ({ title: $(item).find('h2').text(), @@ -36,7 +36,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.qrd-content').html(); return item; @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `国家金融与发展实验室 - ${titleMap[categoryGuid]}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/nikkei/asia/index.js b/lib/v2/nikkei/asia/index.js index ed5d92887..e60340957 100644 --- a/lib/v2/nikkei/asia/index.js +++ b/lib/v2/nikkei/asia/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 currentUrl = 'https://main-asianreview-nikkei.content.pugpig.com/editionfeed/4519/pugpig_atom_contents.json'; @@ -24,7 +24,7 @@ module.exports = async (ctx) => { item.link = item.shareurl; item.category = item.section; - const fulltextcontent = cheerio.load(fulltext.data); + const fulltextcontent = load(fulltext.data); fulltextcontent('.pp-header-group__headline, .lightbox__control, .o-ads, #AdAsia').remove(); fulltextcontent('img').each((_, img) => { if (img.attribs.full) { @@ -44,10 +44,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Nikkei Asia', link: 'https://asia.nikkei.com', image: 'https://main-asianreview-nikkei.content.pugpig.com/pugpig_assets/admin/pub120x120.jpg', item: items, - }; + }); }; diff --git a/lib/v2/nikkei/cn/index.js b/lib/v2/nikkei/cn/index.js index 30ad120fb..a7b373412 100644 --- a/lib/v2/nikkei/cn/index.js +++ b/lib/v2/nikkei/cn/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 parser = require('@/utils/rss-parser'); module.exports = async (ctx) => { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { language = 'cn'; } - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25; const rootUrl = `https://${language === 'zh' ? 'zh.' : ''}cn.nikkei.com`; const isOfficialRSS = path === '/rss'; @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - $ = cheerio.load(response.data); + $ = load(response.data); items = $('dt a') .toArray() @@ -62,7 +62,7 @@ module.exports = async (ctx) => { url: `${item.link}?print=1`, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const divs = content('#contentDiv div'); divs.first().remove(); @@ -82,10 +82,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: isOfficialRSS ? officialFeed.title : $('title').first().text(), description: isOfficialRSS ? officialFeed.description : '', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nikkei/index.js b/lib/v2/nikkei/index.js index 9b201d3aa..a614bfbaa 100644 --- a/lib/v2/nikkei/index.js +++ b/lib/v2/nikkei/index.js @@ -1,10 +1,10 @@ -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.nikkei.com'; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('a[data-rn-inview-track-value]') .toArray() @@ -28,9 +28,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: '日本経済新聞', link: url, item: list, - }; + }); }; diff --git a/lib/v2/nikkei/news.js b/lib/v2/nikkei/news.js index c820e149f..6cd1a7321 100644 --- a/lib/v2/nikkei/news.js +++ b/lib/v2/nikkei/news.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) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { const response = await got(url); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let categoryName = ''; const listSelector = $('div#CONTENTS_MAIN').children('div.m-miM09').not('.PRa'); @@ -61,7 +61,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); $('.notFloated_n1oadkwi').remove(); @@ -76,12 +76,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '日本経済新聞 - ' + categoryName, description: $('meta[name="description"]').attr('content'), link: url, image: $('meta[property="og:image"]').attr('content'), language: 'ja', item: article_type === 'free' ? items.filter((item) => !item.paywall) : items, - }; + }); }; diff --git a/lib/v2/nintendo/direct.js b/lib/v2/nintendo/direct.js index c3cd685eb..b48e1e547 100644 --- a/lib/v2/nintendo/direct.js +++ b/lib/v2/nintendo/direct.js @@ -1,14 +1,14 @@ -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 response = await got('https://www.nintendo.com/nintendo-direct/archive/'); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); delete nextData.props.pageProps.initialApolloState.ROOT_QUERY; @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }), })); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo Direct(任天堂直面会)', link: 'https://www.nintendo.com/nintendo-direct/archive/', description: '最新的任天堂直面会日程信息', item: result, - }; + }); }; diff --git a/lib/v2/nintendo/eshop-cn.js b/lib/v2/nintendo/eshop-cn.js index 2fa9006da..7af4a1440 100644 --- a/lib/v2/nintendo/eshop-cn.js +++ b/lib/v2/nintendo/eshop-cn.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); const software_url = 'https://www.nintendoswitch.com.cn/software/'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const response = await got(software_url); @@ -35,10 +35,10 @@ module.exports = async (ctx) => { data = await util.ProcessItemChina(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo eShop(国服)新游戏', link: 'https://www.nintendoswitch.com.cn/software', description: 'Nintendo(国服)新上架的游戏', item: data, - }; + }); }; diff --git a/lib/v2/nintendo/eshop-hk.js b/lib/v2/nintendo/eshop-hk.js index b36ff92b4..4842ddd8d 100644 --- a/lib/v2/nintendo/eshop-hk.js +++ b/lib/v2/nintendo/eshop-hk.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 response = await got('https://www.nintendo.com.hk/data/json/switch_software.json'); - const data = response.data.filter(({ link }) => link.startsWith('https://')).slice(0, ctx.query.limit ? Number(ctx.query.limit) : 30); + const data = response.data.filter(({ link }) => link.startsWith('https://')).slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30); // 获取游戏描述 const result = await Promise.all( data.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); let description; if (item.link.startsWith('https://store.nintendo.com.hk/')) { @@ -70,10 +70,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo eShop(港服)新游戏', link: 'https://www.nintendo.com.hk/software/switch/', description: 'Nintendo eShop(港服)新上架的游戏', item: result, - }; + }); }; diff --git a/lib/v2/nintendo/eshop-jp.js b/lib/v2/nintendo/eshop-jp.js index e5e7784e5..e7b814406 100644 --- a/lib/v2/nintendo/eshop-jp.js +++ b/lib/v2/nintendo/eshop-jp.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) => { @@ -8,7 +8,7 @@ module.exports = async (ctx) => { searchParams: { opt_sshow: 1, fq: 'ssitu_s:onsale OR ssitu_s:preorder OR memo_bg:forced', - limit: ctx.query.limit ? Number(ctx.query.limit) : 24, + limit: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 24, page: 1, c: '50310840317994813', opt_osale: 1, @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }); const data = response.data.result.items; - ctx.state.data = { + ctx.set('data', { title: 'Nintendo eShop(日服)新游戏', link: 'https://www.nintendo.co.jp/software/switch/index.html', description: 'Nintendo eShop(日服)新上架的游戏', @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: `https://ec.nintendo.com/JP/ja/titles/${item.id}`, pubDate: parseDate(item.pdate), })), - }; + }); }; diff --git a/lib/v2/nintendo/eshop-us.js b/lib/v2/nintendo/eshop-us.js index bd57ec5bd..84ff89919 100644 --- a/lib/v2/nintendo/eshop-us.js +++ b/lib/v2/nintendo/eshop-us.js @@ -1,5 +1,5 @@ -const { art } = require('@/utils/render'); -const got = require('@/utils/got'); +import { art } from '@/utils/render'; +import got from '@/utils/got'; const path = require('path'); module.exports = async (ctx) => { @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }); const data = response.data.hits; - ctx.state.data = { + ctx.set('data', { title: `Nintendo eShop(美服)新游戏`, link: `https://www.nintendo.com/store/games/`, description: `Nintendo eShop(美服)新上架的游戏`, @@ -27,6 +27,6 @@ module.exports = async (ctx) => { description: art(path.join(__dirname, 'templates/eshop_us.art'), item), link: `https://www.nintendo.com${item.url}`, })), - }; + }); ctx.state.json = response.data; }; diff --git a/lib/v2/nintendo/news-china.js b/lib/v2/nintendo/news-china.js index 398152a42..510ef16a4 100644 --- a/lib/v2/nintendo/news-china.js +++ b/lib/v2/nintendo/news-china.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); const news_url = 'https://www.nintendoswitch.com.cn'; @@ -26,10 +26,10 @@ module.exports = async (ctx) => { data = await util.ProcessNewsChina(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo(中国大陆)主页资讯', link: 'https://www.nintendoswitch.com.cn', description: 'Nintendo 中国大陆官网刊登的资讯', item: data, - }; + }); }; diff --git a/lib/v2/nintendo/news.js b/lib/v2/nintendo/news.js index b37415282..b65287de6 100644 --- a/lib/v2/nintendo/news.js +++ b/lib/v2/nintendo/news.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const util = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const response = await got('https://www.nintendo.com.hk/data/json/topics.json'); - const data = response.data.filter((val) => val.only_for !== 'tw' && val.url.startsWith('/topics/article/')).slice(0, ctx.query.limit ? Number(ctx.query.limit) : 30); + const data = response.data.filter((val) => val.only_for !== 'tw' && val.url.startsWith('/topics/article/')).slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30); // 获取新闻正文 const result = await util.ProcessNews(data, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo(香港)主页资讯', link: 'https://www.nintendo.com.hk/topics/', description: 'Nintendo 香港有限公司官网刊登的资讯', @@ -19,5 +19,5 @@ module.exports = async (ctx) => { link: `https://www.nintendo.com.hk${item.url}`, pubDate: parseDate(item.release_date, 'YYYY.M.D'), })), - }; + }); }; diff --git a/lib/v2/nintendo/system-update.js b/lib/v2/nintendo/system-update.js index 3e17fd8d7..a860e8b70 100644 --- a/lib/v2/nintendo/system-update.js +++ b/lib/v2/nintendo/system-update.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const url = 'https://www.nintendo.co.jp/support/switch/system_update/index.html'; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.c-heading-lv3').toArray().slice(1, -2); - ctx.state.data = { + ctx.set('data', { title: 'Nintendo Switch 本体更新情報', link: url, item: list.map((update) => { @@ -34,5 +34,5 @@ module.exports = async (ctx) => { pubDate: new Date(Number.parseInt(matched_date[1]), Number.parseInt(matched_date[2]) - 1, Number.parseInt(matched_date[3])), }; }), - }; + }); }; diff --git a/lib/v2/nintendo/utils.js b/lib/v2/nintendo/utils.js index 6877f3e66..7fd436e40 100644 --- a/lib/v2/nintendo/utils.js +++ b/lib/v2/nintendo/utils.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { JSDOM } = require('jsdom'); -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'); const dayjs = require('dayjs'); const localizedFormat = require('dayjs/plugin/localizedFormat'); @@ -27,12 +27,12 @@ function generateImageLink(link) { return `
`; } -async function load(link) { +async function loadContent(link) { const response = await got(link); const data = response.data; - const $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML + const $ = load(data); // 使用 cheerio 加载返回的 HTML const description = $('.description').html(); return { @@ -45,7 +45,7 @@ async function loadNews(link) { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let description = $('.detail-body-container').html(); const date = $('.topics-articleHead__date').text(); description = description.replaceAll('src="/topics/', 'src="https://www.nintendo.com.hk/topics/'); @@ -58,7 +58,7 @@ async function loadNews(link) { const ProcessItem = (list, caches) => Promise.all( list.map(async (item) => { - const other = await caches.tryGet(item.link, () => load(item.link)); + const other = await caches.tryGet(item.link, () => loadContent(item.link)); return { ...item, ...other }; }) ); diff --git a/lib/v2/nippon/index.js b/lib/v2/nippon/index.js index 1f154c791..a90bae6ab 100644 --- a/lib/v2/nippon/index.js +++ b/lib/v2/nippon/index.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 category = ctx.params.category ?? 'Politics'; + const category = ctx.req.param('category') ?? 'Politics'; const path = category === 'Science,Technology' ? 'condition4' : 'category_code'; const res = await got.get(`https://www.nippon.com/api/search/cn/${path}/20/1/${category}?t=${Date.now()}`); @@ -16,16 +16,16 @@ module.exports = async (ctx) => { list.slice(0, 10).map((item) => ctx.cache.tryGet(item.link, async () => { const res = await got.get(item.link); - const $ = cheerio.load(res.data); + const $ = load(res.data); item.description = $('.editArea').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: `走进日本 - ${category}`, link: 'https://www.nippon.com/cn/economy/', item, - }; + }); }; diff --git a/lib/v2/njglyy/utils/index.js b/lib/v2/njglyy/utils/index.js index afa1b215a..f875d0e43 100644 --- a/lib/v2/njglyy/utils/index.js +++ b/lib/v2/njglyy/utils/index.js @@ -1,11 +1,11 @@ -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'; async function getNoticeList(ctx, url, host, listSelector, itemSelector, titleSelector, contentSelector) { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(listSelector) .toArray() @@ -25,7 +25,7 @@ async function getNoticeList(ctx, url, host, listSelector, itemSelector, titleSe item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $(contentSelector.title).text(); item.description = $(contentSelector.content) .html() diff --git a/lib/v2/njglyy/ygbjypx.js b/lib/v2/njglyy/ygbjypx.js index 7980635ff..d277a97ed 100644 --- a/lib/v2/njglyy/ygbjypx.js +++ b/lib/v2/njglyy/ygbjypx.js @@ -10,9 +10,9 @@ module.exports = async (ctx) => { date: 'span:contains("发布时间")', }); - ctx.state.data = { + ctx.set('data', { title: '南京鼓楼医院 -- 员工版教育培训', link: url, item: out, - }; + }); }; diff --git a/lib/v2/njit/jwc.js b/lib/v2/njit/jwc.js index 65c5b1428..8f4673127 100644 --- a/lib/v2/njit/jwc.js +++ b/lib/v2/njit/jwc.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://jwc.njit.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'jx'; + const type = ctx.req.param('type') ?? 'jx'; const link = host + '/index/' + type + '.htm'; const response = await got({ method: 'get', @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.body); + const $ = load(response.body); const urlList = $('body') .find('ul li span a') @@ -52,7 +52,7 @@ module.exports = async (ctx) => { }; return single; } - const $ = cheerio.load(response.body); + const $ = load(response.body); const single = { title: $('title').text(), link: itemUrl, @@ -98,9 +98,9 @@ module.exports = async (ctx) => { info = '教学'; break; } - ctx.state.data = { + ctx.set('data', { title: '南京工程学院教务处 -- ' + info, link, item: out, - }; + }); }; diff --git a/lib/v2/njit/tzgg.js b/lib/v2/njit/tzgg.js index 5b26d5c29..509732cd2 100644 --- a/lib/v2/njit/tzgg.js +++ b/lib/v2/njit/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'; const url = 'https://www.njit.edu.cn/index/tzgg.htm'; const host = 'https://www.njit.edu.cn'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.body); + const $ = load(response.body); const urlList = $('body') .find('span.text a') @@ -50,7 +50,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.body); + const $ = load(response.body); const single = { title: $('title').text(), link: itemUrl, @@ -66,9 +66,9 @@ module.exports = async (ctx) => { } }) ); - ctx.state.data = { + ctx.set('data', { title: '南京工程学院 -- 通知公告', url, item: out, - }; + }); }; diff --git a/lib/v2/njnu/ceai/ceai.js b/lib/v2/njnu/ceai/ceai.js index 6390a55ce..ae303cf28 100644 --- a/lib/v2/njnu/ceai/ceai.js +++ b/lib/v2/njnu/ceai/ceai.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const util = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let title, path; switch (type) { case 'xygg': @@ -29,16 +29,16 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('span a').get(); const result = await util.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '南京师范大学计电人院 - ' + title, link: 'http://ceai.njnu.edu.cn/', description: '南京师范大学计电人院', item: result, - }; + }); }; diff --git a/lib/v2/njnu/ceai/utils.js b/lib/v2/njnu/ceai/utils.js index 1a9f2dd73..756543f7b 100644 --- a/lib/v2/njnu/ceai/utils.js +++ b/lib/v2/njnu/ceai/utils.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'; // 专门定义一个function用于加载文章内容 -async function load(link) { +async function loadContent(link) { // 异步请求文章 const response = await got.get(link, { https: { @@ -12,7 +12,7 @@ async function load(link) { }, }); // 加载文章内容 - const $ = cheerio.load(response.data); + const $ = load(response.data); const dateStr = $('#xw_xinxi span:nth-child(1)').text(); // 解析日期 const pubDate = timezone(parseDate(dateStr, 'YYYY-MM-DD', 'zh-cn'), +8); @@ -27,7 +27,7 @@ const ProcessFeed = (list, caches) => Promise.all( // 遍历每一篇文章 list.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const $title = $('a'); // 还原相对链接为绝对链接 @@ -43,7 +43,7 @@ const ProcessFeed = (list, caches) => // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => loadContent(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; diff --git a/lib/v2/njnu/jwc/jwc.js b/lib/v2/njnu/jwc/jwc.js index ae55a7d9c..a76df8436 100644 --- a/lib/v2/njnu/jwc/jwc.js +++ b/lib/v2/njnu/jwc/jwc.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const util = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let title, path; switch (type) { case 'jstz': @@ -28,16 +28,16 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list_txt a').get(); const result = await util.ProcessFeed(list, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '南京师范大学教务处 - ' + title, link: 'http://jwc.njnu.edu.cn/', description: '南京师范大学教务处', item: result, - }; + }); }; diff --git a/lib/v2/njnu/jwc/utils.js b/lib/v2/njnu/jwc/utils.js index a29366436..579c7d036 100644 --- a/lib/v2/njnu/jwc/utils.js +++ b/lib/v2/njnu/jwc/utils.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'; // 专门定义一个function用于加载文章内容 -async function load(link) { +async function loadContent(link) { // 异步请求文章 const response = await got.get(link, { https: { @@ -12,7 +12,7 @@ async function load(link) { }, }); // 加载文章内容 - const $ = cheerio.load(response.data); + const $ = load(response.data); const dateStr = $('span+ span').text(); // 解析日期 const pubDate = timezone(parseDate(dateStr, 'YYYY-MM-DD', 'zh-cn'), +8); @@ -30,7 +30,7 @@ const ProcessFeed = (list, caches) => { return Promise.all( // 遍历每一篇文章 list.map(async (item) => { - const $ = cheerio.load(item); + const $ = load(item); const $title = $('a'); // 还原相对链接为绝对链接 @@ -46,7 +46,7 @@ const ProcessFeed = (list, caches) => { // 使用tryGet方法从缓存获取内容。 // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); + const other = await caches.tryGet(itemUrl, () => loadContent(itemUrl)); // 合并解析后的结果集作为该篇文章最终的输出结果 return { ...single, ...other }; diff --git a/lib/v2/nju/admission.js b/lib/v2/nju/admission.js index 4866ba815..c6fa09e4c 100644 --- a/lib/v2/nju/admission.js +++ b/lib/v2/nju/admission.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 category_dict = { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { const response = await got(`https://admission.nju.edu.cn/tzgg`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let script = $('ul').find('script'); script = script['1'].children[0].data; @@ -31,9 +31,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '本科迎新-通知公告', link: 'https://admission.nju.edu.cn/tzgg', item: items[0], - }; + }); }; diff --git a/lib/v2/nju/dafls.js b/lib/v2/nju/dafls.js index edfda534a..86c4d1c4e 100644 --- a/lib/v2/nju/dafls.js +++ b/lib/v2/nju/dafls.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 category_dict = { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const response = await got(`https://dafls.nju.edu.cn/13167/list.htm`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#article97'); // only read first page @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '大外部-通知公告', link: 'https://dafls.nju.edu.cn/13167/list.htm', item: [...items[0]], - }; + }); }; diff --git a/lib/v2/nju/exchangesys.js b/lib/v2/nju/exchangesys.js index a9ec4bccb..aad47c04a 100644 --- a/lib/v2/nju/exchangesys.js +++ b/lib/v2/nju/exchangesys.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const dayjs = require('dayjs'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const type_dict = { news: ['http://elite.nju.edu.cn/exchangesystem/index/moreList', 'http://elite.nju.edu.cn/exchangesystem/index/more?type=xw', '新闻通知'], proj: ['http://elite.nju.edu.cn/exchangesystem/index/moreXmList', 'http://elite.nju.edu.cn/exchangesystem/index/more?type=xm', '交换生项目'], @@ -16,7 +16,7 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `本科生交换生管理系统-${type_dict[type][2]}`, link: type_dict[type][1], item: @@ -42,5 +42,5 @@ module.exports = async (ctx) => { } return null; }), - }; + }); }; diff --git a/lib/v2/nju/gra.js b/lib/v2/nju/gra.js index fc09613eb..63ac6195c 100644 --- a/lib/v2/nju/gra.js +++ b/lib/v2/nju/gra.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 response = await got({ @@ -11,10 +11,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('li.news'); - ctx.state.data = { + ctx.set('data', { title: '研究生院-动态通知', link: 'https://grawww.nju.edu.cn/905/list.htm', item: list @@ -35,5 +35,5 @@ module.exports = async (ctx) => { }) .get() .filter(Boolean), - }; + }); }; diff --git a/lib/v2/nju/hosptial.js b/lib/v2/nju/hosptial.js index 2d7b9bb41..55ee68085 100644 --- a/lib/v2/nju/hosptial.js +++ b/lib/v2/nju/hosptial.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 category_dict = { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { const response = await got(`https://hospital.nju.edu.cn/ggtz/index.html`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let script = $('div .wrapper').find('script'); script = script['1'].children[0].data; @@ -31,9 +31,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '校医院-公告通知', link: 'https://hospital.nju.edu.cn/ggtz/index.html', item: items[0], - }; + }); }; diff --git a/lib/v2/nju/hqjt.js b/lib/v2/nju/hqjt.js index ea07e66bf..a2d717a70 100644 --- a/lib/v2/nju/hqjt.js +++ b/lib/v2/nju/hqjt.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 category_dict = { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const response = await got(`https://webplus.nju.edu.cn/_s25/zbcg/list.psp`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('li.news'); // only read first page @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '后勤集团-招标采购', link: 'https://webplus.nju.edu.cn/_s25/zbcg/list.psp', item: [...items[0]], - }; + }); }; diff --git a/lib/v2/nju/itsc.js b/lib/v2/nju/itsc.js index 7e3f45a78..60d3932e9 100644 --- a/lib/v2/nju/itsc.js +++ b/lib/v2/nju/itsc.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 category_dict = { @@ -13,7 +13,7 @@ module.exports = async (ctx) => { const response = await got(`https://itsc.nju.edu.cn/tzgg/list.htm`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const tmp = $('.list2')[0].children; const infos = []; for (const element of tmp) { @@ -36,9 +36,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: 'ITSC-公告通知', link: 'https://itsc.nju.edu.cn/tzgg/list.htm', item: items[0], - }; + }); }; diff --git a/lib/v2/nju/jjc.js b/lib/v2/nju/jjc.js index c9fffec4a..d4c6b5667 100644 --- a/lib/v2/nju/jjc.js +++ b/lib/v2/nju/jjc.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 category_dict = { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const response = await got(`https://jjc.nju.edu.cn/${c}/list.htm`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#wp_news_w6').children().children().children(); // only read first page @@ -32,9 +32,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `南京大学基建处`, link: 'https://jjc.nju.edu.cn/main.htm', item: [...items[0], ...items[1], ...items[2]], - }; + }); }; diff --git a/lib/v2/nju/jw.js b/lib/v2/nju/jw.js index bf41f5ab1..280da4ea7 100644 --- a/lib/v2/nju/jw.js +++ b/lib/v2/nju/jw.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 type = ctx.params.type; + const type = ctx.req.param('type'); const type_dict = { ggtz: [ 26263, // columnID @@ -37,7 +37,7 @@ module.exports = async (ctx) => { }, }); - ctx.state.data = { + ctx.set('data', { title: `本科生院-${type_dict[type][1]}`, link: type_dict[type][4], item: @@ -55,5 +55,5 @@ module.exports = async (ctx) => { } return ret; }), - }; + }); }; diff --git a/lib/v2/nju/rczp.js b/lib/v2/nju/rczp.js index 69f47f22c..31431d8e9 100644 --- a/lib/v2/nju/rczp.js +++ b/lib/v2/nju/rczp.js @@ -1,9 +1,9 @@ -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'; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const title_dict = { xxfb: { title: '信息发布', channelid: '9531,9532,9533,9534,9535,9419' }, jylgw: { title: '教研类岗位', channelid: '9420,9421,9422,9423' }, @@ -40,9 +40,9 @@ module.exports = async (ctx) => { author: item.username, })); - ctx.state.data = { + ctx.set('data', { title: `人才招聘-${title_dict[type].title}`, link, item: items, - }; + }); }; diff --git a/lib/v2/nju/scit.js b/lib/v2/nju/scit.js index bc4f67dc4..0594892d8 100644 --- a/lib/v2/nju/scit.js +++ b/lib/v2/nju/scit.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 type = ctx.params.type; + const type = ctx.req.param('type'); const type_dict = { tzgg: ['https://scit.nju.edu.cn/10916/list.htm', '通知公告'], kydt: ['https://scit.nju.edu.cn/11003/list.htm', '科研动态'], @@ -16,10 +16,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('li.list_item'); - ctx.state.data = { + ctx.set('data', { title: `科学技术处-${type_dict[type][1]}`, link: type_dict[type][0], item: list @@ -32,5 +32,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/nju/zbb.js b/lib/v2/nju/zbb.js index baa4472a2..31f1a93ef 100644 --- a/lib/v2/nju/zbb.js +++ b/lib/v2/nju/zbb.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 type = ctx.params.type; + const type = ctx.req.param('type'); if (type === 'zfcgyxgk') { const url = `https://zbb.nju.edu.cn/zfcgyxgk/index.chtml`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('dd[cid]'); ctx.state.data = { @@ -52,7 +52,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('dd[cid]'); return list diff --git a/lib/v2/nju/zcc.js b/lib/v2/nju/zcc.js index dfe31cf0b..e3c95b6d9 100644 --- a/lib/v2/nju/zcc.js +++ b/lib/v2/nju/zcc.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 category_dict = { ggtz: '公告通知', @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const response = await got(`https://zcc.nju.edu.cn/sy/tzzhxx/index.html`); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); let script = $('ul.clearfix').find('script'); script = script['1'].children[0].data; @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '资产管理处-公告通知', link: 'https://zcc.nju.edu.cn/sy/tzzhxx/index.html', item: items[0], - }; + }); }; diff --git a/lib/v2/njucm/grabs.js b/lib/v2/njucm/grabs.js index e454a07b7..b1a728ef2 100644 --- a/lib/v2/njucm/grabs.js +++ b/lib/v2/njucm/grabs.js @@ -10,9 +10,9 @@ module.exports = async (ctx) => { date: '.Article_PublishDate', }); - ctx.state.data = { + ctx.set('data', { title: '南京中医药大学 -- 博士招生', link: url, item: out, - }; + }); }; diff --git a/lib/v2/njucm/utils/index.js b/lib/v2/njucm/utils/index.js index ef1327034..641b1fb12 100644 --- a/lib/v2/njucm/utils/index.js +++ b/lib/v2/njucm/utils/index.js @@ -1,11 +1,11 @@ -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'; async function getNoticeList(ctx, url, host, listSelector, titleSelector, contentSelector) { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(listSelector) .toArray() @@ -25,7 +25,7 @@ async function getNoticeList(ctx, url, host, listSelector, titleSelector, conten item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $(contentSelector.title).text(); item.description = $(contentSelector.content) .html() diff --git a/lib/v2/njupt/jwc.js b/lib/v2/njupt/jwc.js index 597a1330a..b0a1cf47c 100644 --- a/lib/v2/njupt/jwc.js +++ b/lib/v2/njupt/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 host = 'https://jwc.njupt.edu.cn'; @@ -10,7 +10,7 @@ const map = { }; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'notice'; + const type = ctx.req.param('type') ?? 'notice'; const link = host + map[type] + '/list.htm'; const response = await got({ method: 'get', @@ -19,7 +19,7 @@ module.exports = async (ctx) => { Referer: host, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const urlList = $('.content') .find('a') @@ -54,7 +54,7 @@ module.exports = async (ctx) => { }; return single; } - const $ = cheerio.load(response.data); + const $ = load(response.data); const single = { title: $('.Article_Title').text(), link: itemUrl, @@ -82,9 +82,9 @@ module.exports = async (ctx) => { if (type === 'news') { info = '教务快讯'; } - ctx.state.data = { + ctx.set('data', { title: '南京邮电大学 -- ' + info, link, item: out, - }; + }); }; diff --git a/lib/v2/njust/cwc.js b/lib/v2/njust/cwc.js index d945908e1..6e50f5879 100644 --- a/lib/v2/njust/cwc.js +++ b/lib/v2/njust/cwc.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const map = new Map([ @@ -11,7 +11,7 @@ const map = new Map([ const host = 'https://cwc.njust.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'); @@ -20,10 +20,10 @@ module.exports = async (ctx) => { const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl, true); - const $ = cheerio.load(html); + const $ = load(html); const list = $('ul.news_list').find('li'); - ctx.state.data = { + ctx.set('data', { title: info.title, link: siteUrl, item: @@ -35,5 +35,5 @@ module.exports = async (ctx) => { link: $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/njust/dgxg.js b/lib/v2/njust/dgxg.js index f988ee7e3..9a618855a 100644 --- a/lib/v2/njust/dgxg.js +++ b/lib/v2/njust/dgxg.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const map = new Map([ @@ -12,7 +12,7 @@ const map = new Map([ const host = 'https://dgxg.njust.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'gstz'; + const type = ctx.req.param('type') ?? 'gstz'; const info = map.get(type); if (!info) { throw new Error('invalid type'); @@ -21,10 +21,10 @@ module.exports = async (ctx) => { const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl, true); - const $ = cheerio.load(html); + const $ = load(html); const list = $('ul.wp_article_list').find('li'); - ctx.state.data = { + ctx.set('data', { title: info.title, link: siteUrl, item: @@ -36,5 +36,5 @@ module.exports = async (ctx) => { link: $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/njust/eo.js b/lib/v2/njust/eo.js index 6ef358a7d..fde04df4f 100644 --- a/lib/v2/njust/eo.js +++ b/lib/v2/njust/eo.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const map = new Map([ @@ -17,8 +17,8 @@ const map = new Map([ const host = 'https://dgxg.njust.edu.cn'; module.exports = async (ctx) => { - const grade = ctx.params.grade ?? '17'; - const type = ctx.params.type ?? 'tz'; + const grade = ctx.req.param('grade') ?? '17'; + const type = ctx.req.param('type') ?? 'tz'; let info = map.get(grade + type); if (!info) { // throw new Error('invalid type'); @@ -28,13 +28,13 @@ module.exports = async (ctx) => { const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl, true); - const $ = cheerio.load(html); + const $ = load(html); if (!info.title) { info.title = $('title').text(); } const list = $('li.list_item'); - ctx.state.data = { + ctx.set('data', { title: info.title, link: siteUrl, item: @@ -46,5 +46,5 @@ module.exports = async (ctx) => { link: $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/njust/eoe.js b/lib/v2/njust/eoe.js index eebcb16b2..8495d1e3a 100644 --- a/lib/v2/njust/eoe.js +++ b/lib/v2/njust/eoe.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const map = new Map([ @@ -11,7 +11,7 @@ const map = new Map([ const host = 'https://eoe.njust.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'); @@ -20,10 +20,10 @@ module.exports = async (ctx) => { const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl, true); - const $ = cheerio.load(html); + const $ = load(html); const list = $('ul.news_ul').find('li'); - ctx.state.data = { + ctx.set('data', { title: info.title, link: siteUrl, item: @@ -35,5 +35,5 @@ module.exports = async (ctx) => { link: $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/njust/gs.js b/lib/v2/njust/gs.js index 47c3bf085..4e3d54e35 100644 --- a/lib/v2/njust/gs.js +++ b/lib/v2/njust/gs.js @@ -1,17 +1,17 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const host = 'https://gs.njust.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'sytzgg_4568'; + const type = ctx.req.param('type') ?? 'sytzgg_4568'; const id = '/' + type; const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl); - const $ = cheerio.load(html); + const $ = load(html); const title = '南京理工大学研究生院 -- ' + $('title').text(); const list = $('ul.news_ul').find('li'); @@ -21,7 +21,7 @@ module.exports = async (ctx) => { let desc = ''; if (url.startsWith('/')) { const data = await getContent(host + url); - desc = cheerio.load(data)('.wp_articlecontent').html(); + desc = load(data)('.wp_articlecontent').html(); } return { @@ -33,9 +33,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title, link: siteUrl, item: items, - }; + }); }; diff --git a/lib/v2/njust/jwc.js b/lib/v2/njust/jwc.js index 6053e115a..213bf81c5 100644 --- a/lib/v2/njust/jwc.js +++ b/lib/v2/njust/jwc.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { getContent } = require('./utils'); const map = new Map([ @@ -13,7 +13,7 @@ const map = new Map([ const host = 'https://jwc.njust.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'xstz'; + const type = ctx.req.param('type') ?? 'xstz'; const info = map.get(type); if (!info) { throw new Error('invalid type'); @@ -22,10 +22,10 @@ module.exports = async (ctx) => { const siteUrl = host + id + '/list.htm'; const html = await getContent(siteUrl, true); - const $ = cheerio.load(html); + const $ = load(html); const list = $('div#wp_news_w3').find('tr'); - ctx.state.data = { + ctx.set('data', { title: info.title, link: siteUrl, item: @@ -37,5 +37,5 @@ module.exports = async (ctx) => { link: $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/njust/utils.js b/lib/v2/njust/utils.js index a5af29ea0..957ac2a79 100644 --- a/lib/v2/njust/utils.js +++ b/lib/v2/njust/utils.js @@ -1,6 +1,9 @@ +import got from '@/utils/got'; +import puppeteer from '@/utils/puppeteer'; + async function getContent(url, pptr = false) { if (pptr) { - const browser = await require('@/utils/puppeteer')({ stealth: true }); + const browser = puppeteer({ stealth: true }); try { const page = await browser.newPage(); // 更改 window.navigator.webdriver 值以避开反爬 @@ -23,7 +26,6 @@ async function getContent(url, pptr = false) { browser.close(); } } else { - const got = require('@/utils/got'); const response = await got(url); const data = response.data; return data; diff --git a/lib/v2/njxzc/home.js b/lib/v2/njxzc/home.js index 28df465d8..049d00b08 100644 --- a/lib/v2/njxzc/home.js +++ b/lib/v2/njxzc/home.js @@ -18,9 +18,9 @@ module.exports = async (ctx) => { '.news_list .news' ); - ctx.state.data = { + ctx.set('data', { title: '南京晓庄学院 -- 通知公告', link: url, item: out, - }; + }); }; diff --git a/lib/v2/njxzc/lib.js b/lib/v2/njxzc/lib.js index bdf482cd5..583b28389 100644 --- a/lib/v2/njxzc/lib.js +++ b/lib/v2/njxzc/lib.js @@ -18,9 +18,9 @@ module.exports = async (ctx) => { '.news' ); - ctx.state.data = { + ctx.set('data', { title: '南京晓庄学院 -- 图书馆通知公告', link: url, item: out, - }; + }); }; diff --git a/lib/v2/njxzc/utils/index.js b/lib/v2/njxzc/utils/index.js index 7a0764ec9..3984c1034 100644 --- a/lib/v2/njxzc/utils/index.js +++ b/lib/v2/njxzc/utils/index.js @@ -1,11 +1,11 @@ -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'; async function getNoticeList(ctx, url, host, titleSelector, dateSelector, contentSelector, listSelector) { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(listSelector) .toArray() @@ -26,7 +26,7 @@ async function getNoticeList(ctx, url, host, titleSelector, dateSelector, conten item.link = response.redirectUrls[0]; item.description = '该通知无法直接预览,请点击原文链接↑查看'; } else { - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $(contentSelector.title).text(); item.description = $(contentSelector.content) .html() diff --git a/lib/v2/nltimes/news.js b/lib/v2/nltimes/news.js index 30eb08d97..8aed1e82c 100644 --- a/lib/v2/nltimes/news.js +++ b/lib/v2/nltimes/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 map = new Map([ ['top-stories', { title: 'NL Times -- Top Stories', suffix: '/top-stories' }], @@ -17,7 +17,7 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'top-stories'; + const category = ctx.req.param('category') ?? 'top-stories'; const suffix = map.get(category).suffix; const rootUrl = 'https://www.nltimes.nl'; @@ -28,7 +28,7 @@ module.exports = async (ctx) => { url: apiUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news-card') .slice(0, 10) @@ -49,7 +49,7 @@ module.exports = async (ctx) => { .get(); const ProcessFeed = (data) => { - const $ = cheerio.load(data); + const $ = load(data); return $('.news-article--body').html(); }; @@ -79,11 +79,11 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: map.get(category).title, language: 'en', link: apiUrl, description: map.get(category).title, item: items, - }; + }); }; diff --git a/lib/v2/nmtv/column.js b/lib/v2/nmtv/column.js index 43d30c8c7..0beb9a150 100644 --- a/lib/v2/nmtv/column.js +++ b/lib/v2/nmtv/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'); module.exports = async (ctx) => { - const id = ctx.params.id ?? '877'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100; + const id = ctx.req.param('id') ?? '877'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; const hostUrl = 'https://vod.m2oplus.nmtv.cn'; const apiRootUrl = 'https://mapi.m2oplus.nmtv.cn'; @@ -43,11 +43,11 @@ module.exports = async (ctx) => { const author = data[0].column_name; const imageUrl = data[0].column_info.indexpic; - ctx.state.data = { + ctx.set('data', { title: `内蒙古广播电视台 - ${author}`, link: items[0].link.split(/\/\d{4}-\d{2}-\d{2}\//)[0], item: items, image: `${imageUrl.host}${imageUrl.filepath}${imageUrl.filename}`, itunes_author: author, - }; + }); }; diff --git a/lib/v2/nodejs/blog.js b/lib/v2/nodejs/blog.js index bc63af5c2..c557d2bd6 100644 --- a/lib/v2/nodejs/blog.js +++ b/lib/v2/nodejs/blog.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://nodejs.org'; const currentUrl = `${rootUrl}/${language}/blog`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('.summary').remove(); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.pubDate = parseDate(content('time').attr('datetime')); item.author = content('.blogpost-meta') @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'News - Node.js', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nogizaka46/blog.js b/lib/v2/nogizaka46/blog.js index d02b8ee99..21022789c 100644 --- a/lib/v2/nogizaka46/blog.js +++ b/lib/v2/nogizaka46/blog.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 rootUrl = 'https://www.nogizaka46.com'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'all'; + const id = ctx.req.param('id') ?? 'all'; const params = id === 'all' ? '' : `?ct=${id}`; const currentUrl = `${rootUrl}/s/n46/api/list/blog${params}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const list = JSON.parse(response.data.slice(4).slice(0, -2)).data; - ctx.state.data = { + ctx.set('data', { allowEmpty: true, title: '乃木坂46 公式ブログ', link: 'https://www.nogizaka46.com/s/n46/diary/MEMBER', @@ -29,5 +29,5 @@ module.exports = async (ctx) => { description: item.text, guid: rootUrl + new URL(item.link).pathname, })), - }; + }); }; diff --git a/lib/v2/nogizaka46/news.js b/lib/v2/nogizaka46/news.js index 15a5afec7..b68d96e03 100644 --- a/lib/v2/nogizaka46/news.js +++ b/lib/v2/nogizaka46/news.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 rootUrl = 'https://www.nogizaka46.com'; module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25; const response = await got({ method: 'get', @@ -24,10 +24,10 @@ module.exports = async (ctx) => { guid: rootUrl + new URL(item.link_url).pathname, })); - ctx.state.data = { + ctx.set('data', { allowEmpty: true, title: '乃木坂46官网 NEWS', link: 'http://www.nogizaka46.com/news/', item: items, - }; + }); }; diff --git a/lib/v2/notateslaapp/update.js b/lib/v2/notateslaapp/update.js index 9ba833855..e51e0daff 100644 --- a/lib/v2/notateslaapp/update.js +++ b/lib/v2/notateslaapp/update.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({ @@ -12,10 +12,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('article[id]'); - ctx.state.data = { + ctx.set('data', { title: '特斯拉系统更新', link: 'https://www.notateslaapp.com/software-updates/history/', description: '特斯拉系统更新 - 最新发布', @@ -32,5 +32,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/notefolio/search.js b/lib/v2/notefolio/search.js index f204576d7..25ac07eb2 100644 --- a/lib/v2/notefolio/search.js +++ b/lib/v2/notefolio/search.js @@ -1,9 +1,9 @@ // 导入所需模组 -const got = require('@/utils/got'); // 自订的 got -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; // 自订的 got +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; // 分类 const categoryMap = [ @@ -133,12 +133,12 @@ module.exports = async (ctx) => { }; }) || []; - ctx.state.data = { + ctx.set('data', { // 源标题 title: `${category}/${order}/${time}/${query} search`, // 源链接 // link: '', // 源文章 item: items, - }; + }); }; diff --git a/lib/v2/notion/database.js b/lib/v2/notion/database.js index e96035e7e..1218036ed 100644 --- a/lib/v2/notion/database.js +++ b/lib/v2/notion/database.js @@ -1,10 +1,10 @@ const { Client, isNotionClientError, APIErrorCode } = require('@notionhq/client'); const logger = require('@/utils/logger'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; const { NotionToMarkdown } = require('notion-to-md'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const md = require('markdown-it')({ html: true, linkify: true, @@ -15,7 +15,7 @@ module.exports = async (ctx) => { throw new Error('Notion RSS is disabled due to the lack of NOTION_TOKEN(relevant config)'); } - const databaseId = ctx.params.databaseId; + const databaseId = ctx.req.param('databaseId'); const notion_api_key = config.notion.key; const notion = new Client({ @@ -31,12 +31,12 @@ module.exports = async (ctx) => { const image = database.cover?.external.url ?? database.icon?.emoji; // List pages under the database - const databaseQuery = parseCustomQuery(ctx.query.query); + const databaseQuery = parseCustomQuery(ctx.req.query('query')); const { results } = await notion.databases.query({ database_id: databaseId, ...databaseQuery, }); - const customProperties = parseCustomQuery(ctx.query.properties) ?? {}; + const customProperties = parseCustomQuery(ctx.req.query('properties')) ?? {}; const properties = { author: customProperties.author ?? 'Author', link: customProperties.link ?? 'URL', @@ -74,7 +74,7 @@ module.exports = async (ctx) => { method: 'get', url: articleLink, }); - const $ = cheerio.load(response.body); + const $ = load(response.body); const articleAuthor = $('meta[name="author"]').attr('content'); const articlePubTime = $('meta[name="publish_date"], meta[name="date"]').attr('content'); return { @@ -118,9 +118,9 @@ module.exports = async (ctx) => { if (isNotionClientError(error)) { if (error.statusCode === APIErrorCode.ObjectNotFound) { - ctx.throw(404, 'The database is not exist'); + throw new Error('The database is not exist'); } else if (error.statusCode === APIErrorCode.Unauthorized) { - ctx.throw(401, 'Please check the config of NOTION_TOKEN'); + throw new Error('Please check the config of NOTION_TOKEN'); } else { ctx.throw(error.statusCode, 'Notion API Error'); } diff --git a/lib/v2/now/news.js b/lib/v2/now/news.js index a41e11676..4b189ee99 100644 --- a/lib/v2/now/news.js +++ b/lib/v2/now/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 categories = { tracker: 123, @@ -9,8 +9,8 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category || ''; - const id = ctx.params.id || ''; + const category = ctx.req.param('category') || ''; + const id = ctx.req.param('id') || ''; const rootUrl = 'https://news.now.com'; @@ -21,7 +21,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(`${category === '' ? '.homeFeaturedNews ' : '.newsCategoryColLeft '}.newsTitle`) .map((_, item) => { @@ -41,7 +41,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const images = detailResponse.data.match(/"imageUrl":"(.*?)","image2Url":/); @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: String(Object.hasOwn(categories, category) ? $('title').text() : ($('.smallSpace.active').text() || '首頁') + ' | Now 新聞'), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nowcoder/discuss.js b/lib/v2/nowcoder/discuss.js index de495da57..090a19e2e 100644 --- a/lib/v2/nowcoder/discuss.js +++ b/lib/v2/nowcoder/discuss.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.nowcoder.com'; module.exports = async (ctx) => { - const type = ctx.params.type; - const order = ctx.params.order; + const type = ctx.req.param('type'); + const order = ctx.req.param('order'); const link = `https://www.nowcoder.com/discuss?type=${type}&order=${order}`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const type_name = $('a.discuss-tab.selected').text(); const order_name = $('li.selected a').text(); @@ -33,7 +33,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(itemUrl, async () => { const response = await got.get(itemUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const date_value = $('span.post-time').text(); @@ -49,9 +49,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${type_name}${order_name}——牛客网讨论区`, link, item: out, - }; + }); }; diff --git a/lib/v2/nowcoder/experience.js b/lib/v2/nowcoder/experience.js index ea814662c..0da57ab34 100644 --- a/lib/v2/nowcoder/experience.js +++ b/lib/v2/nowcoder/experience.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'; const host = 'https://www.nowcoder.com'; module.exports = async (ctx) => { const params = new URLSearchParams(ctx.query); - params.append('tagId', ctx.params.tagId); + params.append('tagId', ctx.req.param('tagId')); const link = new URL('/discuss/experience/json', host); @@ -31,7 +31,7 @@ module.exports = async (ctx) => { list.map((info) => ctx.cache.tryGet(info.link, async () => { const response = await got.get(info.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); info.description = $('.nc-post-content').html(); @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { - title: `牛客面经Tag${ctx.params.tagId}`, + ctx.set('data', { + title: `牛客面经Tag${ctx.req.param('tagId')}`, link: link.href, item: out, - }; + }); }; diff --git a/lib/v2/nowcoder/jobcenter.js b/lib/v2/nowcoder/jobcenter.js index 1469a33bd..50bec560d 100644 --- a/lib/v2/nowcoder/jobcenter.js +++ b/lib/v2/nowcoder/jobcenter.js @@ -1,17 +1,17 @@ const url = require('url'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const rootUrl = `https://www.nowcoder.com/job/center/`; - const currentUrl = `${rootUrl}?${ctx.params.type ? 'type=' + ctx.params.type : ''}${ctx.params.city ? '&city=' + ctx.params.city : ''}${ctx.params.order ? '&order=' + ctx.params.order : ''}${ - ctx.params.recruitType ? '&recruitType=' + ctx.params.recruitType : '' - }${ctx.params.latest ? '&latest=' + ctx.params.latest : ''}`; + const currentUrl = `${rootUrl}?${ctx.req.param('type') ? 'type=' + ctx.req.param('type') : ''}${ctx.req.param('city') ? '&city=' + ctx.req.param('city') : ''}${ctx.req.param('order') ? '&order=' + ctx.req.param('order') : ''}${ + ctx.req.param('recruitType') ? '&recruitType=' + ctx.req.param('recruitType') : '' + }${ctx.req.param('latest') ? '&latest=' + ctx.req.param('latest') : ''}`; const response = await got({ method: 'get', url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul.reco-job-list li') .slice(0, 30) .map((_, item) => { @@ -42,16 +42,16 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.rec-job').html(); return item; }) ) ); - ctx.state.data = { - title: `${ctx.params.recruitType ? (ctx.params.recruitType === '2' ? '社招广场' : '实习广场') : '实习广场'} - 牛客网`, + ctx.set('data', { + title: `${ctx.req.param('recruitType') ? (ctx.req.param('recruitType') === '2' ? '社招广场' : '实习广场') : '实习广场'} - 牛客网`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/nowcoder/recommend.js b/lib/v2/nowcoder/recommend.js index 84b70e788..da43c5a16 100644 --- a/lib/v2/nowcoder/recommend.js +++ b/lib/v2/nowcoder/recommend.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; module.exports = async (ctx) => { const link = `https://www.nowcoder.com/recommand/activity?token=&type=3&_=${Date.now()}`; @@ -7,7 +7,7 @@ module.exports = async (ctx) => { throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`); } const data = responseBody.data.activitys; - ctx.state.data = { + ctx.set('data', { title: '牛客网-推荐', link: 'https://www.nowcoder.com/recommend', description: '牛客网-推荐', @@ -16,5 +16,5 @@ module.exports = async (ctx) => { description: ``, link: `https://www.nowcoder.com${item.url}`, })), - }; + }); }; diff --git a/lib/v2/nowcoder/schedule.js b/lib/v2/nowcoder/schedule.js index 6bd29842e..2199c91ec 100644 --- a/lib/v2/nowcoder/schedule.js +++ b/lib/v2/nowcoder/schedule.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 propertyId = ctx.params.propertyId ?? 0; - const typeId = ctx.params.typeId ?? 0; + const propertyId = ctx.req.param('propertyId') ?? 0; + const typeId = ctx.req.param('typeId') ?? 0; const link = `https://www.nowcoder.com/school/schedule/data?token=&query=&typeId=${typeId}&propertyId=${propertyId}&onlyFollow=false&_=${Date.now()}`; const responseBody = (await got(link)).data; @@ -12,7 +12,7 @@ module.exports = async (ctx) => { } const data = responseBody.data.companyList; - ctx.state.data = { + ctx.set('data', { title: '名企校招日程', link: 'https://www.nowcoder.com/school/schedule', description: '名企校招日程', @@ -28,5 +28,5 @@ module.exports = async (ctx) => { link: `https://www.nowcoder.com/school/schedule/${item.id}`, }; }), - }; + }); }; diff --git a/lib/v2/npm/package.js b/lib/v2/npm/package.js index a087c3dee..9111e8aca 100644 --- a/lib/v2/npm/package.js +++ b/lib/v2/npm/package.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) => { @@ -24,7 +24,7 @@ module.exports = async (ctx) => { } packageVersionList.reverse(); - ctx.state.data = { + ctx.set('data', { title: `${name} - npm`, link: `https://www.npmjs.com/package/${name}`, description: `${name} - npm`, @@ -41,5 +41,5 @@ module.exports = async (ctx) => { guid: `https://www.npmjs.com/package/${name}${packageVersion.modified}`, }, ], - }; + }); }; diff --git a/lib/v2/npr/full.js b/lib/v2/npr/full.js index ba56b7bca..b23a6b061 100644 --- a/lib/v2/npr/full.js +++ b/lib/v2/npr/full.js @@ -1,11 +1,11 @@ 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 getArticleDetail = (link, ctx) => ctx.cache.tryGet(link, async () => { const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const categories = $('.slug').text().trim(); @@ -58,7 +58,7 @@ const getArticleDetail = (link, ctx) => }); module.exports = async (ctx) => { - const endpoint = ctx.params.endpoint || '1001'; + const endpoint = ctx.req.param('endpoint') || '1001'; const feed = await parser.parseURL(`https://feeds.npr.org/${endpoint}/rss.xml`); const items = ( @@ -77,11 +77,11 @@ module.exports = async (ctx) => { ) ).filter(Boolean); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.description, icon: 'https://media.npr.org/images/podcasts/primary/npr_generic_image_300.jpg?s=200', item: items, - }; + }); }; diff --git a/lib/v2/ntdtv/channel.js b/lib/v2/ntdtv/channel.js index 0aea69b6c..e86d9c484 100644 --- a/lib/v2/ntdtv/channel.js +++ b/lib/v2/ntdtv/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.ntdtv.com'; module.exports = async (ctx) => { - const language = ctx.params.language; - const id = ctx.params.id; + const language = ctx.req.param('language'); + const id = ctx.req.param('id'); const url = `${host}/${language}/${id}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('h1.block_title').text(); const list = $('div.list_wrapper > div') .map((_, item) => ({ @@ -26,7 +26,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.post_content').html(); item.pubDate = timezone(parseDate(content('div.time > span').text()), +8); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `新唐人电视台 - ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/nua/dc.js b/lib/v2/nua/dc.js index aad493f15..e9021880d 100644 --- a/lib/v2/nua/dc.js +++ b/lib/v2/nua/dc.js @@ -1,7 +1,7 @@ const util = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const baseUrl = 'https://dc.nua.edu.cn'; @@ -54,10 +54,10 @@ module.exports = async (ctx) => { const items = await util.ProcessList(baseUrl, baseUrl, listName, listDate, webPageName); const results = await util.ProcessFeed(items[0], artiContent, ctx); - ctx.state.data = { + ctx.set('data', { title: 'NUA-设计学院-' + items[1], link: baseUrl, description: '南京艺术学院 设计学院 ' + items[1], item: results, - }; + }); }; diff --git a/lib/v2/nua/gra.js b/lib/v2/nua/gra.js index 9d9daed64..a5a5dc009 100644 --- a/lib/v2/nua/gra.js +++ b/lib/v2/nua/gra.js @@ -2,7 +2,7 @@ const util = require('./utils'); const baseUrl = 'https://grad.nua.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const newsUrl = `${baseUrl}/${type}/list.htm`; const listName = 'li.list_item'; const artiContent = '.read'; @@ -12,10 +12,10 @@ module.exports = async (ctx) => { const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); const results = await util.ProcessFeed(items[0], artiContent, ctx); - ctx.state.data = { + ctx.set('data', { title: 'NUA-研究生处-' + items[1], link: `${baseUrl}/${type}/list.htm`, description: '南京艺术学院 研究生处 ' + items[1], item: results, - }; + }); }; diff --git a/lib/v2/nua/index.js b/lib/v2/nua/index.js index 57ae600b6..868ab837b 100644 --- a/lib/v2/nua/index.js +++ b/lib/v2/nua/index.js @@ -1,7 +1,7 @@ const util = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const baseUrl = 'https://www.nua.edu.cn'; const newsUrl = `${baseUrl}/${type}/list.htm`; @@ -13,10 +13,10 @@ module.exports = async (ctx) => { const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); const results = await util.ProcessFeed(items[0], artiContent, ctx); - ctx.state.data = { + ctx.set('data', { title: 'NUA-' + items[1], link: newsUrl, description: '南京艺术学院 ' + items[1], item: results, - }; + }); }; diff --git a/lib/v2/nua/lib.js b/lib/v2/nua/lib.js index 0046b373e..2a08f89d9 100644 --- a/lib/v2/nua/lib.js +++ b/lib/v2/nua/lib.js @@ -2,7 +2,7 @@ const util = require('./utils'); const baseUrl = 'https://lib.nua.edu.cn'; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); let webPageName; switch (type) { @@ -30,10 +30,10 @@ module.exports = async (ctx) => { const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); const results = await util.ProcessFeed(items[0], artiContent, ctx); - ctx.state.data = { + ctx.set('data', { title: 'NUA-图书馆-' + items[1], link: `${baseUrl}/${type}/list.htm`, description: '南京艺术学院 图书馆 ' + items[1], item: results, - }; + }); }; diff --git a/lib/v2/nua/sxw.js b/lib/v2/nua/sxw.js index 750912afb..e5662eb9d 100644 --- a/lib/v2/nua/sxw.js +++ b/lib/v2/nua/sxw.js @@ -1,7 +1,7 @@ const util = require('./utils'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const baseUrl = 'https://sxw.nua.edu.cn'; const newsUrl = `${baseUrl}/${type}/list.htm`; @@ -13,10 +13,10 @@ module.exports = async (ctx) => { const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName); const results = await util.ProcessFeed(items[0], artiContent, ctx); - ctx.state.data = { + ctx.set('data', { title: 'NUA-双馨网-' + items[1], link: newsUrl, description: '南京艺术学院 双馨网 ' + items[1], item: results, - }; + }); }; diff --git a/lib/v2/nua/utils.js b/lib/v2/nua/utils.js index 543acf04f..79f39d8d2 100644 --- a/lib/v2/nua/utils.js +++ b/lib/v2/nua/utils.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 { fetchArticle } = require('@/utils/wechat-mp'); const pageType = (href) => { @@ -24,7 +24,7 @@ function arti_link(text, href) { async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) { const result = await got(newsUrl, { https: { rejectUnauthorized: false } }); - const $ = cheerio.load(result.data); + const $ = load(result.data); const pageName = $(webPageName).text().trim(); @@ -53,7 +53,7 @@ const ProcessFeed = (items, artiContent, ctx) => case 'in-nua': case 'nua': { const result = await got(item.link, { https: { rejectUnauthorized: false } }); - const $ = cheerio.load(result.data); + const $ = load(result.data); item.author = $('.arti_publisher').text() + ' ' + $('.arti_views').text(); item.description = $(artiContent).html(); return item; diff --git a/lib/v2/nuaa/college/cae.js b/lib/v2/nuaa/college/cae.js index bf262d474..3af4e2efa 100644 --- a/lib/v2/nuaa/college/cae.js +++ b/lib/v2/nuaa/college/cae.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 getCookie = require('../utils/pypasswaf'); const host = 'https://cae.nuaa.edu.cn/'; @@ -17,9 +17,9 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const suffix = map.get(type).suffix; - const getDescription = Boolean(ctx.params.getDescription) || false; + const getDescription = Boolean(ctx.req.param('getDescription')) || false; const link = new URL(suffix, host).href; const cookie = await getCookie(host); const gotConfig = { @@ -28,7 +28,7 @@ module.exports = async (ctx) => { }, }; const response = await got(link, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w6 ul li') .slice(0, 10) @@ -55,7 +55,7 @@ module.exports = async (ctx) => { const pageType = arr.at(-1); if (pageType === 'htm' || pageType === 'html') { const response = await got(itemUrl, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('.wp_articlecontent').html() + '

查看原文'; } }); @@ -70,10 +70,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link, description: '南京航空航天大学自动化学院RSS', item: out, - }; + }); }; diff --git a/lib/v2/nuaa/college/cs.js b/lib/v2/nuaa/college/cs.js index d792bcdc6..a84c9f001 100644 --- a/lib/v2/nuaa/college/cs.js +++ b/lib/v2/nuaa/college/cs.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const getCookie = require('../utils/pypasswaf'); const host = 'https://cs.nuaa.edu.cn/'; @@ -15,8 +15,8 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type; - const getDescription = Boolean(ctx.params.getDescription) || false; + const type = ctx.req.param('type'); + const getDescription = Boolean(ctx.req.param('getDescription')) || false; const suffix = map.get(type).suffix; const link = new URL(suffix, host).href; @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }, }; const response = await got(link, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#news_list ul li') .slice(0, Math.min(Number.parseInt($('.per_count', '#wp_paging_w6').text()), Number.parseInt($('.all_count', '#wp_paging_w6').slice(1).text()))) @@ -54,7 +54,7 @@ module.exports = async (ctx) => { const pageType = arr.at(-1); if (pageType === 'htm' || pageType === 'html') { const response = await got(itemUrl, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('.wp_articlecontent').html() + '

查看原文'; } }); @@ -69,10 +69,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link, description: '南京航空航天大学计算机科学与技术学院RSS', item: out, - }; + }); }; diff --git a/lib/v2/nuaa/jwc/jwc.js b/lib/v2/nuaa/jwc/jwc.js index 96e5b85ba..7f58a076b 100644 --- a/lib/v2/nuaa/jwc/jwc.js +++ b/lib/v2/nuaa/jwc/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 getCookie = require('../utils/pypasswaf'); const host = 'http://aao.nuaa.edu.cn/'; @@ -13,9 +13,9 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const suffix = map.get(type).suffix; - const getDescription = Boolean(ctx.params.getDescription) || false; + const getDescription = Boolean(ctx.req.param('getDescription')) || false; const link = new URL(suffix, host).href; const cookie = await getCookie(host); @@ -25,7 +25,7 @@ module.exports = async (ctx) => { }, }; const response = await got(link, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w8 ul li') .slice(0, 10) @@ -52,7 +52,7 @@ module.exports = async (ctx) => { const pageType = arr.at(-1); if (pageType === 'htm' || pageType === 'html') { const response = await got(itemUrl, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('.wp_articlecontent').html() + '

查看原文'; } }); @@ -67,10 +67,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link, description: '南京航空航天大学教务处RSS', item: out, - }; + }); }; diff --git a/lib/v2/nuaa/utils/pypasswaf.js b/lib/v2/nuaa/utils/pypasswaf.js index c17cc443f..d8840dde5 100644 --- a/lib/v2/nuaa/utils/pypasswaf.js +++ b/lib/v2/nuaa/utils/pypasswaf.js @@ -1,11 +1,12 @@ const puppeteerUtils = require('@/utils/puppeteer-utils'); +import puppeteer from '@/utils/puppeteer'; /** * async function 获取cookie * @desc 返回一个可用的cookie,使用 `got` 发起请求的时候,传入到`options.headers.cookie`即可 */ module.exports = async function getCookie(host) { - 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) => { diff --git a/lib/v2/nuaa/yjsy/yjsy.js b/lib/v2/nuaa/yjsy/yjsy.js index 4b004706f..0532c8509 100644 --- a/lib/v2/nuaa/yjsy/yjsy.js +++ b/lib/v2/nuaa/yjsy/yjsy.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 getCookie = require('../utils/pypasswaf'); const host = 'http://www.graduate.nuaa.edu.cn/'; @@ -12,9 +12,9 @@ const map = new Map([ ]); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const suffix = map.get(type).suffix; - const getDescription = Boolean(ctx.params.getDescription) || false; + const getDescription = Boolean(ctx.req.param('getDescription')) || false; const link = new URL(suffix, host).href; const cookie = await getCookie(host); const gotConfig = { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { }, }; const response = await got(link, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w6 ul li') .slice(0, 10) @@ -50,7 +50,7 @@ module.exports = async (ctx) => { const pageType = arr.at(-1); if (pageType === 'htm' || pageType === 'html') { const response = await got(itemUrl, gotConfig); - const $ = cheerio.load(response.data); + const $ = load(response.data); return $('.wp_articlecontent').html() + '

查看原文'; } }); @@ -65,10 +65,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: map.get(type).title, link, description: '南京航空航天大学研究生院RSS', item: out, - }; + }); }; diff --git a/lib/v2/nuist/bulletin.js b/lib/v2/nuist/bulletin.js index db6a45d7a..8f10769e0 100644 --- a/lib/v2/nuist/bulletin.js +++ b/lib/v2/nuist/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 baseTitle = '南信大信息公告栏'; const baseUrl = 'https://bulletin.nuist.edu.cn'; @@ -22,14 +22,14 @@ const map = { }; module.exports = async (ctx) => { - const category = Object.hasOwn(map, ctx.params.category) ? ctx.params.category : '791'; + const category = Object.hasOwn(map, ctx.req.param('category')) ? ctx.req.param('category') : '791'; const link = `${baseUrl}/${category}/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news_list').find('.news'); - ctx.state.data = { + ctx.set('data', { title: baseTitle + (category === '791' ? '' : ':' + map[category]), link, item: list @@ -57,5 +57,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/nuist/cas.js b/lib/v2/nuist/cas.js index 2aa26733a..09e906222 100644 --- a/lib/v2/nuist/cas.js +++ b/lib/v2/nuist/cas.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 baseTitle = 'NUIST AS(南信大大气科学学院)'; const baseUrl = 'https://cas.nuist.edu.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/index/${category}.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#ctl00_ctl00_body_NewsList') .find('tr.gridline') .toArray() @@ -37,7 +37,7 @@ module.exports = async (ctx) => { let response; try { response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const authorMatch = $('.zzxx') .text() @@ -62,10 +62,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle + ':' + $('.dqlm').find('a').eq(1).text(), description: $('meta[name=description]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/nuist/jwc.js b/lib/v2/nuist/jwc.js index 4d939c464..f4f2e5ab1 100644 --- a/lib/v2/nuist/jwc.js +++ b/lib/v2/nuist/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 baseTitle = '南京信息工程大学-教务处'; const baseUrl = 'https://jwc.nuist.edu.cn'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/${category === 'jxyw' || category === 'xyjx' ? 'index' : 'xxtz'}/${category}.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.main_list ul li') .toArray() .map((item) => { @@ -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.description = $('#vsb_content').html(); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle + ':' + $('.dqwz').find('a').eq(1).text(), link, item: items, - }; + }); }; diff --git a/lib/v2/nuist/library/lib.js b/lib/v2/nuist/library/lib.js index c3a29bcbe..c475757df 100644 --- a/lib/v2/nuist/library/lib.js +++ b/lib/v2/nuist/library/lib.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 baseTitle = '南京信息工程大学图书馆通知'; const baseUrl = 'https://lib.nuist.edu.cn'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const link = baseUrl + '/index/tzgg.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list2 li') .toArray() .map((item) => { @@ -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 = $('#vsb_content').html(); item.pubDate = parseDate($('.date').find('span').eq(0).text(), 'YYYY年MM月DD日'); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle, link, item: items, - }; + }); }; diff --git a/lib/v2/nuist/scs.js b/lib/v2/nuist/scs.js index afa6cdd80..eef4078d9 100644 --- a/lib/v2/nuist/scs.js +++ b/lib/v2/nuist/scs.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 baseTitle = 'NUIST CS(南信大计软院)'; const baseUrl = 'https://scs.nuist.edu.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/${category}/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.newsList ul') .eq(0) @@ -28,7 +28,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 authorMatch = $('.newsTitleAddDate') .text() @@ -40,10 +40,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle + ':' + $('head title').text(), description: $('meta[name=description]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/nuist/sese.js b/lib/v2/nuist/sese.js index fd31d29c1..4c6a7d307 100644 --- a/lib/v2/nuist/sese.js +++ b/lib/v2/nuist/sese.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 baseTitle = 'NUIST ESE(南信大环科院)'; const baseUrl = 'https://sese.nuist.edu.cn'; @@ -10,7 +10,7 @@ module.exports = async (ctx) => { const link = `${baseUrl}/${category}.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#ctl00_ctl00_mainbody_rightbody_listcontent_NewsList .gridline') .toArray() .map((item) => { @@ -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.description = $('#vsb_content_6').html(); @@ -36,10 +36,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle + ':' + $('.lmtitle').text(), description: $('meta[name=description]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/nuist/xgc.js b/lib/v2/nuist/xgc.js index 090a2981e..700c741f6 100644 --- a/lib/v2/nuist/xgc.js +++ b/lib/v2/nuist/xgc.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 baseTitle = '南信大学生工作处'; const baseUrl = 'https://xgc.nuist.edu.cn'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = baseUrl + '/419/list.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.wp_article_list .list_item') .toArray() .map((item) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { let response; try { response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const articleInfo = $('.arti_metas'); @@ -41,9 +41,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: baseTitle, link, item: items.filter(Boolean), - }; + }); }; diff --git a/lib/v2/nuist/yjs.js b/lib/v2/nuist/yjs.js index 3fe190f15..75821dc7a 100644 --- a/lib/v2/nuist/yjs.js +++ b/lib/v2/nuist/yjs.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 path = ctx.path === '/yjs/' ? 'index/tzgg' : ctx.path.replace(/^\/yjs\//, ''); @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.gridlinediv') .toArray() @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const timeMatches = content('.bar') .text() @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nwafu/all.js b/lib/v2/nwafu/all.js index e70f74c67..0882e0887 100644 --- a/lib/v2/nwafu/all.js +++ b/lib/v2/nwafu/all.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 { nwafuMap } = require('./utils'); module.exports = async (ctx) => { const { type = 'jiaowu' } = ctx.params; const response = await got.get(nwafuMap.get(type)[0]); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(nwafuMap.get(type)[1]) .map((index, ele) => { const itemTitle = $(ele).find(nwafuMap.get(type)[2]).text(); @@ -27,17 +27,17 @@ module.exports = async (ctx) => { return item; } const detailResponse = await got.get(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); item.description = $(nwafuMap.get(type)[3]).html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: nwafuMap.get(type)[4], link: nwafuMap.get(type)[0], description: nwafuMap.get(type)[4], item: out, - }; + }); }; diff --git a/lib/v2/nyaa/main.js b/lib/v2/nyaa/main.js index 97496bc3b..3e83ebdd6 100644 --- a/lib/v2/nyaa/main.js +++ b/lib/v2/nyaa/main.js @@ -1,4 +1,4 @@ -const config = require('@/config').value; +import { config } from '@/config'; const Parser = require('rss-parser'); module.exports = async (ctx) => { @@ -36,10 +36,10 @@ module.exports = async (ctx) => { return item; }); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: currentLink, description: feed.description, item: feed.items, - }; + }); }; diff --git a/lib/v2/nytimes/book.js b/lib/v2/nytimes/book.js index 11be6b84b..8c547e5b3 100644 --- a/lib/v2/nytimes/book.js +++ b/lib/v2/nytimes/book.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const categoryList = { 'combined-print-and-e-book-nonfiction': '非虚构类 - 综合', @@ -16,7 +16,7 @@ const categoryList = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'combined-print-and-e-book-nonfiction'; + const category = ctx.req.param('category') ?? 'combined-print-and-e-book-nonfiction'; const url = `https://www.nytimes.com/books/best-sellers/${category}`; @@ -28,7 +28,7 @@ module.exports = async (ctx) => { url, }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); dataTitle = $('h1').eq(0).text(); items = $('article[itemprop=itemListElement]') @@ -63,9 +63,9 @@ module.exports = async (ctx) => { .get(); } - ctx.state.data = { + ctx.set('data', { title: `The New York Times Best Sellers - ${dataTitle}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/nytimes/daily-briefing-chinese.js b/lib/v2/nytimes/daily-briefing-chinese.js index 1aad4fc23..64b888735 100644 --- a/lib/v2/nytimes/daily-briefing-chinese.js +++ b/lib/v2/nytimes/daily-briefing-chinese.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) => { @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); // to remove ads content('.StoryBodyCompanionColumn').last().find('p').last().remove(); @@ -59,9 +59,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '新闻简报 - The New York Times', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/nytimes/index.js b/lib/v2/nytimes/index.js index 7f12af1bb..2002d2296 100644 --- a/lib/v2/nytimes/index.js +++ b/lib/v2/nytimes/index.js @@ -1,7 +1,8 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const parser = require('@/utils/rss-parser'); const utils = require('./utils'); -const cheerio = require('cheerio'); +import { load } from 'cheerio'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { let { lang = '' } = ctx.params; @@ -38,7 +39,7 @@ module.exports = async (ctx) => { // Do nothing } - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const feed = await parser.parseURL(rssUrl); const items = await Promise.all( feed.items.splice(0, 10).map(async (item) => { @@ -74,7 +75,7 @@ module.exports = async (ctx) => { }); if (lang === 'en') { - const $ = cheerio.load(response); + const $ = load(response); if ($('.dual-btn').length > 0) { hasEnVersion = true; link = $('.dual-btn a').last().attr().href; @@ -113,10 +114,10 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title, link: 'https://cn.nytimes.com', description: title, item: items, - }; + }); }; diff --git a/lib/v2/nytimes/utils.js b/lib/v2/nytimes/utils.js index ccaf42ed5..df77369ce 100644 --- a/lib/v2/nytimes/utils.js +++ b/lib/v2/nytimes/utils.js @@ -1,5 +1,5 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const ProcessImage = ($, e) => { const photo = $(e).find('figure').find('picture').find('img'); @@ -30,7 +30,7 @@ const PuppeterGetter = async (ctx, browser, link) => { }; const ProcessFeed = (data, hasEnVersion = false) => { - const $ = cheerio.load(data); + const $ = load(data); let content; const result = {}; diff --git a/lib/v2/oceanengine/arithmetic-index.js b/lib/v2/oceanengine/arithmetic-index.js index 4ca6d121d..9d22b86fb 100644 --- a/lib/v2/oceanengine/arithmetic-index.js +++ b/lib/v2/oceanengine/arithmetic-index.js @@ -1,9 +1,10 @@ const dayjs = require('dayjs'); -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 path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; +import puppeteer from '@/utils/puppeteer'; // Parameters const CACHE_MAX_AGE = config.cache.contentExpire; @@ -80,23 +81,23 @@ module.exports = async (ctx) => { const now = dayjs(); const start_date = now.subtract(DEFAULT_FETCH_DURATION_MONTH, 'month').format('YYYYMMDD'); const end_date = now.format('YYYYMMDD'); - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); if (!keyword) { throw new Error('Invalid keyword'); } - if (ctx.params.channel && !['douyin', 'toutiao'].includes(ctx.params.channel)) { + if (ctx.req.param('channel') && !['douyin', 'toutiao'].includes(ctx.req.param('channel'))) { throw new Error('Invalid channel。 Only support `douyin` or `toutiao`'); } - const channel = ctx.params.channel === 'toutiao' ? 'toutiao' : 'aweme'; // default channel is `douyin` - const channelName = ctx.params.channel === 'toutiao' ? '头条' : '抖音'; + const channel = ctx.req.param('channel') === 'toutiao' ? 'toutiao' : 'aweme'; // default channel is `douyin` + const channelName = ctx.req.param('channel') === 'toutiao' ? '头条' : '抖音'; const link = `https://trendinsight.oceanengine.com/arithmetic-index/analysis?keyword=${keyword}&appName=${channel}`; const item = 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) => { @@ -135,11 +136,11 @@ module.exports = async (ctx) => { false ); - ctx.state.data = { + ctx.set('data', { title: `${keyword} - ${channelName}指数波峰`, link, description: `巨量算数 - ${channelName}算数指数 | 关键词: ${keyword}`, language: 'zh-cn', item, - }; + }); }; diff --git a/lib/v2/odaily/activity.js b/lib/v2/odaily/activity.js index 96b74e4f8..18577d334 100644 --- a/lib/v2/odaily/activity.js +++ b/lib/v2/odaily/activity.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 } = require('./utils'); module.exports = async (ctx) => { - const currentUrl = `${rootUrl}/service/scheme/group/8?page=1&per_page=${ctx.query.limit ?? 25}`; + const currentUrl = `${rootUrl}/service/scheme/group/8?page=1&per_page=${ctx.req.query('limit') ?? 25}`; const response = await got({ method: 'get', @@ -26,7 +26,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]); + const content = load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]); content('img').each(function () { content(this).attr('src', content(this).attr('src').replaceAll('\\"', '')); @@ -39,9 +39,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '活动 - Odaily星球日报', link: `${rootUrl}/activityPage`, item: items, - }; + }); }; diff --git a/lib/v2/odaily/newsflash.js b/lib/v2/odaily/newsflash.js index 302f909db..9187a20a8 100644 --- a/lib/v2/odaily/newsflash.js +++ b/lib/v2/odaily/newsflash.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); module.exports = async (ctx) => { - const currentUrl = `${rootUrl}/api/pp/api/info-flow/newsflash_columns/newsflashes?b_id=&per_page=${ctx.query.limit ?? 100}`; + const currentUrl = `${rootUrl}/api/pp/api/info-flow/newsflash_columns/newsflashes?b_id=&per_page=${ctx.req.query('limit') ?? 100}`; const response = await got({ method: 'get', @@ -18,9 +18,9 @@ module.exports = async (ctx) => { description: `

${item.description}

`, })); - ctx.state.data = { + ctx.set('data', { title: '快讯 - Odaily星球日报', link: `${rootUrl}/newsflash`, item: items, - }; + }); }; diff --git a/lib/v2/odaily/post.js b/lib/v2/odaily/post.js index 6155181ec..0d049fba2 100644 --- a/lib/v2/odaily/post.js +++ b/lib/v2/odaily/post.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); const titles = { @@ -16,9 +16,9 @@ const titles = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? '280'; + const id = ctx.req.param('id') ?? '280'; - const currentUrl = `${rootUrl}/api/pp/api/app-front/feed-stream?feed_id=${id}&b_id=&per_page=${ctx.query.limit ?? 25}`; + const currentUrl = `${rootUrl}/api/pp/api/app-front/feed-stream?feed_id=${id}&b_id=&per_page=${ctx.req.query('limit') ?? 25}`; const response = await got(currentUrl); @@ -39,7 +39,7 @@ module.exports = async (ctx) => { const ssr = JSON.parse(`{${detailResponse.data.match(/window\.__INITIAL_STATE__ = {(.*)}/)[1]}}`); - const content = cheerio.load(ssr.post.detail.content, null, false); + const content = load(ssr.post.detail.content, null, false); content('img').each((_, img) => { img.attribs.src = img.attribs.src.split('?x-oss-process')[0]; img.attribs.src = img.attribs.src.split('!heading')[0]; @@ -55,9 +55,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${titles[id]} - Odaily星球日报`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/odaily/search-news.js b/lib/v2/odaily/search-news.js index 65dcae646..d52c90968 100644 --- a/lib/v2/odaily/search-news.js +++ b/lib/v2/odaily/search-news.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); module.exports = async (ctx) => { - const currentUrl = `${rootUrl}/api/pp/api/search/entity-search?per_page=${ctx.query.limit ?? 25}&keyword=${ctx.params.keyword}&entity_type=newsflash`; + const currentUrl = `${rootUrl}/api/pp/api/search/entity-search?per_page=${ctx.req.query('limit') ?? 25}&keyword=${ctx.req.param('keyword')}&entity_type=newsflash`; const response = await got({ method: 'get', @@ -18,9 +18,9 @@ module.exports = async (ctx) => { description: `

${item.description}

`, })); - ctx.state.data = { + ctx.set('data', { title: '快讯 - Odaily星球日报', - link: `${rootUrl}/search/${ctx.params.keyword}`, + link: `${rootUrl}/search/${ctx.req.param('keyword')}`, item: items, - }; + }); }; diff --git a/lib/v2/odaily/user.js b/lib/v2/odaily/user.js index 89b3b7658..752e10dd7 100644 --- a/lib/v2/odaily/user.js +++ b/lib/v2/odaily/user.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { rootUrl } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); - const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.query.limit ?? 25}`; + const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.req.query('limit') ?? 25}`; let author = ''; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); + const content = load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]); content('img').each(function () { content(this).attr('src', content(this).attr('src').replaceAll('\\"', '')); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${author} - Odaily星球日报`, link: `${rootUrl}/user/${id}`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/app/channel.js b/lib/v2/oeeee/app/channel.js index 882791b5e..deb6c0644 100644 --- a/lib/v2/oeeee/app/channel.js +++ b/lib/v2/oeeee/app/channel.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { parseArticle } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? 50; + const id = ctx.req.param('id') ?? 50; const currentUrl = `https://api-ndapp.oeeee.com/friends.php?m=Zone&a=SpaceDoclist&uid=${id}&type=doc`; const { data: response } = await got(currentUrl); @@ -28,9 +28,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报客户端 - ${channel}`, link: `https://m.mp.oeeee.com/u/${id}.html`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/app/reporter.js b/lib/v2/oeeee/app/reporter.js index f1d486c24..729f75f04 100644 --- a/lib/v2/oeeee/app/reporter.js +++ b/lib/v2/oeeee/app/reporter.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseArticle } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id ?? 0; + const id = ctx.req.param('id') ?? 0; const currentUrl = `https://m.mp.oeeee.com/show.php?m=Doc&a=getAuthorInfo&id=${id}`; const { data: response } = await got(currentUrl); @@ -22,9 +22,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报奥一网 - ${author}`, link: `https://m.mp.oeeee.com/w/${id}.html`, item: items, - }; + }); }; diff --git a/lib/v2/oeeee/utils.js b/lib/v2/oeeee/utils.js index 67e93378c..3e4c9fc21 100644 --- a/lib/v2/oeeee/utils.js +++ b/lib/v2/oeeee/utils.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const parseArticle = (item, tryGet) => tryGet(item.link, async () => { @@ -10,7 +10,7 @@ const parseArticle = (item, tryGet) => url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); // nfapp page: if (content('.post-cont') && content('.post-cont').html()) { diff --git a/lib/v2/oeeee/web.js b/lib/v2/oeeee/web.js index 3bc8ecd61..d527be11b 100644 --- a/lib/v2/oeeee/web.js +++ b/lib/v2/oeeee/web.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { parseArticle } = require('./utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const channel = ctx.params.channel ?? 0; + const channel = ctx.req.param('channel') ?? 0; const currentUrl = `https://www.oeeee.com/api/channel.php?m=Js4channelNews&a=newLatest&cid=${channel}`; const { data: response } = await got(currentUrl); @@ -28,9 +28,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `南方都市报奥一网`, link: `https://www.oeeee.com/api/channel.php?s=/index/index/channel/${channelEname}`, item: items, - }; + }); }; diff --git a/lib/v2/oilchem/index.js b/lib/v2/oilchem/index.js index 4de1945c1..f8710111a 100644 --- a/lib/v2/oilchem/index.js +++ b/lib/v2/oilchem/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const routes = require('./routes'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const type = ctx.params.type ?? ''; - const category = ctx.params.category ?? ''; - const subCategory = ctx.params.subCategory ?? ''; + const type = ctx.req.param('type') ?? ''; + const category = ctx.req.param('category') ?? ''; + const subCategory = ctx.req.param('subCategory') ?? ''; const route = category === '' ? '' : `/${category}${subCategory === '' ? '' : `/${subCategory}`}`; @@ -19,7 +19,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list ul ul li a') .map((_, item) => { @@ -39,7 +39,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#content').html(); item.pubDate = timezone( @@ -58,9 +58,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.hdbox h3').text()} - 隆众资讯`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/oncc/index.js b/lib/v2/oncc/index.js index 8214931ad..9e00bb4aa 100644 --- a/lib/v2/oncc/index.js +++ b/lib/v2/oncc/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const rootUrl = 'https://hk.on.cc'; @@ -35,12 +35,12 @@ const channelMap = { }; module.exports = async (ctx) => { - const language = ctx.params.language; - const channel = ctx.params.channel ?? 'news'; + const language = ctx.req.param('language'); + const channel = ctx.req.param('channel') ?? 'news'; const newsUrl = `${rootUrl}/hk/${channel}/index${languageMap[language]}.html`; const response = await got.get(newsUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#focusNews > div.focusItem[type=article]') .map((_, item) => { const title = $(item).find('div.focusTitle > span').text(); @@ -59,7 +59,7 @@ module.exports = async (ctx) => { list.map(async (item) => { const desc = await ctx.cache.tryGet(item.link, async () => { const detailResponse = await got.get(item.link); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const imageUrl = rootUrl + $('img').eq(0).attr('src'); const content = $('div.breakingNewsContent').html(); const description = art(path.join(__dirname, 'templates/article.art'), { @@ -75,9 +75,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `東網 - ${channelMap[channel][language]}`, link: newsUrl, item: items, - }; + }); }; diff --git a/lib/v2/oncc/money18.js b/lib/v2/oncc/money18.js index edf14b54e..dc77e3706 100644 --- a/lib/v2/oncc/money18.js +++ b/lib/v2/oncc/money18.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const sections = { @@ -20,8 +20,8 @@ const sections = { }; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'exp'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30; + const id = ctx.req.param('id') ?? 'exp'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30; const rootUrl = 'https://money18.on.cc'; const currentUrl = `${rootUrl}/finnews/news_${id === 'industry' ? 'industry.html' : `breaking.html?section=${id}`}`; @@ -92,7 +92,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = art(path.join(__dirname, 'templates/money18.art'), { images: content('.photo img') @@ -107,9 +107,9 @@ module.exports = async (ctx) => { ); } - ctx.state.data = { + ctx.set('data', { title: `東網產經 - ${sections[id]}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/onehu/common.js b/lib/v2/onehu/common.js index 705184a3d..0f4e260ad 100644 --- a/lib/v2/onehu/common.js +++ b/lib/v2/onehu/common.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'https://onehu.xyz'; const response = await got(link); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#board article') .toArray() .map((item) => { @@ -20,9 +20,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link, item: list, - }; + }); }; diff --git a/lib/v2/onet/news.js b/lib/v2/onet/news.js index 225e146a7..bbe8c025a 100644 --- a/lib/v2/onet/news.js +++ b/lib/v2/onet/news.js @@ -1,8 +1,8 @@ const parser = require('@/utils/rss-parser'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { parseArticleContent, parseMainImage } = require('./utils'); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const content = parseArticleContent($); const mainImage = parseMainImage($); @@ -45,12 +45,12 @@ module.exports = async (ctx) => { }; }) ); - ctx.state.data = { + ctx.set('data', { title: feed.title, link: feed.link, description: feed.title, item: items, language: 'pl', image: 'https://ocdn.eu/wiadomosciucs/static/logo2017/onet2017big_dark.png', - }; + }); }; diff --git a/lib/v2/onet/utils.js b/lib/v2/onet/utils.js index af8a9a814..061df7b39 100644 --- a/lib/v2/onet/utils.js +++ b/lib/v2/onet/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const parseMainImage = ($) => { diff --git a/lib/v2/oo-software/changelog.js b/lib/v2/oo-software/changelog.js index 3a0fb7998..2da0e7e61 100644 --- a/lib/v2/oo-software/changelog.js +++ b/lib/v2/oo-software/changelog.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'shutup10'; + const id = ctx.req.param('id') ?? 'shutup10'; const rootUrl = 'https://www.oo-software.com'; const currentUrl = `${rootUrl}/en/${id}/changelog`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.content h4') .toArray() @@ -32,9 +32,9 @@ module.exports = async (ctx) => { items[0].enclosure_url = $('.banner-inlay').find('a').attr('href'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/openai/blog.js b/lib/v2/openai/blog.js index 327005fab..9d352abe2 100644 --- a/lib/v2/openai/blog.js +++ b/lib/v2/openai/blog.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { toTitleCase } = require('@/utils/common-utils'); const { getApiUrl, parseArticle } = require('./common'); module.exports = async (ctx) => { - const tag = ctx.params.tag || ''; + const tag = ctx.req.param('tag') || ''; const rootUrl = 'https://openai.com'; const blogRootUrl = 'https://openai.com/blog'; @@ -36,9 +36,9 @@ module.exports = async (ctx) => { const title = `OpenAI Blog${tag ? ` - ${toTitleCase(tag)}` : ''}`; - ctx.state.data = { + ctx.set('data', { title, link: blogOriginUrl, item: items, - }; + }); }; diff --git a/lib/v2/openai/chatgpt.js b/lib/v2/openai/chatgpt.js index 717d24913..0a5daaef2 100644 --- a/lib/v2/openai/chatgpt.js +++ b/lib/v2/openai/chatgpt.js @@ -1,7 +1,7 @@ const dayjs = require('dayjs'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; dayjs.extend(require('dayjs/plugin/isSameOrBefore')); @@ -18,7 +18,7 @@ module.exports = async (ctx) => { url: articleUrl, }); - const $ = cheerio.load(pageResponse.data); + const $ = load(pageResponse.data); const page = JSON.parse($('script#__NEXT_DATA__').text()); // 页面貌似是用 Next 渲染的,有现成的 JSON 数据可以直接 parse,而避免用 cheerio 去解析主体内容的 HTML const feedTitle = page.props.pageProps.articleContent.title; @@ -89,10 +89,10 @@ module.exports = async (ctx) => { false ); - ctx.state.data = { + ctx.set('data', { title: cache.feedTitle, description: cache.feedDesc, link: articleUrl, item: cache.items, - }; + }); }; diff --git a/lib/v2/openai/common.js b/lib/v2/openai/common.js index 6bf6c9ea0..5e6eeb8fa 100644 --- a/lib/v2/openai/common.js +++ b/lib/v2/openai/common.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); const getApiUrl = async () => { @@ -27,7 +27,7 @@ const parseArticle = (ctx, rootUrl, attributes) => method: 'get', url: textUrl, }); - let content = cheerio.load(detailResponse.data); + let content = load(detailResponse.data); const authors = content('[aria-labelledby="metaAuthorsHeading"] > li > a > span > span') .toArray() diff --git a/lib/v2/openai/research.js b/lib/v2/openai/research.js index 3af8174a3..b4ef832b4 100644 --- a/lib/v2/openai/research.js +++ b/lib/v2/openai/research.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { getApiUrl, parseArticle } = require('./common'); module.exports = async (ctx) => { @@ -24,9 +24,9 @@ module.exports = async (ctx) => { const title = 'OpenAI Research'; - ctx.state.data = { + ctx.set('data', { title, link: researchRootUrl, item: items, - }; + }); }; diff --git a/lib/v2/openwrt/releases.js b/lib/v2/openwrt/releases.js index 7cb8b5e52..9cbee4788 100644 --- a/lib/v2/openwrt/releases.js +++ b/lib/v2/openwrt/releases.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const brand = ctx.params.brand; - const model = ctx.params.model; + const brand = ctx.req.param('brand'); + const model = ctx.req.param('model'); const url = `https://openwrt.org/toh/${brand}/${model}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const table = $('#installation').next(); - ctx.state.data = { + ctx.set('data', { title: $('h1').text() + ' - OpenWrt Releases', link: url, description: $('.dw-content div.level1').text(), @@ -21,5 +21,5 @@ module.exports = async (ctx) => { description: `Firmware OpenWrt Install: ${table.find('.firmware_openwrt_install_url').html()}

Firmware OpenWrt Upgrade: ${$('.firmware_openwrt_upgrade_url').html()}'`, }, ], - }; + }); }; diff --git a/lib/v2/orcid/index.js b/lib/v2/orcid/index.js index c412b738a..1655f7882 100644 --- a/lib/v2/orcid/index.js +++ b/lib/v2/orcid/index.js @@ -1,16 +1,16 @@ -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) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://orcid.org/'; const currentUrl = `${rootUrl}${id}/worksPage.json?offset=0&sort=date&sortAsc=false&pageSize=20`; const response = await got(currentUrl); const items = response.data.groups; - const works = new Array(); - const out = new Array(); + const works = []; + const out = []; for (const item of items) { for (let j = 0; j < item.works.length; j++) { @@ -44,9 +44,9 @@ module.exports = async (ctx) => { return info; }); - ctx.state.data = { + ctx.set('data', { title: 'ORCID Works List' + id, link: currentUrl, item: out, - }; + }); }; diff --git a/lib/v2/oreno3d/get-sec-page-data.js b/lib/v2/oreno3d/get-sec-page-data.js index 429f99aaf..a8e2533ba 100644 --- a/lib/v2/oreno3d/get-sec-page-data.js +++ b/lib/v2/oreno3d/get-sec-page-data.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const rootUrl = 'https://oreno3d.com'; @@ -17,7 +17,7 @@ async function sync_detail(link) { const iwara_link_selector = 'header > figure.video-figure > a'; // 下载 const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 创建列表 const tags = []; const authors = []; diff --git a/lib/v2/oreno3d/main.js b/lib/v2/oreno3d/main.js index 318dc7bf7..082caaac5 100644 --- a/lib/v2/oreno3d/main.js +++ b/lib/v2/oreno3d/main.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 get_sec_page_data = require('./get-sec-page-data'); const rootUrl = 'https://oreno3d.com'; @@ -16,20 +16,20 @@ const sortRename = { function get_user_url(rootUrl, ctx, sort) { let userUrl = ''; // 判断userurl获取位置 - if (ctx.params.keyword) { - const keyword = ctx.params.keyword; + if (ctx.req.param('keyword')) { + const keyword = ctx.req.param('keyword'); userUrl = `${rootUrl}/search?sort=${sort}&keyword=${keyword}`; - } else if (ctx.params.characterid) { - const characterid = ctx.params.characterid; + } else if (ctx.req.param('characterid')) { + const characterid = ctx.req.param('characterid'); userUrl = `${rootUrl}/characters/${characterid}?sort=${sort}`; - } else if (ctx.params.authorid) { - const authorid = ctx.params.authorid; + } else if (ctx.req.param('authorid')) { + const authorid = ctx.req.param('authorid'); userUrl = `${rootUrl}/authors/${authorid}?sort=${sort}`; - } else if (ctx.params.tagid) { - const tagid = ctx.params.tagid; + } else if (ctx.req.param('tagid')) { + const tagid = ctx.req.param('tagid'); userUrl = `${rootUrl}/tags/${tagid}?sort=${sort}`; - } else if (ctx.params.originid) { - const originid = ctx.params.originid; + } else if (ctx.req.param('originid')) { + const originid = ctx.req.param('originid'); userUrl = `${rootUrl}/origins/${originid}?sort=${sort}`; } return userUrl; @@ -38,14 +38,14 @@ module.exports = async (ctx) => { // 获取视频链接列表及标题 function getLinksTitle(response) { const selector = 'a.box'; - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('div.g-main-list').find('h1.main-h').text(); const list = $(selector); return { title, list }; } // 数据爬取和分析 async function getData(response) { - const $ = cheerio.load(response.data); + const $ = load(response.data); // 第一页,获取搜索主标题 const title = getLinksTitle(response).title; const list = getLinksTitle(response).list; @@ -96,13 +96,13 @@ module.exports = async (ctx) => { return { items, title }; } // 参数定义 - const sort = ctx.params.sort; - let pagelimit = ctx.params.pagelimit ?? 1; + const sort = ctx.req.param('sort'); + let pagelimit = ctx.req.param('pagelimit') ?? 1; // 根链接 const userUrl = get_user_url(rootUrl, ctx, sort); // 确认最大页数并比较修改(同时也是获取第一页的内容) const response = await got(userUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const maxPageSelector = 'div.container > main > div.g-main-list > ul.pagination > li:last-child > a'; // 页码判断 if ($(maxPageSelector)) { @@ -149,9 +149,9 @@ module.exports = async (ctx) => { item: realItem, }; // 生成RSS源码 - ctx.state.data = { + ctx.set('data', { title: `${data.title} - ${sortRename[sort]}(Page 1-${pagelimit})`, link: userUrl, item: data.item, - }; + }); }; diff --git a/lib/v2/oschina/news.js b/lib/v2/oschina/news.js index 6682bb44c..686884b1a 100644 --- a/lib/v2/oschina/news.js +++ b/lib/v2/oschina/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; const configs = { all: { @@ -32,7 +32,7 @@ const configs = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? 'all'; + const category = ctx.req.param('category') ?? 'all'; const config = configs[category]; const res = await got(config.ajaxUrl, { @@ -41,7 +41,7 @@ module.exports = async (ctx) => { 'X-Requested-With': 'XMLHttpRequest', }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.items .news-item') .toArray() @@ -65,7 +65,7 @@ module.exports = async (ctx) => { Referer: config.link, }, }); - const content = cheerio.load(detail.data); + const content = load(detail.data); content('.ad-wrap').remove(); item.description = content('.article-detail').html(); @@ -77,7 +77,7 @@ module.exports = async (ctx) => { Referer: config.link, }, }); - const content = cheerio.load(detail.data); + const content = load(detail.data); item.description = content('.file_content').html(); } @@ -86,9 +86,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `开源中国-${config.name}`, link: config.link, item: resultItem, - }; + }); }; diff --git a/lib/v2/oschina/topic.js b/lib/v2/oschina/topic.js index f2e70e80f..5a671e32a 100644 --- a/lib/v2/oschina/topic.js +++ b/lib/v2/oschina/topic.js @@ -1,19 +1,19 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; -async function load(link) { +async function loadContent(link) { const res = await got(link); - const content = cheerio.load(res.data); + const content = load(res.data); return content; } module.exports = async (ctx) => { - const topic = ctx.params.topic; + const topic = ctx.req.param('topic'); const topicUrl = `https://www.oschina.net/question/topic/${topic}?show=time`; - const $ = await load(topicUrl); + const $ = await loadContent(topicUrl); const topicName = $('.topic-info > .topic-header > h3').text(); const list = $('#questionList .question-item') .toArray() @@ -33,7 +33,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { try { - const content = await load(item.link); + const content = await loadContent(item.link); content('.ad-wrap').remove(); item.description = content('#articleContent').html(); } catch { @@ -44,10 +44,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `开源中国-${topicName}`, description: $('.topic-introduction').text(), link: topicUrl, item: resultItem, - }; + }); }; diff --git a/lib/v2/oschina/user.js b/lib/v2/oschina/user.js index 65ffd0c3d..8c3015ef9 100644 --- a/lib/v2/oschina/user.js +++ b/lib/v2/oschina/user.js @@ -1,12 +1,12 @@ -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 timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { const { id, uid } = ctx.params; const res = id ? await got(`https://my.oschina.net/${id}`) : await got(`https://my.oschina.net/u/${uid}`); - const $ = cheerio.load(res.data); + const $ = load(res.data); const author = $('.user-name .name').text(); const list = $('#newestBlogList .blog-item') @@ -31,7 +31,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { if (item.accessible) { const detail = await got(item.link); - const content = cheerio.load(detail.data); + const content = load(detail.data); item.description = content('.article-detail').html(); } @@ -41,10 +41,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: author + '的博客', description: $('.user-text .user-signature').text(), link: `https://my.oschina.net/${id ?? uid}`, item: resultItem, - }; + }); }; diff --git a/lib/v2/oshwhub/explore.js b/lib/v2/oshwhub/explore.js index f24cd63e6..03a00b36f 100644 --- a/lib/v2/oshwhub/explore.js +++ b/lib/v2/oshwhub/explore.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 timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import { art } from '@/utils/render'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const md = require('markdown-it')({ html: true, linkify: true, @@ -49,7 +49,7 @@ const requestImages = (url, tryGet) => module.exports = async (ctx) => { const baseUrl = 'https://oshwhub.com'; - const sortType = ctx.params.sortType ?? 'updatedTime'; + const sortType = ctx.req.param('sortType') ?? 'updatedTime'; const url = `${baseUrl}/explore?projectSort=${sortType}`; const response = await got({ @@ -58,7 +58,7 @@ module.exports = async (ctx) => { }); const html = response.data; - const $ = cheerio.load(html); + const $ = load(html); const title = $('title').text(); const projects = $('a[class="project-link"]'); @@ -72,7 +72,7 @@ module.exports = async (ctx) => { }); const html = response.data; - const $$ = cheerio.load(html); + const $$ = load(html); const projectDetail = $$('div[class="projects-left-top"]'); const title = $$(projectDetail).find('span[class="title"]').text(); @@ -112,10 +112,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title, link: url, description: title, item: items, - }; + }); }; diff --git a/lib/v2/osu/beatmaps/packs.js b/lib/v2/osu/beatmaps/packs.js index c0b9f9b4f..03d9819ae 100644 --- a/lib/v2/osu/beatmaps/packs.js +++ b/lib/v2/osu/beatmaps/packs.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 { type = 'standard' } = ctx.params; @@ -8,10 +8,10 @@ module.exports = async (ctx) => { const link = `https://osu.ppy.sh/beatmaps/packs?type=${type}`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const itemList = $('.beatmap-pack'); - ctx.state.data = { + ctx.set('data', { title: `osu! Beatmap Pack - ${type}`, link, item: itemList.toArray().map((element) => { @@ -31,5 +31,5 @@ module.exports = async (ctx) => { author, }; }), - }; + }); }; diff --git a/lib/v2/otobanana/cast.js b/lib/v2/otobanana/cast.js index 3d92fb271..50002da5c 100644 --- a/lib/v2/otobanana/cast.js +++ b/lib/v2/otobanana/cast.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { apiBase, baseUrl, getUserInfo, renderCast } = require('./utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const casts = castData.results.map((item) => renderCast(item)); - ctx.state.data = { + ctx.set('data', { title: `${userInfo.name} (@${userInfo.username}) - 音声投稿 | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), link: `${baseUrl}/user/${id}`, @@ -20,10 +20,10 @@ module.exports = async (ctx) => { author: userInfo.name, itunes_author: userInfo.name, item: casts, - }; + }); - ctx.state.json = { + ctx.set('json', { userInfo, castData, - }; + }); }; diff --git a/lib/v2/otobanana/livestream.js b/lib/v2/otobanana/livestream.js index e5bea69d9..d47eda905 100644 --- a/lib/v2/otobanana/livestream.js +++ b/lib/v2/otobanana/livestream.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { apiBase, baseUrl, getUserInfo, renderLive } = require('./utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const casts = liveData.results.map((item) => renderLive(item)); - ctx.state.data = { + ctx.set('data', { title: `${userInfo.name} (@${userInfo.username}) - ライブ配信 | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), link: `${baseUrl}/user/${id}`, @@ -20,10 +20,10 @@ module.exports = async (ctx) => { author: userInfo.name, itunes_author: userInfo.name, item: casts, - }; + }); - ctx.state.json = { + ctx.set('json', { userInfo, liveData, - }; + }); }; diff --git a/lib/v2/otobanana/timeline.js b/lib/v2/otobanana/timeline.js index 588e43930..8d1298e97 100644 --- a/lib/v2/otobanana/timeline.js +++ b/lib/v2/otobanana/timeline.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { apiBase, baseUrl, getUserInfo, renderPost } = require('./utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const posts = postData.results.map((item) => renderPost(item)); - ctx.state.data = { + ctx.set('data', { title: `${userInfo.name} (@${userInfo.username}) - タイムライン | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), link: `${baseUrl}/user/${id}`, @@ -20,10 +20,10 @@ module.exports = async (ctx) => { author: userInfo.name, itunes_author: userInfo.name, item: posts, - }; + }); - ctx.state.json = { + ctx.set('json', { userInfo, postData, - }; + }); }; diff --git a/lib/v2/otobanana/utils.js b/lib/v2/otobanana/utils.js index 124d89d1d..9a263c214 100644 --- a/lib/v2/otobanana/utils.js +++ b/lib/v2/otobanana/utils.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 domain = 'otobanana.com'; diff --git a/lib/v2/ouc/it-postgraduate.js b/lib/v2/ouc/it-postgraduate.js index f492dc051..26839b1fd 100644 --- a/lib/v2/ouc/it-postgraduate.js +++ b/lib/v2/ouc/it-postgraduate.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://it.ouc.edu.cn/_s381/16619/list.psp'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.col_news_list .news_list 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/ouc/it-tx.js b/lib/v2/ouc/it-tx.js index 6c61855fa..d31d8707a 100644 --- a/lib/v2/ouc/it-tx.js +++ b/lib/v2/ouc/it-tx.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://it.ouc.edu.cn'; - const id = ctx.params.id || 'xwdt'; + const id = ctx.req.param('id') || 'xwdt'; const link = `${host}/tx/${id}/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const typeTitle = $('span.Column_Anchor').text(); const title = $('li.col_title h2').text(); @@ -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 = '中国海洋大学信息科学与工程学院'; item.description = $('.wp_articlecontent').html(); return item; @@ -35,10 +35,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `信息科学与工程学院团学工作 - ${typeTitle}${title === typeTitle ? '' : title}`, description: '中国海洋大学信息科学与工程学院团学工作', link, item: out, - }; + }); }; diff --git a/lib/v2/ouc/it.js b/lib/v2/ouc/it.js index b018c5bbb..665f5dd22 100644 --- a/lib/v2/ouc/it.js +++ b/lib/v2/ouc/it.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 host = 'https://it.ouc.edu.cn'; const typelist = ['学院要闻', '学院公告', '学术活动']; const urlList = ['xyyw/list.htm', 'xygg/list.htm', 'xshd/list.htm']; - const type = Number.parseInt(ctx.params.type) || 0; + const type = Number.parseInt(ctx.req.param('type')) || 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.col_news_list .news_list li') .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 = '中国海洋大学信息科学与工程学院'; item.description = $('.wp_articlecontent').html(); return item; @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `中国海洋大学信息科学与工程学院${typelist[type]}`, link, item: out, - }; + }); }; diff --git a/lib/v2/ouc/jwc.js b/lib/v2/ouc/jwc.js index b1099775d..61aa7f7c2 100644 --- a/lib/v2/ouc/jwc.js +++ b/lib/v2/ouc/jwc.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'https://jwc.ouc.edu.cn/6517/list.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.wp_article_list li') .toArray() .map((e) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got('https://jwc.ouc.edu.cn' + item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.author = '中国海洋大学教务处'; item.description = $('.wp_articlecontent').html(); return item; @@ -30,10 +30,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '中国海洋大学教务处', link, description: '中国海洋大学教务处最新通知', item: out, - }; + }); }; diff --git a/lib/v2/ouc/jwgl.js b/lib/v2/ouc/jwgl.js index 6f2a88262..b9648825e 100644 --- a/lib/v2/ouc/jwgl.js +++ b/lib/v2/ouc/jwgl.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const link = 'http://jwgl.ouc.edu.cn/public/listSchoolNotices.action?currentPage=1&recordsPerPage=15&qtitle='; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.datalist table tbody tr') .toArray() .map((e) => { @@ -26,17 +26,17 @@ 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 = $('div.notice').html(); return item; }) ) ); - ctx.state.data = { + ctx.set('data', { title: '中国海洋大学选课信息教务通知', link, description: '中国海洋大学选课信息教务通知', item: out, - }; + }); }; diff --git a/lib/v2/ouc/yjs.js b/lib/v2/ouc/yjs.js index a428468b1..30b73ae13 100644 --- a/lib/v2/ouc/yjs.js +++ b/lib/v2/ouc/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.ouc.edu.cn/5926/list.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.wp_article_list li'); - ctx.state.data = { + ctx.set('data', { title: '中国海洋大学研究生院', link, description: '中国海洋大学研究生院通知公告', @@ -23,5 +23,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('.Article_PublishDate').text()), }; }), - }; + }); }; diff --git a/lib/v2/oup/index.js b/lib/v2/oup/index.js index a8191159b..01b150bed 100644 --- a/lib/v2/oup/index.js +++ b/lib/v2/oup/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'; const path = require('path'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const rootUrl = 'https://academic.oup.com'; module.exports = async (ctx) => { - const name = ctx.params.name; + const name = ctx.req.param('name'); const url = `${rootUrl}/${name}/issue`; const response = await got(url); const cookies = response.headers['set-cookie'].map((item) => item.split(';')[0]).join(';'); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.al-article-items') .map((_, item) => ({ title: $(item).find('a.at-articleLink').text(), @@ -28,7 +28,7 @@ module.exports = async (ctx) => { Cookie: cookies, }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('a.linked-name.js-linked-name-trigger').text(); item.description = art(path.join(__dirname, 'templates/article.art'), { @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `OUP - ${name}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/outagereport/index.js b/lib/v2/outagereport/index.js index d69c54368..d43d21627 100644 --- a/lib/v2/outagereport/index.js +++ b/lib/v2/outagereport/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const baseUrl = 'https://outage.report/'; module.exports = async (ctx) => { - const serviceName = ctx.params.name; // Which service do you want to monitor? Have to be the same as what it appears in URL. - const watchCount = ctx.params.count || 10; // How many reports is received during last 20 minutes? 10 reports as default. + const serviceName = ctx.req.param('name'); // Which service do you want to monitor? Have to be the same as what it appears in URL. + const watchCount = ctx.req.param('count') || 10; // How many reports is received during last 20 minutes? 10 reports as default. const url = `${baseUrl}${serviceName}`; const response = await got({ method: 'get', @@ -41,11 +41,11 @@ module.exports = async (ctx) => { } // how this RSS feed looks like - ctx.state.data = { + ctx.set('data', { title: `Is ${serviceName} Down Right Now?`, link: url, description: rssDescribe, item: outageHistory, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/panewslab/author.js b/lib/v2/panewslab/author.js index e5608461a..9018f241c 100644 --- a/lib/v2/panewslab/author.js +++ b/lib/v2/panewslab/author.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 id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.query.limit ?? 25}&LId=1&tw=0&uid=${id}`; + const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.req.query('limit') ?? 25}&LId=1&tw=0&uid=${id}`; const currentUrl = `${rootUrl}/zh/author/${id}.html`; const response = await got({ @@ -31,7 +31,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description += content('#txtinfo').html(); @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `PANews - ${items[0].author}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/panewslab/index.js b/lib/v2/panewslab/index.js index 0e8d52aa5..fc34cce18 100644 --- a/lib/v2/panewslab/index.js +++ b/lib/v2/panewslab/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 categories = { 精选: '', @@ -18,10 +18,10 @@ const categories = { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? '精选'; + const category = ctx.req.param('category') ?? '精选'; const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/webapi/depth/list?LId=1&Rn=${ctx.query.limit ?? 25}&TagId=${categories[category]}&tw=0`; + const apiUrl = `${rootUrl}/webapi/depth/list?LId=1&Rn=${ctx.req.query('limit') ?? 25}&TagId=${categories[category]}&tw=0`; const currentUrl = `${rootUrl}/zh/profundity/index.html`; const response = await got({ @@ -46,7 +46,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description += content('#txtinfo').html(); @@ -55,9 +55,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `PANews - ${category}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/panewslab/news.js b/lib/v2/panewslab/news.js index 2d861c418..255cb332e 100644 --- a/lib/v2/panewslab/news.js +++ b/lib/v2/panewslab/news.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 rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/webapi/flashnews?LId=1&Rn=${ctx.query.limit ?? 50}&tw=0`; + const apiUrl = `${rootUrl}/webapi/flashnews?LId=1&Rn=${ctx.req.query('limit') ?? 50}&tw=0`; const currentUrl = `${rootUrl}/zh/news/index.html`; const response = await got({ @@ -20,9 +20,9 @@ module.exports = async (ctx) => { category: item.tags, })); - ctx.state.data = { + ctx.set('data', { title: 'PANews - 快讯', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/panewslab/topic.js b/lib/v2/panewslab/topic.js index a35c73ac7..6a4a61921 100644 --- a/lib/v2/panewslab/topic.js +++ b/lib/v2/panewslab/topic.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 id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://panewslab.com'; - const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.query.limit ?? 25}&LId=1&sid=${id}&tw=0`; + const apiUrl = `${rootUrl}/webapi/subject/articles?Rn=${ctx.req.query('limit') ?? 25}&LId=1&sid=${id}&tw=0`; const currentUrl = `${rootUrl}/zh/topiclist/${id}.html`; const response = await got({ @@ -31,7 +31,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description += content('#txtinfo').html(); @@ -40,9 +40,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `PANews - ${id}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/papers/index.js b/lib/v2/papers/index.js index 5675e2fc0..17e7c96bf 100644 --- a/lib/v2/papers/index.js +++ b/lib/v2/papers/index.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 = 'arxiv/cs.CL' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 150; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 150; const rootUrl = 'https://papers.cool'; const currentUrl = new URL(category, rootUrl).href; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const pubDate = parseDate( $('p.info') @@ -64,7 +64,7 @@ module.exports = async (ctx) => { const title = $('title').text(); const icon = new URL('favicon.ico', rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: title.split(/-/)[0].trim(), link: currentUrl, @@ -72,5 +72,5 @@ module.exports = async (ctx) => { icon, logo: icon, subtitle: $('h1').first().text(), - }; + }); }; diff --git a/lib/v2/paradigm/writing.js b/lib/v2/paradigm/writing.js index 5c5e3ce0f..6836b6ff7 100644 --- a/lib/v2/paradigm/writing.js +++ b/lib/v2/paradigm/writing.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.paradigm.xyz'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const url = `${baseUrl}/writing`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const buildId = nextData.buildId; @@ -25,7 +25,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.api); - const $ = cheerio.load(response.data.pageProps.content, null, false); + const $ = load(response.data.pageProps.content, null, false); // Remove the TOC $('.toc').remove(); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Paradigm - Writing', link: url, item: items, - }; + }); }; diff --git a/lib/v2/parliament/section77.js b/lib/v2/parliament/section77.js index 6ceeaf22d..93de26699 100644 --- a/lib/v2/parliament/section77.js +++ b/lib/v2/parliament/section77.js @@ -1,6 +1,6 @@ -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 { CookieJar } = require('tough-cookie'); module.exports = async (ctx) => { @@ -53,7 +53,7 @@ module.exports = async (ctx) => { url, cookieJar, }); - const $ = cheerio.load(response); + const $ = load(response); if ($.text() === 'ยังไม่มีข้อมูล') { return result; @@ -84,7 +84,7 @@ module.exports = async (ctx) => { url: item.link, cookieJar, }); - const $ = cheerio.load(response); + const $ = load(response); // Select the first element with the class name 'comment-body' item.title = $('.title h5').first().text(); diff --git a/lib/v2/patagonia/new-arrivals.js b/lib/v2/patagonia/new-arrivals.js index d6947ed57..bf548729c 100644 --- a/lib/v2/patagonia/new-arrivals.js +++ b/lib/v2/patagonia/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.patagonia.com'; const categoryMap = { mens: ['mens-new', 'mens-new-arrivals'], @@ -28,7 +28,7 @@ module.exports = async (ctx) => { }); const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('.product') .map(function () { const data = {}; @@ -47,7 +47,7 @@ module.exports = async (ctx) => { return data; }) .get(); - ctx.state.data = { + ctx.set('data', { title: `Patagonia - New Arrivals - ${category.toUpperCase()}`, link: `${host}/shop/${categoryMap[category][1]}`, description: `Patagonia - New Arrivals - ${category.toUpperCase()}`, @@ -57,5 +57,5 @@ module.exports = async (ctx) => { link: item.link, category: item.category, })), - }; + }); }; diff --git a/lib/v2/paulgraham/article.js b/lib/v2/paulgraham/article.js index c223a0109..ace6713d9 100644 --- a/lib/v2/paulgraham/article.js +++ b/lib/v2/paulgraham/article.js @@ -1,16 +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'; module.exports = async (ctx) => { - 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 = 'http://paulgraham.com'; const currentUrl = new URL('articles.html', rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('font a') .slice(0, limit) @@ -29,7 +29,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 description = content('font').first(); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { const title = $('title').text(); const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${title}`, link: currentUrl, @@ -58,5 +58,5 @@ module.exports = async (ctx) => { subtitle: title, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/penguin-random-house/articles.js b/lib/v2/penguin-random-house/articles.js index 86e8afe13..d05cbc288 100644 --- a/lib/v2/penguin-random-house/articles.js +++ b/lib/v2/penguin-random-house/articles.js @@ -1,11 +1,11 @@ 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 link = 'https://www.penguinrandomhouse.com/articles/'; const res = await got(link); - const $ = cheerio.load(res.data); + const $ = load(res.data); const itemArray = $('.archive-module-half-container,.archive-module-third-container') .map(function () { @@ -18,10 +18,10 @@ module.exports = async (ctx) => { const out = await utils.parseList(itemArray, ctx, utils.parseArticle); - ctx.state.data = { + ctx.set('data', { title: 'Penguin Random House Articles', link, description: 'In-depth interviews, author essays, fascinating essays. Go deeper into the books you love.', item: out, - }; + }); }; diff --git a/lib/v2/penguin-random-house/thereaddown.js b/lib/v2/penguin-random-house/thereaddown.js index b6ecd28b4..c6ccc0a28 100644 --- a/lib/v2/penguin-random-house/thereaddown.js +++ b/lib/v2/penguin-random-house/thereaddown.js @@ -1,11 +1,11 @@ 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 link = 'https://www.penguinrandomhouse.com/the-read-down/'; const res = await got(link); - const $ = cheerio.load(res.data); + const $ = load(res.data); const itemArray = $('.archive-module-half-container,.archive-module-third-container') .map(function () { @@ -18,10 +18,10 @@ module.exports = async (ctx) => { const out = await utils.parseList(itemArray, ctx, utils.parseBooks); - ctx.state.data = { + ctx.set('data', { title: 'Penguin Random House Book Lists', link, description: 'Never wonder what to read next! Check out these lists to find your next favorite book.', item: out, - }; + }); }; diff --git a/lib/v2/penguin-random-house/utils.js b/lib/v2/penguin-random-house/utils.js index 2c6012542..adf244fad 100644 --- a/lib/v2/penguin-random-house/utils.js +++ b/lib/v2/penguin-random-house/utils.js @@ -1,11 +1,11 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const parseBookInList = (element) => { - const $ = cheerio.load(element); + const $ = load(element); const title = $('h2').first().text(); const author = $('h2.author').first().text(); const description = $('.desc').first().text(); @@ -48,7 +48,7 @@ const parsePubDate = (data) => { }; const parseBooks = (element) => { - const $ = cheerio.load(element); + const $ = load(element); const description = $('h2.read-down-text').first().html(); let mainBlock = ''; @@ -66,7 +66,7 @@ const parseBooks = (element) => { }; const parseArticle = (element) => { - const $ = cheerio.load(element); + const $ = load(element); const description = $('h2.hdr-smalltxt').first().html(); const imageSrc = $('div.img-block>img').first().attr('src'); const imageAlt = $('div.img-block>img').first().attr('alt'); @@ -79,7 +79,7 @@ const parseArticle = (element) => { }); $('div.main-content>p,div.main-content>ul').map((i, element) => { - const appending = cheerio.load(element); + const appending = load(element); mainBlock += appending.html(); return appending; }); diff --git a/lib/v2/people/index.js b/lib/v2/people/index.js index db0591f64..eb3078afd 100644 --- a/lib/v2/people/index.js +++ b/lib/v2/people/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 timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { @@ -10,7 +10,7 @@ module.exports = async (ctx) => { let { category = site === 'www' ? '59476' : '' } = ctx.params; category = site === 'cpc' && category === '24h' ? '87228' : category; - 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; if (!isValidHost(site)) { throw new Error('Invalid site'); @@ -22,7 +22,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response, 'gbk')); + const $ = load(iconv.decode(response, 'gbk')); $('em').remove(); $('.bshare-more, .page_n, .page').remove(); @@ -55,7 +55,7 @@ module.exports = async (ctx) => { }); const data = iconv.decode(detailResponse, 'gbk'); - const content = cheerio.load(data); + const content = load(data); content('.paper_num, #rwb_tjyd').remove(); @@ -70,9 +70,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/people/liuyan.js b/lib/v2/people/liuyan.js index 724882a6d..f1f4585d0 100644 --- a/lib/v2/people/liuyan.js +++ b/lib/v2/people/liuyan.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 fid = ctx.params.id; - const state = ctx.params.state ?? '1'; + const fid = ctx.req.param('id'); + const state = ctx.req.param('state') ?? '1'; const rootUrl = 'http://liuyan.people.com.cn'; const currentUrl = `${rootUrl}/threads/list?fid=${fid}#state=${state}`; @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.content').html(); currentForum = currentForum ?? content('#currentForum').text(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${currentForum} - 领导留言板 - 人民网`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/people/xjpjh.js b/lib/v2/people/xjpjh.js index 874b7e057..5364519f7 100644 --- a/lib/v2/people/xjpjh.js +++ b/lib/v2/people/xjpjh.js @@ -1,12 +1,12 @@ -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://jhsjk.people.cn'; module.exports = async (ctx) => { - let keyword = ctx.params.keyword || 'all'; - let year = ctx.params.year || 0; + let keyword = ctx.req.param('keyword') || 'all'; + let year = ctx.req.param('year') || 0; let title = '习近平系列重要讲话'; title = title + '-' + keyword; @@ -23,7 +23,7 @@ module.exports = async (ctx) => { const link = `http://jhsjk.people.cn/result?keywords=${keyword}&year=${year}`; const response = await got.get(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul.list_14.p1_2.clearfix li') .slice(0, 10) @@ -47,7 +47,7 @@ module.exports = async (ctx) => { } const response = await got.get(itemUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const description = $('div.d2txt_con.clearfix').html().trim(); const single = { @@ -60,9 +60,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title, link, item: out, - }; + }); }; diff --git a/lib/v2/peopo/topic.js b/lib/v2/peopo/topic.js index e0c84e484..d3a19f0ae 100644 --- a/lib/v2/peopo/topic.js +++ b/lib/v2/peopo/topic.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'; const baseUrl = 'https://www.peopo.org'; module.exports = async (ctx) => { const { topicId = '159' } = ctx.params; const url = `${baseUrl}/topic/${topicId}`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.view-list-title') .toArray() .map((item) => { @@ -23,7 +23,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 = $('#user-info h3').text(); item.category = $('#node-terms .inline li') @@ -37,10 +37,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, language: 'zh-TW', item: items, - }; + }); }; diff --git a/lib/v2/phoronix/index.js b/lib/v2/phoronix/index.js index 45f93e644..ffab2b236 100644 --- a/lib/v2/phoronix/index.js +++ b/lib/v2/phoronix/index.js @@ -1,6 +1,6 @@ const parser = require('@/utils/rss-parser'); -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const dayjs = require('dayjs'); dayjs.extend(require('dayjs/plugin/utc')); dayjs.extend(require('dayjs/plugin/timezone')); @@ -41,7 +41,7 @@ const feedFetch = async () => { }; const webFetchCb = (response) => { - const $ = cheerio.load(response.body); + const $ = load(response.body); return { title: $('title').text(), link: response.url, @@ -129,7 +129,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(`${articleCacheKey}:${item.link}`, async () => { const response = await got(item.link); const html = response.body; - const $ = cheerio.load(html); + const $ = load(html); const content = $('.content'); // Author @@ -191,7 +191,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(link, async () => { const response = await got(link); const html = response.data; - const $$ = cheerio.load(html); + const $$ = load(html); const page = $$('.content'); return page.html(); }) diff --git a/lib/v2/pianyuan/app.js b/lib/v2/pianyuan/app.js index 9c68f4f2c..2dde299a4 100644 --- a/lib/v2/pianyuan/app.js +++ b/lib/v2/pianyuan/app.js @@ -1,8 +1,8 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const utils = require('./utils'); module.exports = async (ctx) => { - const media = ctx.params.media ?? -1; + const media = ctx.req.param('media') ?? -1; const link_base = 'https://pianyuan.org/'; let description = '电影和剧集'; let link = link_base; @@ -18,17 +18,17 @@ module.exports = async (ctx) => { } const response = await utils.request(link, ctx.cache); - const $ = cheerio.load(response.data); + const $ = load(response.data); const detailLinks = $('#main-container > div > div.col-md-10 > table > tbody > tr') .get() .map((tr) => $(tr).find('td.dt.prel.nobr > a').attr('href')); detailLinks.shift(); const items = await utils.ProcessFeed(detailLinks, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '片源网', description, link: link_base, item: items, - }; + }); }; diff --git a/lib/v2/pianyuan/search.js b/lib/v2/pianyuan/search.js index 4f72607f0..c5b30dea3 100644 --- a/lib/v2/pianyuan/search.js +++ b/lib/v2/pianyuan/search.js @@ -1,4 +1,4 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const utils = require('./utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = link_base + `search?q=${searchKey}`; const response = await utils.request(link, ctx.cache); - const $ = cheerio.load(response.data); + const $ = load(response.data); // 只获取第一页的搜索结果 const searchLinks = $('.nomt > a') .get() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { const link = new URL(e, link_base).href; const single = await ctx.cache.tryGet(link, async () => { const res = await utils.request(link, ctx.cache); - const content = cheerio.load(res.data); + const content = load(res.data); content('.ico.ico_bt') .get() .map((a) => detailLinks.push($(a).attr('href'))); @@ -36,10 +36,10 @@ module.exports = async (ctx) => { const items = await utils.ProcessFeed(detailLinks, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '片源网', description, link: link_base, item: items, - }; + }); }; diff --git a/lib/v2/pianyuan/utils.js b/lib/v2/pianyuan/utils.js index 994a99850..5aff5b27e 100644 --- a/lib/v2/pianyuan/utils.js +++ b/lib/v2/pianyuan/utils.js @@ -1,6 +1,6 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const config = require('@/config').value; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { config } from '@/config'; const security_key = 'pianyuan-security_session_verify'; const PHPSESSID_key = 'pianyuan-PHPSESSID'; const loginauth_key = 'pianyuan-py_loginauth'; @@ -13,7 +13,7 @@ const ProcessFeed = async (list, cache) => { const link = new URL(e, link_base).href; const single = await cache.tryGet(link, async () => { const response = await request(link, cache); - const content = cheerio.load(response.data); + const content = load(response.data); const magnet = content('.btn-primary').attr('href'); const torrent_name = content('body > div.jumbotron.masthead > div > div > div.col-sm-10.col-md-10.col-lg-10.text-left > h1').text(); const name = content('body > div.jumbotron.masthead > div > div > div.col-sm-10.col-md-10.col-lg-10.text-left > h2 > a').text(); diff --git a/lib/v2/picnob/user.js b/lib/v2/picnob/user.js index f8c4dc29e..169b10d8a 100644 --- a/lib/v2/picnob/user.js +++ b/lib/v2/picnob/user.js @@ -1,16 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const { puppeteerGet } = require('./utils'); +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const baseUrl = 'https://www.picnob.com'; const { id } = ctx.params; const url = `${baseUrl}/profile/${id}/`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); // TODO: can't bypass cloudflare 403 error without puppeteer let html; let usePuppeteer = false; @@ -28,7 +29,7 @@ module.exports = async (ctx) => { usePuppeteer = true; } } - const $ = cheerio.load(html); + const $ = load(html); const profileName = $('h1.fullname').text(); const userId = $('input[name=userid]').attr('value'); @@ -61,7 +62,7 @@ module.exports = async (ctx) => { const { data } = await got(link); html = data; } - const $ = cheerio.load(html); + const $ = load(html); return [ ...new Set( $('.post_slide a') @@ -88,11 +89,11 @@ module.exports = async (ctx) => { ); await browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${profileName} (@${id}) - Picnob`, description: $('.info .sum').text(), link: url, image: $('.ava .pic img').attr('src'), item: list, - }; + }); }; diff --git a/lib/v2/picuki/profile.js b/lib/v2/picuki/profile.js index a65d6c61c..98ca28a93 100644 --- a/lib/v2/picuki/profile.js +++ b/lib/v2/picuki/profile.js @@ -1,12 +1,13 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const chrono = require('chrono-node'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; const { puppeteerGet } = require('./utils'); +import puppeteer from '@/utils/puppeteer'; function deVideo(media) { - const $ = cheerio.load(media); + const $ = load(media); let media_deVideo = ''; $('img,video').each((_, medium) => { const tag = medium.name; @@ -20,11 +21,11 @@ function deVideo(media) { module.exports = async (ctx) => { // use Puppeteer due to the obstacle by cloudflare challenge - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); - const id = ctx.params.id; - const displayVideo = ctx.params.functionalFlag !== '0'; - const includeStories = ctx.params.functionalFlag === '10'; + const id = ctx.req.param('id'); + const displayVideo = ctx.req.param('functionalFlag') !== '0'; + const includeStories = ctx.req.param('functionalFlag') === '10'; const profileUrl = `https://www.picuki.com/profile/${id}`; @@ -37,7 +38,7 @@ module.exports = async (ctx) => { config.cache.routeExpire, false ); - const $ = cheerio.load(data); + const $ = load(data); const profileName = $('.profile-name-bottom').text(); const profileImg = $('.profile-avatar > img').attr('src'); @@ -99,7 +100,7 @@ module.exports = async (ctx) => { // re-cache it await ctx.cache.set(url, data); } - const $ = cheerio.load(data); + const $ = load(data); // Instagram 允许最多 10 条图片/视频任意混合于一条 post,picuki 在所有情况下都会将它(们)置于 .single-photo 内 let html = ''; $('.single-photo img').each((_, item) => { @@ -161,11 +162,11 @@ module.exports = async (ctx) => { await browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${profileName} (@${id}) - Picuki`, link: profileUrl, image: profileImg, description: profileDescription, item: items, - }; + }); }; diff --git a/lib/v2/pikabu/community.js b/lib/v2/pikabu/community.js index 45c71feae..cddda1317 100644 --- a/lib/v2/pikabu/community.js +++ b/lib/v2/pikabu/community.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, fixImage, fixVideo } = require('./utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const { data: response } = await got(`${baseUrl}/ajax/${type}/${name}${sortString}`); const items = response.data.stories.map((story) => { - const $ = cheerio.load(story.html, null, false); + const $ = load(story.html, null, false); const data = JSON.parse($('script[type="application/ld+json"]').text()); const content = $('.story__main'); @@ -28,10 +28,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: response.data.title, link: `${baseUrl}/${type}/${name}`, language: 'ru-RU', item: items, - }; + }); }; diff --git a/lib/v2/pikabu/user.js b/lib/v2/pikabu/user.js index 25fbbd6fc..3b7324d87 100644 --- a/lib/v2/pikabu/user.js +++ b/lib/v2/pikabu/user.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 { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const { baseUrl, fixImage, fixVideo } = require('./utils'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { }); const charset = response.headers['content-type'].match(/charset=([\w-]+)/)[1]; // windows-1251 - const $ = cheerio.load(iconv.decode(response.data, charset)); + const $ = load(iconv.decode(response.data, charset)); const items = $('.story__main') .not('.story__placeholder') @@ -35,12 +35,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('meta[property="og:title"]').attr('content'), description: $('.profile__user-about-content').text(), image: $('meta[property="og:image"]').attr('content'), language: 'ru-RU', link, item: items, - }; + }); }; diff --git a/lib/v2/pikabu/utils.js b/lib/v2/pikabu/utils.js index d5acaafe6..f9379ce9d 100644 --- a/lib/v2/pikabu/utils.js +++ b/lib/v2/pikabu/utils.js @@ -1,4 +1,4 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const baseUrl = 'https://pikabu.ru'; diff --git a/lib/v2/pincong/hot.js b/lib/v2/pincong/hot.js index cfaa8caa8..64da97c30 100644 --- a/lib/v2/pincong/hot.js +++ b/lib/v2/pincong/hot.js @@ -1,5 +1,5 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); module.exports = async (ctx) => { @@ -10,10 +10,10 @@ module.exports = async (ctx) => { // use Puppeteer due to the obstacle by cloudflare challenge const html = await puppeteerGet(url, ctx.cache); - const $ = cheerio.load(html); + const $ = load(html); const list = $('div.aw-item'); - ctx.state.data = { + ctx.set('data', { title: '品葱 - 精选', link: `${baseUrl}/hot/${category === '0' ? '' : `category-${category}`}`, item: list @@ -24,5 +24,5 @@ module.exports = async (ctx) => { pubDate: parseDate($(item).find('div.mod-footer .aw-small-text').text()), })) .get(), - }; + }); }; diff --git a/lib/v2/pincong/index.js b/lib/v2/pincong/index.js index 90af5e800..0f7b243f0 100644 --- a/lib/v2/pincong/index.js +++ b/lib/v2/pincong/index.js @@ -1,5 +1,5 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); module.exports = async (ctx) => { @@ -11,16 +11,16 @@ module.exports = async (ctx) => { hot: 'sort_type-hot__day2', }; - url += (ctx.params.sort && sortMap[ctx.params.sort]) || 'recommend-1'; - url += ctx.params.category ? '__category-' + ctx.params.category : ''; + url += (ctx.req.param('sort') && sortMap[ctx.req.param('sort')]) || 'recommend-1'; + url += ctx.req.param('category') ? '__category-' + ctx.req.param('category') : ''; // use Puppeteer due to the obstacle by cloudflare challenge const html = await puppeteerGet(url, ctx.cache); - const $ = cheerio.load(html); + const $ = load(html); const list = $('div.aw-item'); - ctx.state.data = { + ctx.set('data', { title: '品葱 - 发现', link: url, item: list @@ -30,5 +30,5 @@ module.exports = async (ctx) => { pubDate: parseDate($(item).attr('data-created-at') * 1000), })) .get(), - }; + }); }; diff --git a/lib/v2/pincong/topic.js b/lib/v2/pincong/topic.js index 6f46087f0..f22150bac 100644 --- a/lib/v2/pincong/topic.js +++ b/lib/v2/pincong/topic.js @@ -1,18 +1,18 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); module.exports = async (ctx) => { - const url = `${baseUrl}/topic/${ctx.params.topic}`; + const url = `${baseUrl}/topic/${ctx.req.param('topic')}`; // use Puppeteer due to the obstacle by cloudflare challenge const html = await puppeteerGet(url, ctx.cache); - const $ = cheerio.load(html); + const $ = load(html); const list = $('div.aw-item'); - ctx.state.data = { - title: `品葱 - ${ctx.params.topic}`, + ctx.set('data', { + title: `品葱 - ${ctx.req.param('topic')}`, link: url, item: list .map((_, item) => ({ @@ -21,5 +21,5 @@ module.exports = async (ctx) => { pubDate: parseDate($(item).attr('data-created-at') * 1000), })) .get(), - }; + }); }; diff --git a/lib/v2/pincong/utils.js b/lib/v2/pincong/utils.js index abcef2837..b3aa91667 100644 --- a/lib/v2/pincong/utils.js +++ b/lib/v2/pincong/utils.js @@ -1,8 +1,10 @@ +import puppeteer from '@/utils/puppeteer'; + const baseUrl = 'https://pincong.rocks'; const puppeteerGet = (url, cache) => cache.tryGet(url, async () => { - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { diff --git a/lib/v2/pingwest/status.js b/lib/v2/pingwest/status.js index b535e2698..3efa06de3 100644 --- a/lib/v2/pingwest/status.js +++ b/lib/v2/pingwest/status.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.pingwest.com'; @@ -13,12 +13,12 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(response.data.data.list); + const $ = load(response.data.data.list); const items = $('section.item') .toArray() .map((ele) => { const timestamp = ele.attribs['data-t']; - const $item = cheerio.load(ele); + const $item = load(ele); const rightNode = $item('.news-info'); const tag = rightNode.find('.item-tag-list').text(); const title = rightNode.find('.title').text(); @@ -38,10 +38,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: '品玩 - 实时要闻', description: '品玩 - 实时要闻', link: `${baseUrl}/status`, item: items, - }; + }); }; diff --git a/lib/v2/pingwest/tag.js b/lib/v2/pingwest/tag.js index 7b2958813..84f0a3907 100644 --- a/lib/v2/pingwest/tag.js +++ b/lib/v2/pingwest/tag.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); module.exports = async (ctx) => { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const tagId = $('.tag-detail').attr('data-id'); const tagName = $('.tag-detail .info .title').text(); return { tagId, tagName }; @@ -31,13 +31,13 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data.data.list); + const $ = load(response.data.data.list); const items = await utils.articleListParser($, needFullText, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: `品玩 - ${tagName}`, description: `品玩 - ${tagName}`, link: tagUrl, item: items, - }; + }); }; diff --git a/lib/v2/pingwest/user.js b/lib/v2/pingwest/user.js index 58f8c21ee..7722ee74d 100644 --- a/lib/v2/pingwest/user.js +++ b/lib/v2/pingwest/user.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const utils = require('./utils'); module.exports = async (ctx) => { @@ -12,7 +12,7 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const userInfoNode = $('#J_userId'); return { userName: userInfoNode.text(), @@ -32,7 +32,7 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(response.data.data.list); + const $ = load(response.data.data.list); let item = []; const needFullText = option === 'fulltext'; @@ -49,11 +49,11 @@ module.exports = async (ctx) => { article: '文章', state: '动态', }; - ctx.state.data = { + ctx.set('data', { title: `品玩 - ${userName} - ${typeToLabel[type]}`, description: userSign, image: userAvatar, link: aimUrl, item, - }; + }); }; diff --git a/lib/v2/pingwest/utils.js b/lib/v2/pingwest/utils.js index 6d63b0c5e..d2b0f229b 100644 --- a/lib/v2/pingwest/utils.js +++ b/lib/v2/pingwest/utils.js @@ -1,7 +1,7 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; const modifiedLink = (link) => (link.startsWith('http') ? link : `https:${link}`); @@ -10,7 +10,7 @@ const statusListParser = ($) => { .toArray() .map((ele) => { const timestamp = ele.attribs.pt; - const $item = cheerio.load(ele); + const $item = load(ele); const mainNode = $item('.news-detail'); const imgsStr = mainNode .find('img') @@ -37,7 +37,7 @@ const articleListParser = async ($, needFullText, cache) => { $('.item') .toArray() .map(async (ele) => { - const $item = cheerio.load(ele); + const $item = load(ele); let titleNode, authorNode; if ($item('.news-detail').children().length <= 2) { @@ -76,7 +76,7 @@ const articleListParser = async ($, needFullText, cache) => { const getFullArticle = (link, cache) => cache.tryGet(link, async () => { const { data } = await got(link); - const $ = cheerio.load(data); + const $ = load(data); $('img').each((_, ele) => { if (ele.attribs.src.includes('?x-')) { ele.attribs.src = ele.attribs.src.split('?x-')[0]; diff --git a/lib/v2/pixabay/search.js b/lib/v2/pixabay/search.js index 5c01c2d31..31b516cf6 100644 --- a/lib/v2/pixabay/search.js +++ b/lib/v2/pixabay/search.js @@ -1,6 +1,6 @@ -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'); module.exports = async (ctx) => { @@ -16,7 +16,7 @@ module.exports = async (ctx) => { key, q, order, - per_page: ctx.query.limit ?? 200, + per_page: ctx.req.query('limit') ?? 200, }, }); return data; @@ -39,12 +39,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Search ${q} - Pixabay`, description: 'Download & use free nature stock photos in high resolution ✓ New free images everyday ✓ HD to 4K ✓ Best nature pictures for all devices on Pixabay', link: `${baseUrl}/images/search/${q}/${order === 'latest' ? '?order=latest' : ''}`, image: `https://pixabay.com/apple-touch-icon.png`, language: 'en', item: items, - }; + }); }; diff --git a/lib/v2/pixiv/bookmarks.js b/lib/v2/pixiv/bookmarks.js index 3b9ebee95..98b28ebb6 100644 --- a/lib/v2/pixiv/bookmarks.js +++ b/lib/v2/pixiv/bookmarks.js @@ -1,16 +1,16 @@ const { getToken } = require('./token'); const getBookmarks = require('./api/get-bookmarks'); const getUserDetail = require('./api/get-user-detail'); -const config = require('@/config').value; +import { config } from '@/config'; const pixivUtils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.pixiv || !config.pixiv.refreshToken) { throw new Error('pixiv RSS is disabled due to the lack of relevant config'); } - const id = ctx.params.id; + const id = ctx.req.param('id'); const token = await getToken(ctx.cache.tryGet); if (!token) { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { const illusts = bookmarksResponse.data.illusts; const username = userDetailResponse.data.user.name; - ctx.state.data = { + ctx.set('data', { title: `${username} 的收藏`, link: `https://www.pixiv.net/users/${id}/bookmarks/artworks`, description: `${username} 的 pixiv 最新收藏`, @@ -36,5 +36,5 @@ module.exports = async (ctx) => { link: `https://www.pixiv.net/artworks/${illust.id}`, }; }), - }; + }); }; diff --git a/lib/v2/pixiv/illustfollow.js b/lib/v2/pixiv/illustfollow.js index 608906024..e9e5c60a6 100644 --- a/lib/v2/pixiv/illustfollow.js +++ b/lib/v2/pixiv/illustfollow.js @@ -1,8 +1,8 @@ const { getToken } = require('./token'); const getIllustFollows = require('./api/get-illust-follows'); -const config = require('@/config').value; +import { config } from '@/config'; const pixivUtils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.pixiv || !config.pixiv.refreshToken) { @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const response = await getIllustFollows(token); const illusts = response.data.illusts; - ctx.state.data = { + ctx.set('data', { title: `Pixiv关注的新作品`, link: 'https://www.pixiv.net/bookmark_new_illust.php', description: `Pixiv关注的画师们的最新作品`, @@ -30,5 +30,5 @@ module.exports = async (ctx) => { link: `https://www.pixiv.net/artworks/${illust.id}`, }; }), - }; + }); }; diff --git a/lib/v2/pixiv/novels.js b/lib/v2/pixiv/novels.js index 884b02fdd..7146279ac 100644 --- a/lib/v2/pixiv/novels.js +++ b/lib/v2/pixiv/novels.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.pixiv.net'; module.exports = async (ctx) => { @@ -37,11 +37,11 @@ module.exports = async (ctx) => { category: item.tags, })); - ctx.state.data = { + ctx.set('data', { title: data.body.extraData.meta.title, description: data.body.extraData.meta.ogp.description, image: Object.values(data.body.works)[0].profileImageUrl, link: url, item: items, - }; + }); }; diff --git a/lib/v2/pixiv/pixiv-got.js b/lib/v2/pixiv/pixiv-got.js index 2195cc350..98b2ec57e 100644 --- a/lib/v2/pixiv/pixiv-got.js +++ b/lib/v2/pixiv/pixiv-got.js @@ -1,8 +1,8 @@ const tls = require('tls'); const ipRegex = require('ip-regex'); -const got = require('@/utils/got'); +import got from '@/utils/got'; const logger = require('@/utils/logger'); -const pixivConfig = require('@/config').value.pixiv; +import { config } from '@/config'; async function dohResolve(name, jsonDohEndpoint) { try { @@ -31,19 +31,19 @@ const pixivGot = got.extend({ hooks: { beforeRequest: [ async (options) => { - if (!pixivConfig.bypassCdn) { + if (!config.pixiv.bypassCdn) { return; } let hostname = null; - const isIP = ipRegex({ exact: true }).test(pixivConfig.bypassCdnHostname); + const isIP = ipRegex({ exact: true }).test(config.pixiv.bypassCdnHostname); if (isIP) { - hostname = pixivConfig.bypassCdnHostname; + hostname = config.pixiv.bypassCdnHostname; } else { - const addresses = await dohResolve(pixivConfig.bypassCdnHostname, pixivConfig.bypassCdnDoh); + const addresses = await dohResolve(config.pixiv.bypassCdnHostname, config.pixiv.bypassCdnDoh); if (addresses.length) { hostname = addresses[Math.floor(addresses.length * Math.random())]; } else { - logger.warn(`No IPv4 address resolved from ${pixivConfig.bypassCdnHostname}`); + logger.warn(`No IPv4 address resolved from ${config.pixiv.bypassCdnHostname}`); } } if (hostname) { diff --git a/lib/v2/pixiv/ranking.js b/lib/v2/pixiv/ranking.js index c56178d5f..8322906b7 100644 --- a/lib/v2/pixiv/ranking.js +++ b/lib/v2/pixiv/ranking.js @@ -1,8 +1,8 @@ const { getToken } = require('./token'); const getRanking = require('./api/get-ranking'); -const config = require('@/config').value; +import { config } from '@/config'; const pixivUtils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; const titles = { day: 'pixiv 日排行', @@ -60,22 +60,22 @@ module.exports = async (ctx) => { throw new Error('pixiv RSS is disabled due to the lack of relevant config'); } - const mode = alias[ctx.params.mode] ?? ctx.params.mode; - const date = ctx.params.date ? new Date(ctx.params.date) : new Date(); + const mode = alias[ctx.req.param('mode')] ?? ctx.req.param('mode'); + const date = ctx.req.param('date') ? new Date(ctx.req.param('date')) : new Date(); const token = await getToken(ctx.cache.tryGet); if (!token) { throw new Error('pixiv not login'); } - const response = await getRanking(mode, ctx.params.date && date, token); + const response = await getRanking(mode, ctx.req.param('date') && date, token); const illusts = response.data.illusts; const dateStr = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 `; - ctx.state.data = { - title: (ctx.params.date ? dateStr : '') + titles[mode], + ctx.set('data', { + title: (ctx.req.param('date') ? dateStr : '') + titles[mode], link: links[mode], description: dateStr + titles[mode], item: illusts.map((illust, index) => { @@ -89,5 +89,5 @@ module.exports = async (ctx) => { category: illust.tags.map((tag) => tag.name), }; }), - }; + }); }; diff --git a/lib/v2/pixiv/search.js b/lib/v2/pixiv/search.js index 8c89dcc90..aa11c7e0e 100644 --- a/lib/v2/pixiv/search.js +++ b/lib/v2/pixiv/search.js @@ -1,18 +1,18 @@ const { getToken } = require('./token'); const searchPopularIllust = require('./api/search-popular-illust'); const searchIllust = require('./api/search-illust'); -const config = require('@/config').value; +import { config } from '@/config'; const pixivUtils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.pixiv || !config.pixiv.refreshToken) { throw new Error('pixiv RSS is disabled due to the lack of relevant config'); } - const keyword = ctx.params.keyword; - const order = ctx.params.order || 'date'; - const mode = ctx.params.mode; + const keyword = ctx.req.param('keyword'); + const order = ctx.req.param('order') || 'date'; + const mode = ctx.req.param('mode'); const token = await getToken(ctx.cache.tryGet); if (!token) { @@ -28,7 +28,7 @@ module.exports = async (ctx) => { illusts = illusts.filter((item) => item.x_restrict === 1); } - ctx.state.data = { + ctx.set('data', { title: `${keyword} 的 pixiv ${order === 'popular' ? '热门' : ''}内容`, link: `https://www.pixiv.net/tags/${keyword}/artworks`, item: illusts.map((illust) => { @@ -42,5 +42,5 @@ module.exports = async (ctx) => { }; }), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/pixiv/token.js b/lib/v2/pixiv/token.js index 87dcec026..85caa503f 100644 --- a/lib/v2/pixiv/token.js +++ b/lib/v2/pixiv/token.js @@ -1,4 +1,4 @@ -const config = require('@/config').value; +import { config } from '@/config'; const logger = require('@/utils/logger'); const got = require('./pixiv-got'); const { maskHeader } = require('./constants'); diff --git a/lib/v2/pixiv/user.js b/lib/v2/pixiv/user.js index 46c2d6eb5..1e2fbfa3e 100644 --- a/lib/v2/pixiv/user.js +++ b/lib/v2/pixiv/user.js @@ -1,15 +1,15 @@ const { getToken } = require('./token'); const getIllusts = require('./api/get-illusts'); -const config = require('@/config').value; +import { config } from '@/config'; const pixivUtils = require('./utils'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { if (!config.pixiv || !config.pixiv.refreshToken) { throw new Error('pixiv RSS is disabled due to the lack of relevant config'); } - const id = ctx.params.id; + const id = ctx.req.param('id'); const token = await getToken(ctx.cache.tryGet); if (!token) { throw new Error('pixiv not login'); @@ -20,7 +20,7 @@ module.exports = async (ctx) => { const illusts = response.data.illusts; const username = illusts[0].user.name; - ctx.state.data = { + ctx.set('data', { title: `${username} 的 pixiv 动态`, link: `https://www.pixiv.net/users/${id}`, description: `${username} 的 pixiv 最新动态`, @@ -35,5 +35,5 @@ module.exports = async (ctx) => { category: illust.tags.map((t) => t.name), }; }), - }; + }); }; diff --git a/lib/v2/pixiv/utils.js b/lib/v2/pixiv/utils.js index 3b6292772..44fc349f1 100644 --- a/lib/v2/pixiv/utils.js +++ b/lib/v2/pixiv/utils.js @@ -1,4 +1,4 @@ -const config = require('@/config').value; +import { config } from '@/config'; module.exports = { getImgs(illust) { diff --git a/lib/v2/piyao/jrpy.js b/lib/v2/piyao/jrpy.js index 58b9dc500..ecf604b47 100644 --- a/lib/v2/piyao/jrpy.js +++ b/lib/v2/piyao/jrpy.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.piyao.org.cn'; @@ -8,7 +8,7 @@ module.exports = async (ctx) => { const currentUrl = `${rootUrl}/jrpy/index.htm`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul#list li') .map((_, item) => ({ title: $(item).find('a').text(), @@ -20,7 +20,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('div.con_tit > h2').text(); item.description = content('div.con_txt').html(); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '今日辟谣', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pkmer/recent.js b/lib/v2/pkmer/recent.js index 8989f6886..d90e4c08d 100644 --- a/lib/v2/pkmer/recent.js +++ b/lib/v2/pkmer/recent.js @@ -1,21 +1,21 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const baseUrl = 'https://pkmer.cn'; module.exports = async (ctx) => { const { data: response } = await got(`${baseUrl}/page/1/`); - const $ = cheerio.load(response); + const $ = load(response); const items = process($); - ctx.state.data = { + ctx.set('data', { title: 'PKMer', icon: 'https://cdn.pkmer.cn/covers/logo.png!nomark', logo: 'https://cdn.pkmer.cn/covers/logo.png!nomark', link: baseUrl, allowEmpty: true, item: items, - }; + }); }; function process($) { diff --git a/lib/v2/pku/bbs/hot.js b/lib/v2/pku/bbs/hot.js index 9fd00a085..0c999815a 100644 --- a/lib/v2/pku/bbs/hot.js +++ b/lib/v2/pku/bbs/hot.js @@ -1,8 +1,8 @@ -const config = require('@/config').value; -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { config } from '@/config'; +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { const cookie = config.pkubbs.cookie; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { headers.cookie = cookie; } const r = await got('https://bbs.pku.edu.cn/v2/hot-topic.php', { headers }); - const $ = cheerio.load(r.body); + const $ = load(r.body); const listItems = $('#list-content .list-item') .map(function () { return { @@ -28,7 +28,7 @@ module.exports = async (ctx) => { // try catch 处理部分无 Cookie 时无法访问的帖子 try { const r = await got(url, { headers }); - const $ = cheerio.load(r.body); + const $ = load(r.body); const date = $('.post-card:first-child .sl-triangle-container .down-list span').text() || $('.post-card:first-child .sl-triangle-container .title span').text(); return { title, @@ -47,10 +47,10 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: '北大未名BBS 全站十大', link: 'https://bbs.pku.edu.cn/v2/hot-topic.php', description: '北大未名BBS 全站热门话题前十名', item, - }; + }); }; diff --git a/lib/v2/pku/cls/announcement.js b/lib/v2/pku/cls/announcement.js index 3476b9d9b..18f6a3ab4 100644 --- a/lib/v2/pku/cls/announcement.js +++ b/lib/v2/pku/cls/announcement.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 homeUrl = 'https://bio.pku.edu.cn/homes/Index/news/21/21.html'; @@ -9,7 +9,7 @@ const baseUrl = 'https://bio.pku.edu.cn'; module.exports = async (ctx) => { const response = await got(homeUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.normal_list>ul a') .toArray() @@ -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 = $('div.page div.common_width div.col-md-9').first().html(); return item; @@ -34,9 +34,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '北京大学生命科学学院通知公告', link: homeUrl, item: items, - }; + }); }; diff --git a/lib/v2/pku/cls/lecture.js b/lib/v2/pku/cls/lecture.js index a22722624..59d81501c 100644 --- a/lib/v2/pku/cls/lecture.js +++ b/lib/v2/pku/cls/lecture.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 homeUrl = 'http://bio.pku.edu.cn/homes/Index/news_jz/7/7.html'; const baseUrl = 'http://bio.pku.edu.cn'; @@ -8,8 +8,8 @@ const baseUrl = 'http://bio.pku.edu.cn'; module.exports = async (ctx) => { const response = await got(homeUrl); - const $ = cheerio.load(response.data); - ctx.state.data = { + const $ = load(response.data); + ctx.set('data', { title: `北京大学生命科学学院近期讲座`, link: homeUrl, description: `北京大学生命科学学院近期讲座`, @@ -21,5 +21,5 @@ module.exports = async (ctx) => { link: baseUrl + $('a.clearfix').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/pku/eecs.js b/lib/v2/pku/eecs.js index 74082468f..e4c8915e8 100644 --- a/lib/v2/pku/eecs.js +++ b/lib/v2/pku/eecs.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 { eecsMap } = require('./utils'); module.exports = async (ctx) => { const host = 'https://eecs.pku.edu.cn'; - let type = ctx.params && Number.parseInt(ctx.params.type); + let type = ctx.params && Number.parseInt(ctx.req.param('type')); if (type === undefined) { type = 0; } const response = await got(host + '/xygk1/ggtz/' + eecsMap.get(type)); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.hvr-shutter-out-vertical') .toArray() .map((item) => { @@ -30,7 +30,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const detail = await got(item.link); - const content = cheerio.load(detail.data); + const content = load(detail.data); content('input').remove(); content('h1').remove(); @@ -55,10 +55,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: host + '/xygk1/ggtz/' + eecsMap.get(type), description: '北大信科 公告通知', item: items, - }; + }); }; diff --git a/lib/v2/pku/hr.js b/lib/v2/pku/hr.js index a2be6f5f4..5e55728a0 100644 --- a/lib/v2/pku/hr.js +++ b/lib/v2/pku/hr.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const category = ctx.params.category?.replace(/-/g, '/') ?? 'zxgg'; + const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'zxgg'; const rootUrl = 'https://hr.pku.edu.cn/'; const currentUrl = `${rootUrl}/${category}/index.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.item-list li 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('.title').remove(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('h2').text()} - ${$('title').text()}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pku/nsd.js b/lib/v2/pku/nsd.js index 30dfac829..53e9aaa44 100644 --- a/lib/v2/pku/nsd.js +++ b/lib/v2/pku/nsd.js @@ -1,7 +1,7 @@ -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'); +import { parseDate } from '@/utils/parse-date'; const baseUrl = 'https://nsd.pku.edu.cn/sylm/gd/'; @@ -22,7 +22,7 @@ const pageType = (href) => { module.exports = async (ctx) => { const response = await got({ url: baseUrl, https: { rejectUnauthorized: false } }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.maincontent > ul > li') .map((_index, item) => { const href = $(item).find('a').attr('href'); @@ -44,14 +44,14 @@ module.exports = async (ctx) => { case 'pku-news': return ctx.cache.tryGet(item.link, async () => { const detailResponse = await got({ url: item.link, https: { rejectUnauthorized: false } }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.pageArticle > div.col.lf').html(); return item; }); case 'in-site': return ctx.cache.tryGet(item.link, async () => { const detailResponse = await got({ url: item.link, https: { rejectUnauthorized: false } }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('div.article').html(); return item; }); @@ -61,9 +61,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '观点 - 北京大学国家发展研究院', link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/pku/pkuyjs.js b/lib/v2/pku/pkuyjs.js index 245446314..0da532df2 100644 --- a/lib/v2/pku/pkuyjs.js +++ b/lib/v2/pku/pkuyjs.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://admission.pku.edu.cn/zsxx/sszs/index.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.zsxx_cont_list li'); - ctx.state.data = { + ctx.set('data', { title: `${$('.twostage_title_C').text()} - ${$('title').text()}`, link, description: '北京大学研究生院通知公告', @@ -25,5 +25,5 @@ module.exports = async (ctx) => { }; }) .get(), - }; + }); }; diff --git a/lib/v2/pku/rccp/mzyt.js b/lib/v2/pku/rccp/mzyt.js index 9d815a32c..894a582c3 100644 --- a/lib/v2/pku/rccp/mzyt.js +++ b/lib/v2/pku/rccp/mzyt.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://www.rccp.pku.edu.cn/mzyt/'; module.exports = async (ctx) => { const response = await got(baseUrl); - const $ = cheerio.load(response.data); - ctx.state.data = { + const $ = load(response.data); + ctx.set('data', { title: '每周一推 - 北京大学中国政治学研究中心', link: baseUrl, description: $('meta[name="description"]').attr('content'), @@ -19,5 +19,5 @@ module.exports = async (ctx) => { link: baseUrl + $(item).find('a').attr('href'), })) .get(), - }; + }); }; diff --git a/lib/v2/pku/scc/recruit.js b/lib/v2/pku/scc/recruit.js index 5a8b5533e..bbe7305d5 100644 --- a/lib/v2/pku/scc/recruit.js +++ b/lib/v2/pku/scc/recruit.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 arr = { xwrd: 'home!newsHome.action?category=12', @@ -13,11 +13,11 @@ const arr = { const baseUrl = 'https://scc.pku.edu.cn/'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'zpxx'; + const type = ctx.req.param('type') ?? 'zpxx'; const rootUrl = baseUrl + arr[type]; const list_response = await got(rootUrl); - const $ = cheerio.load(list_response.data); + const $ = load(list_response.data); const feed_title = $('h2.category').text(); @@ -36,14 +36,14 @@ module.exports = async (ctx) => { const sorted = list.sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime()).slice(0, 10); - ctx.state.data = { + ctx.set('data', { title: `北京大学学生就业指导服务中心 - ${feed_title}`, link: rootUrl, item: await Promise.all( sorted.map((item) => ctx.cache.tryGet(item.link, async () => { const detail_page = await got(item.link); - const detail = cheerio.load(detail_page.data); + const detail = load(detail_page.data); const script = detail('script', 'div#content-div').html(); if (script !== null) { const content_route = script.match(/\$\("#content-div"\).load\("(\S+)"\)/)[1]; @@ -54,5 +54,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/pku/ss/admission.js b/lib/v2/pku/ss/admission.js index b7cd0572c..77ef87cc8 100644 --- a/lib/v2/pku/ss/admission.js +++ b/lib/v2/pku/ss/admission.js @@ -6,10 +6,10 @@ module.exports = async (ctx) => { const items = await getSingleRecord(host); const out = await Promise.all(items.map((item) => getArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: '北大软微-招生通知', description: '北京大学软件与微电子学院 - 招生通知', link: host, item: out, - }; + }); }; diff --git a/lib/v2/pku/ss/common.js b/lib/v2/pku/ss/common.js index d518c7965..a9354eb4d 100644 --- a/lib/v2/pku/ss/common.js +++ b/lib/v2/pku/ss/common.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://www.ss.pku.edu.cn'; const getSingleRecord = async (url) => { const res = await got(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('#info-list-ul').find('li'); return list.toArray().map((item) => { @@ -24,7 +24,7 @@ const getSingleRecord = async (url) => { const getArticle = (item, tryGet) => tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.article-content').html(); return item; diff --git a/lib/v2/pku/ss/notice.js b/lib/v2/pku/ss/notice.js index 71dfeb058..261ee28de 100644 --- a/lib/v2/pku/ss/notice.js +++ b/lib/v2/pku/ss/notice.js @@ -6,10 +6,10 @@ module.exports = async (ctx) => { const items = await getSingleRecord(host); const out = await Promise.all(items.map((item) => getArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: '北大软微-通知公告', description: '北京大学软件与微电子学院 - 通知公告', link: host, item: out, - }; + }); }; diff --git a/lib/v2/pku/ss/pg-admin.js b/lib/v2/pku/ss/pg-admin.js index 2c7fdd801..f4d32f16c 100644 --- a/lib/v2/pku/ss/pg-admin.js +++ b/lib/v2/pku/ss/pg-admin.js @@ -6,10 +6,10 @@ module.exports = async (ctx) => { const items = await getSingleRecord(host); const out = await Promise.all(items.map((item) => getArticle(item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: '北大软微-硕士统考招生', description: '北京大学软件与微电子学院 - 硕士统考招生通知', link: host, item: out, - }; + }); }; diff --git a/lib/v2/playno1/av.js b/lib/v2/playno1/av.js index b8331c995..7d5ac4b8d 100644 --- a/lib/v2/playno1/av.js +++ b/lib/v2/playno1/av.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { cookieJar, processArticle } = require('./utils'); const baseUrl = 'http://www.playno1.com'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const response = await got(url, { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.fire_float') .toArray() @@ -32,10 +32,10 @@ module.exports = async (ctx) => { items = await processArticle(items, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, item: items, language: 'zh-TW', - }; + }); }; diff --git a/lib/v2/playno1/st.js b/lib/v2/playno1/st.js index 3e9df5126..97ccedc00 100644 --- a/lib/v2/playno1/st.js +++ b/lib/v2/playno1/st.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { cookieJar, processArticle } = require('./utils'); const baseUrl = 'http://stno1.playno1.com'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { const response = await got(url, { cookieJar, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.fallsBox') .toArray() @@ -27,10 +27,10 @@ module.exports = async (ctx) => { items = await processArticle(items, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link: url, item: items, language: 'zh-TW', - }; + }); }; diff --git a/lib/v2/playno1/utils.js b/lib/v2/playno1/utils.js index 18c0de2b9..5839d80f7 100644 --- a/lib/v2/playno1/utils.js +++ b/lib/v2/playno1/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 { CookieJar, Cookie } = require('tough-cookie'); const cookieJar = new CookieJar(); const cookie = Cookie.fromJSON({ @@ -19,7 +19,7 @@ const processArticle = (items, cache) => const detailResponse = await got(item.link, { cookieJar, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#article_content').html(); return item; }) diff --git a/lib/v2/playpcesor/rss.js b/lib/v2/playpcesor/rss.js index 6e37e0e42..d6a7e1de2 100644 --- a/lib/v2/playpcesor/rss.js +++ b/lib/v2/playpcesor/rss.js @@ -1,11 +1,11 @@ -const { parseDate } = require('@/utils/parse-date'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const url = 'https://www.playpcesor.com/'; const response = await got({ method: 'get', url }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $("article[class='post-outer-container']") .map((i, e) => { @@ -24,9 +24,9 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title: '电脑玩物', link: url, item: list, - }; + }); }; diff --git a/lib/v2/plurk/anonymous.js b/lib/v2/plurk/anonymous.js index bebf728d3..7fdbc45dc 100644 --- a/lib/v2/plurk/anonymous.js +++ b/lib/v2/plurk/anonymous.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl, getPlurk } = require('./utils'); module.exports = async (ctx) => { const { data: apiResponse } = await got(`${baseUrl}/Stats/getAnonymousPlurks`, { searchParams: { offset: 0, - limit: ctx.query.limit ? Number(ctx.query.limit) : 200, + limit: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 200, }, }); @@ -14,10 +14,10 @@ module.exports = async (ctx) => { const items = await Promise.all(Object.values(apiResponse).map((item) => getPlurk(`plurk:${item.plurk_id}`, item, 'ಠ_ಠ', ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: 'Anonymous - Plurk', image: 'https://s.plurk.com/2c1574c02566f3b06e91.png', link: `${baseUrl}/anonymous`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/hotlinks.js b/lib/v2/plurk/hotlinks.js index 1ae48cc33..292a1f31b 100644 --- a/lib/v2/plurk/hotlinks.js +++ b/lib/v2/plurk/hotlinks.js @@ -1,20 +1,20 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl, getPlurk } = require('./utils'); module.exports = async (ctx) => { const { data: apiResponse } = await got(`${baseUrl}/hotlinks/getLinks`, { searchParams: { offset: 0, - count: ctx.query.limit ? Number(ctx.query.limit) : 30, + count: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30, }, }); const items = await Promise.all(apiResponse.map((item) => getPlurk(item.link_url.startsWith('https://www.plurk.com/p/') ? item.link_url : `plurk:${item.link_url}`, item, null, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `Hot Links - Plurk`, image: 'https://s.plurk.com/2c1574c02566f3b06e91.png', link: `${baseUrl}/hotlinks`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/news.js b/lib/v2/plurk/news.js index f7a163634..024201126 100644 --- a/lib/v2/plurk/news.js +++ b/lib/v2/plurk/news.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl, fetchFriends, getPlurk } = require('./utils'); module.exports = async (ctx) => { @@ -14,10 +14,10 @@ module.exports = async (ctx) => { const items = await Promise.all(apiResponse.map((item) => getPlurk(`plurk:${item.plurk_id}`, item, names[item.user_id].display_name, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: 'Plurk News - Plurk', image: 'https://s.plurk.com/2c1574c02566f3b06e91.png', link: `${baseUrl}/news`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/search.js b/lib/v2/plurk/search.js index 5173d04f1..3749596a3 100644 --- a/lib/v2/plurk/search.js +++ b/lib/v2/plurk/search.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const dayjs = require('dayjs'); const { baseUrl, getPlurk } = require('./utils'); @@ -17,11 +17,11 @@ module.exports = async (ctx) => { const items = await Promise.all(plurks.map((item) => getPlurk(`plurk:${item.plurk_id}`, item, users[item.user_id].display_name, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `Search "${keyword}" - Plurk`, description: 'Search messages on Plurk', image: 'https://s.plurk.com/e8266f512246cdbc2721.jpg', link: `${baseUrl}/search?q=${encodeURIComponent(keyword)}`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/top.js b/lib/v2/plurk/top.js index 4b1639c1a..0732ac270 100644 --- a/lib/v2/plurk/top.js +++ b/lib/v2/plurk/top.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { baseUrl, getPlurk } = require('./utils'); const categoryList = new Set(['topReplurks', 'topFavorites', 'topResponded']); @@ -13,17 +13,17 @@ module.exports = async (ctx) => { searchParams: { period: 'day', lang, - limit: ctx.query.limit ? Number(ctx.query.limit) : 90, + limit: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 90, }, }); const items = await Promise.all(apiResponse.stats.map((item) => item[1]).map((item) => getPlurk(`plurk:${item.plurk_id}`, item, item.owner.display_name, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: 'Top Plurk - Plurk', image: 'https://s.plurk.com/2c1574c02566f3b06e91.png', link: `${baseUrl}/top#${category}`, item: items, language: lang, - }; + }); }; diff --git a/lib/v2/plurk/topic.js b/lib/v2/plurk/topic.js index 67c4d0b44..3d7326777 100644 --- a/lib/v2/plurk/topic.js +++ b/lib/v2/plurk/topic.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, fetchFriends, getPlurk } = require('./utils'); module.exports = async (ctx) => { @@ -9,11 +9,11 @@ module.exports = async (ctx) => { searchParams: { topic, offset: 0, - limit: ctx.query.limit ? Number(ctx.query.limit) : 30, + limit: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 30, }, }); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); delete apiResponse.pids; delete apiResponse.count; @@ -23,11 +23,11 @@ module.exports = async (ctx) => { const items = await Promise.all(Object.values(apiResponse).map((item) => getPlurk(`plurk:${item.plurk_id}`, item, names[item.user_id].display_name, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[property=og:description]').attr('content'), image: $('meta[property=og:image]').attr('content') || $('meta[name=msapplication-TileImage]').attr('content'), link: `${baseUrl}/topic/${topic}`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/user.js b/lib/v2/plurk/user.js index 35136fbc7..7d2ca876f 100644 --- a/lib/v2/plurk/user.js +++ b/lib/v2/plurk/user.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { baseUrl, fetchFriends, getPlurk } = require('./utils'); module.exports = async (ctx) => { const { user } = ctx.params; const { data: pageResponse } = await got(`${baseUrl}/${user}`); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const publicPlurks = JSON.parse( $('body script[type]') @@ -21,11 +21,11 @@ module.exports = async (ctx) => { const items = await Promise.all(publicPlurks.map((item) => getPlurk(`plurk:${item.plurk_id}`, item, names[item.user_id].display_name, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[property=og:description]').attr('content'), image: $('meta[property=og:image]').attr('content') || $('meta[name=msapplication-TileImage]').attr('content'), link: `${baseUrl}/${user}`, item: items, - }; + }); }; diff --git a/lib/v2/plurk/utils.js b/lib/v2/plurk/utils.js index d436bd2b1..3fb2ef39f 100644 --- a/lib/v2/plurk/utils.js +++ b/lib/v2/plurk/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://www.plurk.com'; @@ -29,7 +29,7 @@ const fetchFriends = async (userIds) => { */ const getPlurk = (plurkGuid, item, author, tryGet) => tryGet(plurkGuid, () => { - const $ = cheerio.load(item.content || item.rendered, null, false); + const $ = load(item.content || item.rendered, null, false); $('img').each((_, e) => { e = $(e); e.removeAttr('height').removeAttr('width'); diff --git a/lib/v2/pnas/index.js b/lib/v2/pnas/index.js index 366e2753c..3d01ce639 100644 --- a/lib/v2/pnas/index.js +++ b/lib/v2/pnas/index.js @@ -1,11 +1,12 @@ -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 { setCookies } = require('@/utils/puppeteer-utils'); const { CookieJar } = require('tough-cookie'); const logger = require('@/utils/logger'); +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const baseUrl = 'https://www.pnas.org'; @@ -22,7 +23,7 @@ module.exports = async (ctx) => { await ctx.cache.set('pnas:cookieJar', cookieJar.toJSON()); } - const $ = cheerio.load(res); + const $ = load(res); const list = $('.card--row-reversed .card-content') .toArray() .map((item) => { @@ -35,7 +36,7 @@ module.exports = async (ctx) => { }; }); - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const out = await Promise.all( list.map((item) => @@ -56,7 +57,7 @@ module.exports = async (ctx) => { const res = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const $ = cheerio.load(res); + const $ = load(res); const PNASdataLayer = JSON.parse( $('script') .text() @@ -90,12 +91,12 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${$('.banner-widget__content h1').text()} - PNAS`, description: $('.banner-widget__content p').text(), image: 'https://www.pnas.org/favicon.ico', language: 'en-US', link, item: out, - }; + }); }; diff --git a/lib/v2/pornhub/category-url.js b/lib/v2/pornhub/category-url.js index 8640648fd..7e97325b8 100644 --- a/lib/v2/pornhub/category-url.js +++ b/lib/v2/pornhub/category-url.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); const { headers, parseItems } = require('./utils'); @@ -11,15 +11,15 @@ module.exports = async (ctx) => { } const { data: response } = await got(link, { headers }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('#videoCategory .videoBox') .toArray() .map((e) => parseItems($(e))); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/pornhub/category.js b/lib/v2/pornhub/category.js index bdad4f120..0358fcc7c 100644 --- a/lib/v2/pornhub/category.js +++ b/lib/v2/pornhub/category.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 { defaultDomain, renderDescription } = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; module.exports = async (ctx) => { - const category = ctx.params.caty; + const category = ctx.req.param('caty'); const categories = await ctx.cache.tryGet('pornhub:categories', async () => { const { data } = await got(`${defaultDomain}/webmasters/categories`); @@ -36,9 +36,9 @@ module.exports = async (ctx) => { category: [...new Set([...item.tags.map((t) => t.tag_name), ...item.categories.map((c) => c.category)])], })); - ctx.state.data = { + ctx.set('data', { title: `Pornhub - ${categoryName}`, link: `${defaultDomain}/video?c=${categoryId}`, item: list, - }; + }); }; diff --git a/lib/v2/pornhub/model.js b/lib/v2/pornhub/model.js index 349e4f84c..36751eb66 100644 --- a/lib/v2/pornhub/model.js +++ b/lib/v2/pornhub/model.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); const { headers, parseItems } = require('./utils'); @@ -11,12 +11,12 @@ module.exports = async (ctx) => { } const { data: response } = await got(link, { headers }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('#mostRecentVideosSection .videoBox') .toArray() .map((e) => parseItems($(e))); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), description: $('section.aboutMeSection').text().trim(), link, @@ -25,5 +25,5 @@ module.exports = async (ctx) => { icon: $('#getAvatar').attr('src'), language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/pornhub/pornstar.js b/lib/v2/pornhub/pornstar.js index 98fc1bf84..9fb3170d5 100644 --- a/lib/v2/pornhub/pornstar.js +++ b/lib/v2/pornhub/pornstar.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); const { headers, parseItems } = require('./utils'); @@ -11,12 +11,12 @@ module.exports = async (ctx) => { } const { data: response } = await got(link, { headers }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('#mostRecentVideosSection .videoBox') .toArray() .map((e) => parseItems($(e))); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), description: $('section.aboutMeSection').text().trim(), link, @@ -25,5 +25,5 @@ module.exports = async (ctx) => { icon: $('#getAvatar').attr('src'), language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/pornhub/search.js b/lib/v2/pornhub/search.js index 6aaa5d7d4..5d586e90e 100644 --- a/lib/v2/pornhub/search.js +++ b/lib/v2/pornhub/search.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 { defaultDomain, renderDescription } = require('./utils'); module.exports = async (ctx) => { @@ -15,9 +15,9 @@ module.exports = async (ctx) => { category: [...new Set([...item.tags.map((t) => t.tag_name), ...item.categories.map((c) => c.category)])], })); - ctx.state.data = { + ctx.set('data', { title: `Pornhub - ${keyword}`, link: currentUrl, item: list, - }; + }); }; diff --git a/lib/v2/pornhub/users.js b/lib/v2/pornhub/users.js index aff830af1..2aa2d11e2 100644 --- a/lib/v2/pornhub/users.js +++ b/lib/v2/pornhub/users.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { isValidHost } = require('@/utils/valid-host'); const { headers, parseItems } = require('./utils'); @@ -11,12 +11,12 @@ module.exports = async (ctx) => { } const { data: response } = await got(link, { headers }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.videoUList .videoBox') .toArray() .map((e) => parseItems($(e))); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), description: $('.aboutMeText').text().trim(), link, @@ -26,5 +26,5 @@ module.exports = async (ctx) => { language: $('html').attr('lang'), allowEmpty: true, item: items, - }; + }); }; diff --git a/lib/v2/pornhub/utils.js b/lib/v2/pornhub/utils.js index 1996ccad0..a7944aefd 100644 --- a/lib/v2/pornhub/utils.js +++ b/lib/v2/pornhub/utils.js @@ -1,6 +1,6 @@ -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); -const { parseRelativeDate } = require('@/utils/parse-date'); +import { parseRelativeDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); const defaultDomain = 'https://www.pornhub.com'; diff --git a/lib/v2/postman/release-notes.js b/lib/v2/postman/release-notes.js index 8061f82fa..2f0744625 100644 --- a/lib/v2/postman/release-notes.js +++ b/lib/v2/postman/release-notes.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const md = require('markdown-it')({ html: true, }); @@ -19,9 +19,9 @@ module.exports = async (ctx) => { description: md.render(item.content), })); - ctx.state.data = { + ctx.set('data', { title: 'Release Notes | Postman', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/producthunt/today.js b/lib/v2/producthunt/today.js index ca1e84505..8ae1527e6 100644 --- a/lib/v2/producthunt/today.js +++ b/lib/v2/producthunt/today.js @@ -1,13 +1,13 @@ -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 response = await got('https://www.producthunt.com/'); - const data = JSON.parse(cheerio.load(response.data)('#__NEXT_DATA__').html()); + const data = JSON.parse(load(response.data)('#__NEXT_DATA__').html()); const list = Object.values(data.props.apolloState) .filter((o) => o.__typename === 'Post') @@ -19,7 +19,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.slug, async () => { const detailresponse = await got(`https://www.producthunt.com/posts/${item.slug}`); - const data = JSON.parse(cheerio.load(detailresponse.data)('#__NEXT_DATA__').html()); + const data = JSON.parse(load(detailresponse.data)('#__NEXT_DATA__').html()); const descData = data.props.apolloState[`Post${item.id}`]; return { @@ -36,9 +36,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Product Hunt Today Popular', link: 'https://www.producthunt.com/', item: items, - }; + }); }; diff --git a/lib/v2/ps/monthly-games.js b/lib/v2/ps/monthly-games.js index 978a79c8a..8b4849068 100644 --- a/lib/v2/ps/monthly-games.js +++ b/lib/v2/ps/monthly-games.js @@ -1,13 +1,13 @@ -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'; module.exports = async (ctx) => { const baseUrl = 'https://www.playstation.com/en-sg/ps-plus/whats-new/'; const { data: response } = await got(baseUrl); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.cmp-experiencefragment--your-latest-monthly-games .box') .toArray() @@ -23,9 +23,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'PlayStation Plus Monthly Games', link: baseUrl, item: list, - }; + }); }; diff --git a/lib/v2/ps/trophy.js b/lib/v2/ps/trophy.js index 78f75a163..28df49fc4 100644 --- a/lib/v2/ps/trophy.js +++ b/lib/v2/ps/trophy.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got({ method: 'get', url: `https://psnprofiles.com/${id}?order=last-trophy`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.zebra tr') .filter(function () { return $(this).find('.progress-bar span').text() !== '0%'; @@ -27,7 +27,7 @@ module.exports = async (ctx) => { url: link, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.zebra tr.completed'); const items = list @@ -78,9 +78,9 @@ module.exports = async (ctx) => { } result = result.sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate)); - ctx.state.data = { + ctx.set('data', { title: `${id} 的 PSN 奖杯`, link: `https://psnprofiles.com/${id}/log`, item: result, - }; + }); }; diff --git a/lib/v2/pts/curations.js b/lib/v2/pts/curations.js index c48cc3fca..fdb468e3a 100644 --- a/lib/v2/pts/curations.js +++ b/lib/v2/pts/curations.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 = $('.project-intro') .last() @@ -34,11 +34,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title') .text() .replace(/第\d+頁 | /, ''), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pts/index.js b/lib/v2/pts/index.js index 38b16a0e3..6f340c47c 100644 --- a/lib/v2/pts/index.js +++ b/lib/v2/pts/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 = $('h2 a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.author = content('.reporter-container a') .toArray() @@ -58,11 +58,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title') .text() .replace(/第\d+頁 | /, ''), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pts/live.js b/lib/v2/pts/live.js index 081387287..28e505d61 100644 --- a/lib/v2/pts/live.js +++ b/lib/v2/pts/live.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 id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://news.pts.org.tw'; const currentUrl = `${rootUrl}/live/${id}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: apiUrl, }); - let items = response.data.data.blogArticleList.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30).map((item) => ({ + let items = response.data.data.blogArticleList.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30).map((item) => ({ link: `${rootUrl}/live/api/liveblog/article?articleId=${item}&model=main`, })); @@ -41,9 +41,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `公視新聞網 PNN - ${response.data.data.title.replace(/【不斷更新】/, '')}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pts/projects.js b/lib/v2/pts/projects.js index 93198627d..bfe3b6c08 100644 --- a/lib/v2/pts/projects.js +++ b/lib/v2/pts/projects.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 = $('h3 a') .toArray() @@ -34,11 +34,11 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title') .text() .replace(/第\d+頁 | /, ''), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pubmed/trending.js b/lib/v2/pubmed/trending.js index adb0fae2e..c5a66214d 100644 --- a/lib/v2/pubmed/trending.js +++ b/lib/v2/pubmed/trending.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 filters = ctx.params.filters; + const filters = ctx.req.param('filters'); const rootUrl = 'https://pubmed.ncbi.nlm.nih.gov'; const currentUrl = `${rootUrl}/trending${filters ? `?filter=${filters.replaceAll(',', '&filter=')}` : ''}`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a[data-article-id]') .toArray() @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.doi = content('meta[name="citation_doi"]').attr('content'); item.pubDate = parseDate(content('meta[name="citation_date"]').attr('content')); @@ -50,9 +50,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Trending page - PubMed', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pumc/mdadmission.js b/lib/v2/pumc/mdadmission.js index 5425a7666..c4c4dc3ba 100644 --- a/lib/v2/pumc/mdadmission.js +++ b/lib/v2/pumc/mdadmission.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 limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; const rootUrl = 'https://mdadmission.pumc.edu.cn'; const currentUrl = `${rootUrl}/mdweb/site!noticeList?param.infoTypeId=&rows=${limit}&pages=1`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('div.media') .toArray() @@ -43,7 +43,7 @@ module.exports = async (ctx) => { }, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('h3').remove(); @@ -54,9 +54,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '北京协和医学院招生网 - 通知公告', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/putty/changes.js b/lib/v2/putty/changes.js index 393b9d290..d47a97c8b 100644 --- a/lib/v2/putty/changes.js +++ b/lib/v2/putty/changes.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.chiark.greenend.org.uk'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data.replaceAll('href="releases', 'class="version" href="releases')); + const $ = load(response.data.replaceAll('href="releases', 'class="version" href="releases')); const items = $('.version') .toArray() @@ -28,9 +28,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/pwc/sustainability.js b/lib/v2/pwc/sustainability.js index 0dd381c03..6c1bf2813 100644 --- a/lib/v2/pwc/sustainability.js +++ b/lib/v2/pwc/sustainability.js @@ -1,13 +1,14 @@ -const cheerio = require('cheerio'); +import { load } from 'cheerio'; const logger = require('@/utils/logger'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const baseUrl = 'https://www.strategyand.pwc.com/at/en/functions/sustainability-strategy/publications.html'; const feedLang = 'en'; const feedDescription = 'Sustainability Publications from PwC Strategy&'; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); logger.http(`Requesting ${baseUrl}`); await page.setRequestInterception(true); @@ -20,7 +21,7 @@ module.exports = async (ctx) => { const response = await page.content(); page.close(); - const $ = cheerio.load(response); + const $ = load(response); const list = $('div#wrapper article') .toArray() @@ -48,11 +49,11 @@ module.exports = async (ctx) => { browser.close(); - ctx.state.data = { + ctx.set('data', { title: 'PwC Strategy& - Sustainability Publications', link: baseUrl, language: feedLang, description: feedDescription, item: items, - }; + }); }; diff --git a/lib/v2/qbitai/category.js b/lib/v2/qbitai/category.js index 291bd9b1a..606b33792 100644 --- a/lib/v2/qbitai/category.js +++ b/lib/v2/qbitai/category.js @@ -1,6 +1,6 @@ const parser = require('@/utils/rss-parser'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category } = ctx.params; @@ -16,12 +16,12 @@ module.exports = async (ctx) => { description: item['content:encoded'], })); - ctx.state.data = { + ctx.set('data', { // 源标题 title: `量子位-${category}`, // 源链接 link: `https://www.qbitai.com/category/${category}`, // 源文章 item: items, - }; + }); }; diff --git a/lib/v2/qbitai/tag.js b/lib/v2/qbitai/tag.js index cd0fc9e2e..6eb566017 100644 --- a/lib/v2/qbitai/tag.js +++ b/lib/v2/qbitai/tag.js @@ -1,6 +1,6 @@ const parser = require('@/utils/rss-parser'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { tag } = ctx.params; @@ -16,12 +16,12 @@ module.exports = async (ctx) => { description: item['content:encoded'], })); - ctx.state.data = { + ctx.set('data', { // 源标题 title: `量子位-${tag}`, // 源链接 link: `https://www.qbitai.com/tag/${tag}`, // 源文章 item: items, - }; + }); }; diff --git a/lib/v2/qbittorrent/news.js b/lib/v2/qbittorrent/news.js index 5391adb2a..9493abdb3 100644 --- a/lib/v2/qbittorrent/news.js +++ b/lib/v2/qbittorrent/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; module.exports = async (ctx) => { const baseUrl = 'https://www.qbittorrent.org'; @@ -20,7 +20,7 @@ module.exports = async (ctx) => { false ); - const $ = cheerio.load(response); + const $ = load(response); const item = $('.stretcher') .find('h3') @@ -45,15 +45,15 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'qBittorrent News', link: `${baseUrl}/news.php`, item, - }; + }); - ctx.state.json = { + ctx.set('json', { title: 'qBittorrent News', link: `${baseUrl}/news.php`, item, - }; + }); }; diff --git a/lib/v2/qdu/houqin.js b/lib/v2/qdu/houqin.js index 12bf0f03b..b397e6ec2 100644 --- a/lib/v2/qdu/houqin.js +++ b/lib/v2/qdu/houqin.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 base = 'https://houqin.qdu.edu.cn/'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: `${base}index/tzgg.htm`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.n_newslist').children(); const items = await Promise.all( list.map((i, item) => { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { return ctx.cache.tryGet(itemUrl, async () => { let description = ''; const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); if ( $('.article_body') .find('div > h4') @@ -54,10 +54,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '青岛大学 - 后勤管理处通知', link: `${base}index/tzgg.htm`, description: '青岛大学 - 后勤管理处通知', item: items, - }; + }); }; diff --git a/lib/v2/qdu/jwc.js b/lib/v2/qdu/jwc.js index c199ebf3e..5fb81c040 100644 --- a/lib/v2/qdu/jwc.js +++ b/lib/v2/qdu/jwc.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 base = 'https://jwc.qdu.edu.cn/'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: `${base}jwtz.htm`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.notice_item').children(); const items = await Promise.all( list.map((i, item) => { @@ -27,7 +27,7 @@ module.exports = async (ctx) => { description = itemTitle; } else { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); description = $('title').text() === '系统提示' ? itemTitle // 内网限制访问内容,仅返回标题 @@ -43,10 +43,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '青岛大学 - 教务处通知', link: `${base}jwtz.htm`, description: '青岛大学 - 教务处通知', item: items, - }; + }); }; diff --git a/lib/v2/qianp/news.js b/lib/v2/qianp/news.js index 8ab55c8ee..134db2e60 100644 --- a/lib/v2/qianp/news.js +++ b/lib/v2/qianp/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 { getTokenAndSecret } = require('./utils'); module.exports = async (ctx) => { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const { data: response } = await got(url, { headers, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.newslist .infor') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { const { data: response } = await got(item.link, { headers, }); - const $ = cheerio.load(response); + const $ = load(response); item.category = [...new Set($('meta[name=keywords]').attr('content').split(','))]; item.author = $('meta[name=author]').attr('content'); @@ -47,11 +47,11 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[name="description"]').attr('content'), link: url, image: `${baseUrl}/favicon.ico`, item: items, - }; + }); }; diff --git a/lib/v2/qianp/utils.js b/lib/v2/qianp/utils.js index ab274f5cf..0101fd22c 100644 --- a/lib/v2/qianp/utils.js +++ b/lib/v2/qianp/utils.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const getTokenAndSecret = (tryGet) => tryGet('qianp:token', async () => { diff --git a/lib/v2/qianzhan/column.js b/lib/v2/qianzhan/column.js index 5655db8d6..82dc3d0ca 100644 --- a/lib/v2/qianzhan/column.js +++ b/lib/v2/qianzhan/column.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 rootUrl = 'https://www.qianzhan.com/analyst/'; @@ -18,14 +18,14 @@ module.exports = async (ctx) => { } const response = await got(rootUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const links = $('.ptb30.bb1e.clf .f22 a').map((_, item) => $(item).attr('href')); const items = await Promise.all( links.map((_, item) => ctx.cache.tryGet(item, async () => { const detailResponse = await got(item); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const description = $('#divArtBody').html(); const title = $('#h_title').text(); const pubDate = timezone(parseDate($('#pubtime_baidu').text().split('• ')[1], 'YYYY-MM-DD HH:mm:ss'), +8); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `前瞻经济学人 - ${titles[type]}`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/qianzhan/rank.js b/lib/v2/qianzhan/rank.js index cd5115952..66dfb8872 100644 --- a/lib/v2/qianzhan/rank.js +++ b/lib/v2/qianzhan/rank.js @@ -1,21 +1,21 @@ -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 type = ctx.params.type === 'week' ? 1 : 2; + const type = ctx.req.param('type') === 'week' ? 1 : 2; const rootUrl = 'https://www.qianzhan.com/analyst/'; const response = await got(rootUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const links = $(`#div_hotlist ul[idx='${type}'] a`).map((_, item) => $(item).attr('href')); const items = await Promise.all( links.map((_, item) => ctx.cache.tryGet(item, async () => { const detailResponse = await got(item); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const description = $('#divArtBody').html(); const title = $('#h_title').text(); const pubDate = timezone(parseDate($('#pubtime_baidu').text().split('• ')[1], 'YYYY-MM-DD HH:mm:ss'), +8); @@ -32,9 +32,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `前瞻经济学人 - ${type === 1 ? '周排行' : '月排行'}`, link: rootUrl, item: items, - }; + }); }; diff --git a/lib/v2/qidian/author.js b/lib/v2/qidian/author.js index 8b515f0da..6747f9815 100644 --- a/lib/v2/qidian/author.js +++ b/lib/v2/qidian/author.js @@ -1,16 +1,16 @@ -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 timezone = require('@/utils/timezone'); +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://my.qidian.com'; const currentUrl = `${rootUrl}/author/${id}/`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const authorName = $('.header-msg h1').contents().first().text().trim(); const items = $('.author-work .author-item') .toArray() @@ -32,10 +32,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${authorName} - 起点中文网`, description: $('.header-msg-desc').text().trim(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qidian/chapter.js b/lib/v2/qidian/chapter.js index ef23ba576..02ebe0efe 100644 --- a/lib/v2/qidian/chapter.js +++ b/lib/v2/qidian/chapter.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 id = ctx.params.id; + const id = ctx.req.param('id'); const response = await got(`https://m.qidian.com/book/${id}.html`); - const $ = cheerio.load(response.data); + const $ = load(response.data); const name = $('meta[property="og:title"]').attr('content'); const coverUrl = `https:${$('.detail__header-cover__img').attr('src')}`; const { data: catalog } = await got(`https://m.qidian.com/book/${id}/catalog/`); - const $c = cheerio.load(catalog); + const $c = load(catalog); const { pageContext } = JSON.parse($c('#vite-plugin-ssr_pageContext').text()); const chapterItem = pageContext.pageProps.pageData.vs @@ -23,11 +23,11 @@ module.exports = async (ctx) => { link: `https://vipreader.qidian.com/chapter/${id}/${c.id}`, })); - ctx.state.data = { + ctx.set('data', { title: `起点 ${name}`, link: `https://book.qidian.com/info/${id}`, description: $('#bookSummary content').text(), image: coverUrl, item: chapterItem, - }; + }); }; diff --git a/lib/v2/qidian/forum.js b/lib/v2/qidian/forum.js index 657debca7..e6662c6a1 100644 --- a/lib/v2/qidian/forum.js +++ b/lib/v2/qidian/forum.js @@ -1,9 +1,9 @@ -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 id = ctx.params.id; + const id = ctx.req.param('id'); const url = `https://forum.qidian.com/NewForum/List.aspx?BookId=${id}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(forum_response.data); + const $ = load(forum_response.data); const name = $('.main-header>h1').text(); const cover_url = $('img.forum_book').attr('src'); const list = $('li.post-wrap>.post'); @@ -29,10 +29,10 @@ module.exports = async (ctx) => { }); } - ctx.state.data = { + ctx.set('data', { title: `起点 《${name}》讨论区`, link: url, image: cover_url, item: items, - }; + }); }; diff --git a/lib/v2/qidian/free-next.js b/lib/v2/qidian/free-next.js index 5643035c4..5b4c9660c 100644 --- a/lib/v2/qidian/free-next.js +++ b/lib/v2/qidian/free-next.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 type = ctx.params.type; + const type = ctx.req.param('type'); let link, title; if (type === 'mm') { @@ -14,7 +14,7 @@ module.exports = async (ctx) => { } const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.other-rec-wrap li'); const out = list @@ -33,10 +33,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title, description: `限时免费下期预告-${title}`, link, item: out, - }; + }); }; diff --git a/lib/v2/qidian/free.js b/lib/v2/qidian/free.js index 7abeeb485..2e93a8c1e 100644 --- a/lib/v2/qidian/free.js +++ b/lib/v2/qidian/free.js @@ -1,9 +1,9 @@ -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 type = ctx.params.type; + const type = ctx.req.param('type'); let link, title; if (type === 'mm') { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { } const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#limit-list li'); const out = list @@ -36,10 +36,10 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { + ctx.set('data', { title, description: `限时免费-${title}`, link, item: out, - }; + }); }; diff --git a/lib/v2/qingting/channel.js b/lib/v2/qingting/channel.js index d7d48962b..522056615 100644 --- a/lib/v2/qingting/channel.js +++ b/lib/v2/qingting/channel.js @@ -1,23 +1,23 @@ -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'; module.exports = async (ctx) => { - const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.params.id}`; + const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.req.param('id')}`; let response = await got(channelUrl); const title = response.data.data.title; - const programUrl = `https://i.qingting.fm/capi/channel/${ctx.params.id}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; + const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; response = await got(programUrl); const items = response.data.data.programs.map((item) => ({ title: item.title, - link: `https://www.qingting.fm/channels/${ctx.params.id}/programs/${item.id}/`, + link: `https://www.qingting.fm/channels/${ctx.req.param('id')}/programs/${item.id}/`, pubDate: timezone(parseDate(item.update_time), +8), })); - ctx.state.data = { + ctx.set('data', { title: `${title} - 蜻蜓FM`, - link: `https://www.qingting.fm/channels/${ctx.params.id}`, + link: `https://www.qingting.fm/channels/${ctx.req.param('id')}`, item: await Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { @@ -28,5 +28,5 @@ module.exports = async (ctx) => { }) ) ), - }; + }); }; diff --git a/lib/v2/qingting/podcast.js b/lib/v2/qingting/podcast.js index 7d148a6d4..0e53e344c 100644 --- a/lib/v2/qingting/podcast.js +++ b/lib/v2/qingting/podcast.js @@ -1,10 +1,10 @@ const crypto = require('crypto'); -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'; module.exports = async (ctx) => { - const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.params.id}`; + const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.req.param('id')}`; let response = await got({ method: 'get', url: channelUrl, @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const channel_img = response.data.data.thumbs['400_thumb']; const authors = response.data.data.podcasters.map((author) => author.nick_name).join(','); const desc = response.data.data.description; - const programUrl = `https://i.qingting.fm/capi/channel/${ctx.params.id}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; + const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`; response = await got({ method: 'get', url: programUrl, @@ -27,10 +27,10 @@ module.exports = async (ctx) => { const resultItems = await Promise.all( response.data.data.programs.map((item) => - ctx.cache.tryGet(`qingting:podcast:${ctx.params.id}:${item.id}`, async () => { - const link = `https://www.qingting.fm/channels/${ctx.params.id}/programs/${item.id}/`; + ctx.cache.tryGet(`qingting:podcast:${ctx.req.param('id')}:${item.id}`, async () => { + const link = `https://www.qingting.fm/channels/${ctx.req.param('id')}/programs/${item.id}/`; - const path = `/audiostream/redirect/${ctx.params.id}/${item.id}?access_token=&device_id=MOBILESITE&qingting_id=&t=${Date.now()}`; + const path = `/audiostream/redirect/${ctx.req.param('id')}/${item.id}?access_token=&device_id=MOBILESITE&qingting_id=&t=${Date.now()}`; const sign = crypto.createHmac('md5', 'fpMn12&38f_2e').update(path).digest('hex').toString(); const [detailRes, mediaRes] = await Promise.all([ @@ -66,12 +66,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${title} - 蜻蜓FM`, description: desc, itunes_author: authors, image: channel_img, - link: `https://www.qingting.fm/channels/${ctx.params.id}`, + link: `https://www.qingting.fm/channels/${ctx.req.param('id')}`, item: resultItems, - }; + }); }; diff --git a/lib/v2/qipamaijia/index.js b/lib/v2/qipamaijia/index.js index f58b56c8d..23787e85c 100644 --- a/lib/v2/qipamaijia/index.js +++ b/lib/v2/qipamaijia/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const rootUrl = 'https://www.qipamaijia.com'; module.exports = async (ctx) => { - const cate = ctx.params.cate ?? ''; + const cate = ctx.req.param('cate') ?? ''; const url = `${rootUrl}/${cate}`; const response = await got({ @@ -14,7 +14,7 @@ module.exports = async (ctx) => { rejectUnauthorized: false, }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = $('#highlight').text(); const items = $('div.col_l > div.block') .map((_index, item) => ({ @@ -24,9 +24,9 @@ module.exports = async (ctx) => { })) .get(); - ctx.state.data = { + ctx.set('data', { title: `奇葩买家秀 - ${title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/qiyoujiage/price.js b/lib/v2/qiyoujiage/price.js index b2926700f..54bf80fc7 100644 --- a/lib/v2/qiyoujiage/price.js +++ b/lib/v2/qiyoujiage/price.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const md5 = require('@/utils/md5'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import md5 from '@/utils/md5'; module.exports = async (ctx) => { const { path } = ctx.params; const link = `http://www.qiyoujiage.com/${path}.shtml`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const priceText = $('#youjia').text(); const item = [ @@ -19,10 +19,10 @@ module.exports = async (ctx) => { }, ]; - ctx.state.data = { + ctx.set('data', { title: $('title').text(), description: $('meta[name="Description"]').attr('content'), link, item, - }; + }); }; diff --git a/lib/v2/qlu/notice.js b/lib/v2/qlu/notice.js index 648c3f495..ba47ea798 100644 --- a/lib/v2/qlu/notice.js +++ b/lib/v2/qlu/notice.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.qlu.edu.cn'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: `${host}/tzggsh/list1.htm`, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('ul.news_list.list2').children(); const items = await Promise.all( @@ -27,7 +27,7 @@ module.exports = async (ctx) => { description = itemTitle; } else { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); description = $('.read').html().trim(); } return { @@ -40,10 +40,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `齐鲁工业大学 - 通知公告`, link: `${host}/tzggsh/list1.htm`, description: '齐鲁工业大学 - 通知公告', item: items, - }; + }); }; diff --git a/lib/v2/qm120/news.js b/lib/v2/qm120/news.js index 492d8b06c..fbce6e123 100644 --- a/lib/v2/qm120/news.js +++ b/lib/v2/qm120/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 category = ctx.params.category ?? 'jdxw'; + const category = ctx.req.param('category') ?? 'jdxw'; const rootUrl = 'http://www.qm120.com'; const currentUrl = `${rootUrl}/news/${category}`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.lb2boxls ul li a') .toArray() @@ -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('.neirong_body').html(); item.pubDate = timezone(parseDate(content('.neirong_head p span').eq(1).text()), +8); @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.zt_liebiao_tit').text()} - 全民健康网`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/apps/card.js b/lib/v2/qoo-app/apps/card.js index 30809e107..f03ef6483 100644 --- a/lib/v2/qoo-app/apps/card.js +++ b/lib/v2/qoo-app/apps/card.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 { appsUrl } = require('../utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${appsUrl}${lang ? `/${lang}` : ''}/app-card/${id}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.qoo-post-item') .toArray() @@ -29,10 +29,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/apps/comment.js b/lib/v2/qoo-app/apps/comment.js index 78fa1afe6..b0a851e5b 100644 --- a/lib/v2/qoo-app/apps/comment.js +++ b/lib/v2/qoo-app/apps/comment.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 { appsUrl } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -15,7 +15,7 @@ module.exports = async (ctx) => { sort: 'create', }, }); - const $ = cheerio.load(response); + const $ = load(response); const items = $('.qoo-post-item') .toArray() @@ -34,10 +34,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/apps/note.js b/lib/v2/qoo-app/apps/note.js index 8d911f96d..3855decda 100644 --- a/lib/v2/qoo-app/apps/note.js +++ b/lib/v2/qoo-app/apps/note.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 { appsUrl } = require('../utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${appsUrl}${lang ? `/${lang}` : ''}/app-note/${id}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.qoo-note-wrap') .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); $('footer').remove(); item.description = $('article .content').html(); @@ -38,10 +38,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/apps/post.js b/lib/v2/qoo-app/apps/post.js index c7f1b5f8a..450915af5 100644 --- a/lib/v2/qoo-app/apps/post.js +++ b/lib/v2/qoo-app/apps/post.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 { appsUrl, newsUrl, fixImg } = require('../utils'); module.exports = async (ctx) => { @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${appsUrl}${lang ? `/${lang}` : ''}/app-post/${id}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.qoo-post-item') .toArray() @@ -30,7 +30,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(`${newsUrl}${lang ? `/${lang}` : ''}/wp-json/wp/v2/posts/${item.postId}`); - const $ = cheerio.load(data.content.rendered, null, false); + const $ = load(data.content.rendered, null, false); fixImg($); @@ -42,10 +42,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/news.js b/lib/v2/qoo-app/news.js index d628b7e03..c552979b4 100644 --- a/lib/v2/qoo-app/news.js +++ b/lib/v2/qoo-app/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 { newsUrl, siteIcon, fixImg } = require('./utils'); @@ -10,12 +10,12 @@ module.exports = async (ctx) => { const { data } = await got(apiUrl, { searchParams: { - per_page: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100, + per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100, }, }); const items = data.map((item) => { - const $ = cheerio.load(item.content.rendered, null, false); + const $ = load(item.content.rendered, null, false); fixImg($); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: 'QooApp : Anime Game Platform', description: lang === 'en' @@ -37,5 +37,5 @@ module.exports = async (ctx) => { link: `${newsUrl}${lang ? `/${lang}` : ''}`, language: lang === 'en' ? 'en' : 'zh', item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/notes/note.js b/lib/v2/qoo-app/notes/note.js index 6e7bb12ae..8d68a7127 100644 --- a/lib/v2/qoo-app/notes/note.js +++ b/lib/v2/qoo-app/notes/note.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 { ssoUrl, notesUrl } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -11,13 +11,13 @@ module.exports = async (ctx) => { const link = `${notesUrl}/note/${id}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const { data } = await got(api, { searchParams: { sort: 'newest', for: 'web', - limit: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100, + limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100, type: 'note', object_id: id, }, @@ -34,10 +34,10 @@ module.exports = async (ctx) => { guid: `qoo-app:notes:note:${id}:${item.id}`, })); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/notes/topic.js b/lib/v2/qoo-app/notes/topic.js index 0f99cba5d..5110fb6ef 100644 --- a/lib/v2/qoo-app/notes/topic.js +++ b/lib/v2/qoo-app/notes/topic.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { notesUrl, extractNotes } = require('../utils'); module.exports = async (ctx) => { @@ -7,14 +7,14 @@ module.exports = async (ctx) => { const link = `${notesUrl}${lang ? `/${lang}` : ''}/topic/${topic}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const items = extractNotes($); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/notes/user.js b/lib/v2/qoo-app/notes/user.js index cd721fd8e..92f9040df 100644 --- a/lib/v2/qoo-app/notes/user.js +++ b/lib/v2/qoo-app/notes/user.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { notesUrl, extractNotes } = require('../utils'); module.exports = async (ctx) => { @@ -7,14 +7,14 @@ module.exports = async (ctx) => { const link = `${notesUrl}${lang ? `/${lang}` : ''}/user/${uid}`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const items = extractNotes($); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/user/app-comment.js b/lib/v2/qoo-app/user/app-comment.js index 14fbf0ad5..641c10ea3 100644 --- a/lib/v2/qoo-app/user/app-comment.js +++ b/lib/v2/qoo-app/user/app-comment.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 { userUrl, appsUrl } = require('../utils'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -17,7 +17,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response); + const $ = load(response); const username = $('.person .name').text(); const items = data.list.map((item) => ({ @@ -31,11 +31,11 @@ module.exports = async (ctx) => { author: username, })); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), link, image: decodeURIComponent($('.person div.slot').attr('data-args')).replace('avatar=', '').split('?')[0], language: $('html').attr('lang'), item: items, - }; + }); }; diff --git a/lib/v2/qoo-app/utils.js b/lib/v2/qoo-app/utils.js index f47f4d939..2451a1fcd 100644 --- a/lib/v2/qoo-app/utils.js +++ b/lib/v2/qoo-app/utils.js @@ -1,5 +1,5 @@ -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const appsUrl = 'https://apps.qoo-app.com'; const newsUrl = 'https://news.qoo-app.com'; diff --git a/lib/v2/qq/ac/comic.js b/lib/v2/qq/ac/comic.js index 3d8429e53..12dc5233e 100644 --- a/lib/v2/qq/ac/comic.js +++ b/lib/v2/qq/ac/comic.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, mobileRootUrl } = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const currentUrl = `${rootUrl}/Comic/comicInfo/id/${id}`; const mobileCurrentUrl = `${mobileRootUrl}/comic/index/id/${id}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: mobileCurrentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const author = $('.author-wr') .toArray() @@ -34,10 +34,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `${$('h1').text()} - 腾讯动漫`, link: currentUrl, item: items, description: `

${$('.head-info-desc').text()}

`, - }; + }); }; diff --git a/lib/v2/qq/ac/rank.js b/lib/v2/qq/ac/rank.js index 9093d263e..f9e9865f9 100644 --- a/lib/v2/qq/ac/rank.js +++ b/lib/v2/qq/ac/rank.js @@ -11,8 +11,8 @@ module.exports = async (ctx) => { female: '女生榜', }; - const type = ctx.params.type ?? 'mt'; - const time = ctx.params.time ?? 'cur'; + const type = ctx.req.param('type') ?? 'mt'; + const time = ctx.req.param('time') ?? 'cur'; const currentUrl = `${rootUrl}/Rank/comicRank/type/${type}`; diff --git a/lib/v2/qq/ac/utils.js b/lib/v2/qq/ac/utils.js index df3af92f2..f8fa90dfa 100644 --- a/lib/v2/qq/ac/utils.js +++ b/lib/v2/qq/ac/utils.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; const path = require('path'); const rootUrl = 'https://ac.qq.com'; @@ -15,10 +15,10 @@ module.exports = { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $(`${time ? `.${time}-month-data ` : ''}.text-overflow`) - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -38,7 +38,7 @@ module.exports = { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.link = item.guid; item.author = content('.author-wr') diff --git a/lib/v2/qq/fact/index.js b/lib/v2/qq/fact/index.js index 7b6b2a8bd..45512d82f 100644 --- a/lib/v2/qq/fact/index.js +++ b/lib/v2/qq/fact/index.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; const CryptoJS = require('crypto-js'); -const { art } = require('@/utils/render'); +import { art } from '@/utils/render'; const path = require('path'); const getRequestToken = () => { @@ -38,7 +38,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const nextData = JSON.parse($('#__NEXT_DATA__').text()); const { initialState } = nextData.props.pageProps; @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '较真查证平台 - 腾讯新闻', link: `${baseUrl}/home`, item: items, - }; + }); }; diff --git a/lib/v2/qq/kg/cache.js b/lib/v2/qq/kg/cache.js index e3241eb48..4e6db0747 100644 --- a/lib/v2/qq/kg/cache.js +++ b/lib/v2/qq/kg/cache.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); module.exports = { diff --git a/lib/v2/qq/kg/reply.js b/lib/v2/qq/kg/reply.js index 35bffe006..78909cb30 100644 --- a/lib/v2/qq/kg/reply.js +++ b/lib/v2/qq/kg/reply.js @@ -1,12 +1,12 @@ const cache = require('./cache'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const playId = ctx.params.playId; + const playId = ctx.req.param('playId'); const url = `https://node.kg.qq.com/play?s=${playId}`; const play_item = await cache.getPlayInfo(ctx, playId, ''); - ctx.state.data = { + ctx.set('data', { title: `${play_item.name} - ${play_item.author} 的评论`, link: url, image: play_item.itunes_item_image, @@ -17,5 +17,5 @@ module.exports = async (ctx) => { link: url, guid: `ksong:${play_item.ksong_mid}:${item.comment_id}`, })), - }; + }); }; diff --git a/lib/v2/qq/kg/user.js b/lib/v2/qq/kg/user.js index 819450757..caac932c3 100644 --- a/lib/v2/qq/kg/user.js +++ b/lib/v2/qq/kg/user.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { JSDOM } = require('jsdom'); const cache = require('./cache'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const userId = ctx.params.userId; + const userId = ctx.req.param('userId'); const url = `https://node.kg.qq.com/personal?uid=${userId}`; const response = await got(url); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${author} - 全民K歌`, link: url, description: data.share.content, @@ -46,5 +46,5 @@ module.exports = async (ctx) => { image: authorimg, itunes_author: author, itunes_category: '全民K歌', - }; + }); }; diff --git a/lib/v2/qq88/index.js b/lib/v2/qq88/index.js index 5bc35a9f3..b47811915 100644 --- a/lib/v2/qq88/index.js +++ b/lib/v2/qq88/index.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const category = ctx.params.category ?? ''; + const category = ctx.req.param('category') ?? ''; const rootUrl = 'https://qq88.info'; const currentUrl = category ? `${rootUrl}/?cat=${category}` : rootUrl; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.entry-title a') .slice(0, 15) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { method: 'get', url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const links = content('.entry-content').find('a[download]'); @@ -52,9 +52,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.page-title').text() || '首页'} - 秋爸日字`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qqorw/index.js b/lib/v2/qqorw/index.js index efc7c1391..773a08051 100644 --- a/lib/v2/qqorw/index.js +++ b/lib/v2/qqorw/index.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { category = '' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 10; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10; const rootUrl = 'https://qqorw.cn'; const currentUrl = new URL(category, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); let items = $('article.excerpt') .slice(0, limit) @@ -40,7 +40,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('div.contenttxt').prev().nextAll().remove(); @@ -62,7 +62,7 @@ module.exports = async (ctx) => { const icon = new URL('favicon.ico', rootUrl).href; const title = $('header.archive-header h1 a').last().text(); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${title ? ` - ${title}` : ''}`, link: currentUrl, @@ -73,5 +73,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('meta[name="keywords"]').prop('content'), author, - }; + }); }; diff --git a/lib/v2/questmobile/report.js b/lib/v2/questmobile/report.js index 6700b676f..fb22b93f0 100644 --- a/lib/v2/questmobile/report.js +++ b/lib/v2/questmobile/report.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); /** @@ -26,7 +26,7 @@ const parseTree = (tree, result = []) => { module.exports = async (ctx) => { const { industry, label } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://www.questmobile.com.cn'; const apiUrl = new URL('api/v2/report/article-list', rootUrl).href; @@ -80,7 +80,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('div.text div.daoyu').remove(); @@ -104,14 +104,14 @@ module.exports = async (ctx) => { const { data: currentResponse } = await got(currentUrl); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[property="og:title"]').prop('content').split(/-/)[0]; const categories = [industryObj?.value, labelObj?.value].filter(Boolean); const image = $(`img[alt="${author}"]`).prop('src'); const icon = $('link[rel="shortcut icon"]').prop('href'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author}${categories.length === 0 ? '' : ` - ${categories.join(' - ')}`}`, link: currentUrl, @@ -123,5 +123,5 @@ module.exports = async (ctx) => { subtitle: $('meta[name="keywords"]').prop('content'), author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/qa.js b/lib/v2/quicker/qa.js index 28dc7d9e6..98b732d97 100644 --- a/lib/v2/quicker/qa.js +++ b/lib/v2/quicker/qa.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'all'; - const state = ctx.params.state ?? ''; + const category = ctx.req.param('category') ?? 'all'; + const state = ctx.req.param('state') ?? ''; const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/QA${category === 'all' ? '' : `?category=${category}`}${state ? `?state=${state}` : ''}`; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a.question-title') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('div[data-note="最后更新人信息"]').remove(); @@ -56,10 +56,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/share.js b/lib/v2/quicker/share.js index 8c16cb06d..623bf86b3 100644 --- a/lib/v2/quicker/share.js +++ b/lib/v2/quicker/share.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category ?? 'Recent'; + const category = ctx.req.param('category') ?? 'Recent'; const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/Share/${category}`; @@ -14,10 +14,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('table tbody tr') - .slice(1, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(1, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item).find('td a').first(); @@ -36,7 +36,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('section').last().remove(); content('#app').children().slice(0, 2).remove(); @@ -52,10 +52,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/user.js b/lib/v2/quicker/user.js index cdbedcc0b..8686e7980 100644 --- a/lib/v2/quicker/user.js +++ b/lib/v2/quicker/user.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const category = ctx.params.category; - const id = ctx.params.id; + const category = ctx.req.param('category'); + const id = ctx.req.param('id'); const rootUrl = 'https://getquicker.net'; const currentUrl = `${rootUrl}/User/${category}/${id}`; @@ -15,10 +15,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('table tbody tr') - .slice(1, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(1, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item).find('td a').first(); @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('section').last().remove(); content('#app').children().slice(0, 2).remove(); @@ -53,10 +53,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/quicker/versions.js b/lib/v2/quicker/versions.js index ece5f7a0e..1f4e4533d 100644 --- a/lib/v2/quicker/versions.js +++ b/lib/v2/quicker/versions.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://getquicker.net'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.version') .toArray() @@ -28,9 +28,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/qweather/3days.js b/lib/v2/qweather/3days.js index f3f7e8c03..9f6cf76d7 100644 --- a/lib/v2/qweather/3days.js +++ b/lib/v2/qweather/3days.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const config = require('@/config').value; +import { config } from '@/config'; const WEATHER_API = 'https://devapi.qweather.com/v7/weather/3d'; const AIR_QUALITY_API = 'https://devapi.qweather.com/v7/air/5d'; @@ -12,12 +12,12 @@ module.exports = async (ctx) => { if (!config.hefeng.key) { throw new Error('QWeather RSS is disabled due to the lack of relevant config'); } - const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => { - const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.params.location}&key=${config.hefeng.key}`); + const id = await ctx.cache.tryGet(ctx.req.param('location') + '_id', async () => { + const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.req.param('location')}&key=${config.hefeng.key}`); return response.data.location[0].id; }); const weatherData = await ctx.cache.tryGet( - ctx.params.location, + ctx.req.param('location'), async () => { const response = await got(`${WEATHER_API}?key=${config.hefeng.key}&location=${id}`); return response.data; @@ -26,7 +26,7 @@ module.exports = async (ctx) => { false ); const airQualityData = await ctx.cache.tryGet( - `qweather:air:${ctx.params.location}`, + `qweather:air:${ctx.req.param('location')}`, async () => { const airQualityResponse = await got(`${AIR_QUALITY_API}?location=${id}&key=${config.hefeng.key}`); return airQualityResponse.data; @@ -58,16 +58,16 @@ module.exports = async (ctx) => { item, }), pubDate: combined.updateTime, - guid: '位置:' + ctx.params.location + '--日期:' + item.fxDate, + guid: '位置:' + ctx.req.param('location') + '--日期:' + item.fxDate, link: combined.fxLink, author, })); - ctx.state.data = { - title: ctx.params.location + '未来三天天气', - description: ctx.params.location + '未来三天天气情况,使用和风彩云 API (包括空气质量)', + ctx.set('data', { + title: ctx.req.param('location') + '未来三天天气', + description: ctx.req.param('location') + '未来三天天气情况,使用和风彩云 API (包括空气质量)', item: items, link: combined.fxLink, author, - }; + }); }; diff --git a/lib/v2/qweather/now.js b/lib/v2/qweather/now.js index dabeb667b..1455ea66c 100644 --- a/lib/v2/qweather/now.js +++ b/lib/v2/qweather/now.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const rootUrl = 'https://devapi.qweather.com/v7/weather/now?'; module.exports = async (ctx) => { - const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => { - const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.params.location}&key=${config.hefeng.key}`); + const id = await ctx.cache.tryGet(ctx.req.param('location') + '_id', async () => { + const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.req.param('location')}&key=${config.hefeng.key}`); const data = []; for (const i in response.data.location) { data.push(response.data.location[i]); @@ -15,7 +15,7 @@ module.exports = async (ctx) => { }); const requestUrl = rootUrl + 'key=' + config.hefeng.key + '&location=' + id; const responseData = await ctx.cache.tryGet( - ctx.params.location + '_now', + ctx.req.param('location') + '_now', async () => { const response = await got(requestUrl); return response.data; @@ -30,16 +30,16 @@ module.exports = async (ctx) => { const time_show = timeObj.toLocaleString(); - ctx.state.data = { - title: ctx.params.location + '实时天气', - description: ctx.params.location + '实时天气状况', + ctx.set('data', { + title: ctx.req.param('location') + '实时天气', + description: ctx.req.param('location') + '实时天气状况', item: data.map((item) => ({ title: '观测时间:' + time_show, description: art(path.join(__dirname, 'templates/now.art'), { item }), pubDate: timeObj, - guid: '位置:' + ctx.params.location + '--时间:' + time_show, + guid: '位置:' + ctx.req.param('location') + '--时间:' + time_show, link: responseData.fxLink, })), link: responseData.fxLink, - }; + }); }; diff --git a/lib/v2/radio-canada/latest.js b/lib/v2/radio-canada/latest.js index c5aa007c9..39ff5b5e1 100644 --- a/lib/v2/radio-canada/latest.js +++ b/lib/v2/radio-canada/latest.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const language = ctx.params.language ?? 'en'; + const language = ctx.req.param('language') ?? 'en'; const rootUrl = 'https://ici.radio-canada.ca'; const apiRootUrl = 'https://services.radio-canada.ca'; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { url: item.link, }); - const $ = cheerio.load(detailResponse.data); + const $ = load(detailResponse.data); const rcState = $('script:contains("window._rcState_ = JSON.parse")') .text() .match(/JSON\.parse\((".*")\);/)[1]; @@ -42,9 +42,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: response.data.meta.title, link: response.data.metric.metrikContent.omniture.url, item: items, - }; + }); }; diff --git a/lib/v2/radio/album.js b/lib/v2/radio/album.js index 456e2e614..be5984f98 100644 --- a/lib/v2/radio/album.js +++ b/lib/v2/radio/album.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const CryptoJS = require('crypto-js'); module.exports = async (ctx) => { const KEY = 'f0fc4c668392f9f9a447e48584c214ee'; - const id = ctx.params.id; - const size = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; const rootUrl = 'https://www.radio.cn'; const apiRootUrl = 'https://ytmsout.radio.cn'; @@ -94,7 +94,7 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data.columnName}`, link: currentUrl, item: items, @@ -102,5 +102,5 @@ module.exports = async (ctx) => { itunes_author: data.anchorpersons, description: data.descriptions ?? data.descriptionSimple, itunes_category: data.atypeInfo.map((c) => c.categoryName).join(','), - }; + }); }; diff --git a/lib/v2/radio/index.js b/lib/v2/radio/index.js index 182c4c9ed..f14beb018 100644 --- a/lib/v2/radio/index.js +++ b/lib/v2/radio/index.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const id = ctx.params.id; - const size = ctx.query.limit ?? '100'; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ?? '100'; const rootUrl = 'https://www.radio.cn'; const apiRootUrl = 'http://tacc.radio.cn'; @@ -44,12 +44,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data.odchannel.name}`, link: currentUrl, item: items, image: data.odchannel.imageUrl[0].url, itunes_author: data.odchannel.commissioningEditorName || data.odchannel.editorName || data.odchannel.source || 'radio.cn', description: data.odchannel.description || data.odchannel.sub_title || '', - }; + }); }; diff --git a/lib/v2/radio/zhibo.js b/lib/v2/radio/zhibo.js index 3f52df1ff..233b4529b 100644 --- a/lib/v2/radio/zhibo.js +++ b/lib/v2/radio/zhibo.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const CryptoJS = require('crypto-js'); module.exports = async (ctx) => { const KEY = 'f0fc4c668392f9f9a447e48584c214ee'; - const id = ctx.params.id; - const size = ctx.query.limit ?? '100'; + const id = ctx.req.param('id'); + const size = ctx.req.query('limit') ?? '100'; const params = `columnId=${id}&pageNo=0&pageSize=${size}`; @@ -62,12 +62,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `云听 - ${data[0].name}`, link: currentUrl, item: items, image: iconUrl, itunes_author: 'radio.cn', description: data[0].des, - }; + }); }; diff --git a/lib/v2/rarehistoricalphotos/index.js b/lib/v2/rarehistoricalphotos/index.js index c95f91c56..7587a37e9 100644 --- a/lib/v2/rarehistoricalphotos/index.js +++ b/lib/v2/rarehistoricalphotos/index.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const baseUrl = 'https://rarehistoricalphotos.com'; module.exports = async (ctx) => { const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { - per_page: ctx.query.limit ? Number(ctx.query.limit) : undefined, + per_page: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : undefined, }, }); @@ -17,12 +17,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.date_gmt), })); - ctx.state.data = { + ctx.set('data', { title: 'Rare Historical Photos', description: 'And the story behind them...', link: baseUrl, image: 'https://rarehistoricalphotos.com/wp-content/uploads/2022/04/cropped-rarehistoricalphotos-32x32.png', language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/rattibha/user.js b/lib/v2/rattibha/user.js index 124c4a657..31725908e 100644 --- a/lib/v2/rattibha/user.js +++ b/lib/v2/rattibha/user.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://rattibha.com'; @@ -37,9 +37,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `سلاسل تغريدات ${twitterUser}`, link: `${baseUrl}/${twitterUser}`, item: items, - }; + }); }; diff --git a/lib/v2/rawkuma/manga.js b/lib/v2/rawkuma/manga.js index 191af8308..9c8bf55bb 100644 --- a/lib/v2/rawkuma/manga.js +++ b/lib/v2/rawkuma/manga.js @@ -1,19 +1,19 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://rawkuma.com'; const currentUrl = new URL(`/manga/${id}`, rootUrl).href; const { data: response } = await got(currentUrl); - const $ = cheerio.load(response); + const $ = load(response); const author = $('div.fmed span').eq(1).text().trim(); const category = $('div.wd-full span.mgen a[rel="tag"]') @@ -42,7 +42,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const { data: detailResponse } = await got(item.link); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); const imageMatches = detailResponse.match(/"images":(\[.*?])}],"lazyload"/); @@ -67,7 +67,7 @@ module.exports = async (ctx) => { .prop('href') .replace(/-\d+x\d+/, ''); - ctx.state.data = { + ctx.set('data', { item: items, title: $('title').text(), link: currentUrl, @@ -77,5 +77,5 @@ module.exports = async (ctx) => { logo: icon, subtitle: $('div.wd-full span').text(), author, - }; + }); }; diff --git a/lib/v2/reactnewsletter/reactnewsletter.js b/lib/v2/reactnewsletter/reactnewsletter.js index 3c20d2f48..243394985 100644 --- a/lib/v2/reactnewsletter/reactnewsletter.js +++ b/lib/v2/reactnewsletter/reactnewsletter.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const currentURL = 'https://reactnewsletter.com/issues'; -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const resp = await got(currentURL); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); const text = $('script#__NEXT_DATA__').text(); const json = JSON.parse(text); @@ -16,10 +16,10 @@ module.exports = async (ctx) => { link: `/issues/${item.slug}`, })); - ctx.state.data = { + ctx.set('data', { title: 'reactnewsletter.dev', description: 'Stay up to date on the latest React news, tutorials, resources, and more. Delivered every Tuesday, for free.', link: currentURL, item: items, - }; + }); }; diff --git a/lib/v2/readhub/daily.js b/lib/v2/readhub/daily.js index 9dfbfdb7f..bbcd53047 100644 --- a/lib/v2/readhub/daily.js +++ b/lib/v2/readhub/daily.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { rootUrl, processItems } = require('./util'); module.exports = async (ctx) => { - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 11; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 11; const currentUrl = new URL('daily', rootUrl).href; @@ -20,14 +20,14 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[name="application-name"]').prop('content'); const subtitle = $('meta[property="og:title"]').prop('content'); const image = 'https://readhub-oss.nocode.com/static/readhub.png'; const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -39,5 +39,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/readhub/index.js b/lib/v2/readhub/index.js index e64428a2f..a71fe1aaa 100644 --- a/lib/v2/readhub/index.js +++ b/lib/v2/readhub/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const path = require('path'); const { rootUrl, apiTopicUrl, art, processItems } = require('./util'); module.exports = async (ctx) => { const { category = '' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30; const currentUrl = new URL(category ?? '', rootUrl).href; @@ -39,14 +39,14 @@ module.exports = async (ctx) => { items = await processItems(items, ctx.cache.tryGet); - const $ = cheerio.load(currentResponse); + const $ = load(currentResponse); const author = $('meta[property="og:site_name"]').prop('content'); const subtitle = $(`a[data-path="/${category}"]`).text(); const image = $('link[rel="preload"][as="image"]').prop('href'); const icon = $('meta[property="og:image"]').prop('content'); - ctx.state.data = { + ctx.set('data', { item: items, title: `${author} - ${subtitle}`, link: currentUrl, @@ -58,5 +58,5 @@ module.exports = async (ctx) => { subtitle, author, allowEmpty: true, - }; + }); }; diff --git a/lib/v2/readhub/util.js b/lib/v2/readhub/util.js index b6890d4a5..afb35e63d 100644 --- a/lib/v2/readhub/util.js +++ b/lib/v2/readhub/util.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); const dayjs = require('dayjs'); diff --git a/lib/v2/remnote/changelog.js b/lib/v2/remnote/changelog.js index 9b4c419f4..7090ca529 100644 --- a/lib/v2/remnote/changelog.js +++ b/lib/v2/remnote/changelog.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; const FQDN = 'feedback.remnote.com'; const apiGateway = 'https://gateway.hellonext.co'; @@ -21,12 +21,12 @@ module.exports = async (ctx) => { pubDate: parseDate(item.published_at.timestamp), })); - ctx.state.data = { + ctx.set('data', { title: 'Changelog | RemNote', description: 'Vote or request new RemNote features. Subscribe to get updates about new features from RemNote.', link: `https://${FQDN}/changelog`, image: 'https://vault.hnxt.dev/uploads/organization_customization/favicon/3970/88153ff13b4b03492ddfee6e675228c1.png', item: items, language: 'en-US', - }; + }); }; diff --git a/lib/v2/researchgate/publications.js b/lib/v2/researchgate/publications.js index 8451f6c67..af2914cf4 100644 --- a/lib/v2/researchgate/publications.js +++ b/lib/v2/researchgate/publications.js @@ -1,12 +1,13 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://www.researchgate.net'; const currentUrl = `${rootUrl}/profile/${id}`; - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const page = await browser.newPage(); await page.setRequestInterception(true); page.on('request', (request) => { @@ -16,11 +17,11 @@ module.exports = async (ctx) => { const response = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const $ = cheerio.load(response); + const $ = load(response); const list = $('div[itemprop="headline"] a') .toArray() - .slice(0, ctx.query.limit ? Number(ctx.query.limit) : 15) + .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 15) .map((item) => { item = $(item); return { @@ -40,7 +41,7 @@ module.exports = async (ctx) => { await page.goto(item.link); const detailResponse = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); item.doi = content('meta[property="citation_doi"]').attr('content'); item.pubDate = parseDate(content('meta[property="citation_publication_date"]').attr('content')); @@ -62,9 +63,9 @@ module.exports = async (ctx) => { await browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${$('meta[property="profile:username"]').attr('content')}'s Publications - ResearchGate`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/reuters/common.js b/lib/v2/reuters/common.js index 5fa03002b..c4a0641f0 100644 --- a/lib/v2/reuters/common.js +++ b/lib/v2/reuters/common.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const MUST_FETCH_BY_TOPICS = new Set(['authors']); const CAN_USE_SOPHI = ['world']; - const category = ctx.params.category; - const topic = ctx.params.topic ?? (category === 'authors' ? 'reuters' : ''); - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; - const useSophi = ctx.query.sophi === 'true' && 'topic' !== '' && CAN_USE_SOPHI.includes(category); + const category = ctx.req.param('category'); + const topic = ctx.req.param('topic') ?? (category === 'authors' ? 'reuters' : ''); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; + const useSophi = ctx.req.query('sophi') === 'true' && 'topic' !== '' && CAN_USE_SOPHI.includes(category); const section_id = `/${category}/${topic ? `${topic}/` : ''}`; const { title, description, rootUrl, response } = await (async () => { @@ -77,10 +77,10 @@ module.exports = async (ctx) => { const results = await Promise.allSettled( items.map((item) => - ctx.query.mode === 'fulltext' + ctx.req.query('mode') === 'fulltext' ? ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); if (detailResponse.url.startsWith('https://www.reuters.com/investigates/')) { const ldJson = JSON.parse(content('script[type="application/ld+json"]').text()); @@ -131,11 +131,11 @@ module.exports = async (ctx) => { ); items = results.filter((r) => r.status === 'fulfilled').map((r) => r.value); - ctx.state.data = { + ctx.set('data', { title, description, image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116', link: `https://www.reuters.com${section_id}`, item: items, - }; + }); }; diff --git a/lib/v2/reuters/investigates.js b/lib/v2/reuters/investigates.js index f61016eb8..2c337bb2f 100644 --- a/lib/v2/reuters/investigates.js +++ b/lib/v2/reuters/investigates.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.reuters.com'; const currentUrl = `${rootUrl}/investigates/`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('article.section-article-container.row') .map((_, item) => ({ @@ -19,7 +19,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.title = content('title').text(); item.description = content('article.special-report').html(); @@ -31,9 +31,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('h1.series-subtitle').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/rfa/index.js b/lib/v2/rfa/index.js index e73e200d4..9f94cee2f 100644 --- a/lib/v2/rfa/index.js +++ b/lib/v2/rfa/index.js @@ -1,19 +1,19 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - let url = 'https://www.rfa.org/' + (ctx.params.language ?? 'english'); + let url = 'https://www.rfa.org/' + (ctx.req.param('language') ?? 'english'); - if (ctx.params.channel) { - url += '/' + ctx.params.channel; + if (ctx.req.param('channel')) { + url += '/' + ctx.req.param('channel'); } - if (ctx.params.subChannel) { - url += '/' + ctx.params.subChannel; + if (ctx.req.param('subChannel')) { + url += '/' + ctx.req.param('subChannel'); } const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const selectors = ['div[id=topstorywidefull]', 'div.two_featured', 'div.three_featured', 'div.single_column_teaser', 'div.sectionteaser', 'div.specialwrap']; const list = []; @@ -31,7 +31,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { const content = await got(item.link); - const description = cheerio.load(content.data); + const description = load(content.data); item.description = description('#headerimg').html() + description('div[id=storytext]').html(); item.pubDate = parseDate(description('span[id=story_date]').text()); if (description('meta[property=og:audio]').attr('content') !== undefined) { @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'RFA', link: 'https://www.rfa.org/', item: result, - }; + }); }; diff --git a/lib/v2/rfi/news.js b/lib/v2/rfi/news.js index ceed07565..698bcd0d1 100644 --- a/lib/v2/rfi/news.js +++ b/lib/v2/rfi/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www.rfi.fr/'; - const path = ctx.params.path ?? 'en'; + const path = ctx.req.param('path') ?? 'en'; const currentUrl = `${rootUrl}${path.endsWith('/') ? path : `${path}/`}`; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('aside[data-org-type="aside-content--highlighted"], aside[data-org-type="aside-content--sponsors"]').remove(); @@ -27,7 +27,7 @@ module.exports = async (ctx) => { items.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.m-interstitial, .m-em-quote svg, .o-self-promo').remove(); @@ -56,7 +56,7 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), description: $('meta[name="description"]').attr('content'), link: currentUrl, @@ -65,5 +65,5 @@ module.exports = async (ctx) => { logo: new URL($('link[rel="apple-touch-icon"]').attr('href'), currentUrl).href, item: items, language: $('html').attr('lang'), - }; + }); }; diff --git a/lib/v2/right/forum.js b/lib/v2/right/forum.js index 94f2383ff..e7a9d252f 100644 --- a/lib/v2/right/forum.js +++ b/lib/v2/right/forum.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? '31'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 20; + const id = ctx.req.param('id') ?? '31'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20; const rootUrl = 'https://www.right.com.cn'; const currentUrl = `${rootUrl}/forum/forum-${id}-1.html`; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); $('a[title="隐藏置顶帖"]').each(function () { $(this).parents('tbody').remove(); @@ -41,7 +41,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.pstatus').remove(); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('.xs2 a').text()} - 恩山无线论坛`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/rodong/news.js b/lib/v2/rodong/news.js index 4ac45959a..7aac6c2e0 100644 --- a/lib/v2/rodong/news.js +++ b/lib/v2/rodong/news.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'http://www.rodong.rep.kp'; @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const link = `${host}/${language}/index.php?MkBAMkAxQA==`; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.date_news_list .row') .toArray() .map((item) => { @@ -26,7 +26,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); $('.news_Title, .NewsDetail, .News_Detail, #moveNews').remove(); item.description = $('.col-sm-8').html(); @@ -36,10 +36,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link, item: items, - }; + }); }; diff --git a/lib/v2/routledge/book-series.js b/lib/v2/routledge/book-series.js index 0ad430541..1be90d983 100644 --- a/lib/v2/routledge/book-series.js +++ b/lib/v2/routledge/book-series.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { @@ -21,7 +21,7 @@ module.exports = async (ctx) => { view: 'list', }, }); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.row.book') .toArray() @@ -46,7 +46,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const isbn = $('meta[property="books:isbn"]').attr('content'); const { data: image } = await got('https://productimages.routledge.com', { searchParams: { @@ -69,10 +69,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('head meta[name="description"]').attr('content'), link: pageUrl, item: items, - }; + }); }; diff --git a/lib/v2/rsc/journal.js b/lib/v2/rsc/journal.js index 5943bc79a..6ba36a32c 100644 --- a/lib/v2/rsc/journal.js +++ b/lib/v2/rsc/journal.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { const { id, category = 'allrecentarticles' } = ctx.params; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 50; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; const rootUrl = 'https://pubs.rsc.org'; const currentUrl = new URL(`en/journals/journalissues/${id}#!recentarticles`, rootUrl).href; @@ -22,7 +22,7 @@ module.exports = async (ctx) => { }, }); - let $ = cheerio.load(response); + let $ = load(response); $('div.capsule__article-image').each(function () { $(this).replaceWith( @@ -66,7 +66,7 @@ module.exports = async (ctx) => { if (item.category.pop()) { const { data: detailResponse } = await got(item.link.replace(/\/articlelanding\//, '/articlehtml/')); - const content = cheerio.load(detailResponse); + const content = load(detailResponse); content('#pnlArticleAccess, #pnlArticleContent').remove(); content('div.abstract, div.article-abstract__heading').prevAll().remove(); @@ -86,11 +86,11 @@ module.exports = async (ctx) => { const { data: detailResponse } = await got(currentUrl); - $ = cheerio.load(detailResponse); + $ = load(detailResponse); const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; - ctx.state.data = { + ctx.set('data', { item: items, title: $('meta[name="citation_title"]').prop('content'), link: currentUrl, @@ -102,5 +102,5 @@ module.exports = async (ctx) => { subtitle: $('title').text(), author: $('meta[name="citation_journal_abbrev"]').prop('content'), allowEmpty: true, - }; + }); }; diff --git a/lib/v2/rsshub/routes.js b/lib/v2/rsshub/routes.js index 4e1e6389b..6cff1e548 100644 --- a/lib/v2/rsshub/routes.js +++ b/lib/v2/rsshub/routes.js @@ -1,8 +1,8 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { - const isEnglish = ctx.params.lang !== 'zh'; + const isEnglish = ctx.req.param('lang') !== 'zh'; const lang = isEnglish ? '' : 'zh/'; const types = [ @@ -36,7 +36,7 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const page = $('.page').toArray(); const item = $('.routeBlock').toArray(); return { page, item, type }; @@ -44,13 +44,13 @@ module.exports = async (ctx) => { ); const list = all.flatMap(({ page, item, type }) => item.map((item) => ({ page, item, type }))); - ctx.state.data = { + ctx.set('data', { title: isEnglish ? 'RSSHub has new routes' : 'RSSHub 有新路由啦', link: 'https://docs.rsshub.app', description: isEnglish ? 'Everything is RSSible' : '万物皆可 RSS', language: isEnglish ? 'en-us' : 'zh-cn', item: list.map(({ page, item, type }) => { - const $ = cheerio.load(page); + const $ = load(page); item = $(item); const h2Title = item.prevAll('h2').eq(0); const h3Title = item.prevAll('h3').eq(0); @@ -61,5 +61,5 @@ module.exports = async (ctx) => { guid: item.attr('id'), }; }), - }; + }); }; diff --git a/lib/v2/rsshub/transform/html.js b/lib/v2/rsshub/transform/html.js index 5f12adbd7..93a94345d 100644 --- a/lib/v2/rsshub/transform/html.js +++ b/lib/v2/rsshub/transform/html.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -12,8 +12,8 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); - const $ = cheerio.load(response.data); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); + const $ = load(response.data); const rssTitle = routeParams.get('title') || $('title').text(); const item = routeParams.get('item') || 'html'; const items = $(item) @@ -56,10 +56,10 @@ module.exports = async (ctx) => { }) .filter(Boolean); - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/rsshub/transform/json.js b/lib/v2/rsshub/transform/json.js index 9c183c950..ff567eb1f 100644 --- a/lib/v2/rsshub/transform/json.js +++ b/lib/v2/rsshub/transform/json.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; function jsonGet(obj, attr) { if (typeof attr !== 'string') { @@ -16,7 +16,7 @@ function jsonGet(obj, attr) { module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -24,14 +24,14 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); let rssTitle = routeParams.get('title'); if (!rssTitle) { const resp = await got({ method: 'get', url: new URL(url).origin, }); - const $ = cheerio.load(resp.data); + const $ = load(resp.data); rssTitle = $('title').text(); } @@ -49,10 +49,10 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/rsshub/transform/sitemap.js b/lib/v2/rsshub/transform/sitemap.js index 18de638f3..2d901fe58 100644 --- a/lib/v2/rsshub/transform/sitemap.js +++ b/lib/v2/rsshub/transform/sitemap.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; module.exports = async (ctx) => { if (!config.feature.allow_user_supply_unsafe_domain) { - ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); + throw new Error(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); } const { url } = ctx.params; const response = await got({ @@ -12,8 +12,8 @@ module.exports = async (ctx) => { url, }); - const routeParams = new URLSearchParams(ctx.params.routeParams); - const $ = cheerio.load(response.data, { xmlMode: true }); + const routeParams = new URLSearchParams(ctx.req.param('routeParams')); + const $ = load(response.data, { xmlMode: true }); const rssTitle = routeParams.get('title') || ($('urlset url').length && $('urlset url').first().find('loc').text() ? $('urlset url').first().find('loc').text() : 'Sitemap'); @@ -41,10 +41,10 @@ module.exports = async (ctx) => { .filter(Boolean) : []; - ctx.state.data = { + ctx.set('data', { title: rssTitle, link: url, description: `Proxy ${url}`, item: items, - }; + }); }; diff --git a/lib/v2/ruancan/category.js b/lib/v2/ruancan/category.js index a2a7edbee..3239d9a09 100644 --- a/lib/v2/ruancan/category.js +++ b/lib/v2/ruancan/category.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category; + const category = ctx.req.param('category'); const currentUrl = `/cat/${category}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/search.js b/lib/v2/ruancan/search.js index ec3d7ff58..df17fd81c 100644 --- a/lib/v2/ruancan/search.js +++ b/lib/v2/ruancan/search.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const keyword = ctx.params.keyword; + const keyword = ctx.req.param('keyword'); const currentUrl = `/?s=${keyword}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/user.js b/lib/v2/ruancan/user.js index 3117e0ee0..4ea2ed657 100644 --- a/lib/v2/ruancan/user.js +++ b/lib/v2/ruancan/user.js @@ -1,7 +1,7 @@ const fetchFeed = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const currentUrl = `/i/${id}`; ctx.state.data = await fetchFeed(ctx, currentUrl); diff --git a/lib/v2/ruancan/utils.js b/lib/v2/ruancan/utils.js index 4bc21001d..b3b475b04 100644 --- a/lib/v2/ruancan/utils.js +++ b/lib/v2/ruancan/utils.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx, currentUrl) => { const rootUrl = 'https://www.ruancan.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx, currentUrl) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.item-title a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 15) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15) .toArray() .map((item) => { item = $(item); @@ -33,7 +33,7 @@ module.exports = async (ctx, currentUrl) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.entry-copyright').remove(); diff --git a/lib/v2/ruc/hr.js b/lib/v2/ruc/hr.js index 4dc05b387..b2565e9b0 100644 --- a/lib/v2/ruc/hr.js +++ b/lib/v2/ruc/hr.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const category = ctx.params.category?.replace(/-/g, '/') ?? 'tzgg'; + const category = ctx.req.param('category')?.replace(/-/g, '/') ?? 'tzgg'; const rootUrl = 'http://hr.ruc.edu.cn'; const currentUrl = `${rootUrl}/${category}/index.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a[title]') .toArray() @@ -37,7 +37,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.neirong').html(); item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]); @@ -50,9 +50,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/runtrail/posts.js b/lib/v2/runtrail/posts.js index 0ed141ec5..eb558dca1 100644 --- a/lib/v2/runtrail/posts.js +++ b/lib/v2/runtrail/posts.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://runtrail.cn'; const { data: response } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { searchParams: { _embed: true, - per_page: ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30, + per_page: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30, }, }); @@ -26,9 +26,9 @@ module.exports = async (ctx) => { link: item.link, })); - ctx.state.data = { + ctx.set('data', { title: '最新文章 - 跑野大爆炸', link: baseUrl, item: items, - }; + }); }; diff --git a/lib/v2/rustcc/jobs.js b/lib/v2/rustcc/jobs.js index e7f785fc3..607453aa1 100644 --- a/lib/v2/rustcc/jobs.js +++ b/lib/v2/rustcc/jobs.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const base_url = 'https://rustcc.cn'; @@ -15,19 +15,19 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.article-list li').get(); - ctx.state.data = { + ctx.set('data', { title: 'Rust语言中文社区 | 招聘', link: jobs_url, description: `获取Rust语言中文社区的最新招聘`, item: await Promise.all(list.map((item) => getFeedItem(item))), - }; + }); }; function getFeedItem(item) { - const $ = cheerio.load(item); + const $ = load(item); const title = $('.title'); return { diff --git a/lib/v2/sakurazaka46/blog.js b/lib/v2/sakurazaka46/blog.js index a8ee1b711..42a5a5dea 100644 --- a/lib/v2/sakurazaka46/blog.js +++ b/lib/v2/sakurazaka46/blog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'all'; - const page = ctx.params.page ?? '0'; + const id = ctx.req.param('id') ?? 'all'; + const page = ctx.req.param('page') ?? '0'; const rootUrl = 'https://sakurazaka46.com'; const params = id === 'all' ? `?page=${page}` : `?page=${page}&ct=${id}`; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.com-blog-part .box a') .toArray() @@ -38,7 +38,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.box-article').html(); item.pubDate = timezone(parseDate(content('.blog-foot .date').text()), +9); @@ -48,9 +48,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${$('title').text()}${id ? ` - ${$('.name').first().text()}` : ''}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sakurazaka46/news.js b/lib/v2/sakurazaka46/news.js index 04edf4c1e..6934da0e4 100644 --- a/lib/v2/sakurazaka46/news.js +++ b/lib/v2/sakurazaka46/news.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://sakurazaka46.com'; @@ -11,10 +11,10 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.com-news-part .box a') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 30) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30) .toArray() .map((item) => { item = $(item); @@ -34,7 +34,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.article').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/samsung/research/blog.js b/lib/v2/samsung/research/blog.js index ab5c47f40..3d5237547 100644 --- a/lib/v2/samsung/research/blog.js +++ b/lib/v2/samsung/research/blog.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://research.samsung.com'; @@ -32,7 +32,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.news-con').html(); @@ -41,9 +41,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'BLOG | Samsung Research', link: `${rootUrl}/blog`, item: items, - }; + }); }; diff --git a/lib/v2/saraba1st/digest.js b/lib/v2/saraba1st/digest.js index 89ee1182b..628da33c3 100644 --- a/lib/v2/saraba1st/digest.js +++ b/lib/v2/saraba1st/digest.js @@ -1,24 +1,24 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const tid = ctx.params.tid; + const tid = ctx.req.param('tid'); const cookieString = config.saraba1st.cookie ?? ''; const res = await got('https://bbs.saraba1st.com/2b/' + tid + '.html', { headers: { Cookie: cookieString, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const title = $('head title').text().replace(/-.*/, ''); const list = $('#threadlisttableid tbody[id^="normalthread_"] tr'); const count = list - .slice(0, ctx.query.limit ? Number(ctx.query.limit) : 20) + .slice(0, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20) .toArray() .map((each) => { each = $(each); @@ -41,12 +41,12 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `Stage1 论坛 - ${title}`, link: `https://bbs.saraba1st.com/2b/${tid}.html`, // item: await resultItems, item: resultItems, - }; + }); }; async function fetchContent(url) { @@ -57,7 +57,7 @@ async function fetchContent(url) { Cookie: cookieString, }, }); - const subind = cheerio.load(subres.data); + const subind = load(subres.data); const stubS = subind('
'); subind('#postlist') .find('div[id*="post_"] ') diff --git a/lib/v2/saraba1st/thread.js b/lib/v2/saraba1st/thread.js index aea4c8261..a74ca52bc 100644 --- a/lib/v2/saraba1st/thread.js +++ b/lib/v2/saraba1st/thread.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 config = require('@/config').value; -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { config } from '@/config'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const tid = ctx.params.tid; + const tid = ctx.req.param('tid'); const cookieString = config.saraba1st.cookie ?? ''; const res = await got('https://bbs.saraba1st.com/2b/forum.php', { @@ -20,7 +20,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const title = $('#thread_subject').text(); const list = $('#postlist > div[id^=post_]:not(:first-of-type)'); @@ -55,9 +55,9 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: `Stage1 论坛 - ${title}`, link: `https://bbs.saraba1st.com/2b/thread-${tid}-1-1.html`, item: resultItems, - }; + }); }; diff --git a/lib/v2/sass/gs/index.js b/lib/v2/sass/gs/index.js index f74406b00..dbb4a7342 100644 --- a/lib/v2/sass/gs/index.js +++ b/lib/v2/sass/gs/index.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 host = 'https://gs.sass.org.cn'; module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); const url = `${host}/${type}/list.htm`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.column-news-list .cols_list .cols'); const items = await Promise.all( list.map((i, item) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { let description = ''; if (itemUrl) { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); description = $('.read .wp_articlecontent').length ? $('.read .wp_articlecontent').html().trim() : itemTitle; } else { description = itemTitle; @@ -37,10 +37,10 @@ module.exports = async (ctx) => { }) ); // 处理返回 - ctx.state.data = { + ctx.set('data', { title: '上海社会科学院 - 研究生院', link: url, description: '上海社会科学院 - 研究生院', item: items, - }; + }); }; diff --git a/lib/v2/scau/yjs.js b/lib/v2/scau/yjs.js index 343cd4b09..539aeff91 100644 --- a/lib/v2/scau/yjs.js +++ b/lib/v2/scau/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://yzb.scau.edu.cn/2136/list1.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w25 tr'); - ctx.state.data = { + ctx.set('data', { title: '华南农业大学研招办', link, description: '华农研讯', @@ -23,5 +23,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('td').eq(3).text(), 'YYYY/MM/DD'), }; }), - }; + }); }; diff --git a/lib/v2/scau/yjsy.js b/lib/v2/scau/yjsy.js index 1e0259a2e..95742e082 100644 --- a/lib/v2/scau/yjsy.js +++ b/lib/v2/scau/yjsy.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://yjsy.scau.edu.cn/208/list1.htm'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w25 tr td tr'); - ctx.state.data = { + ctx.set('data', { title: '华南农业大学研究生院', link, description: '通知公告', @@ -23,5 +23,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('td').eq(2).text(), 'YYYY/MM/DD'), }; }), - }; + }); }; diff --git a/lib/v2/science/blogs.js b/lib/v2/science/blogs.js index a5f5287b2..10aad2587 100644 --- a/lib/v2/science/blogs.js +++ b/lib/v2/science/blogs.js @@ -1,7 +1,8 @@ -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { baseUrl } = require('./utils'); -const config = require('@/config').value; +import { config } from '@/config'; +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { name = 'pipeline' } = ctx.params; @@ -10,7 +11,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); @@ -32,7 +33,7 @@ module.exports = async (ctx) => { false ); - const $ = cheerio.load(response, { xmlMode: true }); + const $ = load(response, { xmlMode: true }); const items = $('item') .toArray() .map((item) => { @@ -51,12 +52,12 @@ module.exports = async (ctx) => { const name_re = /Keyword search result for Blog Series: (?[^-]+) --/; const { blog_name = 'Unknown Title' } = $('channel > description').text().match(name_re).groups; - ctx.state.data = { + ctx.set('data', { title: `Science Blogs: ${blog_name}`, description: `A Science.org blog called ${blog_name}`, image: `${baseUrl}/apple-touch-icon.png`, link: `${baseUrl}/blogs/${name}`, language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/science/cover.js b/lib/v2/science/cover.js index afc33e22f..c9f67867f 100644 --- a/lib/v2/science/cover.js +++ b/lib/v2/science/cover.js @@ -7,10 +7,10 @@ // signaling: Science Signaling // stm: Science Translational Medicine -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 { baseUrl } = require('./utils'); @@ -22,7 +22,7 @@ module.exports = async (ctx) => { cookie: 'cookiePolicy=iaccept;', }, }); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const items = $('.browse-journals .browse-journals__item') .not('.partner-journals') @@ -58,12 +58,12 @@ module.exports = async (ctx) => { }; }); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('meta[property="og:description"]').attr('content'), image: `${baseUrl}/apple-touch-icon.png`, link: pageURL, language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/science/current.js b/lib/v2/science/current.js index 4cd039f36..05bf8bba6 100644 --- a/lib/v2/science/current.js +++ b/lib/v2/science/current.js @@ -7,9 +7,10 @@ // signaling: Science Signaling // stm: Science Translational Medicine -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; const { baseUrl, fetchDesc, getItem } = require('./utils'); +import puppeteer from '@/utils/puppeteer'; module.exports = async (ctx) => { const { journal = 'science' } = ctx.params; @@ -20,23 +21,23 @@ module.exports = async (ctx) => { cookie: 'cookiePolicy=iaccept;', }, }); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const pageTitleName = $('head > title').text(); const list = $('.toc__section .card') .toArray() .map((item) => getItem(item, $)); - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const items = await fetchDesc(list, browser, ctx.cache.tryGet); await browser.close(); - ctx.state.data = { + ctx.set('data', { title: `${pageTitleName} | Current Issue`, description: `Current Issue of ${pageTitleName}`, image: `${baseUrl}/apple-touch-icon.png`, link: pageURL, language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/science/early.js b/lib/v2/science/early.js index 8a031c26e..fa4837354 100644 --- a/lib/v2/science/early.js +++ b/lib/v2/science/early.js @@ -1,5 +1,6 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); +import { load } from 'cheerio'; +import got from '@/utils/got'; +import puppeteer from '@/utils/puppeteer'; const { baseUrl, fetchDesc, getItem } = require('./utils'); @@ -12,22 +13,22 @@ module.exports = async (ctx) => { cookie: 'cookiePolicy=iaccept;', }, }); - const $ = cheerio.load(res); + const $ = load(res); const list = $('.card-content .card-header') .toArray() .map((item) => getItem(item, $)); - const browser = await require('@/utils/puppeteer')(); + const browser = puppeteer(); const items = await fetchDesc(list, browser, ctx.cache.tryGet); await browser.close(); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), description: $('.body02').text().trim(), image: `${baseUrl}/apple-touch-icon.png`, link: pageUrl, language: 'en-US', item: items, - }; + }); }; diff --git a/lib/v2/science/utils.js b/lib/v2/science/utils.js index 42a4f3fc1..620d4f4b0 100644 --- a/lib/v2/science/utils.js +++ b/lib/v2/science/utils.js @@ -1,7 +1,7 @@ -const cheerio = require('cheerio'); -const { art } = require('@/utils/render'); +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 baseUrl = 'https://www.science.org'; @@ -22,7 +22,7 @@ const fetchDesc = (list, browser, tryGet) => const res = await page.evaluate(() => document.documentElement.innerHTML); await page.close(); - const $ = cheerio.load(res); + const $ = load(res); const abstract = $('div#abstracts').html(); const content = $('.news-article-content--featured').length ? $('.news-article-content--featured').html() diff --git a/lib/v2/sciencedirect/journal.js b/lib/v2/sciencedirect/journal.js index 22b9fd158..1578cfe24 100644 --- a/lib/v2/sciencedirect/journal.js +++ b/lib/v2/sciencedirect/journal.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'; const { decodeCFEmail } = require('./cf-email'); module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://www.sciencedirect.com'; const currentUrl = `${rootUrl}/journal/${id}/articles-in-press`; @@ -43,7 +43,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('a.__cf_email__').each((_, e) => { e = content(e); @@ -61,9 +61,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `${response.data.match(/\\"displayName\\":\\"(.*?)\\",\\"/)[1]} - ScienceDirect`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sciencenet/blog.js b/lib/v2/sciencenet/blog.js index a08d15833..49e62663e 100644 --- a/lib/v2/sciencenet/blog.js +++ b/lib/v2/sciencenet/blog.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const iconv = require('iconv-lite'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const type = ctx.params.type ?? 'recommend'; - const time = ctx.params.time ?? '5'; - const sort = ctx.params.sort ?? '1'; + const type = ctx.req.param('type') ?? 'recommend'; + const time = ctx.req.param('time') ?? '5'; + const sort = ctx.req.param('sort') ?? '1'; const rootUrl = 'http://blog.sciencenet.cn'; const currentUrl = `${rootUrl}/blog.php?mod=${type}&type=list&op=${time}&ord=${sort}`; @@ -18,10 +18,10 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const $ = load(iconv.decode(response.data, 'gbk')); let items = $('tr td a[title]') - .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); @@ -42,7 +42,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + const content = load(iconv.decode(detailResponse.data, 'gbk')); item.author = content('.xs2').text(); item.description = content('#blog_article').html(); @@ -53,9 +53,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '科学网 - 精选博文', link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sciencenet/user.js b/lib/v2/sciencenet/user.js index 07749e3e7..9b3cb99b9 100644 --- a/lib/v2/sciencenet/user.js +++ b/lib/v2/sciencenet/user.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 timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id; + const id = ctx.req.param('id'); const rootUrl = 'https://blog.sciencenet.cn'; const currentUrl = `${rootUrl}/u/${id}`; @@ -16,17 +16,17 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - let $ = cheerio.load(iconv.decode(response.data, 'gbk')); + let $ = load(iconv.decode(response.data, 'gbk')); response = await got({ method: 'get', url: $('.xg1 a').eq(1).attr('href'), }); - $ = cheerio.load(response.data); + $ = 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); @@ -46,7 +46,7 @@ module.exports = async (ctx) => { responseType: 'buffer', }); - const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + const content = load(iconv.decode(detailResponse.data, 'gbk')); item.author = content('.xs2').text(); item.description = content('#blog_article').html(); @@ -57,9 +57,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `科学网 - ${items[0].author}的博文`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/scmp/index.js b/lib/v2/scmp/index.js index 362408f5c..185c78341 100644 --- a/lib/v2/scmp/index.js +++ b/lib/v2/scmp/index.js @@ -1,13 +1,13 @@ -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'; const { parseItem } = require('./utils'); module.exports = async (ctx) => { - const categoryId = ctx.params.category_id; + const categoryId = ctx.req.param('category_id'); const rssUrl = `https://www.scmp.com/rss/${categoryId}/feed`; const { data: response } = await got(rssUrl); - const $ = cheerio.load(response, { + const $ = load(response, { xmlMode: true, }); @@ -44,11 +44,11 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => parseItem))); - ctx.state.json = { + ctx.set('json', { items, - }; + }); - ctx.state.data = { + ctx.set('data', { title: $('channel > title').text(), link: $('channel > link').text(), description: $('channel > description').text(), @@ -57,5 +57,5 @@ module.exports = async (ctx) => { icon: 'https://assets.i-scmp.com/static/img/icons/scmp-icon-256x256.png', logo: 'https://customerservice.scmp.com/img/logo_scmp@2x.png', image: $('channel > image > url').text(), - }; + }); }; diff --git a/lib/v2/scmp/router.js b/lib/v2/scmp/router.js index 34c464f02..93fe765e8 100644 --- a/lib/v2/scmp/router.js +++ b/lib/v2/scmp/router.js @@ -1,5 +1,5 @@ module.exports = (router) => { - router.redirect('/coronavirus', '/scmp/topics/coronavirus-pandemic-all-stories'); + router.get('/coronavirus', (c) => c.redirect('/scmp/topics/coronavirus-pandemic-all-stories')); router.get('/:category_id', require('./index')); router.get('/topics/:topic', require('./topic')); }; diff --git a/lib/v2/scmp/topic.js b/lib/v2/scmp/topic.js index 30e3968e1..cbc562f43 100644 --- a/lib/v2/scmp/topic.js +++ b/lib/v2/scmp/topic.js @@ -1,14 +1,14 @@ -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'; const { parseItem } = require('./utils'); module.exports = async (ctx) => { const { topic } = ctx.params; - const limit = Number.parseInt(ctx.query.limit, 10) || 30; + const limit = Number.parseInt(ctx.req.query('limit'), 10) || 30; const pageUrl = `https://www.scmp.com/topics/${topic}`; const { data: pageResponse } = await got(pageUrl); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); const topicData = nextData.props.pageProps.payload.data.topic; @@ -48,12 +48,12 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => parseItem(item)))); - ctx.state.json = { + ctx.set('json', { nextData, apiResponse, - }; + }); - ctx.state.data = { + ctx.set('data', { title: topicData.name, link: pageUrl, description: topicData.description.text, @@ -62,5 +62,5 @@ module.exports = async (ctx) => { icon: 'https://assets.i-scmp.com/static/img/icons/scmp-icon-256x256.png', logo: 'https://customerservice.scmp.com/img/logo_scmp@2x.png', image: 'https://assets-v2.i-scmp.com/production/_next/static/media/default-image.d1be8967.png', - }; + }); }; diff --git a/lib/v2/scmp/utils.js b/lib/v2/scmp/utils.js index 5b6dfdf77..540bd0941 100644 --- a/lib/v2/scmp/utils.js +++ b/lib/v2/scmp/utils.js @@ -1,6 +1,6 @@ -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'; const renderHTML = (node) => { if (!node) { @@ -67,7 +67,7 @@ const parseItem = async (item) => { return item; } - const $ = cheerio.load(response); + const $ = load(response); const nextData = JSON.parse($('script#__NEXT_DATA__').text()); const { article } = nextData.props.pageProps.payload.data; diff --git a/lib/v2/scnu/cs/match.js b/lib/v2/scnu/cs/match.js index 70c336a70..7f1fa9264 100644 --- a/lib/v2/scnu/cs/match.js +++ b/lib/v2/scnu/cs/match.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 = 'http://cs.scnu.edu.cn'; @@ -12,10 +12,10 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.listshow li a'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, description: '华南师范大学计算机学院 学科竞赛', @@ -32,5 +32,5 @@ module.exports = async (ctx) => { link: item.attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/scnu/jw.js b/lib/v2/scnu/jw.js index 38b1b201b..df1272e33 100644 --- a/lib/v2/scnu/jw.js +++ b/lib/v2/scnu/jw.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 = 'http://jw.scnu.edu.cn'; @@ -12,10 +12,10 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.notice_01').find('li'); - ctx.state.data = { + ctx.set('data', { title: $('title').first().text(), link: url, description: '华南师范大学教务处 - 通知公告', @@ -29,5 +29,5 @@ module.exports = async (ctx) => { link: item.find('a').attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/scnu/library.js b/lib/v2/scnu/library.js index d5cfbb5a0..e36cf95ff 100644 --- a/lib/v2/scnu/library.js +++ b/lib/v2/scnu/library.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://lib.scnu.edu.cn'; @@ -12,10 +12,10 @@ module.exports = async (ctx) => { Referer: baseUrl, }, }); - const $ = cheerio.load(res.data); + const $ = load(res.data); const list = $('.article-list').find('li'); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: url, description: '华南师范大学图书馆 - 通知公告', @@ -29,5 +29,5 @@ module.exports = async (ctx) => { link: item.find('a').attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/scnu/physics-school-announcements-and-news.js b/lib/v2/scnu/physics-school-announcements-and-news.js index b891a05bb..0e9233185 100644 --- a/lib/v2/scnu/physics-school-announcements-and-news.js +++ b/lib/v2/scnu/physics-school-announcements-and-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 getAritlces = async (category, url, cache) => { const { data } = await got(url); - const $ = cheerio.load(data); + const $ = load(data); const spiderResult = $('ul.article-list') .children() .toArray() @@ -24,7 +24,7 @@ const getAritlces = async (category, url, cache) => { .map((item) => cache.tryGet(item.link, async () => { const { data } = await got(item.link); - const $ = cheerio.load(data); + const $ = load(data); const aritcleContent = $(data).find('div.detail').html(); item.description = aritcleContent; return item; @@ -53,11 +53,11 @@ module.exports.announcementsRouter = async (ctx) => { 学工: 'https://physics.scnu.edu.cn/NEWS/Notices/Students/', }; const items = await getItemsFromURLs(URLs, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '华南师范大学物理与电信工程学院通知', link: 'https://physics.scnu.edu.cn/NEWS/Notices/', item: items, - }; + }); }; module.exports.newsRouter = async (ctx) => { @@ -86,9 +86,9 @@ module.exports.researchNewsRouter = async (ctx) => { 科研成果: 'https://physics.scnu.edu.cn/RESEARCH/Achievements/', }; const items = await getItemsFromURLs(URLs, ctx.cache); - ctx.state.data = { + ctx.set('data', { title: '华南师范大学物理与电信工程学院科学研究动态', link: 'https://physics.scnu.edu.cn/RESEARCH/', item: items, - }; + }); }; diff --git a/lib/v2/scnu/ss.js b/lib/v2/scnu/ss.js index 9309e1842..56cadfcd4 100644 --- a/lib/v2/scnu/ss.js +++ b/lib/v2/scnu/ss.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 = 'http://ss.scnu.edu.cn/tongzhigonggao/'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.listshow li a'); - ctx.state.data = { + ctx.set('data', { title: '华南师范大学软件学院', link, item: @@ -24,5 +24,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('.time').text()), }; }), - }; + }); }; diff --git a/lib/v2/scnu/yjs.js b/lib/v2/scnu/yjs.js index d5497ef82..068e1d88f 100644 --- a/lib/v2/scnu/yjs.js +++ b/lib/v2/scnu/yjs.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const link = 'https://yz.scnu.edu.cn/tongzhigonggao/ssgg/'; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.listmod div a'); - ctx.state.data = { + ctx.set('data', { title: '华南师范大学研究生院', link, description: '华南师范大学研究生院通知公告', @@ -20,5 +20,5 @@ module.exports = async (ctx) => { link: item.attr('href'), }; }), - }; + }); }; diff --git a/lib/v2/sctv/programme.js b/lib/v2/sctv/programme.js index 0cb75e05d..e2ea04b75 100644 --- a/lib/v2/sctv/programme.js +++ b/lib/v2/sctv/programme.js @@ -1,13 +1,13 @@ -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 id = ctx.params.id ?? '1'; - const limit = ctx.params.limit ? Number.parseInt(ctx.params.limit) : 15; - const isFull = /t|y/i.test(ctx.params.isFull ?? 'true'); + const id = ctx.req.param('id') ?? '1'; + const limit = ctx.req.param('limit') ? Number.parseInt(ctx.req.param('limit')) : 15; + const isFull = /t|y/i.test(ctx.req.param('isFull') ?? 'true'); const rootUrl = 'https://www.sctv.com'; const apiRootUrl = 'https://kscgc.sctv-tf.com'; @@ -71,10 +71,10 @@ module.exports = async (ctx) => { } } - ctx.state.data = { + ctx.set('data', { title: `四川广播电视台 - ${name}`, link: currentUrl, - item: items.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 100), + item: items.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100), image: cover, - }; + }); }; diff --git a/lib/v2/scut/jwc/news.js b/lib/v2/scut/jwc/news.js index 0e8503677..c6d2d504f 100644 --- a/lib/v2/scut/jwc/news.js +++ b/lib/v2/scut/jwc/news.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const url = require('url'); const querystring = require('querystring'); @@ -103,9 +103,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学教务处新闻动态', link: listPageUrl, item: out, - }; + }); }; diff --git a/lib/v2/scut/jwc/notice.js b/lib/v2/scut/jwc/notice.js index b5584784f..e8d207b3f 100644 --- a/lib/v2/scut/jwc/notice.js +++ b/lib/v2/scut/jwc/notice.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const url = require('url'); const querystring = require('querystring'); @@ -54,7 +54,7 @@ const generateArticleLink = (id) => `

链接: resolveRelativeUrl(data.content) + generateArticleLink(data.id); module.exports = async (ctx) => { - const categoryName = ctx.params.category || 'all'; + const categoryName = ctx.req.param('category') || 'all'; const categoryMeta = categoryMap[categoryName]; const qs = querystring.stringify({ @@ -113,9 +113,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学教务处学院通知 - ' + categoryMeta.title, link: listPageUrl, item: out, - }; + }); }; diff --git a/lib/v2/scut/scet/notice.js b/lib/v2/scut/scet/notice.js index 590461159..4f9ed51e8 100644 --- a/lib/v2/scut/scet/notice.js +++ b/lib/v2/scut/scet/notice.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const link = 'https://www2.scut.edu.cn/jtxs/24241/list.htm'; @@ -10,10 +10,10 @@ module.exports = async (ctx) => { const data = response.data; - const $ = cheerio.load(data); + const $ = load(data); const list = $('#wp_news_w5 li'); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学土木与交通学院 - 学工通知', link, item: @@ -27,5 +27,5 @@ module.exports = async (ctx) => { pubDate: item.find('.Article_PublishDate').text(), }; }), - }; + }); }; diff --git a/lib/v2/scut/seie/news-ccenter.js b/lib/v2/scut/seie/news-ccenter.js index f042d0000..f59b5273c 100644 --- a/lib/v2/scut/seie/news-ccenter.js +++ b/lib/v2/scut/seie/news-ccenter.js @@ -1,12 +1,12 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const rootUrl = 'https://www2.scut.edu.cn'; const url = `${rootUrl}/ee/16285/list.htm`; const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news_ul li'); const articleList = list.toArray().map((item) => { @@ -23,7 +23,7 @@ module.exports = async (ctx) => { articleList.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(`${rootUrl}${item.link}`); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('.wp_articlecontent *').each((_, child) => { const childElem = content(child); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学电子与信息学院 - 新闻速递', link: url, item: items, - }; + }); }; diff --git a/lib/v2/scut/smae/notice.js b/lib/v2/scut/smae/notice.js index 4a1535180..b5c22d13f 100644 --- a/lib/v2/scut/smae/notice.js +++ b/lib/v2/scut/smae/notice.js @@ -1,7 +1,7 @@ // 导入必要的模组 -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const categoryMap = { gwxx: { title: '公务信息', tag: '20616' }, @@ -16,12 +16,12 @@ const categoryMap = { module.exports = async (ctx) => { const baseUrl = 'http://www2.scut.edu.cn'; - const categoryName = ctx.params.category || 'yjsjw'; + const categoryName = ctx.req.param('category') || 'yjsjw'; const categoryMeta = categoryMap[categoryName]; const url = `${baseUrl}/smae/${categoryMeta.tag}/list.htm`; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#wp_news_w6 ul li.news') .toArray() .map((item) => { @@ -38,7 +38,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('div.wp_articlecontent').html(); @@ -46,9 +46,9 @@ module.exports = async (ctx) => { }) ) ); - ctx.state.data = { + ctx.set('data', { title: `华南理工大学机械与汽车工程学院 - ${categoryMeta.title}`, link: url, item: items, - }; + }); }; diff --git a/lib/v2/scut/yjs.js b/lib/v2/scut/yjs.js index a1ac8457c..77df9ff82 100644 --- a/lib/v2/scut/yjs.js +++ b/lib/v2/scut/yjs.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const baseUrl = 'https://www2.scut.edu.cn'; const link = `${baseUrl}/graduate/14562/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#wp_news_w4 a'); - ctx.state.data = { + ctx.set('data', { title: '华南理工大学研究生院', link, description: '华南理工大学研究生院通知公告', @@ -26,5 +26,5 @@ module.exports = async (ctx) => { pubDate: parseDate(item.find('span').text()), }; }), - }; + }); }; diff --git a/lib/v2/scvtc/xygg.js b/lib/v2/scvtc/xygg.js index e316aaab3..f0b43b9ff 100644 --- a/lib/v2/scvtc/xygg.js +++ b/lib/v2/scvtc/xygg.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const currentUrl = 'https://www.scvtc.edu.cn/ggfw1/xygg.htm'; const response = await got(currentUrl); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('div.text-list ul li') .toArray() .map((item) => { @@ -22,7 +22,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('#vsb_content').html(); @@ -31,10 +31,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('head title').text(), decription: $('meta[name=description]').attr('content'), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sdu/cmse.js b/lib/v2/sdu/cmse.js index 957b6afd6..74755f840 100644 --- a/lib/v2/sdu/cmse.js +++ b/lib/v2/sdu/cmse.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'http://www.cmse.sdu.edu.cn/'; const typelist = ['通知公告', '学院新闻', '本科生教育', '研究生教育', '学术动态']; const urlList = ['zxzx/tzgg.htm', 'zxzx/xyxw.htm', 'zxzx/bksjy.htm', 'zxzx/yjsjy.htm', 'zxzx/xsdt.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.article_list li') .map((_, e) => { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { item.link = new URL(item.link.slice('3'), host).href; return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('.contentTitle').text(); item.author = @@ -50,10 +50,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学材料科学与工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/cs.js b/lib/v2/sdu/cs.js index 7b4386bee..a4310e351 100644 --- a/lib/v2/sdu/cs.js +++ b/lib/v2/sdu/cs.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const { finishArticleItem } = require('@/utils/wechat-mp'); const host = 'https://www.cs.sdu.edu.cn/'; @@ -8,12 +8,12 @@ const typelist = ['学院公告', '学术报告', '科技简讯']; const urlList = ['xygg.htm', 'xsbg.htm', 'kjjx.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.dqlb ul li') .map((_, e) => { @@ -36,7 +36,7 @@ module.exports = async (ctx) => { return item; } const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('.xqnr_tit h2').text().trim(); item.author = $('.xqnr_tit span').eq(1).text().trim().replace('编辑:', '') || '山东大学计算机科学与技术学院'; @@ -48,10 +48,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学计算机科学与技术学院${typelist[type]}通知`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/epe.js b/lib/v2/sdu/epe.js index e71d37550..0467596b5 100644 --- a/lib/v2/sdu/epe.js +++ b/lib/v2/sdu/epe.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const host = 'https://www.epe.sdu.edu.cn/'; const typelist = ['学院动态', '通知公告', '学术论坛']; const urlList = ['zxzx/xydt.htm', 'zxzx/tzgg.htm', 'zxzx/xslt.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('#page_right_main li a') .map((_, e) => { @@ -31,7 +31,7 @@ module.exports = async (ctx) => { item.link = new URL(item.link.slice('3'), host).href; return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const info = $('#show_info').text().split(/\s{4}/); const date = info[0].split(':')[1]; @@ -46,10 +46,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学能源与动力工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/extractor/sdrj.js b/lib/v2/sdu/extractor/sdrj.js index 42adf19cf..1e43c125c 100644 --- a/lib/v2/sdu/extractor/sdrj.js +++ b/lib/v2/sdu/extractor/sdrj.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#vsb_content').html(); author = $("form[name='_newscontent_fromname'] > h1").text(); const exactDateLine = $("form[name='_newscontent_fromname'] > p.info").text().trim(); diff --git a/lib/v2/sdu/extractor/view.js b/lib/v2/sdu/extractor/view.js index ff5e39b92..e9393ac46 100644 --- a/lib/v2/sdu/extractor/view.js +++ b/lib/v2/sdu/extractor/view.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#vsb_content').html(); author = $("form[name='_newscontent_fromname'] > div > p:last-of-type").text(); const exactDateLine = $('.news_tit > p:last-child').text(); diff --git a/lib/v2/sdu/extractor/wh/jwc.js b/lib/v2/sdu/extractor/wh/jwc.js index ede8c49ad..88083fb5d 100644 --- a/lib/v2/sdu/extractor/wh/jwc.js +++ b/lib/v2/sdu/extractor/wh/jwc.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); const form = $("form[name='_newscontent_fromname']"); form.find('h2').remove(); const exactDateElement = form.find('#author'); diff --git a/lib/v2/sdu/extractor/wh/news.js b/lib/v2/sdu/extractor/wh/news.js index c5ff784a7..63a0135be 100644 --- a/lib/v2/sdu/extractor/wh/news.js +++ b/lib/v2/sdu/extractor/wh/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = (link, ctx) => ctx.cache.tryGet(link, async () => { let content, author, exactDate; try { const result = await got(link); - const $ = cheerio.load(result.data); + const $ = load(result.data); content = $('#main-content').html(); author = $('#source').text(); const exactDateLine = $('.news_tit > p:last-child').text(); diff --git a/lib/v2/sdu/mech.js b/lib/v2/sdu/mech.js index 93c2cdf62..c332e3967 100644 --- a/lib/v2/sdu/mech.js +++ b/lib/v2/sdu/mech.js @@ -1,18 +1,18 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const typelist = ['通知公告', '院所新闻', '教学信息', '学术动态', '学院简报']; const urlList = ['xwdt/tzgg.htm', 'xwdt/ysxw.htm', 'xwdt/jxxx.htm', 'xwdt/xsdt.htm', 'xwdt/xyjb.htm']; const host = 'https://www.mech.sdu.edu.cn/'; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('#page_list li a') .slice(0, 1) @@ -35,7 +35,7 @@ module.exports = async (ctx) => { } return ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const info = $('#show_info').text().split(/\s{4}/); const date = info[0].split(':')[1]; @@ -51,10 +51,10 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学机械工程学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/sc.js b/lib/v2/sdu/sc.js index 9fe5c26df..69fac7b3c 100644 --- a/lib/v2/sdu/sc.js +++ b/lib/v2/sdu/sc.js @@ -1,17 +1,17 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const host = 'https://www.sc.sdu.edu.cn/'; const typelist = ['通知公告', '学术动态', '本科教育', '研究生教育']; const urlList = ['tzgg.htm', 'kxyj/xsyg.htm', 'rcpy/bkjy.htm', 'rcpy/yjsjy.htm']; module.exports = async (ctx) => { - const type = ctx.params.type ? Number.parseInt(ctx.params.type) : 0; + const type = ctx.req.param('type') ? Number.parseInt(ctx.req.param('type')) : 0; const link = new URL(urlList[type], host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); let item = $('.newlist01 li') .map((_, e) => { @@ -32,7 +32,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.title = $('h3').text(); item.author = @@ -52,10 +52,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `山东大学软件学院${typelist[type]}`, description: $('title').text(), link, item, - }; + }); }; diff --git a/lib/v2/sdu/wh/jwc.js b/lib/v2/sdu/wh/jwc.js index e664d38f0..e00c546ff 100644 --- a/lib/v2/sdu/wh/jwc.js +++ b/lib/v2/sdu/wh/jwc.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const data = require('../data').wh.jwc; const extractor = require('../extractor'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; module.exports = async (ctx) => { - const column = ctx.params.column ?? 'gztz'; + const column = ctx.req.param('column') ?? 'gztz'; const baseUrl = data.url; const response = await got(baseUrl + data.columns[column].url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.articleul li'); const out = await Promise.all( items.map(async (index, item) => { @@ -34,9 +34,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${data.name} ${data.columns[column].name}`, link: baseUrl + data.columns[column].url, item: out, - }; + }); }; diff --git a/lib/v2/sdu/wh/news.js b/lib/v2/sdu/wh/news.js index 1abd25594..93d8d64ee 100644 --- a/lib/v2/sdu/wh/news.js +++ b/lib/v2/sdu/wh/news.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const data = require('../data').wh.news; const extractor = require('../extractor'); -const { parseDate } = require('@/utils/parse-date'); +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const column = ctx.params.column ?? 'xyyw'; + const column = ctx.req.param('column') ?? 'xyyw'; const baseUrl = data.url; const response = await got(baseUrl + data.columns[column].url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const items = $('.n_newslist li'); const out = await Promise.all( items.map(async (index, item) => { @@ -30,9 +30,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `${data.name} ${data.columns[column].name}`, link: baseUrl + data.columns[column].url, item: out, - }; + }); }; diff --git a/lib/v2/sdust/yjsy/zhaosheng.js b/lib/v2/sdust/yjsy/zhaosheng.js index 8cfc1144c..1c52bb5b8 100644 --- a/lib/v2/sdust/yjsy/zhaosheng.js +++ b/lib/v2/sdust/yjsy/zhaosheng.js @@ -1,9 +1,9 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? 'tzgg'; + const id = ctx.req.param('id') ?? 'tzgg'; const rootUrl = 'https://yjsy.sdust.edu.cn'; const currentUrl = `${rootUrl}/zhaosheng/${id}.htm`; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('.pageUl ul li a') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); item.description = content('.txt, .v_news_content').html(); @@ -44,9 +44,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sdzk/index.js b/lib/v2/sdzk/index.js index a6f7764d6..eaa52c32e 100644 --- a/lib/v2/sdzk/index.js +++ b/lib/v2/sdzk/index.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const bcid = ctx.params.bcid ?? '1'; - const cid = ctx.params.cid ?? '16'; + const bcid = ctx.req.param('bcid') ?? '1'; + const cid = ctx.req.param('cid') ?? '16'; const rootUrl = 'https://www.sdzk.cn'; const currentUrl = `${rootUrl}/NewsList.aspx?BCID=${bcid}${cid ? `&CID=${cid}` : ''}`; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('a[title]') .toArray() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const info = content('div.laylist-r em').text(); @@ -47,9 +47,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: $('title').text(), link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/sec-in/index.js b/lib/v2/sec-in/index.js index d3e073d56..43aabc0ed 100644 --- a/lib/v2/sec-in/index.js +++ b/lib/v2/sec-in/index.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got('https://sec-in.com/api/v1/Common/getArticleList?tabs=newest'); @@ -11,9 +11,9 @@ module.exports = async (ctx) => { author: item.member_info.nickname, category: item.article_tag, })); - ctx.state.data = { + ctx.set('data', { title: 'SecIN信息安全技术社区', link: 'https://sec-in.com/', item: items, - }; + }); }; diff --git a/lib/v2/sec-wiki/weekly.js b/lib/v2/sec-wiki/weekly.js index adc010539..315eebea9 100644 --- a/lib/v2/sec-wiki/weekly.js +++ b/lib/v2/sec-wiki/weekly.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -// const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +// import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const { data } = await got('https://www.sec-wiki.com/weekly/index'); @@ -8,9 +8,9 @@ module.exports = async (ctx) => { link: `https://www.sec-wiki.com/weekly/${item[1]}`, description: item[3], })); - ctx.state.data = { + ctx.set('data', { title: 'SecWiki-安全维基', link: 'https://www.sec-wiki.com/', item: items, - }; + }); }; diff --git a/lib/v2/secrss/author.js b/lib/v2/secrss/author.js index ee221ff0c..df9a8e95b 100644 --- a/lib/v2/secrss/author.js +++ b/lib/v2/secrss/author.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles/group?author='; - const author = ctx.params.author; + const author = ctx.req.param('author'); const host = 'https://www.secrss.com'; const res = await got(`${api}${author}`); const dataArray = res.data.data.list; @@ -14,7 +14,7 @@ module.exports = async (ctx) => { const itemUrl = `${host}${item.url}`; return ctx.cache.tryGet(itemUrl, async () => { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('.article-body').html().trim(); return { title: item.title, @@ -27,9 +27,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `安全内参-${author}`, link: 'https://www.secrss.com', item: items, - }; + }); }; diff --git a/lib/v2/secrss/category.js b/lib/v2/secrss/category.js index 212c43268..8e0982d57 100644 --- a/lib/v2/secrss/category.js +++ b/lib/v2/secrss/category.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; module.exports = async (ctx) => { const api = 'https://www.secrss.com/api/articles?tag='; @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const itemUrl = `${host}/articles/${item.id}`; return ctx.cache.tryGet(itemUrl, async () => { const result = await got(itemUrl); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('.article-body').html().trim(); return { title: item.title, @@ -29,9 +29,9 @@ module.exports = async (ctx) => { }) ); - ctx.state.data = { + ctx.set('data', { title: `安全内参-${category}`, link: 'https://www.secrss.com', item: items, - }; + }); }; diff --git a/lib/v2/seekingalpha/index.js b/lib/v2/seekingalpha/index.js index b7aea4dd8..1e5ec817c 100644 --- a/lib/v2/seekingalpha/index.js +++ b/lib/v2/seekingalpha/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const dayjs = require('dayjs'); const baseUrl = 'https://seekingalpha.com'; @@ -13,7 +13,7 @@ module.exports = async (ctx) => { cacheBuster: category === 'news' ? dayjs().format('YYYY-MM-DD') : undefined, id: symbol.toLowerCase(), include: 'author,primaryTickers,secondaryTickers,sentiments', - 'page[size]': ctx.query.limit ? Number(ctx.query.limit) : category === 'news' ? 40 : 20, + 'page[size]': ctx.req.query('limit') ? Number(ctx.req.query('limit')) : category === 'news' ? 40 : 20, }, }); @@ -29,7 +29,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const summary = $('[data-test-id=article-summary-title]').length ? $('[data-test-id=article-summary-title]').html() + $('[data-test-id=article-summary-title]').next().html() : ''; @@ -44,7 +44,7 @@ module.exports = async (ctx) => { ) : []; - ctx.state.data = { + ctx.set('data', { title: response.data.meta.page.title, description: response.data.meta.page.description, link: pageUrl, @@ -52,5 +52,5 @@ module.exports = async (ctx) => { item: items, allowEmpty: true, language: 'en-US', - }; + }); }; diff --git a/lib/v2/segmentfault/blogs.js b/lib/v2/segmentfault/blogs.js index 0ab77575c..975b25119 100644 --- a/lib/v2/segmentfault/blogs.js +++ b/lib/v2/segmentfault/blogs.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -13,9 +13,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault-Blogs-${tag}`, link: `${host}/t/${tag}/blogs`, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/channel.js b/lib/v2/segmentfault/channel.js index 00d530604..21e67bc42 100644 --- a/lib/v2/segmentfault/channel.js +++ b/lib/v2/segmentfault/channel.js @@ -1,5 +1,5 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -12,12 +12,12 @@ module.exports = async (ctx) => { query: 'channel', slug: name, offset: 0, - size: ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 20, + size: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20, mode: 'scrollLoad', }, }); - const $ = cheerio.load(pageResponse); + const $ = load(pageResponse); const channelName = $('#leftNav > a.active').text(); const list = parseList(apiResponse.rows); @@ -26,9 +26,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault - ${channelName}`, link, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/user.js b/lib/v2/segmentfault/user.js index 636d37498..f645e0cac 100644 --- a/lib/v2/segmentfault/user.js +++ b/lib/v2/segmentfault/user.js @@ -1,4 +1,4 @@ -const got = require('@/utils/got'); +import got from '@/utils/got'; const { host, acw_sc__v2, parseList, parseItems } = require('./utils'); module.exports = async (ctx) => { @@ -15,9 +15,9 @@ module.exports = async (ctx) => { const items = await Promise.all(list.map((item) => parseItems(acwScV2Cookie, item, ctx.cache.tryGet))); - ctx.state.data = { + ctx.set('data', { title: `segmentfault - ${author}`, link: `${host}/u/${name}`, item: items, - }; + }); }; diff --git a/lib/v2/segmentfault/utils.js b/lib/v2/segmentfault/utils.js index bf19c3e8a..582962e79 100644 --- a/lib/v2/segmentfault/utils.js +++ b/lib/v2/segmentfault/utils.js @@ -1,8 +1,8 @@ const zlib = require('zlib'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const { getAcwScV2ByArg1 } = require('@/v2/5eplay/utils'); const host = 'https://segmentfault.com'; @@ -48,7 +48,7 @@ const parseItems = (cookie, item, tryGet) => cookie: `acw_sc__v2=${cookie};`, }, }); - const content = cheerio.load(response.data); + const content = load(response.data); item.description = content('article').html(); item.category = content('.badge-tag') diff --git a/lib/v2/sehuatang/index.js b/lib/v2/sehuatang/index.js index 5e298795d..b7dfdee72 100644 --- a/lib/v2/sehuatang/index.js +++ b/lib/v2/sehuatang/index.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const { CookieJar } = require('tough-cookie'); const cookieJar = new CookieJar(); @@ -38,7 +38,7 @@ const forumIdMaps = { }; module.exports = async (ctx) => { - const subformName = ctx.params.subforumid ?? 'gqzwzm'; + const subformName = ctx.req.param('subforumid') ?? 'gqzwzm'; const subformId = subformName in forumIdMaps ? forumIdMaps[subformName] : subformName; const { type } = ctx.params; const typefilter = type ? `&filter=typeid&typeid=${type}` : ''; @@ -53,10 +53,10 @@ module.exports = async (ctx) => { cookieJar, headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#threadlisttableid tbody[id^=normalthread]') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -77,7 +77,7 @@ module.exports = async (ctx) => { headers, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const postMessage = $("td[id^='postmessage']").slice(0, 1); const images = $(postMessage).find('img'); for (const image of images) { @@ -121,9 +121,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `色花堂 - ${$('#pt > div:nth-child(1) > a:last-child').text()}`, link, item: out, - }; + }); }; diff --git a/lib/v2/sehuatang/user.js b/lib/v2/sehuatang/user.js index fbcfbdff1..5bd151d6d 100644 --- a/lib/v2/sehuatang/user.js +++ b/lib/v2/sehuatang/user.js @@ -1,8 +1,8 @@ // 导入必要的模组 -const got = require('@/utils/got'); // 自订的 got -const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 -const { parseDate } = require('@/utils/parse-date'); -const config = require('@/config').value; +import got from '@/utils/got'; // 自订的 got +import { load } from 'cheerio'; // 可以使用类似 jQuery 的 API HTML 解析器 +import { parseDate } from '@/utils/parse-date'; +import { config } from '@/config'; const baseUrl = 'https://sehuatang.org/'; @@ -11,7 +11,7 @@ module.exports = async (ctx) => { throw new Error('Sehuatang RSS is disabled due to the lack of relevant config'); } // 从Url参数中获取uid - const uid = ctx.params.uid; + const uid = ctx.req.param('uid'); const link = `${baseUrl}home.php?mod=space&uid=${uid}&do=thread&view=me&from=space`; const response = await got(link, { @@ -22,10 +22,10 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('#delform tr:not(.th)') - .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 25) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25) .toArray() .map((item) => { item = $(item); @@ -51,7 +51,7 @@ module.exports = async (ctx) => { }, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); const postMessage = $("[id^='postmessage']").slice(0, 1); const images = $(postMessage).find('img'); for (const image of images) { @@ -103,10 +103,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { // 在此处输出您的 RSS title: `${$('.mt').text()}的帖子-色花堂`, link, item: out, - }; + }); }; diff --git a/lib/v2/sensortower/blog.js b/lib/v2/sensortower/blog.js index 5cab8617e..ddcb88b43 100644 --- a/lib/v2/sensortower/blog.js +++ b/lib/v2/sensortower/blog.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const path = require('path'); module.exports = async (ctx) => { - const language = ctx.params.language ?? ''; + const language = ctx.req.param('language') ?? ''; const rootUrl = 'https://sensortower.com'; const currentUrl = `${rootUrl}${language ? `/${language}` : ''}/blog`; @@ -29,7 +29,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); const detail = JSON.parse(`{${detailResponse.data.match(/("title":.*?),"body":/)[1]}}`); content('h1').remove(); @@ -60,10 +60,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: 'Sensor Tower - Blog', link: currentUrl, item: items, language: language ?? 'en-US', - }; + }); }; diff --git a/lib/v2/setn/index.js b/lib/v2/setn/index.js index 8dfc38f3a..13d7d4b04 100644 --- a/lib/v2/setn/index.js +++ b/lib/v2/setn/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; const defaultRootUrl = 'https://www.setn.com'; @@ -42,8 +42,8 @@ const getCurrentUrl = (category) => { }; module.exports = async (ctx) => { - const category = ctx.params.category ?? '即時'; - const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit) : 42; + const category = ctx.req.param('category') ?? '即時'; + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 42; const currentUrl = getCurrentUrl(category); @@ -52,7 +52,7 @@ module.exports = async (ctx) => { url: currentUrl, }); - const $ = cheerio.load(response.data); + const $ = load(response.data); let items = $('#NewsList, .newsList, .hotNewsList') .find('.newsItems, .st-news, .all_three_list, div.title-word') @@ -78,7 +78,7 @@ module.exports = async (ctx) => { url: item.link, }); - const content = cheerio.load(detailResponse.data); + const content = load(detailResponse.data); content('#gad_setn_innity_oop_1x1').remove(); @@ -92,9 +92,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `三立新聞網 - ${category}`, link: currentUrl, item: items, - }; + }); }; diff --git a/lib/v2/seu/cse/index.js b/lib/v2/seu/cse/index.js index bac2cb9c5..c66daf2fd 100644 --- a/lib/v2/seu/cse/index.js +++ b/lib/v2/seu/cse/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://cse.seu.edu.cn'; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const link = new URL(`${id}/list.htm`, host).href; const { data: response } = await got(link); - const $ = cheerio.load(response); + const $ = load(response); const list = $('.news_list .news') .toArray() @@ -45,7 +45,7 @@ module.exports = async (ctx) => { } throw error; } - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('div.wp_articlecontent').html(); @@ -54,10 +54,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { link, title: `${$('meta[name=keywords]').attr('content')}${$('meta[name=description]').attr('content')} -- ${$('head title').text()}`, description: '东南大学计算机技术与工程学院RSS', item: out, - }; + }); }; diff --git a/lib/v2/seu/radio/academic.js b/lib/v2/seu/radio/academic.js index e607decc1..ccafeff0b 100644 --- a/lib/v2/seu/radio/academic.js +++ b/lib/v2/seu/radio/academic.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://radio.seu.edu.cn'; const link = new URL('_s29/15986/list.psp', host).href; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.list_item') .toArray() @@ -25,7 +25,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.author = $('.arti_publisher').text().replace('发布者:', ''); item.description = $('.wp_articlecontent').html(); @@ -35,9 +35,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '东南大学信息科学与工程学院 -- 学术活动', link, item: out, - }; + }); }; diff --git a/lib/v2/seu/yjs.js b/lib/v2/seu/yjs.js index b0037a961..1862e5b94 100644 --- a/lib/v2/seu/yjs.js +++ b/lib/v2/seu/yjs.js @@ -1,11 +1,11 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const url = 'https://seugs.seu.edu.cn/26671/list.htm'; module.exports = async (ctx) => { const response = await got(url); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $('.news') .toArray() .map((element) => { @@ -21,7 +21,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $('.wp_articlecontent').html(); item.pubDate = new Date(item.date).toUTCString(); return item; @@ -29,9 +29,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: '东南大学研究生公告', link: url, item: items, - }; + }); }; diff --git a/lib/v2/seu/yzb/index.js b/lib/v2/seu/yzb/index.js index ab545a2c2..773243829 100644 --- a/lib/v2/seu/yzb/index.js +++ b/lib/v2/seu/yzb/index.js @@ -1,6 +1,6 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { const host = 'https://yzb.seu.edu.cn'; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { const url = new URL(`${id}/list.htm`, host).href; const { data: response } = await got(url); - const $ = cheerio.load(response); + const $ = load(response); const list = $('#wp_news_w3 td tbody tr') .toArray() @@ -34,7 +34,7 @@ module.exports = async (ctx) => { list.map((item) => ctx.cache.tryGet(item.link, async () => { const { data: response } = await got(item.link); - const $ = cheerio.load(response); + const $ = load(response); item.description = $('.Article_Content').html(); @@ -43,9 +43,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { link: url, title: `东南大学研究生招生网 -- ${$('head title').text()}`, item: items, - }; + }); }; diff --git a/lib/v2/shcstheatre/programs.js b/lib/v2/shcstheatre/programs.js index 5d3776644..c33ad3796 100644 --- a/lib/v2/shcstheatre/programs.js +++ b/lib/v2/shcstheatre/programs.js @@ -1,14 +1,14 @@ -const got = require('@/utils/got'); -const { art } = require('@/utils/render'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { art } from '@/utils/render'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import { load } from 'cheerio'; const path = require('path'); module.exports = async (ctx) => { const url = 'https://www.shcstheatre.com/Program/programList.aspx'; const res = await got.get(url); - const $ = cheerio.load(res.data); + const $ = load(res.data); const items = await Promise.all( $('#datarow .program-name a').map((_, elem) => { const link = new URL($(elem).attr('href'), url); @@ -30,10 +30,10 @@ module.exports = async (ctx) => { ); const image = $('.menu-logo img').attr('src'); - ctx.state.data = { + ctx.set('data', { title: '上海文化广场 - 节目列表', link: url, image, item: items, - }; + }); }; diff --git a/lib/v2/shiep/index.js b/lib/v2/shiep/index.js index 2c5ecd900..9850146da 100644 --- a/lib/v2/shiep/index.js +++ b/lib/v2/shiep/index.js @@ -1,13 +1,13 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); +import got from '@/utils/got'; +import { load } from 'cheerio'; const dayjs = require('dayjs'); const path = require('path'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; const { config } = require('./config'); module.exports = async (ctx) => { - const type = ctx.params.type; + const type = ctx.req.param('type'); if (!Object.keys(config).includes(type)) { throw new Error(`Invalid type: ${type}`); @@ -20,11 +20,11 @@ module.exports = async (ctx) => { } const host = `https://${type}.shiep.edu.cn`; - const id = ctx.params.id || config[type].id; + const id = ctx.req.param('id') || config[type].id; const link = type === 'career' ? `${host}/news/index/tag/${id}` : `${host}/${id}/list.htm`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const list = $(listSelector) .toArray() @@ -48,7 +48,7 @@ module.exports = async (ctx) => { ctx.cache.tryGet(item.link, async () => { try { const response = await got(item.link); - const $ = cheerio.load(response.data); + const $ = load(response.data); item.description = $(descriptionSelector).length > 0 @@ -64,9 +64,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `上海电力大学-${title}`, link, item: items, - }; + }); }; diff --git a/lib/v2/shisu/news.js b/lib/v2/shisu/news.js index bc58b68c5..78da8b50a 100644 --- a/lib/v2/shisu/news.js +++ b/lib/v2/shisu/news.js @@ -1,7 +1,7 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; const url = 'https://news.shisu.edu.cn'; const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316ae531f.png'; @@ -9,7 +9,7 @@ const banner = 'https://news.shisu.edu.cn/news/index/39adf3d9ae414bc39c6d3b9316a module.exports = async (ctx) => { const { section = 'news' } = ctx.params; const { data: r } = await got(`${url}/${section}/index.html`); - const $ = cheerio.load(r); + const $ = load(r); let itemsoup; switch (section) { case 'news': @@ -42,7 +42,7 @@ module.exports = async (ctx) => { itemsoup.map((j) => ctx.cache.tryGet(j.link, async () => { const { data: r } = await got(j.link); - const $ = cheerio.load(r); + const $ = load(r); const img = $('.tempWrap > ul > li:nth-child(1)> img').attr('src'); j.description = $('.ot_main_r .content').html(); j.author = $('.math_time_l > span:nth-child(3)').text().trim(); @@ -55,10 +55,10 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title: `上外新闻|SISU TODAY -${section.charAt(0).toUpperCase() + section.slice(1)}`, image: 'https://bkimg.cdn.bcebos.com/pic/8d5494eef01f3a296b70affa9825bc315c607c4d?x-bce-process=image/resize,m_lfit,w_536,limit_1/quality,Q_70', link: `${url}/${section}/index.html`, item: items, - }; + }); }; diff --git a/lib/v2/shmeea/index.js b/lib/v2/shmeea/index.js index 6fc1c22f3..87aba2d6e 100644 --- a/lib/v2/shmeea/index.js +++ b/lib/v2/shmeea/index.js @@ -1,15 +1,15 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); +import got from '@/utils/got'; +import { load } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; module.exports = async (ctx) => { - const id = ctx.params.id ?? '08000'; + const id = ctx.req.param('id') ?? '08000'; const baseURL = 'https://www.shmeea.edu.cn'; const link = `${baseURL}/page/${id}/index.html`; const response = await got(link); - const $ = cheerio.load(response.data); + const $ = load(response.data); const title = `上海市教育考试院-${$('#main .pageh4-tit').text().trim()}`; @@ -32,7 +32,7 @@ module.exports = async (ctx) => { } const result = await got(item.link); - const $ = cheerio.load(result.data); + const $ = load(result.data); const description = $('#ivs_content').html(); const pbTimeText = $('#ivs_title .PBtime').text().trim(); @@ -45,9 +45,9 @@ module.exports = async (ctx) => { ) ); - ctx.state.data = { + ctx.set('data', { title, link, item: items, - }; + }); };