🦄 refactor: Refactoring using hono

This commit is contained in:
imsyy
2024-04-08 16:35:58 +08:00
parent 7459858767
commit 34ab73a3f1
95 changed files with 3555 additions and 6345 deletions

43
src/routes/weibo.ts Normal file
View File

@@ -0,0 +1,43 @@
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
const routeData: RouterData = {
name: "weibo",
title: "微博",
type: "热搜榜",
description: "实时热点,每分钟更新一次",
link: "https://s.weibo.com/top/summary/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};
const getList = async (noCache: boolean) => {
const url = `https://weibo.com/ajax/side/hotSearch`;
const result = await get({ url, noCache, ttl: 60 });
const list = result.data.data.realtime;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["weibo"]) => {
const key = v.word_scheme ? v.word_scheme : `#${v.word}`;
return {
id: v.mid,
title: v.word,
desc: v.note || key,
author: v.category,
hot: v.raw_hot,
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
key,
)}&t=31&band_rank=1&Refer=top`,
};
}),
};
};