diff --git a/lib/v2/alternativeto/platform.js b/lib/v2/alternativeto/platform.js index 07a1a6bbdd..c0a6f4e42a 100644 --- a/lib/v2/alternativeto/platform.js +++ b/lib/v2/alternativeto/platform.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const { baseURL, puppeteerGet } = require('./utils'); import { load } from 'cheerio'; @@ -7,7 +8,7 @@ module.exports = async (ctx) => { const link = `https://alternativeto.net/platform/${name}/?${query.toString()}`; // use Puppeteer due to the obstacle by cloudflare challenge - const html = await puppeteerGet(link, ctx.cache); + const html = await puppeteerGet(link, cache); const $ = load(html); ctx.set('data', { diff --git a/lib/v2/alternativeto/software.js b/lib/v2/alternativeto/software.js index edf4bc067c..ff93df804e 100644 --- a/lib/v2/alternativeto/software.js +++ b/lib/v2/alternativeto/software.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const { baseURL, puppeteerGet } = require('./utils'); import { load } from 'cheerio'; @@ -7,7 +8,7 @@ module.exports = async (ctx) => { const link = `https://alternativeto.net/software/${name}/?${query.toString()}`; // use Puppeteer due to the obstacle by cloudflare challenge - const html = await puppeteerGet(link, ctx.cache); + const html = await puppeteerGet(link, cache); const $ = load(html); ctx.set('data', { diff --git a/lib/v2/bit/cs/cs.js b/lib/v2/bit/cs/cs.js index 2bc4c2ef0d..d10de38d0b 100644 --- a/lib/v2/bit/cs/cs.js +++ b/lib/v2/bit/cs/cs.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -13,7 +14,7 @@ module.exports = async (ctx) => { const list = $('.box_list01 li').toArray(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: $('title').text(), diff --git a/lib/v2/bit/jwc/jwc.js b/lib/v2/bit/jwc/jwc.js index 853da95ae6..7eeec9028c 100644 --- a/lib/v2/bit/jwc/jwc.js +++ b/lib/v2/bit/jwc/jwc.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -13,7 +14,7 @@ module.exports = async (ctx) => { const list = $('li.gpTextArea').toArray(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: $('title').text(), diff --git a/lib/v2/bjfu/it/index.js b/lib/v2/bjfu/it/index.js index b7d3134686..924cdbe8c9 100644 --- a/lib/v2/bjfu/it/index.js +++ b/lib/v2/bjfu/it/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -40,7 +41,7 @@ module.exports = async (ctx) => { const list = $('.item-content').toArray(); - const result = await util.ProcessFeed(base, list, ctx.cache); // 感谢@hoilc指导 + const result = await util.ProcessFeed(base, list, cache); // 感谢@hoilc指导 ctx.set('data', { title: '北林信息 - ' + title, diff --git a/lib/v2/bjfu/jwc/index.js b/lib/v2/bjfu/jwc/index.js index 09fbf7629a..278fed8bc8 100644 --- a/lib/v2/bjfu/jwc/index.js +++ b/lib/v2/bjfu/jwc/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -39,7 +40,7 @@ module.exports = async (ctx) => { const list = $('.list_c li').slice(0, 15).toArray(); - const result = await util.ProcessFeed(base, list, ctx.cache); // 感谢@hoilc指导 + const result = await util.ProcessFeed(base, list, cache); // 感谢@hoilc指导 ctx.set('data', { title: '北林教务处 - ' + title, diff --git a/lib/v2/bjfu/news/index.js b/lib/v2/bjfu/news/index.js index b2947a91be..97f1cce820 100644 --- a/lib/v2/bjfu/news/index.js +++ b/lib/v2/bjfu/news/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -47,7 +48,7 @@ module.exports = async (ctx) => { const list = $('.news_ul li').slice(0, 12).toArray(); - const result = await util.ProcessFeed(base, list, ctx.cache); // 感谢@hoilc指导 + const result = await util.ProcessFeed(base, list, cache); // 感谢@hoilc指导 ctx.set('data', { title: '北林新闻- ' + title, diff --git a/lib/v2/caai/index.js b/lib/v2/caai/index.js index a5470a20c7..e832ed962b 100644 --- a/lib/v2/caai/index.js +++ b/lib/v2/caai/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ module.exports = async (ctx) => { const info = utils.fetchAllArticles(res.data); const $ = load(res.data); - const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache))); + const details = await Promise.all(info.map((e) => utils.detailPage(e, cache))); ctx.set('json', { info, diff --git a/lib/v2/ccf/tfbd/index.js b/lib/v2/ccf/tfbd/index.js index 151fb7dcec..66c8a74399 100644 --- a/lib/v2/ccf/tfbd/index.js +++ b/lib/v2/ccf/tfbd/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import got from '@/utils/got'; import { load } from 'cheerio'; @@ -8,7 +9,7 @@ module.exports = async (ctx) => { const info = utils.fetchAllArticles(res.data); const $ = load(res.data); - const details = await Promise.all(info.map((e) => utils.detailPage(e, ctx.cache))); + const details = await Promise.all(info.map((e) => utils.detailPage(e, cache))); ctx.set('json', { info, diff --git a/lib/v2/dcard/section.js b/lib/v2/dcard/section.js index 4d158e049d..6bc225a60e 100644 --- a/lib/v2/dcard/section.js +++ b/lib/v2/dcard/section.js @@ -56,7 +56,7 @@ module.exports = async (ctx) => { })); // parse fulltext for first `limit` items - const result = await utils.ProcessFeed(items, cookies, browser, limit, ctx.cache); + const result = await utils.ProcessFeed(items, cookies, browser, limit, cache); await browser.close(); ctx.set('data', { diff --git a/lib/v2/dlsite/utils.js b/lib/v2/dlsite/utils.js index c8e63ff1cd..2398c49689 100644 --- a/lib/v2/dlsite/utils.js +++ b/lib/v2/dlsite/utils.js @@ -5,6 +5,7 @@ import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; import { art } from '@/utils/render'; const dayjs = require('dayjs'); +import * as path from 'node:path'; const rootUrl = 'https://www.dlsite.com'; @@ -45,11 +46,11 @@ const getDetails = async (works) => { const ProcessItems = async (ctx) => { art.defaults.imports.formatDate = formatDate; - const path = getSubPath(ctx) === '/' ? '/home/new' : getSubPath(ctx); + const subPath = getSubPath(ctx) === '/' ? '/home/new' : getSubPath(ctx); const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 100; - const currentUrl = `${rootUrl}${addFilters(path, defaultFilters)}`; + const currentUrl = `${rootUrl}${addFilters(subPath, defaultFilters)}`; const response = await got({ method: 'get', diff --git a/lib/v2/douban/people/wish.js b/lib/v2/douban/people/wish.js index 6df02fd944..54f07d1611 100644 --- a/lib/v2/douban/people/wish.js +++ b/lib/v2/douban/people/wish.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const querystring = require('querystring'); import { load } from 'cheerio'; import got from '@/utils/got'; @@ -15,7 +16,7 @@ module.exports = async (ctx) => { const url = `https://movie.douban.com/people/${userid}/wish?start=${page * pageSize}`; tasks.push( - ctx.cache + cache .tryGet( url, async () => { diff --git a/lib/v2/dribbble/utils.js b/lib/v2/dribbble/utils.js index 819ecbff89..388d6f7b4a 100644 --- a/lib/v2/dribbble/utils.js +++ b/lib/v2/dribbble/utils.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -140,7 +141,7 @@ const getData = async (ctx, url, title) => { const list = $('ol.dribbbles.group > li').toArray(); // Process the list items using the ProcessFeed function - const result = await ProcessFeed(list, ctx.cache); + const result = await ProcessFeed(list, cache); // Return an object containing the retrieved data and metadata return { diff --git a/lib/v2/ehentai/favorites.js b/lib/v2/ehentai/favorites.js index 112aa03b01..eb7ad0c4d3 100644 --- a/lib/v2/ehentai/favorites.js +++ b/lib/v2/ehentai/favorites.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const EhAPI = require('./ehapi'); module.exports = async (ctx) => { @@ -10,7 +11,7 @@ module.exports = async (ctx) => { const bittorrent = routeParams.get('bittorrent') || false; const embed_thumb = routeParams.get('embed_thumb') || false; const inline_set = ctx.req.param('order') === 'posted' ? 'fs_p' : 'fs_f'; - const items = await EhAPI.getFavoritesItems(ctx.cache, favcat, inline_set, page, bittorrent, embed_thumb); + const items = await EhAPI.getFavoritesItems(cache, favcat, inline_set, page, bittorrent, embed_thumb); ctx.set( 'data', diff --git a/lib/v2/ehentai/search.js b/lib/v2/ehentai/search.js index c19db03165..c93f5655f0 100644 --- a/lib/v2/ehentai/search.js +++ b/lib/v2/ehentai/search.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const EhAPI = require('./ehapi'); module.exports = async (ctx) => { @@ -10,9 +11,9 @@ module.exports = async (ctx) => { if (page) { // 如果定义了page,就要覆盖params params = params.replace(/&*next=[^&]$/, '').replace(/next=[^&]&/, ''); - items = await EhAPI.getSearchItems(ctx.cache, params, page, bittorrent, embed_thumb); + items = await EhAPI.getSearchItems(cache, params, page, bittorrent, embed_thumb); } else { - items = await EhAPI.getSearchItems(ctx.cache, params, undefined, bittorrent, embed_thumb); + items = await EhAPI.getSearchItems(cache, params, undefined, bittorrent, embed_thumb); } let title = params; const match = /f_search=([^&]+)/.exec(title); diff --git a/lib/v2/ehentai/tag.js b/lib/v2/ehentai/tag.js index 15f8bbeb21..9888faec71 100644 --- a/lib/v2/ehentai/tag.js +++ b/lib/v2/ehentai/tag.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const EhAPI = require('./ehapi'); module.exports = async (ctx) => { @@ -6,7 +7,7 @@ module.exports = async (ctx) => { const routeParams = new URLSearchParams(ctx.req.param('routeParams')); const bittorrent = routeParams.get('bittorrent') || false; const embed_thumb = routeParams.get('embed_thumb') || false; - const items = await EhAPI.getTagItems(ctx.cache, tag, page, bittorrent, embed_thumb); + const items = await EhAPI.getTagItems(cache, tag, page, bittorrent, embed_thumb); ctx.set( 'data', diff --git a/lib/v2/flyert/creditcard.js b/lib/v2/flyert/creditcard.js index 7c08cad750..4274793861 100644 --- a/lib/v2/flyert/creditcard.js +++ b/lib/v2/flyert/creditcard.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -78,7 +79,7 @@ module.exports = async (ctx) => { const list = $("[id*='normalthread']").get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: `飞客茶馆信用卡 - ${bankname}`, diff --git a/lib/v2/freecomputerbooks/index.js b/lib/v2/freecomputerbooks/index.js index 77be282e9f..eb14947328 100644 --- a/lib/v2/freecomputerbooks/index.js +++ b/lib/v2/freecomputerbooks/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { load } from 'cheerio'; import * as path from 'node:path'; @@ -31,7 +32,7 @@ module.exports = async (ctx) => { item: await Promise.all( $('ul[id^=newBooks] > li') .toArray() - .map((elem) => buildPostItem($(elem), categoryTitle, ctx.cache)) + .map((elem) => buildPostItem($(elem), categoryTitle, cache)) ), }); }; diff --git a/lib/v2/furstar/index.js b/lib/v2/furstar/index.js index 5c029da9a5..7c567e04c8 100644 --- a/lib/v2/furstar/index.js +++ b/lib/v2/furstar/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; @@ -11,7 +12,7 @@ module.exports = async (ctx) => { }); const info = utils.fetchAllCharacters(res.data, base); - const details = await Promise.all(info.map((e) => utils.detailPage(e.detailPage, ctx.cache))); + const details = await Promise.all(info.map((e) => utils.detailPage(e.detailPage, cache))); ctx.set('json', { info, diff --git a/lib/v2/grubstreet/utils.js b/lib/v2/grubstreet/utils.js index 23b635e505..7c63b1ad14 100644 --- a/lib/v2/grubstreet/utils.js +++ b/lib/v2/grubstreet/utils.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; @@ -69,7 +70,7 @@ const getData = async (ctx, url, title, description) => { // limit the list to only 25 articles, to make sure that load times remain reasonable 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); + const result = await ProcessFeed(list, cache); return { title, diff --git a/lib/v2/hrbust/jwzx.js b/lib/v2/hrbust/jwzx.js index 67eb4090c4..8b2c58be93 100644 --- a/lib/v2/hrbust/jwzx.js +++ b/lib/v2/hrbust/jwzx.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const utils = require('./utils'); @@ -22,7 +23,7 @@ module.exports = async (ctx) => { 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))); + const details = await Promise.all(info.map((e) => utils.detailPage(e, cache))); // ctx.set('json', { // info, diff --git a/lib/v2/infoq/recommend.js b/lib/v2/infoq/recommend.js index 056e22a665..f568f88fd1 100644 --- a/lib/v2/infoq/recommend.js +++ b/lib/v2/infoq/recommend.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const utils = require('./utils'); @@ -15,7 +16,7 @@ module.exports = async (ctx) => { }); const data = resp.data.data; - const items = await utils.ProcessFeed(data, ctx.cache); + const items = await utils.ProcessFeed(data, cache); ctx.set('data', { title: 'InfoQ 推荐', diff --git a/lib/v2/infoq/topic.js b/lib/v2/infoq/topic.js index 566fcdc2b2..086a1ff25d 100644 --- a/lib/v2/infoq/topic.js +++ b/lib/v2/infoq/topic.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const utils = require('./utils'); @@ -30,7 +31,7 @@ module.exports = async (ctx) => { }); const data = resp.data.data; - const items = await utils.ProcessFeed(data, ctx.cache); + const items = await utils.ProcessFeed(data, cache); ctx.set('data', { title: `InfoQ 话题 - ${topicName}`, diff --git a/lib/v2/instagram/private-api/index.js b/lib/v2/instagram/private-api/index.js index 035e584492..84b72e35b7 100644 --- a/lib/v2/instagram/private-api/index.js +++ b/lib/v2/instagram/private-api/index.js @@ -72,7 +72,7 @@ module.exports = async (ctx) => { ig.state.proxyUrl = config.instagram.proxy; } - await login(ig, ctx.cache); + await login(ig, cache); let data; try { diff --git a/lib/v2/instagram/web-api/index.js b/lib/v2/instagram/web-api/index.js index 2d1797963a..05bc02d893 100644 --- a/lib/v2/instagram/web-api/index.js +++ b/lib/v2/instagram/web-api/index.js @@ -30,7 +30,7 @@ module.exports = async (ctx) => { cookieJar = CookieJar.fromJSON(cookieJar); } - if (!wwwClaimV2 && cookie && !(await checkLogin(cookieJar, ctx.cache))) { + if (!wwwClaimV2 && cookie && !(await checkLogin(cookieJar, cache))) { throw new Error('Invalid cookie'); } @@ -38,7 +38,7 @@ module.exports = async (ctx) => { let items; switch (category) { case 'user': { - const userInfo = await getUserInfo(key, cookieJar, ctx.cache); + const userInfo = await getUserInfo(key, cookieJar, cache); // User feed metadata const biography = userInfo.biography; @@ -51,7 +51,7 @@ module.exports = async (ctx) => { feedLogo = userInfo.profile_pic_url_hd ?? userInfo.hd_profile_pic_url_info?.url ?? userInfo.profile_pic_url; feedLink = `${baseUrl}/${username}`; - items = cookie ? await getUserFeedItems(id, username, cookieJar, ctx.cache) : [...userInfo.edge_felix_video_timeline.edges, ...userInfo.edge_owner_to_timeline_media.edges]; + items = cookie ? await getUserFeedItems(id, username, cookieJar, cache) : [...userInfo.edge_felix_video_timeline.edges, ...userInfo.edge_owner_to_timeline_media.edges]; break; } diff --git a/lib/v2/jianshu/collection.js b/lib/v2/jianshu/collection.js index 5543e38bfc..fd3198d295 100644 --- a/lib/v2/jianshu/collection.js +++ b/lib/v2/jianshu/collection.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -18,7 +19,7 @@ module.exports = async (ctx) => { const $ = load(data); const list = $('.note-list li').get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: $('title').text(), diff --git a/lib/v2/jianshu/home.js b/lib/v2/jianshu/home.js index 1406d89747..a8b088bcee 100644 --- a/lib/v2/jianshu/home.js +++ b/lib/v2/jianshu/home.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -16,7 +17,7 @@ module.exports = async (ctx) => { const $ = load(data); const list = $('.note-list li').get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: '简书首页', diff --git a/lib/v2/jianshu/user.js b/lib/v2/jianshu/user.js index d5638aa1a7..d106f70c69 100644 --- a/lib/v2/jianshu/user.js +++ b/lib/v2/jianshu/user.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -18,7 +19,7 @@ module.exports = async (ctx) => { const $ = load(data); const list = $('.note-list li').get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: $('title').text(), diff --git a/lib/v2/juejin/category.js b/lib/v2/juejin/category.js index 1cbb44dee7..aab2685355 100644 --- a/lib/v2/juejin/category.js +++ b/lib/v2/juejin/category.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -28,7 +29,7 @@ module.exports = async (ctx) => { if (response.data.data) { originalData = response.data.data; } - const resultItems = await util.ProcessFeed(originalData, ctx.cache); + const resultItems = await util.ProcessFeed(originalData, cache); ctx.set('data', { title: `掘金 ${cat.category_name}`, diff --git a/lib/v2/juejin/collection.js b/lib/v2/juejin/collection.js index 161a87bd69..c746597974 100644 --- a/lib/v2/juejin/collection.js +++ b/lib/v2/juejin/collection.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -14,7 +15,7 @@ module.exports = async (ctx) => { items = collectPage.data.data.article_list.slice(0, 10); } - const result = await util.ProcessFeed(items, ctx.cache); + const result = await util.ProcessFeed(items, cache); ctx.set('data', { title: '掘金 - 单个收藏夹', diff --git a/lib/v2/juejin/column.js b/lib/v2/juejin/column.js index 45f477f3e1..8c6bcf4caa 100644 --- a/lib/v2/juejin/column.js +++ b/lib/v2/juejin/column.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -20,7 +21,7 @@ module.exports = async (ctx) => { const { data } = response.data; const detailData = detail.data.data; const columnName = detailData && detailData.column_version && detailData.column_version.title; - const resultItems = await util.ProcessFeed(data, ctx.cache); + const resultItems = await util.ProcessFeed(data, cache); ctx.set('data', { title: `掘金专栏-${columnName}`, diff --git a/lib/v2/juejin/favorites.js b/lib/v2/juejin/favorites.js index cc0fb56134..3c820d2336 100644 --- a/lib/v2/juejin/favorites.js +++ b/lib/v2/juejin/favorites.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -27,7 +28,7 @@ module.exports = async (ctx) => { posts.push(...item); } - const result = await util.ProcessFeed(posts, ctx.cache); + const result = await util.ProcessFeed(posts, cache); ctx.set('data', { title: '掘金 - 收藏集', diff --git a/lib/v2/juejin/posts.js b/lib/v2/juejin/posts.js index 348456636e..c24f41f3b6 100644 --- a/lib/v2/juejin/posts.js +++ b/lib/v2/juejin/posts.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -14,7 +15,7 @@ module.exports = async (ctx) => { }); const { data } = response.data; const username = data[0] && data[0].author_user_info && data[0].author_user_info.user_name; - const resultItems = await util.ProcessFeed(data, ctx.cache); + const resultItems = await util.ProcessFeed(data, cache); ctx.set('data', { title: `掘金专栏-${username}`, diff --git a/lib/v2/juejin/tag.js b/lib/v2/juejin/tag.js index 21a482d756..19a93b31c5 100644 --- a/lib/v2/juejin/tag.js +++ b/lib/v2/juejin/tag.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -29,7 +30,7 @@ module.exports = async (ctx) => { if (response.data.data) { originalData = response.data.data.slice(0, 10); } - const resultItems = await util.ProcessFeed(originalData, ctx.cache); + const resultItems = await util.ProcessFeed(originalData, cache); ctx.set('data', { title: `掘金 ${tag}`, diff --git a/lib/v2/juejin/trending.js b/lib/v2/juejin/trending.js index 31de69ec97..186e2329cd 100644 --- a/lib/v2/juejin/trending.js +++ b/lib/v2/juejin/trending.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); @@ -69,7 +70,7 @@ module.exports = async (ctx) => { entrylist = trendingResponse.data.data.filter((item) => item.item_type === 2).map((item) => item.item_info); } - const resultItems = await util.ProcessFeed(entrylist, ctx.cache); + const resultItems = await util.ProcessFeed(entrylist, cache); ctx.set('data', { title, diff --git a/lib/v2/jump/discount.js b/lib/v2/jump/discount.js index d0a1e5c5bd..0db406f5cf 100644 --- a/lib/v2/jump/discount.js +++ b/lib/v2/jump/discount.js @@ -87,7 +87,7 @@ const getAllPageDiscountItem = async (countries, platform, termsId, totalNum) => // for (const idx in allDiscountItem) { // logger.info(idx); // // eslint-disable-next-line no-await-in-loop -// const detail = await getGameDetail(allDiscountItem[idx], ctx.cache); +// const detail = await getGameDetail(allDiscountItem[idx], cache); // allDiscountItem[idx].detail = detail; // logger.info(detail); // }; diff --git a/lib/v2/leiphone/index.js b/lib/v2/leiphone/index.js index 5064cb0519..7a93b6c637 100644 --- a/lib/v2/leiphone/index.js +++ b/lib/v2/leiphone/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const utils = require('./utils'); @@ -14,7 +15,7 @@ module.exports = async (ctx) => { .slice(0, 10) .get() .map((e) => $(e).attr('href')); - const items = await utils.ProcessFeed(list, ctx.cache); + const items = await utils.ProcessFeed(list, cache); ctx.set('data', { title: `雷峰网${todo === 'category' ? ` ${keyword}` : ''}`, diff --git a/lib/v2/leiphone/newsflash.js b/lib/v2/leiphone/newsflash.js index fb8b9b5eaa..e406c6fe5b 100644 --- a/lib/v2/leiphone/newsflash.js +++ b/lib/v2/leiphone/newsflash.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const utils = require('./utils'); // import { load } from 'cheerio'; @@ -8,7 +9,7 @@ module.exports = async (ctx) => { const article = (res.data || {}).article || []; const list = article.map((item) => item.url); - const items = await utils.ProcessFeed(list, ctx.cache); + const items = await utils.ProcessFeed(list, cache); ctx.set('data', { title: '雷峰网 业界资讯', diff --git a/lib/v2/lfsyd/home.js b/lib/v2/lfsyd/home.js index 0721095f5e..5cc9d102b9 100644 --- a/lib/v2/lfsyd/home.js +++ b/lib/v2/lfsyd/home.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; const { ProcessForm, ProcessFeed } = require('./utils'); @@ -32,7 +33,7 @@ module.exports = async (ctx) => { guid: item.post.title, postId: item.post.id, })); - const items = await ProcessFeed(ctx.cache, articleList); + const items = await ProcessFeed(cache, articleList); ctx.set('data', { title: '首页 - 旅法师营地', diff --git a/lib/v2/lfsyd/old-home.js b/lib/v2/lfsyd/old-home.js index 43cd9648bb..5387f1e0b2 100644 --- a/lib/v2/lfsyd/old-home.js +++ b/lib/v2/lfsyd/old-home.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; const { ProcessFeed } = require('./utils'); @@ -19,7 +20,7 @@ module.exports = async (ctx) => { })) .filter((item) => item.title !== undefined); - const items = await ProcessFeed(ctx.cache, articleList); + const items = await ProcessFeed(cache, articleList); ctx.set('data', { title: '旅法师营地 - 首页资讯(旧版)', diff --git a/lib/v2/lfsyd/tag.js b/lib/v2/lfsyd/tag.js index 3fe9b6e3fa..437cd7e844 100644 --- a/lib/v2/lfsyd/tag.js +++ b/lib/v2/lfsyd/tag.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; const { ProcessForm, ProcessFeed } = require('./utils'); @@ -54,7 +55,7 @@ module.exports = async (ctx) => { postId: item.feed.source_id, })); - const items = await ProcessFeed(ctx.cache, articleList); + const items = await ProcessFeed(cache, articleList); ctx.set('data', { title: `${tagName || tagJson[0].tag} - 旅法师营地 `, diff --git a/lib/v2/lfsyd/user.js b/lib/v2/lfsyd/user.js index 6df113735c..b9ab9aa9e6 100644 --- a/lib/v2/lfsyd/user.js +++ b/lib/v2/lfsyd/user.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { parseDate } from '@/utils/parse-date'; const { ProcessForm, ProcessFeed } = require('./utils'); @@ -38,7 +39,7 @@ module.exports = async (ctx) => { postId: item.event_data.post_id, })); - const items = await ProcessFeed(ctx.cache, articleList); + const items = await ProcessFeed(cache, articleList); ctx.set('data', { title: `${nickname} - 旅法师营地 `, diff --git a/lib/v2/nhentai/other.js b/lib/v2/nhentai/other.js index 70d2a5a035..8254105171 100644 --- a/lib/v2/nhentai/other.js +++ b/lib/v2/nhentai/other.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const { getSimple, getDetails, getTorrents } = require('./util'); const supportedKeys = new Set(['parody', 'character', 'tag', 'artist', 'group', 'language', 'category']); @@ -16,9 +17,9 @@ module.exports = async (ctx) => { 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); + items = await getDetails(cache, simples, limit); } else if (mode === 'torrent') { - items = await getTorrents(ctx.cache, simples, limit); + items = await getTorrents(cache, simples, limit); } ctx.set('data', { diff --git a/lib/v2/nhentai/search.js b/lib/v2/nhentai/search.js index 49ab43ef4b..42771af945 100644 --- a/lib/v2/nhentai/search.js +++ b/lib/v2/nhentai/search.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const { getSimple, getDetails, getTorrents } = require('./util'); module.exports = async (ctx) => { @@ -10,9 +11,9 @@ module.exports = async (ctx) => { 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); + items = await getDetails(cache, simples, limit); } else if (mode === 'torrent') { - items = await getTorrents(ctx.cache, simples, limit); + items = await getTorrents(cache, simples, limit); } ctx.set('data', { diff --git a/lib/v2/nintendo/eshop-cn.js b/lib/v2/nintendo/eshop-cn.js index 7af4a14400..2fbb27730f 100644 --- a/lib/v2/nintendo/eshop-cn.js +++ b/lib/v2/nintendo/eshop-cn.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); const software_url = 'https://www.nintendoswitch.com.cn/software/'; @@ -33,7 +34,7 @@ module.exports = async (ctx) => { pubDate: parseDate(item.publishTime, 'YYYY.MM.DD'), })); - data = await util.ProcessItemChina(data, ctx.cache); + data = await util.ProcessItemChina(data, cache); ctx.set('data', { title: 'Nintendo eShop(国服)新游戏', diff --git a/lib/v2/nintendo/news-china.js b/lib/v2/nintendo/news-china.js index 510ef16a4b..b0a0eb7fb1 100644 --- a/lib/v2/nintendo/news-china.js +++ b/lib/v2/nintendo/news-china.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); const news_url = 'https://www.nintendoswitch.com.cn'; @@ -24,7 +25,7 @@ module.exports = async (ctx) => { link: `${news_url}/topics/${item.jumpUrl}`, })); - data = await util.ProcessNewsChina(data, ctx.cache); + data = await util.ProcessNewsChina(data, cache); ctx.set('data', { title: 'Nintendo(中国大陆)主页资讯', diff --git a/lib/v2/nintendo/news.js b/lib/v2/nintendo/news.js index b65287de66..deb421fff5 100644 --- a/lib/v2/nintendo/news.js +++ b/lib/v2/nintendo/news.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; const util = require('./utils'); import { parseDate } from '@/utils/parse-date'; @@ -7,7 +8,7 @@ module.exports = async (ctx) => { 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); + const result = await util.ProcessNews(data, cache); ctx.set('data', { title: 'Nintendo(香港)主页资讯', diff --git a/lib/v2/njnu/ceai/ceai.js b/lib/v2/njnu/ceai/ceai.js index ae303cf285..57bb707c79 100644 --- a/lib/v2/njnu/ceai/ceai.js +++ b/lib/v2/njnu/ceai/ceai.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -33,7 +34,7 @@ module.exports = async (ctx) => { const list = $('span a').get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: '南京师范大学计电人院 - ' + title, diff --git a/lib/v2/njnu/jwc/jwc.js b/lib/v2/njnu/jwc/jwc.js index a76df84360..b8f30195cc 100644 --- a/lib/v2/njnu/jwc/jwc.js +++ b/lib/v2/njnu/jwc/jwc.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -32,7 +33,7 @@ module.exports = async (ctx) => { const list = $('.list_txt a').get(); - const result = await util.ProcessFeed(list, ctx.cache); + const result = await util.ProcessFeed(list, cache); ctx.set('data', { title: '南京师范大学教务处 - ' + title, diff --git a/lib/v2/pianyuan/app.js b/lib/v2/pianyuan/app.js index 2dde299a4d..335be9d9e6 100644 --- a/lib/v2/pianyuan/app.js +++ b/lib/v2/pianyuan/app.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { load } from 'cheerio'; const utils = require('./utils'); @@ -17,13 +18,13 @@ module.exports = async (ctx) => { } } - const response = await utils.request(link, ctx.cache); + const response = await utils.request(link, cache); 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); + const items = await utils.ProcessFeed(detailLinks, cache); ctx.set('data', { title: '片源网', diff --git a/lib/v2/pianyuan/search.js b/lib/v2/pianyuan/search.js index b6807b6fb6..20e7c7d84d 100644 --- a/lib/v2/pianyuan/search.js +++ b/lib/v2/pianyuan/search.js @@ -9,7 +9,7 @@ module.exports = async (ctx) => { const searchKey = ctx.originalUrl.split('&q=')[1]; const link = link_base + `search?q=${searchKey}`; - const response = await utils.request(link, ctx.cache); + const response = await utils.request(link, cache); const $ = load(response.data); // 只获取第一页的搜索结果 const searchLinks = $('.nomt > a') @@ -25,7 +25,7 @@ module.exports = async (ctx) => { searchLinks.map(async (e) => { const link = new URL(e, link_base).href; const single = await cache.tryGet(link, async () => { - const res = await utils.request(link, ctx.cache); + const res = await utils.request(link, cache); const content = load(res.data); content('.ico.ico_bt') .get() @@ -35,7 +35,7 @@ module.exports = async (ctx) => { }) ); - const items = await utils.ProcessFeed(detailLinks, ctx.cache); + const items = await utils.ProcessFeed(detailLinks, cache); ctx.set('data', { title: '片源网', diff --git a/lib/v2/pincong/hot.js b/lib/v2/pincong/hot.js index 8e462a71de..3525dffd96 100644 --- a/lib/v2/pincong/hot.js +++ b/lib/v2/pincong/hot.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); @@ -8,7 +9,7 @@ module.exports = async (ctx) => { const url = `${baseUrl}/hot/list/category-${category}`; // use Puppeteer due to the obstacle by cloudflare challenge - const html = await puppeteerGet(url, ctx.cache); + const html = await puppeteerGet(url, cache); const $ = load(html); const list = $('div.aw-item'); diff --git a/lib/v2/pincong/index.js b/lib/v2/pincong/index.js index 0f7b243f0b..754322f559 100644 --- a/lib/v2/pincong/index.js +++ b/lib/v2/pincong/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); @@ -15,7 +16,7 @@ module.exports = async (ctx) => { 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 html = await puppeteerGet(url, cache); const $ = load(html); const list = $('div.aw-item'); diff --git a/lib/v2/pincong/topic.js b/lib/v2/pincong/topic.js index f22150bacf..73b725b642 100644 --- a/lib/v2/pincong/topic.js +++ b/lib/v2/pincong/topic.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; const { baseUrl, puppeteerGet } = require('./utils'); @@ -6,7 +7,7 @@ module.exports = async (ctx) => { 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 html = await puppeteerGet(url, cache); const $ = load(html); const list = $('div.aw-item'); diff --git a/lib/v2/pingwest/tag.js b/lib/v2/pingwest/tag.js index 4f49c69bab..325ee54edb 100644 --- a/lib/v2/pingwest/tag.js +++ b/lib/v2/pingwest/tag.js @@ -33,7 +33,7 @@ module.exports = async (ctx) => { }); const $ = load(response.data.data.list); - const items = await utils.articleListParser($, needFullText, ctx.cache); + const items = await utils.articleListParser($, needFullText, cache); ctx.set('data', { title: `品玩 - ${tagName}`, diff --git a/lib/v2/pingwest/user.js b/lib/v2/pingwest/user.js index 08a350b832..0c7cf55879 100644 --- a/lib/v2/pingwest/user.js +++ b/lib/v2/pingwest/user.js @@ -39,7 +39,7 @@ module.exports = async (ctx) => { const needFullText = option === 'fulltext'; switch (type) { case 'article': - item = await utils.articleListParser($, needFullText, ctx.cache); + item = await utils.articleListParser($, needFullText, cache); break; case 'state': item = utils.statusListParser($); diff --git a/lib/v2/playno1/av.js b/lib/v2/playno1/av.js index 75ba889d71..71d8b0fed3 100644 --- a/lib/v2/playno1/av.js +++ b/lib/v2/playno1/av.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -30,7 +31,7 @@ module.exports = async (ctx) => { }; }); - items = await processArticle(items, ctx.cache); + items = await processArticle(items, cache); ctx.set('data', { title: $('head title').text(), diff --git a/lib/v2/playno1/st.js b/lib/v2/playno1/st.js index 53a64de579..0b724ed499 100644 --- a/lib/v2/playno1/st.js +++ b/lib/v2/playno1/st.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -25,7 +26,7 @@ module.exports = async (ctx) => { }; }); - items = await processArticle(items, ctx.cache); + items = await processArticle(items, cache); ctx.set('data', { title: $('head title').text(), diff --git a/lib/v2/scnu/physics-school-announcements-and-news.js b/lib/v2/scnu/physics-school-announcements-and-news.js index e0a0b95c53..3be4f1618e 100644 --- a/lib/v2/scnu/physics-school-announcements-and-news.js +++ b/lib/v2/scnu/physics-school-announcements-and-news.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import timezone from '@/utils/timezone'; @@ -52,7 +53,7 @@ module.exports.announcementsRouter = async (ctx) => { 综合: 'https://physics.scnu.edu.cn/NEWS/Notices/General/', 学工: 'https://physics.scnu.edu.cn/NEWS/Notices/Students/', }; - const items = await getItemsFromURLs(URLs, ctx.cache); + const items = await getItemsFromURLs(URLs, cache); ctx.set('data', { title: '华南师范大学物理与电信工程学院通知', link: 'https://physics.scnu.edu.cn/NEWS/Notices/', @@ -68,7 +69,7 @@ module.exports.newsRouter = async (ctx) => { 科研新闻: 'https://physics.scnu.edu.cn/NEWS/News/Research/', 院友新闻: 'https://physics.scnu.edu.cn/NEWS/News/People/', }; - const items = await getItemsFromURLs(URLs, ctx.cache); + const items = await getItemsFromURLs(URLs, cache); ctx.set('data', { title: '华南师范大学物理与电信工程学院新闻动态', link: 'https://physics.scnu.edu.cn/NEWS/News/', @@ -85,7 +86,7 @@ module.exports.researchNewsRouter = async (ctx) => { 重大项目: 'https://physics.scnu.edu.cn/RESEARCH/Projects/', 科研成果: 'https://physics.scnu.edu.cn/RESEARCH/Achievements/', }; - const items = await getItemsFromURLs(URLs, ctx.cache); + const items = await getItemsFromURLs(URLs, cache); ctx.set('data', { title: '华南师范大学物理与电信工程学院科学研究动态', link: 'https://physics.scnu.edu.cn/RESEARCH/', diff --git a/lib/v2/shmeea/self-study.js b/lib/v2/shmeea/self-study.js index f1417f4ab9..82b71578b9 100644 --- a/lib/v2/shmeea/self-study.js +++ b/lib/v2/shmeea/self-study.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -51,7 +52,7 @@ module.exports = async (ctx) => { const $ = load(data); const list = $('#main > div.container > div > div.span9 > div.page-he > div > ul > li').get(); - const detail = await load_detail(list, ctx.cache); + const detail = await load_detail(list, cache); ctx.set('data', { title: '上海自学考试 - 通知公告', diff --git a/lib/v2/shmtu/jwc.js b/lib/v2/shmtu/jwc.js index 7a9d33a487..77a0a1236a 100644 --- a/lib/v2/shmtu/jwc.js +++ b/lib/v2/shmtu/jwc.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -46,7 +47,7 @@ module.exports = async (ctx) => { }; }); - const result = await ProcessFeed(list, ctx.cache); + const result = await ProcessFeed(list, cache); ctx.set('data', { title: `上海海事大学 ${info}`, diff --git a/lib/v2/shmtu/portal.js b/lib/v2/shmtu/portal.js index 6b5efde719..ae23232c95 100644 --- a/lib/v2/shmtu/portal.js +++ b/lib/v2/shmtu/portal.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -70,7 +71,7 @@ module.exports = async (ctx) => { author: item.field_department[0], })); - const result = await processFeed(list, ctx.cache); + const result = await processFeed(list, cache); ctx.set('data', { title: `上海海事大学 ${info}`, diff --git a/lib/v2/shmtu/www.js b/lib/v2/shmtu/www.js index 7072373ffc..0918b8b228 100644 --- a/lib/v2/shmtu/www.js +++ b/lib/v2/shmtu/www.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -47,7 +48,7 @@ module.exports = async (ctx) => { }; }); - const result = await ProcessFeed(list, ctx.cache); + const result = await ProcessFeed(list, cache); ctx.set('data', { title: `上海海事大学 ${info}`, diff --git a/lib/v2/stdaily/digitalpaper.js b/lib/v2/stdaily/digitalpaper.js index 530c2a4e90..378db8f257 100644 --- a/lib/v2/stdaily/digitalpaper.js +++ b/lib/v2/stdaily/digitalpaper.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import * as path from 'node:path'; import { art } from '@/utils/render'; import got from '@/utils/got'; @@ -115,7 +116,7 @@ module.exports = async (ctx) => { // get pages' article list allPageArticleLists.push(...(await Promise.all(restPageLists.map((getPageArticleList) => getPageArticleList()))).flat()); // get all articles - const items = await getListArticles(allPageArticleLists, ctx.cache); + const items = await getListArticles(allPageArticleLists, cache); ctx.set('data', { title: `科技日报`, diff --git a/lib/v2/swjtu/jtys/yjs.js b/lib/v2/swjtu/jtys/yjs.js index df712c722a..379cafe324 100644 --- a/lib/v2/swjtu/jtys/yjs.js +++ b/lib/v2/swjtu/jtys/yjs.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -42,7 +43,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.toArray().map((i) => { const item = $(i); - return getItem(item, ctx.cache); + return getItem(item, cache); }) ); diff --git a/lib/v2/swjtu/jwc.js b/lib/v2/swjtu/jwc.js index 69da6d9701..754209431c 100644 --- a/lib/v2/swjtu/jwc.js +++ b/lib/v2/swjtu/jwc.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -54,7 +55,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.toArray().map((i) => { const item = $(i); - return getItem(item, ctx.cache); + return getItem(item, cache); }) ); diff --git a/lib/v2/swjtu/jyzpxx.js b/lib/v2/swjtu/jyzpxx.js index 3fd68261a0..133ca5ab4c 100644 --- a/lib/v2/swjtu/jyzpxx.js +++ b/lib/v2/swjtu/jyzpxx.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import got from '@/utils/got'; @@ -15,7 +16,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.map((item) => { const key = `${rootURL}/zpxx/data/zpxx/${item.zpxxid}`; - return utils.descpPage(key, ctx.cache); + return utils.descpPage(key, cache); }) ); diff --git a/lib/v2/swjtu/xg.js b/lib/v2/swjtu/xg.js index 049beac84b..d56467de16 100644 --- a/lib/v2/swjtu/xg.js +++ b/lib/v2/swjtu/xg.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; @@ -66,7 +67,7 @@ module.exports = async (ctx) => { const items = await Promise.all( list.toArray().map((i) => { const item = $(i); - return getItem(item, ctx.cache); + return getItem(item, cache); }) ); diff --git a/lib/v2/szu/yz/index.js b/lib/v2/szu/yz/index.js index 4734a1edae..b26efb4c9b 100644 --- a/lib/v2/szu/yz/index.js +++ b/lib/v2/szu/yz/index.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; const util = require('./utils'); @@ -40,7 +41,7 @@ module.exports = async (ctx) => { const list = $(struct[type].selector.list).find(struct[type].selector.item).toArray(); const name = $('title').text(); - const result = await util.ProcessFeed(list, ctx.cache, struct[type]); + const result = await util.ProcessFeed(list, cache, struct[type]); ctx.set('data', { title: map.get(type).title, diff --git a/lib/v2/trending/all-trending.js b/lib/v2/trending/all-trending.js index 594776e124..6aca423ff4 100644 --- a/lib/v2/trending/all-trending.js +++ b/lib/v2/trending/all-trending.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const dayjs = require('dayjs'); dayjs.extend(require('dayjs/plugin/utc')); dayjs.extend(require('dayjs/plugin/timezone')); @@ -175,7 +176,7 @@ module.exports = async (ctx) => { .map((keyword) => keyword.trim()); const keywordStr = keywordList.join(', '); - const data = await fetchAllData(keywordList, dateList, ctx.cache).catch(() => []); + const data = await fetchAllData(keywordList, dateList, cache).catch(() => []); const item = data.length > 0 ? data.map((i, index) => createItem(i, keywordList, index === 0)) diff --git a/lib/v2/twitter/web-api/login.js b/lib/v2/twitter/web-api/login.js index 7d548180c5..9a2858847b 100644 --- a/lib/v2/twitter/web-api/login.js +++ b/lib/v2/twitter/web-api/login.js @@ -7,6 +7,7 @@ import { config } from '@/config'; const { v5: uuidv5 } = require('uuid'); const { authenticator } = require('otplib'); import logger from '@/utils/logger'; +import cache from '@/utils/cache'; const NAMESPACE = 'd41d092b-b007-48f7-9129-e9538d2d8fe9'; const username = config.twitter.username; @@ -27,8 +28,8 @@ const headers = { Authorization: bearerToken, }; -async function login(tryGet) { - return await tryGet( +async function login() { + return await cache.tryGet( `twitter:authentication:${username}`, async () => { logger.debug('Twitter login start.'); diff --git a/lib/v2/twitter/web-api/media.js b/lib/v2/twitter/web-api/media.js index 741cfb2d72..d600d7d583 100644 --- a/lib/v2/twitter/web-api/media.js +++ b/lib/v2/twitter/web-api/media.js @@ -1,4 +1,3 @@ -import cache from '@/utils/cache'; const utils = require('../utils'); // import { config } from '@/config'; const { getUser, getUserMedia } = require('./twitter-api'); @@ -9,9 +8,9 @@ module.exports = async (ctx) => { const { count } = utils.parseRouteParams(ctx.req.param('routeParams')); const params = count ? { count } : {}; - await initToken(cache.tryGet); - const userInfo = await getUser(ctx.cache, id); - const data = await getUserMedia(ctx.cache, id, params); + await initToken(); + const userInfo = await getUser(id); + const data = await getUserMedia(id, params); const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; ctx.set('data', { diff --git a/lib/v2/twitter/web-api/search.js b/lib/v2/twitter/web-api/search.js index efb0898f12..7fb71c8270 100644 --- a/lib/v2/twitter/web-api/search.js +++ b/lib/v2/twitter/web-api/search.js @@ -1,11 +1,10 @@ -import cache from '@/utils/cache'; const utils = require('../utils'); const { getSearch } = require('./twitter-api'); const { initToken } = require('./token'); module.exports = async (ctx) => { const keyword = ctx.req.param('keyword'); - await initToken(cache.tryGet); + await initToken(); const data = await getSearch(keyword); ctx.set('data', { diff --git a/lib/v2/twitter/web-api/token.js b/lib/v2/twitter/web-api/token.js index 877c8b1c37..76d40d3790 100644 --- a/lib/v2/twitter/web-api/token.js +++ b/lib/v2/twitter/web-api/token.js @@ -5,9 +5,9 @@ let tokenIndex = 0; let authentication = null; let first = true; -async function initToken(tryGet) { +async function initToken() { if (config.twitter.username && config.twitter.password && !authentication && first) { - authentication = await login(tryGet); + authentication = await login(); first = false; } } diff --git a/lib/v2/twitter/web-api/tweet.js b/lib/v2/twitter/web-api/tweet.js index 1998d02e59..2659c39d1d 100644 --- a/lib/v2/twitter/web-api/tweet.js +++ b/lib/v2/twitter/web-api/tweet.js @@ -1,4 +1,3 @@ -import cache from '@/utils/cache'; // import { config } from '@/config'; const { getUser, getUserTweet } = require('./twitter-api'); const utils = require('../utils'); @@ -12,9 +11,9 @@ module.exports = async (ctx) => { const routeParams = new URLSearchParams(ctx.req.param('original')); const original = fallback(undefined, queryToBoolean(routeParams.get('original')), false); const params = { focalTweetId: status }; - await initToken(cache.tryGet); - const userInfo = await getUser(ctx.cache, id); - const data = await getUserTweet(ctx.cache, id, params); + await initToken(); + const userInfo = await getUser(id); + const data = await getUserTweet(id, params); const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; const item = original && config.isPackage ? data : utils.ProcessFeed(ctx, { data }); diff --git a/lib/v2/twitter/web-api/twitter-api.js b/lib/v2/twitter/web-api/twitter-api.js index 2883a77fe7..1755944399 100644 --- a/lib/v2/twitter/web-api/twitter-api.js +++ b/lib/v2/twitter/web-api/twitter-api.js @@ -6,6 +6,7 @@ const OAuth = require('oauth-1.0a'); const CryptoJS = require('crypto-js'); const queryString = require('query-string'); const { getToken } = require('./token'); +import cache from '@/utils/cache'; const twitterGot = async (url, params) => { const token = await getToken(); @@ -195,18 +196,18 @@ const userByAuto = (id) => { } return userByScreenName(id); }; -const getUserData = (cache, id) => cache.tryGet(`twitter-userdata-${id}`, () => userByAuto(id)); -const getUserID = async (cache, id) => { - const userData = await getUserData(cache, id); +const getUserData = (id) => cache.tryGet(`twitter-userdata-${id}`, () => userByAuto(id)); +const getUserID = async (id) => { + const userData = await getUserData(id); return (userData.data?.user || userData.data?.user_result)?.result?.rest_id; }; -const getUser = async (cache, id) => { - const userData = await getUserData(cache, id); +const getUser = async (id) => { + const userData = await getUserData(id); return (userData.data?.user || userData.data?.user_result)?.result?.legacy; }; -const cacheTryGet = async (cache, _id, params, func) => { - const id = await getUserID(cache, _id); +const cacheTryGet = async (_id, params, func) => { + const id = await getUserID(_id); if (id === undefined) { throw new Error('User not found'); } @@ -218,18 +219,18 @@ const cacheTryGet = async (cache, _id, params, func) => { // returns: // 1. nothing for some users // 2. HOT tweets for the other users, instead of the LATEST ones -const _getUserTweets = (cache, id, params = {}) => cacheTryGet(cache, id, params, getUserTweetsByID); +const _getUserTweets = (id, params = {}) => cacheTryGet(id, params, getUserTweetsByID); // workaround for the above issue: // 1. getUserTweetsAndReplies return LATEST tweets and replies, which requires filtering // a. if one replies a lot (e.g. elonmusk), there is sometimes no tweets left after filtering, caching may help // 2. getUserMedia return LATEST media tweets, which is a good plus -const getUserTweets = async (cache, id, params = {}) => { +const getUserTweets = async (id, params = {}) => { let tweets = []; - const rest_id = await getUserID(cache, id); + const rest_id = await getUserID(id); await Promise.all( [_getUserTweets, getUserTweetsAndReplies, getUserMedia].map(async (func) => { try { - tweets.push(...(await func(cache, id, params))); + tweets.push(...(await func(id, params))); } catch (error) { logger.warn(`Failed to get tweets for ${id} with ${func.name}: ${error}`); } @@ -261,10 +262,10 @@ const getUserTweets = async (cache, id, params = {}) => { cache.set(cacheKey, JSON.stringify(tweets)); return tweets; }; -const getUserTweetsAndReplies = (cache, id, params = {}) => cacheTryGet(cache, id, params, getUserTweetsAndRepliesByID); -const getUserMedia = (cache, id, params = {}) => cacheTryGet(cache, id, params, getUserMediaByID); -// const getUserLikes = (cache, id, params = {}) => cacheTryGet(cache, id, params, getUserLikesByID); -const getUserTweet = (cache, id, params) => cacheTryGet(cache, id, params, getUserTweetByStatus); +const getUserTweetsAndReplies = (id, params = {}) => cacheTryGet(id, params, getUserTweetsAndRepliesByID); +const getUserMedia = (id, params = {}) => cacheTryGet(id, params, getUserMediaByID); +// const getUserLikes = (id, params = {}) => cacheTryGet(id, params, getUserLikesByID); +const getUserTweet = (id, params) => cacheTryGet(id, params, getUserTweetByStatus); const getSearch = async (keywords, params = {}) => gatherLegacyFromData(await timelineKeywords(keywords, params)); diff --git a/lib/v2/twitter/web-api/user.js b/lib/v2/twitter/web-api/user.js index d320932459..1f7b410e16 100644 --- a/lib/v2/twitter/web-api/user.js +++ b/lib/v2/twitter/web-api/user.js @@ -1,4 +1,3 @@ -import cache from '@/utils/cache'; const utils = require('../utils'); const { getUser, getUserTweets, getUserTweetsAndReplies, excludeRetweet } = require('./twitter-api'); const { initToken } = require('./token'); @@ -10,9 +9,9 @@ module.exports = async (ctx) => { const { count, exclude_replies, include_rts } = utils.parseRouteParams(ctx.req.param('routeParams')); const params = count ? { count } : {}; - await initToken(cache.tryGet); - const userInfo = await getUser(ctx.cache, id); - let data = await (exclude_replies ? getUserTweets(ctx.cache, id, params) : getUserTweetsAndReplies(ctx.cache, id, params)); + await initToken(); + const userInfo = await getUser(id); + let data = await (exclude_replies ? getUserTweets(id, params) : getUserTweetsAndReplies(id, params)); if (!include_rts) { data = excludeRetweet(data); } diff --git a/lib/v2/xiaohongshu/board.js b/lib/v2/xiaohongshu/board.js index a00df73807..a16f5381e8 100644 --- a/lib/v2/xiaohongshu/board.js +++ b/lib/v2/xiaohongshu/board.js @@ -1,10 +1,11 @@ +import cache from '@/utils/cache'; import { parseDate } from '@/utils/parse-date'; import timezone from '@/utils/timezone'; const { getBoard } = require('./util'); module.exports = async (ctx) => { const url = `https://www.xiaohongshu.com/board/${ctx.req.param('board_id')}`; - const main = await getBoard(url, ctx.cache); + const main = await getBoard(url, cache); const albumInfo = main.albumInfo; const title = albumInfo.name; diff --git a/lib/v2/xiaohongshu/notes.js b/lib/v2/xiaohongshu/notes.js index 83b410d475..dafa0ad315 100644 --- a/lib/v2/xiaohongshu/notes.js +++ b/lib/v2/xiaohongshu/notes.js @@ -1,10 +1,11 @@ +import cache from '@/utils/cache'; const { getNotes, formatText, formatNote } = require('./util'); module.exports = async (ctx) => { const userId = ctx.req.param('user_id'); const url = `https://www.xiaohongshu.com/user/profile/${userId}`; - const { user, notes } = await getNotes(url, ctx.cache); + const { user, notes } = await getNotes(url, cache); ctx.set('data', { title: `${user.nickname} - 笔记 • 小红书 / RED`, diff --git a/lib/v2/xiaohongshu/user.js b/lib/v2/xiaohongshu/user.js index 398af977f4..bdfe972fba 100644 --- a/lib/v2/xiaohongshu/user.js +++ b/lib/v2/xiaohongshu/user.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const { getUser } = require('./util'); module.exports = async (ctx) => { @@ -9,7 +10,7 @@ module.exports = async (ctx) => { userPageData: { basicInfo, interactions, tags }, notes, collect, - } = await getUser(url, ctx.cache); + } = await getUser(url, cache); const title = `${basicInfo.nickname} - ${category === 'notes' ? '笔记' : '收藏'} • 小红书 / RED`; const description = `${basicInfo.desc} ${tags.map((t) => t.name).join(' ')} ${interactions.map((i) => `${i.count} ${i.name}`).join(' ')}`; diff --git a/lib/v2/youtube/channel.js b/lib/v2/youtube/channel.js index 984ea27277..49c785ca99 100644 --- a/lib/v2/youtube/channel.js +++ b/lib/v2/youtube/channel.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import { config } from '@/config'; import { parseDate } from '@/utils/parse-date'; @@ -13,9 +14,9 @@ module.exports = async (ctx) => { throw new Error(`Invalid YouTube channel ID. \nYou may want to use /youtube/user/:id instead.`); } - const playlistId = (await utils.getChannelWithId(id, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads; + const playlistId = (await utils.getChannelWithId(id, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads; - const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; + const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items; ctx.set('data', { title: `${data[0].snippet.channelTitle} - YouTube`, diff --git a/lib/v2/youtube/custom.js b/lib/v2/youtube/custom.js index e9c8b60963..f5b32bc5f3 100644 --- a/lib/v2/youtube/custom.js +++ b/lib/v2/youtube/custom.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import { config } from '@/config'; import got from '@/utils/got'; @@ -19,9 +20,9 @@ module.exports = async (ctx) => { .match(/ytInitialData = ({.*?});/)[1] ); const externalId = ytInitialData.metadata.channelMetadataRenderer.externalId; - const playlistId = (await utils.getChannelWithId(externalId, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads; + const playlistId = (await utils.getChannelWithId(externalId, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads; - const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; + const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items; ctx.set('data', { title: `${username} - YouTube`, diff --git a/lib/v2/youtube/live.js b/lib/v2/youtube/live.js index 790999b717..0aa0872a84 100644 --- a/lib/v2/youtube/live.js +++ b/lib/v2/youtube/live.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import { config } from '@/config'; import { parseDate } from '@/utils/parse-date'; @@ -21,12 +22,12 @@ module.exports = async (ctx) => { channelName = $('meta[itemprop="name"]').attr('content'); if (!channelId) { - const channelInfo = (await utils.getChannelWithUsername(username, 'snippet', ctx.cache)).data.items[0]; + const channelInfo = (await utils.getChannelWithUsername(username, 'snippet', cache)).data.items[0]; channelId = channelInfo.id; channelName = channelInfo.snippet.title; } - const data = (await utils.getLive(channelId, ctx.cache)).data.items; + const data = (await utils.getLive(channelId, cache)).data.items; ctx.set('data', { title: `${channelName || username}'s Live Status`, diff --git a/lib/v2/youtube/playlist.js b/lib/v2/youtube/playlist.js index 58c287ecb7..a7a3531597 100644 --- a/lib/v2/youtube/playlist.js +++ b/lib/v2/youtube/playlist.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import { config } from '@/config'; import { parseDate } from '@/utils/parse-date'; @@ -9,9 +10,9 @@ module.exports = async (ctx) => { const id = ctx.req.param('id'); const embed = !ctx.req.param('embed'); - const playlistTitle = (await utils.getPlaylist(id, 'snippet', ctx.cache)).data.items[0].snippet.title; + const playlistTitle = (await utils.getPlaylist(id, 'snippet', cache)).data.items[0].snippet.title; - const data = (await utils.getPlaylistItems(id, 'snippet', ctx.cache)).data.items.filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video'); + const data = (await utils.getPlaylistItems(id, 'snippet', cache)).data.items.filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video'); ctx.set('data', { title: `${playlistTitle} by ${data[0].snippet.channelTitle} - YouTube`, diff --git a/lib/v2/youtube/subscriptions.js b/lib/v2/youtube/subscriptions.js index 80acd1032e..a8225b8fb5 100644 --- a/lib/v2/youtube/subscriptions.js +++ b/lib/v2/youtube/subscriptions.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; import { config } from '@/config'; const utils = require('./utils'); import { parseDate } from '@/utils/parse-date'; @@ -9,15 +10,15 @@ module.exports = async (ctx) => { } const embed = !ctx.req.param('embed'); - const channelIds = (await utils.getSubscriptions('snippet', ctx.cache)).data.items.map((item) => item.snippet.resourceId.channelId); + const channelIds = (await utils.getSubscriptions('snippet', cache)).data.items.map((item) => item.snippet.resourceId.channelId); const playlistIds = []; - for await (const playlistId of asyncPool(30, channelIds, async (channelId) => (await utils.getChannelWithId(channelId, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads)) { + for await (const playlistId of asyncPool(30, channelIds, async (channelId) => (await utils.getChannelWithId(channelId, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads)) { playlistIds.push(playlistId); } let items = []; - for await (const item of asyncPool(30, playlistIds, async (playlistId) => (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache))?.data.items)) { + for await (const item of asyncPool(30, playlistIds, async (playlistId) => (await utils.getPlaylistItems(playlistId, 'snippet', cache))?.data.items)) { items.push(item); } diff --git a/lib/v2/youtube/user.js b/lib/v2/youtube/user.js index 93c1da04e7..a88056c16e 100644 --- a/lib/v2/youtube/user.js +++ b/lib/v2/youtube/user.js @@ -1,3 +1,4 @@ +import cache from '@/utils/cache'; const utils = require('./utils'); import { config } from '@/config'; import { parseDate } from '@/utils/parse-date'; @@ -19,11 +20,11 @@ module.exports = async (ctx) => { const $ = load(response.data); const channelId = $('meta[itemprop="identifier"]').attr('content'); channelName = $('meta[itemprop="name"]').attr('content'); - playlistId = (await utils.getChannelWithId(channelId, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads; + playlistId = (await utils.getChannelWithId(channelId, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads; } - playlistId = playlistId || (await utils.getChannelWithUsername(username, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads; + playlistId = playlistId || (await utils.getChannelWithUsername(username, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads; - const data = (await utils.getPlaylistItems(playlistId, 'snippet', ctx.cache)).data.items; + const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items; ctx.set('data', { title: `${channelName || username} - YouTube`,