refactor: use cache utils directly (#22316)
This commit is contained in:
parent
b24e8736b5
commit
9807609a4d
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -40,7 +39,7 @@ async function handler(ctx) {
|
|||
imgsrc: e.imgsrc,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((e) => parseDyArticle(e, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((e) => parseDyArticle(e)));
|
||||
|
||||
return {
|
||||
title: `网易号 - ${list[0].author}`,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -49,7 +48,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseDyArticle(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseDyArticle(item)));
|
||||
|
||||
return {
|
||||
title: `${$('head title').text()} - 网易号`,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { load } from 'cheerio';
|
|||
import { raw } from 'hono/html';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
const renderDescription = (imgsrc, postBody) =>
|
||||
|
|
@ -17,8 +18,8 @@ const renderDescription = (imgsrc, postBody) =>
|
|||
</>
|
||||
);
|
||||
|
||||
const parseDyArticle = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const parseDyArticle = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link, {
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, ProcessThreads, rootUrl, types } from './utils';
|
||||
|
||||
|
|
@ -53,6 +52,6 @@ async function handler(ctx) {
|
|||
return {
|
||||
title: `一亩三分地 - ${id}${types[type]}`,
|
||||
link: currentUrl,
|
||||
item: await ProcessThreads(cache.tryGet, apiUrl, order),
|
||||
item: await ProcessThreads(apiUrl, order),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, ProcessThreads, rootUrl, types } from './utils';
|
||||
|
||||
|
|
@ -73,6 +72,6 @@ async function handler(ctx) {
|
|||
return {
|
||||
title: `一亩三分地 - ${Object.hasOwn(sections, id) ? sections[id] : id}${types[type]}`,
|
||||
link: currentUrl,
|
||||
item: await ProcessThreads(cache.tryGet, apiUrl, order),
|
||||
item: await ProcessThreads(apiUrl, order),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, ProcessThreads, rootUrl, types } from './utils';
|
||||
|
||||
|
|
@ -35,6 +34,6 @@ async function handler(ctx) {
|
|||
return {
|
||||
title: `一亩三分地 - ${types[type]}`,
|
||||
link: rootUrl,
|
||||
item: await ProcessThreads(cache.tryGet, apiUrl, order),
|
||||
item: await ProcessThreads(apiUrl, order),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import presetHTML5 from '@bbob/preset-html5';
|
|||
import type { BBobCoreTagNodeTree } from '@bbob/types';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ const swapLinebreak = (tree: BBobCoreTagNodeTree) =>
|
|||
return node;
|
||||
});
|
||||
|
||||
const ProcessThreads = async (tryGet, apiUrl, order) => {
|
||||
const ProcessThreads = async (apiUrl, order) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
|
|
@ -46,7 +47,7 @@ const ProcessThreads = async (tryGet, apiUrl, order) => {
|
|||
category: [item.forum_name, ...(item.tags ? item.tags.map((t) => t.displayname) : [])],
|
||||
};
|
||||
|
||||
return tryGet(result.link, async () => {
|
||||
return cache.tryGet(result.link, async () => {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(items.map((item) => ProcessItem(item, cache.tryGet)));
|
||||
items = await Promise.all(items.map((item) => ProcessItem(item)));
|
||||
|
||||
return {
|
||||
title: `36氪 - ${categories[category].title}`,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { getSubPath } from '@/utils/common-utils';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
|
@ -65,7 +64,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
if (!/^\/(?:search|newsflashes)/.test(path)) {
|
||||
items = await Promise.all(items.map((item) => ProcessItem(item, cache.tryGet)));
|
||||
items = await Promise.all(items.map((item) => ProcessItem(item)));
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import ofetch from '@/utils/ofetch';
|
|||
|
||||
export const rootUrl = 'https://www.36kr.com';
|
||||
|
||||
export const ProcessItem = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
export const ProcessItem = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await ofetch(item.link);
|
||||
|
||||
const cipherTextList = detailResponse.match(/\{"state":"(.*)","isEncrypt":true\}/) ?? [];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item)));
|
||||
|
||||
return {
|
||||
title: $('head title').text().split('_', 1)[0],
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -61,7 +60,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const out = await Promise.all(list.map((item) => parseArticle(item, cache.tryGet)));
|
||||
const out = await Promise.all(list.map((item) => parseArticle(item)));
|
||||
|
||||
return {
|
||||
title: '3DM - ' + $('title').text().split('_', 1)[0],
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const parseArticle = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const parseArticle = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = load(response);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async function handler(ctx) {
|
|||
|
||||
let categoryName = '最新消息';
|
||||
if (!isLatest) {
|
||||
const categories = await getCategories(cache.tryGet);
|
||||
const categories = await getCategories();
|
||||
categoryName = categories.find((c) => c.id === Number.parseInt(category)).name;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@ import { raw } from 'hono/html';
|
|||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
const getCategories = (tryGet) =>
|
||||
tryGet('4gamers:categories', async () => {
|
||||
const getCategories = () =>
|
||||
cache.tryGet('4gamers:categories', async () => {
|
||||
const { data: response } = await got('https://www.4gamers.com.tw/site/api/news/category');
|
||||
|
||||
return response.data.map((category) => ({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { fetchItems, rootUrl } from './util';
|
||||
|
||||
|
|
@ -34,5 +33,5 @@ async function handler(ctx) {
|
|||
|
||||
const currentUrl = new URL(`class/${category}.html`, rootUrl).href;
|
||||
|
||||
return await fetchItems(limit, currentUrl, cache.tryGet);
|
||||
return await fetchItems(limit, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { fetchItems, rootUrl } from './util';
|
||||
|
||||
|
|
@ -30,5 +29,5 @@ async function handler(ctx) {
|
|||
|
||||
const currentUrl = new URL(`top/${category.split(/_/, 1)[0]}_1.html`, rootUrl).href;
|
||||
|
||||
return await fetchItems(limit, currentUrl, cache.tryGet);
|
||||
return await fetchItems(limit, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ import { load } from 'cheerio';
|
|||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
import iconv from 'iconv-lite';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const rootUrl = 'https://www.56kog.com';
|
||||
|
||||
const fetchItems = async (limit, currentUrl, tryGet) => {
|
||||
const fetchItems = async (limit, currentUrl) => {
|
||||
const { data: response } = await got(currentUrl, {
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
|
@ -31,7 +32,7 @@ const fetchItems = async (limit, currentUrl, tryGet) => {
|
|||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
try {
|
||||
const { data: detailResponse } = await got(item.link, {
|
||||
responseType: 'buffer',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -55,7 +54,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
return {
|
||||
item: await ProcessFeed(limit, cache.tryGet, items),
|
||||
item: await ProcessFeed(limit, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
description: $('div.tips').text(),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { load } from 'cheerio';
|
|||
|
||||
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { ossUrl, ProcessFeed, rootUrl } from './utils';
|
||||
|
|
@ -62,7 +61,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
return {
|
||||
item: await ProcessFeed(limit, cache.tryGet, items),
|
||||
item: await ProcessFeed(limit, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
description: $('div.thinktank-author-description-box p').text(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
return {
|
||||
item: await ProcessFeed(limit, cache.tryGet, items),
|
||||
item: await ProcessFeed(limit, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
language: 'zh-cn',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -7,10 +8,10 @@ import timezone from '@/utils/timezone';
|
|||
const ossUrl = 'https://oss.aisixiang.com';
|
||||
const rootUrl = 'https://www.aisixiang.com';
|
||||
|
||||
const ProcessFeed = (limit, tryGet, items) =>
|
||||
const ProcessFeed = (limit, items) =>
|
||||
Promise.all(
|
||||
items.slice(0, limit).map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const content = load(detailResponse);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -58,7 +57,7 @@ async function handler(ctx) {
|
|||
});
|
||||
|
||||
return {
|
||||
item: await ProcessFeed(limit, cache.tryGet, items),
|
||||
item: await ProcessFeed(limit, items),
|
||||
title: `爱思想 - ${title}`,
|
||||
link: currentUrl,
|
||||
description: $('div.tips p').text(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { config } from '@/config';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
export const getData = (tryGet) => {
|
||||
export const getData = () => {
|
||||
const bgmCalendarUrl = 'https://api.bgm.tv/calendar';
|
||||
const bgmDataUrl = 'https://cdn.jsdelivr.net/npm/bangumi-data/dist/data.json';
|
||||
|
||||
|
|
@ -9,21 +10,19 @@ export const getData = (tryGet) => {
|
|||
|
||||
return Promise.all(
|
||||
urls.map((item, i) =>
|
||||
tryGet(
|
||||
cache.tryGet(
|
||||
item,
|
||||
async () => {
|
||||
const { data } = await got(item);
|
||||
|
||||
if (i === 1) {
|
||||
// 只保留有 bangumi id 的番剧
|
||||
const items = [];
|
||||
for (const item of data.items) {
|
||||
const bgmSite = item.sites.find((s) => s.site === 'bangumi');
|
||||
if (bgmSite) {
|
||||
item.bgmId = bgmSite.id;
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
const items = data.items
|
||||
.map((item) => {
|
||||
const bgmSite = item.sites.find((s) => s.site === 'bangumi');
|
||||
return bgmSite ? { ...item, bgmId: bgmSite.id } : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
data.items = items;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { getData } from './_base';
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ const renderTodayDescription = (bgm, siteMeta) =>
|
|||
);
|
||||
|
||||
async function handler() {
|
||||
const [list, data] = await getData(cache.tryGet);
|
||||
const [list, data] = await getData();
|
||||
const siteMeta = data.siteMeta;
|
||||
|
||||
const today = new Date(Date.now());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
import { renderPost } from './templates/post';
|
||||
|
|
@ -32,10 +31,10 @@ async function handler(ctx) {
|
|||
const handle = ctx.req.param('handle');
|
||||
const space = ctx.req.param('space');
|
||||
|
||||
const DID = await resolveHandle(handle, cache.tryGet);
|
||||
const DID = await resolveHandle(handle);
|
||||
const uri = `at://${DID}/app.bsky.feed.generator/${space}`;
|
||||
const profile = await getFeedGenerator(uri, cache.tryGet);
|
||||
const feeds = await getFeed(uri, cache.tryGet);
|
||||
const profile = await getFeedGenerator(uri);
|
||||
const feeds = await getFeed(uri);
|
||||
|
||||
const items = feeds.feed.map(({ post }) => ({
|
||||
title: post.record.text.split('\n', 1)[0],
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import querystring from 'node:querystring';
|
|||
|
||||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
import { renderPost } from './templates/post';
|
||||
|
|
@ -52,9 +51,9 @@ async function handler(ctx) {
|
|||
const routeParams = querystring.parse(ctx.req.param('routeParams'));
|
||||
const filter = routeParams.filter || 'posts_and_author_threads';
|
||||
|
||||
const DID = await resolveHandle(handle, cache.tryGet);
|
||||
const profile = await getProfile(DID, cache.tryGet);
|
||||
const authorFeed = await getAuthorFeed(DID, filter, cache.tryGet);
|
||||
const DID = await resolveHandle(handle);
|
||||
const profile = await getProfile(DID);
|
||||
const authorFeed = await getAuthorFeed(DID, filter);
|
||||
|
||||
const items = authorFeed.feed.map(({ post }) => ({
|
||||
title: post.record.text.split('\n', 1)[0],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { config } from '@/config';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
/**
|
||||
|
|
@ -6,8 +7,8 @@ import got from '@/utils/got';
|
|||
*/
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/identity/resolveHandle.json
|
||||
const resolveHandle = (handle, tryGet) =>
|
||||
tryGet(`bsky:${handle}`, async () => {
|
||||
const resolveHandle = (handle) =>
|
||||
cache.tryGet(`bsky:${handle}`, async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle', {
|
||||
searchParams: {
|
||||
handle,
|
||||
|
|
@ -17,8 +18,8 @@ const resolveHandle = (handle, tryGet) =>
|
|||
});
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/actor/getProfile.json
|
||||
const getProfile = (did, tryGet) =>
|
||||
tryGet(`bsky:profile:${did}`, async () => {
|
||||
const getProfile = (did) =>
|
||||
cache.tryGet(`bsky:profile:${did}`, async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile', {
|
||||
searchParams: {
|
||||
actor: did,
|
||||
|
|
@ -28,8 +29,8 @@ const getProfile = (did, tryGet) =>
|
|||
});
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getAuthorFeed.json
|
||||
const getAuthorFeed = (did, filter, tryGet) =>
|
||||
tryGet(
|
||||
const getAuthorFeed = (did, filter) =>
|
||||
cache.tryGet(
|
||||
`bsky:authorFeed:${did}:${filter}`,
|
||||
async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed', {
|
||||
|
|
@ -46,8 +47,8 @@ const getAuthorFeed = (did, filter, tryGet) =>
|
|||
);
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getFeed.json
|
||||
const getFeed = (uri, tryGet) =>
|
||||
tryGet(
|
||||
const getFeed = (uri) =>
|
||||
cache.tryGet(
|
||||
`bsky:feed:${uri}`,
|
||||
async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/app.bsky.feed.getFeed', {
|
||||
|
|
@ -63,8 +64,8 @@ const getFeed = (uri, tryGet) =>
|
|||
);
|
||||
|
||||
// https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/feed/getFeedGenerator.json
|
||||
const getFeedGenerator = (uri, tryGet) =>
|
||||
tryGet(
|
||||
const getFeedGenerator = (uri) =>
|
||||
cache.tryGet(
|
||||
`bsky:feedGenerator:${uri}`,
|
||||
async () => {
|
||||
const { data } = await got('https://public.api.bsky.app/xrpc/app.bsky.feed.getFeedGenerator', {
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ const loadContent = (id, { chapter, pages }) => {
|
|||
return description;
|
||||
};
|
||||
|
||||
const getChapters = (id, list, tryGet) =>
|
||||
const getChapters = (id, list) =>
|
||||
Promise.all(
|
||||
list.map((item) =>
|
||||
tryGet(item.link, () => {
|
||||
cache.tryGet(item.link, () => {
|
||||
item.description = loadContent(id, item);
|
||||
|
||||
return item;
|
||||
|
|
@ -91,7 +91,7 @@ async function handler(ctx) {
|
|||
})
|
||||
.toReversed();
|
||||
|
||||
const chapters = await getChapters(id, list, cache.tryGet);
|
||||
const chapters = await getChapters(id, list);
|
||||
|
||||
return {
|
||||
title: $('head title').text(),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -39,6 +38,6 @@ export async function handler(ctx) {
|
|||
return {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: await ProcessItems(items, ctx.req.query('limit'), cache.tryGet),
|
||||
item: await ProcessItems(items, ctx.req.query('limit')),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const rootUrl = 'https://www.cnbeta.com.tw';
|
||||
|
||||
const ProcessItems = (items, limit, tryGet) =>
|
||||
const ProcessItems = (items, limit) =>
|
||||
Promise.all(
|
||||
items.slice(0, limit ? Number.parseInt(limit) : 60).map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link);
|
||||
|
||||
const content = load(detailResponse.data);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export const route: Route = {
|
|||
|
||||
async function handler(ctx) {
|
||||
const { id, coverOnly = 'true', quality = '1' } = ctx.req.param();
|
||||
const uuid = await getUuid(cache.tryGet);
|
||||
const uuid = await getUuid();
|
||||
const {
|
||||
data: { data: book },
|
||||
} = await getBook(id, uuid);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import CryptoJS from 'crypto-js';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
const apiHost = 'https://api.creative-comic.tw';
|
||||
|
|
@ -48,8 +49,8 @@ const getImgKey = (pageId, uuid) =>
|
|||
},
|
||||
});
|
||||
|
||||
const getUuid = (tryGet) =>
|
||||
tryGet('creative-comic:uuid', async () => {
|
||||
const getUuid = () =>
|
||||
cache.tryGet('creative-comic:uuid', async () => {
|
||||
const { data } = await got(`${apiHost}/guest`, {
|
||||
headers: {
|
||||
device,
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ const pathMap = {
|
|||
},
|
||||
};
|
||||
|
||||
const getCookie = async (context, tryGet) => {
|
||||
const getCookie = async (context) => {
|
||||
if (!cookie) {
|
||||
cookie = await tryGet('cw:cookie', async () => {
|
||||
cookie = await cache.tryGet('cw:cookie', async () => {
|
||||
const page = await context.newPage();
|
||||
await page.route('**/*', (route) => {
|
||||
const request = route.request();
|
||||
|
|
@ -53,7 +53,7 @@ const getCookie = async (context, tryGet) => {
|
|||
const parsePage = async (path, context, ctx) => {
|
||||
const pageUrl = `${baseUrl}${pathMap[path].pageUrl(ctx.req.param('channel'))}`;
|
||||
|
||||
const cookie = await getCookie(context, cache.tryGet);
|
||||
const cookie = await getCookie(context);
|
||||
const page = await context.newPage();
|
||||
await page.route('**/*', (route) => {
|
||||
const request = route.request();
|
||||
|
|
@ -71,7 +71,7 @@ const parsePage = async (path, context, ctx) => {
|
|||
const $ = load(response);
|
||||
|
||||
const list = parseList($, ctx.req.query('limit') ? Number(ctx.req.query('limit')) : pathMap[path].limit);
|
||||
const items = await parseItems(list, context, cache.tryGet);
|
||||
const items = await parseItems(list, context);
|
||||
|
||||
return { $, items };
|
||||
};
|
||||
|
|
@ -89,13 +89,13 @@ const parseList = ($, limit) =>
|
|||
})
|
||||
.slice(0, limit);
|
||||
|
||||
const parseItems = (list, context, tryGet) =>
|
||||
const parseItems = (list, context) =>
|
||||
Promise.all(
|
||||
list.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
const response = await ofetch(item.link, {
|
||||
headers: {
|
||||
Cookie: await getCookie(context, tryGet),
|
||||
Cookie: await getCookie(context),
|
||||
'User-Agent': config.ua,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, getInfo, processItems, rootUrl } from './util';
|
||||
|
||||
|
|
@ -33,12 +32,12 @@ async function handler(ctx) {
|
|||
const apiUrl = new URL('v2/author/author/detail', apiRootUrl).href;
|
||||
const currentUrl = new URL(`author/${id}`, rootUrl).href;
|
||||
|
||||
const items = await processItems(apiUrl, limit, cache.tryGet, {
|
||||
const items = await processItems(apiUrl, limit, {
|
||||
author_id: id,
|
||||
});
|
||||
|
||||
return {
|
||||
item: items,
|
||||
...(await getInfo(currentUrl, cache.tryGet)),
|
||||
...(await getInfo(currentUrl)),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, getInfo, processItems, rootUrl } from './util';
|
||||
|
||||
|
|
@ -37,7 +36,6 @@ async function handler(ctx) {
|
|||
const items = await processItems(
|
||||
apiUrl,
|
||||
limit,
|
||||
cache.tryGet,
|
||||
id === 'news'
|
||||
? {}
|
||||
: {
|
||||
|
|
@ -47,6 +45,6 @@ async function handler(ctx) {
|
|||
|
||||
return {
|
||||
item: items,
|
||||
...(await getInfo(currentUrl, cache.tryGet)),
|
||||
...(await getInfo(currentUrl)),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { apiRootUrl, getInfo, processItems, rootUrl } from './util';
|
||||
|
||||
|
|
@ -33,12 +32,12 @@ async function handler(ctx) {
|
|||
const apiUrl = new URL('v2/content/tag/tagList', apiRootUrl).href;
|
||||
const currentUrl = new URL(`label/${name}`, rootUrl).href;
|
||||
|
||||
const items = await processItems(apiUrl, limit, cache.tryGet, {
|
||||
const items = await processItems(apiUrl, limit, {
|
||||
tag: name,
|
||||
});
|
||||
|
||||
return {
|
||||
item: items,
|
||||
...(await getInfo(currentUrl, cache.tryGet)),
|
||||
...(await getInfo(currentUrl)),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -8,13 +9,12 @@ const apiRootUrl = 'https://api1.cyzone.cn';
|
|||
const apiShowUrl = new URL('v2/content/app_content/show', apiRootUrl).href;
|
||||
|
||||
/**
|
||||
* Retrieves information from a given URL using a provided tryGet function.
|
||||
* Retrieves information from a given URL.
|
||||
* @param {string} url - The URL to retrieve information from.
|
||||
* @param {Function} tryGet - The tryGet function that handles the retrieval process.
|
||||
* @returns {Promise<Object>} - A promise that resolves to an object containing the retrieved information.
|
||||
*/
|
||||
const getInfo = (url, tryGet) =>
|
||||
tryGet(url, async () => {
|
||||
const getInfo = (url) =>
|
||||
cache.tryGet(url, async () => {
|
||||
const { data: response } = await got(url);
|
||||
|
||||
const $ = load(response);
|
||||
|
|
@ -40,11 +40,10 @@ const getInfo = (url, tryGet) =>
|
|||
* Process the item list and return the resulting array.
|
||||
* @param {string} apiUrl - The URL of the API.
|
||||
* @param {number} limit - The limit of the results.
|
||||
* @param {function} tryGet - The tryGet function that handles the retrieval process.
|
||||
* @param {...Object} searchParams - The search parameter objects.
|
||||
* @returns {Promise<Array>} - The processed item array.
|
||||
*/
|
||||
const processItems = async (apiUrl, limit, tryGet, ...params) => {
|
||||
const processItems = async (apiUrl, limit, ...params) => {
|
||||
// Merge search parameters
|
||||
let searchParams = {
|
||||
size: limit,
|
||||
|
|
@ -76,7 +75,7 @@ const processItems = async (apiUrl, limit, tryGet, ...params) => {
|
|||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(`cyzone-${item.guid}`, async () => {
|
||||
cache.tryGet(`cyzone-${item.guid}`, async () => {
|
||||
const { data: detailResponse } = await got.post(apiShowUrl, {
|
||||
json: {
|
||||
content_id: item.guid,
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ async function handler(ctx) {
|
|||
postId: item.postId,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((item) => getPost(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => getPost(item)));
|
||||
|
||||
return {
|
||||
title: boardDetail.title,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => getPost(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => getPost(item)));
|
||||
|
||||
return {
|
||||
title: `${userInfo.nickname} 的个人主页 - 丁香园论坛 - 专业医生社区,医学、药学、生命科学、科研学术交流`,
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => getPost(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => getPost(item)));
|
||||
|
||||
return {
|
||||
title: specialDetail.name,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -33,8 +34,8 @@ const sign = (params) => {
|
|||
return CryptoJS.SHA1(searchParams.toString()).toString();
|
||||
};
|
||||
|
||||
const getPost = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const getPost = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const postParams = {
|
||||
postId: item.postId,
|
||||
serverTimestamp: Date.now(),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiUrl, favicon, getBParam, getBuildId, getGToken, parseItem, parseList } from './utils';
|
||||
|
|
@ -64,7 +63,7 @@ Language
|
|||
async function handler(ctx) {
|
||||
const { categoryId = '1', lang = 'en' } = ctx.req.param();
|
||||
const { limit = 20 } = ctx.req.query();
|
||||
const gToken = await getGToken(cache.tryGet);
|
||||
const gToken = await getGToken();
|
||||
const bParam = getBParam(lang);
|
||||
|
||||
const { data: response } = await got.post(`${apiUrl}/feed/list/recommended`, {
|
||||
|
|
@ -81,10 +80,10 @@ async function handler(ctx) {
|
|||
throw new Error(response.msg);
|
||||
}
|
||||
|
||||
const buildId = await getBuildId(cache.tryGet);
|
||||
const buildId = await getBuildId();
|
||||
|
||||
const list = parseList(response.data.list, lang, buildId);
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: 'Followin',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { baseUrl, getBuildId, parseItem, parseList } from './utils';
|
||||
|
|
@ -31,14 +30,14 @@ async function handler(ctx) {
|
|||
const { kolId, lang = 'en' } = ctx.req.param();
|
||||
const { limit = 10 } = ctx.req.query();
|
||||
|
||||
const buildId = await getBuildId(cache.tryGet);
|
||||
const buildId = await getBuildId();
|
||||
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/kol/${kolId}.json`);
|
||||
|
||||
const { queries } = response.pageProps.dehydratedState;
|
||||
const { data: profile } = queries.find((q) => q.queryKey[0] === '/user/get_profile').state;
|
||||
|
||||
const list = parseList(queries.find((q) => q.queryKey[0] === '/feed/list/user').state.data.pages[0].list.slice(0, limit), lang, buildId);
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `${profile.nickname} - Followin`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { baseUrl, favicon, getBuildId, parseItem, parseList } from './utils';
|
||||
|
|
@ -44,11 +43,11 @@ async function handler(ctx) {
|
|||
const { lang = 'en' } = ctx.req.param();
|
||||
const { limit = 20 } = ctx.req.query();
|
||||
|
||||
const buildId = await getBuildId(cache.tryGet);
|
||||
const buildId = await getBuildId();
|
||||
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/news.json`);
|
||||
|
||||
const list = parseList(response.pageProps.dehydratedState.queries.find((q) => q.queryKey[0] === '/feed/list/recommended/news').state.data.pages[0].list.slice(0, limit), lang, buildId);
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `${lang === 'en' ? 'News' : lang === 'vi' ? 'Bản tin' : '快讯'} - Followin`,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ async function handler(ctx) {
|
|||
const { tagId, lang = 'en' } = ctx.req.param();
|
||||
const { limit = 20 } = ctx.req.query();
|
||||
|
||||
const buildId = await getBuildId(cache.tryGet);
|
||||
const buildId = await getBuildId();
|
||||
const tagInfo = await cache.tryGet(`followin:tag:${tagId}:${lang}`, async () => {
|
||||
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/tag/${tagId}.json`);
|
||||
const { queries } = response.pageProps.dehydratedState;
|
||||
|
|
@ -39,7 +39,7 @@ async function handler(ctx) {
|
|||
return tagInfo;
|
||||
});
|
||||
|
||||
const gToken = await getGToken(cache.tryGet);
|
||||
const gToken = await getGToken();
|
||||
const bParam = getBParam(lang);
|
||||
const { data: tagResponse } = await got.post(`${apiUrl}/feed/list/tag`, {
|
||||
headers: {
|
||||
|
|
@ -57,7 +57,7 @@ async function handler(ctx) {
|
|||
}
|
||||
|
||||
const list = parseList(tagResponse.data.list.slice(0, limit), lang, buildId);
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `${tagInfo.name} - Followin`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { baseUrl, getBuildId, parseItem, parseList } from './utils';
|
||||
|
|
@ -31,14 +30,14 @@ async function handler(ctx) {
|
|||
const { topicId, lang = 'en' } = ctx.req.param();
|
||||
const { limit = 20 } = ctx.req.query();
|
||||
|
||||
const buildId = await getBuildId(cache.tryGet);
|
||||
const buildId = await getBuildId();
|
||||
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/${lang}/topic/${topicId}.json`);
|
||||
|
||||
const { queries } = response.pageProps.dehydratedState;
|
||||
const { data: topicInfo } = queries.find((q) => q.queryKey[0] === '/topic/info').state;
|
||||
|
||||
const list = parseList(queries.find((q) => q.queryKey[0] === '/feed/list/topic').state.data.pages[0].list.slice(0, limit), lang, buildId);
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `${topicInfo.title} - Followin`,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { raw } from 'hono/html';
|
|||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import { config } from '@/config';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -44,8 +45,8 @@ const getBParam = (lang) => ({
|
|||
i: 'official',
|
||||
});
|
||||
|
||||
const getBuildId = (tryGet) =>
|
||||
tryGet(
|
||||
const getBuildId = () =>
|
||||
cache.tryGet(
|
||||
'followin:buildId',
|
||||
async () => {
|
||||
const { data: pageResponse } = await got(baseUrl);
|
||||
|
|
@ -57,8 +58,8 @@ const getBuildId = (tryGet) =>
|
|||
false
|
||||
);
|
||||
|
||||
const getGToken = (tryGet) =>
|
||||
tryGet('followin:gtoken', async () => {
|
||||
const getGToken = () =>
|
||||
cache.tryGet('followin:gtoken', async () => {
|
||||
const { data } = await got.post(`${apiUrl}/user/gtoken`);
|
||||
return data.data.gtoken;
|
||||
});
|
||||
|
|
@ -74,8 +75,8 @@ const parseList = (list, lang, buildId) =>
|
|||
nextData: `${baseUrl}/_next/data/${buildId}/${lang}/feed/${item.id}.json`,
|
||||
}));
|
||||
|
||||
const parseItem = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const parseItem = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data } = await got(item.nextData);
|
||||
|
||||
const { queries } = data.pageProps.dehydratedState;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: '格隆汇-财经资讯动态-股市行情',
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { load } from 'cheerio';
|
|||
|
||||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { parseItem } from './utils';
|
||||
|
|
@ -60,7 +59,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `最热文章 - ${type === 0 ? '日排行' : '周排行'} - 格隆汇`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ async function handler(ctx) {
|
|||
pubDate: parseDate(item.timestamp, 'X'),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `格隆汇 - 关键词 “${keyword}” 的文章`,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { load } from 'cheerio';
|
|||
|
||||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ async function handler(ctx) {
|
|||
pubDate: parseDate(item.timestamp, 'X'),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `格隆汇 - 主题 ${$('span.user-nick').text()} 的文章`,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ async function handler(ctx) {
|
|||
pubDate: parseDate(item.createTimestamp, 'X'),
|
||||
}));
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseItem(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseItem(item)));
|
||||
|
||||
return {
|
||||
title: `格隆汇 - 用户 ${data.result[0].user.nick} 的文章`,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate, parseRelativeDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const parseItem = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const parseItem = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: res } = await got(item.link);
|
||||
const $ = load(res);
|
||||
if (item.link.startsWith('https://www.gelonghui.com/live/')) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -10,13 +11,12 @@ const rootUrl = 'https://www.chinamine-safety.gov.cn';
|
|||
* Process the item list and return the resulting array.
|
||||
*
|
||||
* @param {Object[]} items - The items to process.
|
||||
* @param {Function} tryGet - The tryGet function that handles the retrieval process.
|
||||
* @returns {Promise<Object[]>} - A promise that resolves to an array of processed items.
|
||||
*/
|
||||
const processItems = async (items, tryGet) =>
|
||||
const processItems = async (items) =>
|
||||
await Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (!item.link.endsWith('html')) {
|
||||
return item;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -80,7 +79,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
items = await processItems(items, cache.tryGet);
|
||||
items = await processItems(items);
|
||||
|
||||
return {
|
||||
item: items,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -232,7 +231,7 @@ async function handler(ctx) {
|
|||
};
|
||||
});
|
||||
|
||||
items = await processItems(items, cache.tryGet);
|
||||
items = await processItems(items);
|
||||
|
||||
return {
|
||||
item: items,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -27,7 +26,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: response.data.category ? `${response.data.category.publishName} | 香港01` : `Channel: ${id} | 香港01`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -37,7 +36,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: '熱門新聞、全城熱話及社會時事 | 香港01',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -27,7 +26,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.blocks[0].articles, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.blocks[0].articles, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: `${response.data.title} | 香港01`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -37,7 +36,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: '即時 | 香港01',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -27,7 +26,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: `${id} | 香港01`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -91,7 +92,7 @@ const renderDescription = ({ image, teasers, blocks }) =>
|
|||
</>
|
||||
);
|
||||
|
||||
const ProcessItems = (items, limit, tryGet) =>
|
||||
const ProcessItems = (items, limit) =>
|
||||
Promise.all(
|
||||
items
|
||||
.filter((item) => item.type !== 2)
|
||||
|
|
@ -104,7 +105,7 @@ const ProcessItems = (items, limit, tryGet) =>
|
|||
author: item.data.authors.map((a) => a.publishName).join(', '),
|
||||
}))
|
||||
.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiRootUrl, ProcessItems, rootUrl } from './utils';
|
||||
|
|
@ -27,7 +26,7 @@ async function handler(ctx) {
|
|||
url: apiUrl,
|
||||
});
|
||||
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'), cache.tryGet);
|
||||
const items = await ProcessItems(response.data.items, ctx.req.query('limit'));
|
||||
|
||||
return {
|
||||
title: `${response.data.category.publishName} | 香港01`,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable unicorn/prefer-code-point */
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
|
|
@ -97,7 +96,7 @@ async function handler(ctx) {
|
|||
// Taken from /caixin/blog.js
|
||||
content
|
||||
.find('#view > p')
|
||||
.filter((_, e) => e.children[0]?.data === String.fromCharCode(160))
|
||||
.filter((_, e) => e.children[0]?.data === String.fromCodePoint(160))
|
||||
.remove();
|
||||
|
||||
// fix lazyload image
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ async function handler(ctx) {
|
|||
language,
|
||||
size: Number.parseInt(ctx.req.query('limit')) || 15,
|
||||
};
|
||||
const gameInfo = await getI18nGameInfo(gids, language, cache.tryGet);
|
||||
const typeInfo = await getI18nType(language, cache.tryGet);
|
||||
const gameInfo = await getI18nGameInfo(gids, language);
|
||||
const typeInfo = await getI18nType(language);
|
||||
const list = await getEventList(params);
|
||||
const items = await getPostContent(list, params);
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
const getGameInfoList = (tryGet) =>
|
||||
tryGet('hoyolab:gameNameList', async () => {
|
||||
const getGameInfoList = () =>
|
||||
cache.tryGet('hoyolab:gameNameList', async () => {
|
||||
const { data } = await got('https://bbs-api-os-static.hoyolab.com/community/apihub/static/api/getAppConfig');
|
||||
return JSON.parse(data.data.config.hoyolab_game_info_list);
|
||||
});
|
||||
|
||||
const getI18nGameInfo = async (gid, language, tryGet) => {
|
||||
const gameNameList = await getGameInfoList(tryGet);
|
||||
const getI18nGameInfo = async (gid, language) => {
|
||||
const gameNameList = await getGameInfoList();
|
||||
const game = gameNameList.find((item) => item.game_id === Number(gid));
|
||||
return {
|
||||
name: game?.game_name_list.find((item) => item.locale === language)?.raw_name ?? game?.game_name_list.find((item) => item.locale === 'en-us')?.raw_name,
|
||||
|
|
@ -15,8 +16,8 @@ const getI18nGameInfo = async (gid, language, tryGet) => {
|
|||
};
|
||||
};
|
||||
|
||||
const getI18nType = (language, tryGet) =>
|
||||
tryGet(`hoyolab:type:${language}`, async () => {
|
||||
const getI18nType = (language) =>
|
||||
cache.tryGet(`hoyolab:type:${language}`, async () => {
|
||||
const { data } = await got(`https://webstatic.hoyoverse.com/admin/mi18n/bbs_oversea/m07281525151831/m07281525151831-${language}.json`);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiArticleRootUrl, buildFeedMetadata, buildHuxiuRouteTitlePrefix, processItems, rootUrl } from './util';
|
||||
|
|
@ -54,7 +53,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data?.dataList ?? response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data?.dataList ?? response.data.datalist, limit);
|
||||
const rawTitle = response.data?.share_info?.share_title ?? response.data?.name ?? '全部';
|
||||
|
||||
const data = buildFeedMetadata({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiClubRootUrl, buildHuxiuRouteTitlePrefix, fetchApiRouteData, processItems, rootUrl } from './util';
|
||||
|
|
@ -61,7 +60,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.datalist, limit);
|
||||
|
||||
return {
|
||||
item: items,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiArticleRootUrl, buildHuxiuRouteTitlePrefix, fetchApiRouteData, processItems, rootUrl } from './util';
|
||||
|
|
@ -36,7 +35,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.datalist, limit);
|
||||
|
||||
const data = await fetchApiRouteData<{
|
||||
name: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiMemberRootUrl, buildHuxiuRouteTitlePrefix, fetchMemberData, processItems } from './util';
|
||||
|
|
@ -37,7 +36,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.datalist, limit);
|
||||
|
||||
const data = await fetchMemberData(id, type, response.data.datalist ?? [], buildHuxiuRouteTitlePrefix(route.name));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiMomentRootUrl, buildFeedMetadata, buildHuxiuRouteTitlePrefix, processItems, rootUrl } from './util';
|
||||
|
|
@ -40,7 +39,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.moment_list.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.moment_list.datalist, limit);
|
||||
|
||||
const data = buildFeedMetadata({
|
||||
title: '24 小时',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiSearchRootUrl, buildFeedMetadata, buildHuxiuRouteTitlePrefix, generateSignature, processItems, rootUrl, siteTitle } from './util';
|
||||
|
|
@ -48,7 +47,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.datalist, limit);
|
||||
|
||||
const data = buildFeedMetadata({
|
||||
title: `搜索结果-${keyword}`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiArticleRootUrl, buildHuxiuRouteTitlePrefix, fetchApiRouteData, processItems, rootUrl } from './util';
|
||||
|
|
@ -36,7 +35,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
|
||||
const items = await processItems(response.data.datalist, limit, cache.tryGet);
|
||||
const items = await processItems(response.data.datalist, limit);
|
||||
|
||||
const data = await fetchApiRouteData<{
|
||||
tag_name: string;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { load } from 'cheerio';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -511,10 +512,9 @@ const mapItem = (item) => {
|
|||
*
|
||||
* @param {Object[]} items - The items to process.
|
||||
* @param {number} limit - The maximum number of items to process.
|
||||
* @param {Function} tryGet - The tryGet function that handles the retrieval process.
|
||||
* @returns {Promise<Object[]>} - A promise that resolves to an array of processed items.
|
||||
*/
|
||||
const processItems = async (items, limit, tryGet) => {
|
||||
const processItems = async (items, limit) => {
|
||||
const processedItems = items
|
||||
.map((item) => mapItem(item))
|
||||
.filter(Boolean)
|
||||
|
|
@ -522,7 +522,7 @@ const processItems = async (items, limit, tryGet) => {
|
|||
|
||||
return await Promise.all(
|
||||
processedItems.map((item) =>
|
||||
tryGet(item.guid, async () => {
|
||||
cache.tryGet(item.guid, async () => {
|
||||
const isExternalLink = !new RegExp(domain, 'i').test(new URL(item.link).hostname);
|
||||
const isMoment = item.guid.startsWith('huxiu-moment');
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { renderItems } from '../common-utils';
|
|||
import { ig, login } from './utils';
|
||||
|
||||
// loadContent pulls the desired user/tag/etc
|
||||
async function loadContent(category, nameOrId, tryGet) {
|
||||
async function loadContent(category, nameOrId) {
|
||||
let feedTitle, feedLink, feedDescription, feedLogo;
|
||||
let itemsRaw;
|
||||
|
||||
|
|
@ -18,11 +18,11 @@ async function loadContent(category, nameOrId, tryGet) {
|
|||
let userInfo, username, id;
|
||||
if (Number.isNaN(nameOrId)) {
|
||||
username = nameOrId;
|
||||
id = await tryGet(`instagram:getIdByUsername:${username}`, () => ig.user.getIdByUsername(username), 31_536_000); // 1 year since it will never change
|
||||
userInfo = await tryGet(`instagram:userInfo:${id}`, () => ig.user.info(id));
|
||||
id = await cache.tryGet(`instagram:getIdByUsername:${username}`, () => ig.user.getIdByUsername(username), 31_536_000); // 1 year since it will never change
|
||||
userInfo = await cache.tryGet(`instagram:userInfo:${id}`, () => ig.user.info(id));
|
||||
} else {
|
||||
id = nameOrId;
|
||||
userInfo = await tryGet(`instagram:userInfo:${id}`, () => ig.user.info(id));
|
||||
userInfo = await cache.tryGet(`instagram:userInfo:${id}`, () => ig.user.info(id));
|
||||
username = userInfo.username;
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ async function loadContent(category, nameOrId, tryGet) {
|
|||
feedTitle = `${fullName} (@${username}) - Instagram`;
|
||||
feedLink = `https://www.instagram.com/${username}`;
|
||||
|
||||
itemsRaw = await tryGet(`instagram:feed:${id}`, () => ig.feed.user(id).items(), config.cache.routeExpire, false);
|
||||
itemsRaw = await cache.tryGet(`instagram:feed:${id}`, () => ig.feed.user(id).items(), config.cache.routeExpire, false);
|
||||
break;
|
||||
}
|
||||
case 'tags': {
|
||||
|
|
@ -42,7 +42,7 @@ async function loadContent(category, nameOrId, tryGet) {
|
|||
feedTitle = `#${tag} - Instagram`;
|
||||
feedLink = `https://www.instagram.com/explore/tags/${tag}`;
|
||||
|
||||
itemsRaw = await tryGet(`instagram:tags:${tag}`, () => ig.feed.tags(tag, 'recent').items(), config.cache.routeExpire, false);
|
||||
itemsRaw = await cache.tryGet(`instagram:tags:${tag}`, () => ig.feed.tags(tag, 'recent').items(), config.cache.routeExpire, false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -129,7 +129,7 @@ async function handler(ctx) {
|
|||
|
||||
let data;
|
||||
try {
|
||||
data = await loadContent(category, key, cache.tryGet);
|
||||
data = await loadContent(category, key);
|
||||
} catch (error) {
|
||||
logger.error(`Instagram error: ${error}`);
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -21,5 +20,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_bestrated.php?list&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -30,5 +29,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/tl_bestreviews.php?list&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultGenre, defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -26,5 +25,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_genre.php?list&g=${genre}&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMaker, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -31,5 +30,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_maker.php?list&m=${maker}&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -21,5 +20,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_mostwanted.php?list&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -17,5 +16,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_newentries.php?list`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -21,5 +20,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_newrelease.php?list&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, defaultMode, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -37,5 +36,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_star.php?list&s=${id}&mode=${mode}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -17,5 +16,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/vl_update.php?list`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { defaultLanguage, ProcessItems, rootUrl } from './utils';
|
||||
|
||||
|
|
@ -22,5 +21,5 @@ async function handler(ctx) {
|
|||
const language = ctx.req.param('language') ?? defaultLanguage;
|
||||
const currentUrl = `${rootUrl}/${language}/${type}.php?list&u=${id}`;
|
||||
|
||||
return await ProcessItems(language, currentUrl, cache.tryGet);
|
||||
return await ProcessItems(language, currentUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { load } from 'cheerio';
|
|||
import { raw } from 'hono/html';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ const renderDescription = ({ cover, info, comment, videos, thumbs }) =>
|
|||
{thumbs?.length ? thumbs.map((thumb) => <img src={thumb} />) : null}
|
||||
</>
|
||||
);
|
||||
const ProcessItems = async (language, currentUrl, tryGet) => {
|
||||
const ProcessItems = async (language, currentUrl) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
|
|
@ -64,7 +65,7 @@ const ProcessItems = async (language, currentUrl, tryGet) => {
|
|||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(item.url, async () => {
|
||||
cache.tryGet(item.url, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.url,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
|
||||
import { baseUrl, getBoards } from './utils';
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ export const route: Route = {
|
|||
};
|
||||
|
||||
async function handler() {
|
||||
const items = await getBoards(cache.tryGet);
|
||||
const items = await getBoards();
|
||||
|
||||
return {
|
||||
title: '看板列表',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export const route: Route = {
|
|||
async function handler(ctx) {
|
||||
let { board = 'all' } = ctx.req.param();
|
||||
|
||||
const boards = await getBoards(cache.tryGet);
|
||||
const boards = await getBoards();
|
||||
let boardInfo;
|
||||
if (board !== 'all') {
|
||||
boardInfo = boards.find((b) => b.id === board || b.alias === board);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { renderMedia } from './templates/desc';
|
||||
|
||||
const baseUrl = 'https://meteor.today';
|
||||
|
||||
const getBoards = (tryGet) =>
|
||||
tryGet('meteor:boards', async () => {
|
||||
const getBoards = () =>
|
||||
cache.tryGet('meteor:boards', async () => {
|
||||
const { data: response } = await got.post(`${baseUrl}/board/get_boards`, {
|
||||
json: {
|
||||
isCollege: 'false',
|
||||
|
|
|
|||
|
|
@ -61,14 +61,14 @@ async function handler(ctx) {
|
|||
// add that item alone to the "to be processed" array.
|
||||
|
||||
let items = isCategory
|
||||
? await getItems(cache.tryGet, currentUrl, id, 'div.rowMod', 'ul.slides li a')
|
||||
? await getItems(currentUrl, id, 'div.rowMod', 'ul.slides li a')
|
||||
: [
|
||||
{
|
||||
link: currentUrl,
|
||||
},
|
||||
];
|
||||
|
||||
items = await Promise.all(items.slice(0, limit).map((item) => getItemInfo(cache.tryGet, item.link)));
|
||||
items = await Promise.all(items.slice(0, limit).map((item) => getItemInfo(item.link)));
|
||||
|
||||
// If the link of the entry is "#",
|
||||
// it indicates that there are currently no relevant resources available for that specific item.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -9,15 +10,14 @@ const rootUrl = 'https://nzmz.xyz';
|
|||
|
||||
/**
|
||||
* Retrieve all movies and TV shows under a specified category on the homepage and obtain their detail links.
|
||||
* @param {function} tryGet - cache.tryGet
|
||||
* @param {string} homeUrl - Homepage URL
|
||||
* @param {string} id - Category id
|
||||
* @param {string} modSelector - Selector for mods
|
||||
* @param {string} itemSelector - Selector for items
|
||||
* @returns {Array} An array containing the links in the map.
|
||||
*/
|
||||
const getItems = async (tryGet, homeUrl, id, modSelector, itemSelector) => {
|
||||
const response = await tryGet(homeUrl, async () => {
|
||||
const getItems = async (homeUrl, id, modSelector, itemSelector) => {
|
||||
const response = await cache.tryGet(homeUrl, async () => {
|
||||
const { data: response } = await got(homeUrl);
|
||||
|
||||
return response;
|
||||
|
|
@ -40,12 +40,11 @@ const getItems = async (tryGet, homeUrl, id, modSelector, itemSelector) => {
|
|||
|
||||
/**
|
||||
* Obtain the information corresponding to a given movie or TV show item based on the provided URL.
|
||||
* @param {function} tryGet - cache.tryGet
|
||||
* @param {string} itemUrl - Item URL
|
||||
* @returns {Object} An object containing information of the item.
|
||||
*/
|
||||
const getItemInfo = (tryGet, itemUrl) =>
|
||||
tryGet(`newzmz#${itemUrl.match(/details-(.*?)\.html/)[1]}`, async () => {
|
||||
const getItemInfo = (itemUrl) =>
|
||||
cache.tryGet(`newzmz#${itemUrl.match(/details-(.*?)\.html/)[1]}`, async () => {
|
||||
const { data: detailResponse } = await got(itemUrl);
|
||||
|
||||
const content = load(detailResponse);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -35,7 +34,7 @@ async function handler(ctx) {
|
|||
|
||||
const channel = list[1] ? list[1].channel : '';
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item)));
|
||||
|
||||
return {
|
||||
title: `南方都市报客户端 - ${channel}`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { renderDescription } from '../templates/description';
|
||||
|
|
@ -41,7 +40,7 @@ async function handler(ctx) {
|
|||
|
||||
const author = response.data.info ? response.data.info.name : '';
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item)));
|
||||
|
||||
return {
|
||||
title: `南方都市报奥一网 - ${author}`,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const parseArticle = (item, tryGet) =>
|
||||
tryGet(item.link, async () => {
|
||||
const parseArticle = (item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
|
@ -48,7 +47,7 @@ async function handler(ctx) {
|
|||
|
||||
const channelEname = list[1] ? list[1].channelEname : '';
|
||||
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item, cache.tryGet)));
|
||||
const items = await Promise.all(list.map((item) => parseArticle(item)));
|
||||
|
||||
return {
|
||||
title: '南方都市报奥一网',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiBase, baseUrl, getUserInfo, renderCast } from './utils';
|
||||
|
|
@ -30,7 +29,7 @@ export const route: Route = {
|
|||
async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
|
||||
const userInfo = await getUserInfo(id, cache.tryGet);
|
||||
const userInfo = await getUserInfo(id);
|
||||
const { data: castData } = await got(`${apiBase}/users/${id}/casts/`);
|
||||
|
||||
const casts = castData.results.map((item) => renderCast(item));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiBase, baseUrl, getUserInfo, renderLive } from './utils';
|
||||
|
|
@ -30,7 +29,7 @@ export const route: Route = {
|
|||
async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
|
||||
const userInfo = await getUserInfo(id, cache.tryGet);
|
||||
const userInfo = await getUserInfo(id);
|
||||
const { data: liveData } = await got(`${apiBase}/users/${id}/livestreams/`);
|
||||
|
||||
const casts = liveData.results.map((item) => renderLive(item));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import { apiBase, baseUrl, getUserInfo, renderPost } from './utils';
|
||||
|
|
@ -30,7 +29,7 @@ export const route: Route = {
|
|||
async function handler(ctx) {
|
||||
const id = ctx.req.param('id');
|
||||
|
||||
const userInfo = await getUserInfo(id, cache.tryGet);
|
||||
const userInfo = await getUserInfo(id);
|
||||
const { data: postData } = await got(`${apiBase}/users/${id}/posts/`);
|
||||
|
||||
const posts = postData.results.map((item) => renderPost(item));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { raw } from 'hono/html';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
|
|
@ -8,8 +9,8 @@ const domain = 'otobanana.com';
|
|||
const apiBase = `https://api.${domain}`;
|
||||
const baseUrl = `https://${domain}`;
|
||||
|
||||
const getUserInfo = (id, tryGet) =>
|
||||
tryGet(`otobanana:user:${id}`, async () => {
|
||||
const getUserInfo = (id) =>
|
||||
cache.tryGet(`otobanana:user:${id}`, async () => {
|
||||
const { data } = await got(`${apiBase}/users/${id}/`);
|
||||
return data;
|
||||
});
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue