diff --git a/lib/v2/bilibili/vsearch.js b/lib/v2/bilibili/vsearch.js index 25f2f58b7..cace8b8e1 100644 --- a/lib/v2/bilibili/vsearch.js +++ b/lib/v2/bilibili/vsearch.js @@ -1,3 +1,4 @@ +const config = require('@/config').value; const got = require('@/utils/got'); const { parseDate } = require('@/utils/parse-date'); const utils = require('./utils'); @@ -11,24 +12,31 @@ module.exports = async (ctx) => { const kw_url = encodeURIComponent(kw); const tids = ctx.params.tid ?? 0; - await got('https://www.bilibili.com', { - cookieJar, - }); + const data = await ctx.cache.tryGet( + `bilibili:vsearch:${tids}:${kw}:${order}`, + async () => { + await got('https://www.bilibili.com', { + cookieJar, + }); - const response = await got('https://api.bilibili.com/x/web-interface/search/type', { - headers: { - Referer: `https://search.bilibili.com/all?keyword=${kw_url}`, + const response = await got('https://api.bilibili.com/x/web-interface/search/type', { + headers: { + Referer: `https://search.bilibili.com/all?keyword=${kw_url}`, + }, + cookieJar, + searchParams: { + search_type: 'video', + highlight: 1, + keyword: kw, + order, + tids, + }, + }); + return response.data.data.result; }, - cookieJar, - searchParams: { - search_type: 'video', - highlight: 1, - keyword: kw, - order, - tids, - }, - }); - const data = response.data.data.result; + config.cache.routeExpire, + false + ); ctx.state.data = { title: `${kw} - bilibili`,