diff --git a/lib/v2/alternativeto/platform.js b/lib/v2/alternativeto/platform.js index 07a1a6bbd..c0a6f4e42 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 edf4bc067..ff93df804 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 2bc4c2ef0..d10de38d0 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 853da95ae..7eeec9028 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 b7d313468..924cdbe8c 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 09fbf7629..278fed8bc 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 b2947a91b..97f1cce82 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 a5470a20c..e832ed962 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 151fb7dce..66c8a7439 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 4d158e049..6bc225a60 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 c8e63ff1c..2398c4968 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 6df02fd94..54f07d161 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 819ecbff8..388d6f7b4 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 112aa03b0..eb7ad0c4d 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 c19db0316..c93f5655f 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 15f8bbeb2..9888faec7 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 7c08cad75..427479386 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 77be282e9..eb1494732 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 5c029da9a..7c567e04c 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 23b635e50..7c63b1ad1 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 67eb4090c..8b2c58be9 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 056e22a66..f568f88fd 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 566fcdc2b..086a1ff25 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 035e58449..84b72e35b 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 2d1797963..05bc02d89 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 5543e38bf..fd3198d29 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 1406d8974..a8b088bce 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 d5638aa1a..d106f70c6 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 1cbb44dee..aab268535 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 161a87bd6..c74659797 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 45f477f3e..8c6bcf4ca 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 cc0fb5613..3c820d233 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 348456636..c24f41f3b 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 21a482d75..19a93b31c 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 31de69ec9..186e2329c 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 d0a1e5c5b..0db406f5c 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 5064cb051..7a93b6c63 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 fb8b9b5ea..e406c6fe5 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 0721095f5..5cc9d102b 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 43cd9648b..5387f1e0b 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 3fe9b6e3f..437cd7e84 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 6df113735..b9ab9aa9e 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 70d2a5a03..825410517 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 49ab43ef4..42771af94 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 7af4a1440..2fbb27730 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 510ef16a4..b0a0eb7fb 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 b65287de6..deb421fff 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 ae303cf28..57bb707c7 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 a76df8436..b8f30195c 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 2dde299a4..335be9d9e 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 b6807b6fb..20e7c7d84 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 8e462a71d..3525dffd9 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 0f7b243f0..754322f55 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 f22150bac..73b725b64 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 4f49c69ba..325ee54ed 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 08a350b83..0c7cf5587 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 75ba889d7..71d8b0fed 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 53a64de57..0b724ed49 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 e0a0b95c5..3be4f1618 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 f1417f4ab..82b71578b 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 7a9d33a48..77a0a1236 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 6b5efde71..ae23232c9 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 7072373ff..0918b8b22 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 530c2a4e9..378db8f25 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 df712c722..379cafe32 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 69da6d970..754209431 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 3fd68261a..133ca5ab4 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 049beac84..d56467de1 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 4734a1eda..b26efb4c9 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 594776e12..6aca423ff 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 7d548180c..9a2858847 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 741cfb2d7..d600d7d58 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 efb0898f1..7fb71c827 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 877c8b1c3..76d40d379 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 1998d02e5..2659c39d1 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 2883a77fe..175594439 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 d32093245..1f7b410e1 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 a00df7380..a16f5381e 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 83b410d47..dafa0ad31 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 398af977f..bdfe972fb 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 984ea2727..49c785ca9 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 e9c8b6096..f5b32bc5f 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 790999b71..0aa0872a8 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 58c287ecb..a7a353159 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 80acd1032..a8225b8fb 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 93c1da04e..a88056c16 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`,