feat: v3 migration - 12/n

This commit is contained in:
DIYgod 2024-02-29 02:50:25 +08:00
parent 6b1100dda7
commit ce80d52dbf
No known key found for this signature in database
86 changed files with 201 additions and 131 deletions

View File

@ -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', {

View File

@ -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', {

View File

@ -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(),

View File

@ -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(),

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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', {

View File

@ -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',

View File

@ -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 () => {

View File

@ -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 {

View File

@ -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',

View File

@ -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);

View File

@ -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',

View File

@ -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}`,

View File

@ -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))
),
});
};

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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 推荐',

View File

@ -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}`,

View File

@ -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 {

View File

@ -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;
}

View File

@ -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(),

View File

@ -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: '简书首页',

View File

@ -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(),

View File

@ -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}`,

View File

@ -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: '掘金 - 单个收藏夹',

View File

@ -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}`,

View File

@ -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: '掘金 - 收藏集',

View File

@ -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}`,

View File

@ -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}`,

View File

@ -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,

View File

@ -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);
// };

View File

@ -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}` : ''}`,

View File

@ -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: '雷峰网 业界资讯',

View File

@ -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: '首页 - 旅法师营地',

View File

@ -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: '旅法师营地 - 首页资讯(旧版)',

View File

@ -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} - 旅法师营地 `,

View File

@ -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} - 旅法师营地 `,

View File

@ -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', {

View File

@ -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', {

View File

@ -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国服新游戏',

View File

@ -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中国大陆主页资讯',

View File

@ -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香港主页资讯',

View File

@ -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,

View File

@ -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,

View File

@ -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: '片源网',

View File

@ -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: '片源网',

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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}`,

View File

@ -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($);

View File

@ -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(),

View File

@ -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(),

View File

@ -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/',

View File

@ -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: '上海自学考试 - 通知公告',

View File

@ -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}`,

View File

@ -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}`,

View File

@ -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}`,

View File

@ -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: `科技日报`,

View File

@ -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);
})
);

View File

@ -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);
})
);

View File

@ -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);
})
);

View File

@ -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);
})
);

View File

@ -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,

View File

@ -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))

View File

@ -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.');

View File

@ -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', {

View File

@ -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', {

View File

@ -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;
}
}

View File

@ -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 });

View File

@ -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));

View File

@ -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);
}

View File

@ -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;

View File

@ -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`,

View File

@ -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(' ')}`;

View File

@ -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 <code>/youtube/user/:id</code> 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`,

View File

@ -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`,

View File

@ -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`,

View File

@ -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`,

View File

@ -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);
}

View File

@ -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`,