🐞 fix: 部分类型错误

- 新增 米游社 综合接口
This commit is contained in:
imsyy
2024-12-03 18:09:32 +08:00
parent afb7c7d515
commit 098b80865b
37 changed files with 1656 additions and 748 deletions

View File

@@ -1,24 +1,26 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { post } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
const typeMap: Record<string, string> = {
hot: "人气榜",
video: "视频榜",
comment: "热议榜",
collect: "收藏榜",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "36kr",
title: "36氪",
type: "热榜",
type: typeMap[type],
params: {
type: {
name: "热榜分类",
type: {
hot: "人气榜",
video: "视频榜",
comment: "热议榜",
collect: "收藏榜",
},
type: typeMap,
},
},
link: "https://m.36kr.com/hot-list-m",
@@ -30,7 +32,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { type } = options;
const url = `https://gateway.36kr.com/api/mis/nav/home/nav/rank/${type}`;
const result = await post({
@@ -67,7 +69,7 @@ const getList = async (options: Options, noCache: boolean) => {
cover: item.widgetImage,
author: item.authorName,
timestamp: getTime(v.publishTime),
hot: item.statCollect,
hot: item.statCollect || undefined,
url: `https://www.36kr.com/p/${v.itemId}`,
mobileUrl: `https://m.36kr.com/p/${v.itemId}`,
};

View File

@@ -1,4 +1,4 @@
import type { RouterData } from "../types.js";
import type { RouterData, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { getToken, sign } from "../utils/getToken/51cto.js";
import { get } from "../utils/getData.js";
@@ -19,7 +19,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
return routeData;
};
const getList = async (noCache: boolean) => {
const getList = async (noCache: boolean): Promise<RouterResType> => {
const url = `https://api-media.51cto.com/index/index/recommend`;
const params = {
page: 1,
@@ -49,6 +49,7 @@ const getList = async (noCache: boolean) => {
cover: v.cover,
desc: v.abstract,
timestamp: getTime(v.pubdate),
hot: undefined,
url: v.url,
mobileUrl: v.url,
})),

View File

@@ -1,5 +1,4 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import { web } from "../utils/getData.js";
import { extractRss, parseRSS } from "../utils/parseRSS.js";
import { getTime } from "../utils/getTime.js";
@@ -31,7 +30,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { type } = options;
const url = `https://www.52pojie.cn/forum.php?mod=guide&view=${type}&rss=1`;
const result = await web({
@@ -41,26 +40,24 @@ const getList = async (options: Options, noCache: boolean) => {
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
});
const parseData = async () => {
if (typeof result?.data === "string") {
const rssContent = extractRss(result.data);
return await parseRSS(rssContent);
} else {
return [];
}
if (typeof result?.data !== "string") return [];
const rssContent = extractRss(result.data);
if (!rssContent) return [];
return await parseRSS(rssContent);
};
const list = await parseData();
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["discuz"]) => ({
id: v.guid,
title: v.title,
desc: v.content,
author: v.author,
timestamp: getTime(v.pubDate),
hot: null,
url: v.link,
mobileUrl: v.link,
data: list.map((v, i) => ({
id: v.guid || i,
title: v.title || "",
desc: v.content || "",
author: v.author || "",
timestamp: getTime(v.pubDate || 0),
hot: 0,
url: v.link || "",
mobileUrl: v.link || "",
})),
};
};

View File

@@ -1,8 +1,29 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
const typeMap: Record<string, string> = {
"-1": "综合",
"155": "番剧",
"1": "动画",
"60": "娱乐",
"201": "生活",
"58": "音乐",
"123": "舞蹈·偶像",
"59": "游戏",
"70": "科技",
"68": "影视",
"69": "体育",
"125": "鱼塘",
};
const rangeMap: Record<string, string> = {
DAY: "今日",
THREE_DAYS: "三日",
WEEK: "本周",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "-1";
const range = c.req.query("range") || "DAY";
@@ -10,33 +31,16 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
const routeData: RouterData = {
name: "acfun",
title: "AcFun",
type: "排行榜",
type: `排行榜 · ${typeMap[type]}`,
description: "AcFun是一家弹幕视频网站致力于为每一个人带来欢乐。",
params: {
type: {
name: "频道",
type: {
"-1": "全站综合",
"155": "番剧",
"1": "动画",
"60": "娱乐",
"201": "生活",
"58": "音乐",
"123": "舞蹈·偶像",
"59": "游戏",
"70": "科技",
"68": "影视",
"69": "体育",
"125": "鱼塘",
},
type: typeMap,
},
range: {
name: "时间",
type: {
DAY: "今日",
THREE_DAYS: "三日",
WEEK: "本周",
},
type: rangeMap,
},
},
link: "https://www.acfun.cn/rank/list/",
@@ -48,7 +52,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { type, range } = options;
const url = `https://www.acfun.cn/rest/pc-direct/rank/channel?channelId=${type === "-1" ? "" : type}&rankLimit=30&rankPeriod=${range}`;
const result = await get({

View File

@@ -1,25 +1,27 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
const typeMap: Record<string, string> = {
realtime: "热搜",
novel: "小说",
movie: "电影",
teleplay: "电视剧",
car: "汽车",
game: "游戏",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "realtime";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "baidu",
title: "百度",
type: "热搜榜",
type: typeMap[type],
params: {
type: {
name: "热搜类别",
type: {
realtime: "热搜",
novel: "小说",
movie: "电影",
teleplay: "电视剧",
car: "汽车",
game: "游戏",
},
type: typeMap,
},
},
link: "https://top.baidu.com/board",
@@ -31,7 +33,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { type } = options;
const url = `https://top.baidu.com/board?tab=${type}`;
const result = await get({
@@ -55,8 +57,8 @@ const getList = async (options: Options, noCache: boolean) => {
desc: v.desc,
cover: v.img,
author: v.show?.length ? v.show : "",
timestamp: null,
hot: Number(v.hotScore),
timestamp: 0,
hot: Number(v.hotScore || 0),
url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`,
mobileUrl: v.rawUrl,
})),

View File

@@ -1,35 +1,37 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import getBiliWbi from "../utils/getToken/bilibili.js";
import { getTime } from "../utils/getTime.js";
const typeMap: Record<string, string> = {
"0": "全站",
"1": "动画",
"3": "音乐",
"4": "游戏",
"5": "娱乐",
"36": "科技",
"119": "鬼畜",
"129": "舞蹈",
"155": "时尚",
"160": "生活",
"168": "国创相关",
"188": "数码",
"181": "影视",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "0";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "bilibili",
title: "哔哩哔哩",
type: "热门榜",
type: `热榜 · ${typeMap[type]}`,
description: "你所热爱的,就是你的生活",
params: {
type: {
name: "排行榜分区",
type: {
0: "全站",
1: "动画",
3: "音乐",
4: "游戏",
5: "娱乐",
36: "科技",
119: "鬼畜",
129: "舞蹈",
155: "时尚",
160: "生活",
168: "国创相关",
188: "数码",
181: "影视",
},
type: typeMap,
},
},
link: "https://www.bilibili.com/v/popular/rank/all",
@@ -41,7 +43,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { type } = options;
const wbiData = await getBiliWbi();
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?tid=${type}&type=all&${wbiData}`;
@@ -64,10 +66,10 @@ const getList = async (options: Options, noCache: boolean) => {
id: v.bvid,
title: v.title,
desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"),
author: v.owner.name,
cover: v.pic?.replace(/http:/, "https:"),
author: v.owner?.name,
timestamp: getTime(v.pubdate),
hot: v.stat.view,
hot: v.stat?.view || 0,
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
})),
@@ -93,7 +95,7 @@ const getList = async (options: Options, noCache: boolean) => {
id: v.bvid,
title: v.title,
desc: v.desc || "该视频暂无简介",
cover: v.pic.replace(/http:/, "https:"),
cover: v.pic?.replace(/http:/, "https:"),
author: v.author,
timestamp: null,
hot: v.video_review,

View File

@@ -35,8 +35,8 @@ const getList = async (noCache: boolean) => {
cover: v.tpic,
author: v.username,
desc: v.ttitle,
timestamp: null,
hot: null,
timestamp: undefined,
hot: undefined,
url: v.shareUrl,
mobileUrl: v.shareUrl,
})),

View File

@@ -1,4 +1,4 @@
import type { RouterData } from "../types.js";
import type { RouterData, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
@@ -19,7 +19,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
return routeData;
};
const getList = async (noCache: boolean) => {
const getList = async (noCache: boolean): Promise<RouterResType> => {
const url = "https://blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=30";
const result = await get({ url, noCache });
const list = result.data.data;

View File

@@ -1,6 +1,7 @@
import type { RouterData } from "../types.js";
import { load } from "cheerio";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
@@ -42,9 +43,9 @@ const getList = async (noCache: boolean) => {
title: dom.find("h3 a").text().trim(),
cover: dom.find(".pic-wrap img").attr("src"),
desc: dom.find(".block p").text().trim(),
timestamp: dom.find("span.pubtime").text().trim(),
hot: null,
url,
timestamp: getTime(dom.find("span.pubtime").text().trim()),
hot: 0,
url: url || `https://www.douban.com/group/topic/${getNumbers(url)}`,
mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`,
};
});

View File

@@ -7,7 +7,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
const routeData: RouterData = {
name: "douban-movie",
title: "豆瓣电影",
type: "新片排行榜",
type: "新片榜",
link: "https://movie.douban.com/chart",
total: data?.length || 0,
updateTime,
@@ -51,9 +51,9 @@ const getList = async (noCache: boolean) => {
title: `${score}${dom.find("a").attr("title")}`,
cover: dom.find("img").attr("src"),
desc: dom.find("p.pl").text(),
timestamp: null,
timestamp: undefined,
hot: getNumbers(dom.find("span.pl").text()),
url,
url: url || `https://movie.douban.com/subject/${getNumbers(url)}/`,
mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`,
};
});

View File

@@ -1,9 +1,9 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
const mappings = {
const mappings: Record<string, string> = {
O_TIME: "发震时刻(UTC+8)",
LOCATION_C: "参考位置",
M: "震级(M)",
@@ -13,34 +13,12 @@ const mappings = {
SAVE_TIME: "录入时间",
};
const typeMappings = {
1: "最近24小时地震信息",
2: "最近48小时地震信息",
3: "最近7天地震信息",
4: "最近30天地震信息",
5: "最近一年3.0级以上地震信息",
6: "最近一年地震信息",
7: "最近一年3.0级以下地震",
8: "最近一年4.0级以上地震信息",
9: "最近一年5.0级以上地震信息",
0: "最近一年6.0级以上地震信息",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "5";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
const routeData: RouterData = {
name: "earthquake",
title: "中国地震台",
type: "地震速报",
params: {
type: {
name: "速报分类",
type: {
...typeMappings,
},
},
},
link: "https://news.ceic.ac.cn/",
total: data?.length || 0,
updateTime,
@@ -50,12 +28,12 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
const url = `http://www.ceic.ac.cn/ajax/speedsearch?num=${type}`;
const getList = async (noCache: boolean) => {
const url = `https://news.ceic.ac.cn/speedsearch.html`;
const result = await get({ url, noCache });
const data = result.data.replace(/,"page":"(.*?)","num":/, ',"num":');
const list = JSON.parse(data.substring(1, data.length - 1)).shuju;
const regex = /const newdata = (\[.*?\]);/s;
const match = result.data.match(regex);
const list = match && match[1] ? JSON.parse(match[1]) : [];
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
@@ -63,14 +41,16 @@ const getList = async (options: Options, noCache: boolean) => {
const contentBuilder = [];
const { NEW_DID, LOCATION_C, M } = v;
for (const mappingsKey in mappings) {
contentBuilder.push(`${mappings[mappingsKey]}${v[mappingsKey]}`);
contentBuilder.push(
`${mappings[mappingsKey as keyof typeof mappings]}${v[mappingsKey as keyof typeof v]}`,
);
}
return {
id: NEW_DID,
title: `${LOCATION_C}发生${M}级地震`,
desc: contentBuilder.join("\n"),
timestamp: getTime(v["O_TIME"]),
hot: null,
timestamp: getTime(v["O_TIME" as keyof typeof v]),
hot: undefined,
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
};

View File

@@ -27,8 +27,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
};
const getList = async (options: Options, noCache: boolean) => {
const { month, day } = options;
const monthStr = month.toString().padStart(2, "0");
const dayStr = day.toString().padStart(2, "0");
const monthStr = month?.toString().padStart(2, "0");
const dayStr = day?.toString().padStart(2, "0");
const url = `https://baike.baidu.com/cms/home/eventsOnHistory/${monthStr}.json`;
const result = await get({
url,
@@ -37,7 +37,7 @@ const getList = async (options: Options, noCache: boolean) => {
_: new Date().getTime(),
},
});
const list = result.data[monthStr][monthStr + dayStr];
const list = monthStr ? result.data[monthStr][monthStr + dayStr] : [];
return {
fromCache: result.fromCache,
updateTime: result.updateTime,

View File

@@ -1,25 +1,26 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import { web } from "../utils/getData.js";
import { extractRss, parseRSS } from "../utils/parseRSS.js";
import { getTime } from "../utils/getTime.js";
const typeMap: Record<string, string> = {
hot: "最新热门",
digest: "最新精华",
new: "最新回复",
newthread: "最新发表",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "hostloc",
title: "全球主机交流",
type: "榜单",
type: typeMap[type],
params: {
type: {
name: "榜单分类",
type: {
hot: "最新热门",
digest: "最新精华",
new: "最新回复",
newthread: "最新发表",
},
type: typeMap,
},
},
link: "https://hostloc.com/",
@@ -41,26 +42,24 @@ const getList = async (options: Options, noCache: boolean) => {
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
});
const parseData = async () => {
if (typeof result?.data === "string") {
const rssContent = extractRss(result.data);
return await parseRSS(rssContent);
} else {
return [];
}
if (typeof result?.data !== "string") return [];
const rssContent = extractRss(result.data);
if (!rssContent) return [];
return await parseRSS(rssContent);
};
const list = await parseData();
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["discuz"]) => ({
id: v.guid,
title: v.title,
desc: v.content,
author: v.author,
timestamp: getTime(v.pubDate),
hot: null,
url: v.link,
mobileUrl: v.link,
data: list.map((v, i) => ({
id: v.guid || i,
title: v.title || "",
desc: v.content || "",
author: v.author || "",
timestamp: getTime(v.pubDate || 0),
hot: undefined,
url: v.link || "",
mobileUrl: v.link || "",
})),
};
};

View File

@@ -21,7 +21,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
// 标题处理
const titleProcessing = (text: string) => {
const paragraphs = text.split("<br><br>");
const title = paragraphs.shift().replace(/。$/, "");
const title = paragraphs.shift()?.replace(/。$/, "");
const intro = paragraphs.join("<br><br>");
return { title, intro };
};
@@ -47,8 +47,8 @@ const getList = async (noCache: boolean) => {
author: v.user_info.username,
timestamp: getTime(v.publish_time),
hot: null,
url: v.url || "https://www.huxiu.com/moment/",
mobileUrl: v.url || "https://m.huxiu.com/moment/",
url: v.url || `https://www.huxiu.com/moment/${v.object_id}.html`,
mobileUrl: v.url || `https://m.huxiu.com/moment/${v.object_id}.html`,
})),
};
};

View File

@@ -32,8 +32,8 @@ const getList = async (noCache: boolean) => {
desc: v.post_content,
timestamp: getTime(v.created_at),
hot: v.like_count || v.comment_count,
url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url,
mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url,
url: v.buzz_original_url || `https://www.ifanr.com/${v.id}`,
mobileUrl: v.buzz_original_url || `https://www.ifanr.com/digest/${v.id}`,
})),
};
};

View File

@@ -44,10 +44,10 @@ const getList = async (noCache: boolean) => {
title: dom.find(".newsbody h2").text().trim(),
desc: dom.find(".newsbody p").text().trim(),
cover: dom.find("img").attr("data-original"),
timestamp: getTime(dateTime),
timestamp: getTime(dateTime || 0),
hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
url: href || undefined,
mobileUrl: href ? replaceLink(href) : undefined,
url: href || "",
mobileUrl: href ? replaceLink(href) : "",
};
});
return {

View File

@@ -1,6 +1,7 @@
import type { RouterData } from "../types.js";
import { load } from "cheerio";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
@@ -43,10 +44,10 @@ const getList = async (noCache: boolean) => {
id: href ? Number(replaceLink(href, true)) : 100000,
title: dom.find(".plc-title").text().trim(),
cover: dom.find("img").attr("data-original"),
timestamp: dom.find("span.post-time").text().trim(),
timestamp: getTime(dom.find("span.post-time").text().trim()),
hot: Number(dom.find(".review-num").text().replace(/\D/g, "")),
url: href ? replaceLink(href) : undefined,
mobileUrl: href || undefined,
url: href ? replaceLink(href) : "",
mobileUrl: href ? replaceLink(href) : "",
};
});
return {

View File

@@ -45,8 +45,8 @@ const getList = async (noCache: boolean) => {
cover: dom.find("img").attr("src"),
desc: dom.find("p.abstract").text()?.trim(),
author: dom.find("a.nickname").text()?.trim(),
hot: null,
timestamp: null,
hot: undefined,
timestamp: undefined,
url: `https://www.jianshu.com${href}`,
mobileUrl: `https://www.jianshu.com${href}`,
};

View File

@@ -29,7 +29,7 @@ const getList = async (noCache: boolean) => {
title: v.content.title,
author: v.author.name,
hot: v.content_counter.hot_rank,
timestamp: null,
timestamp: undefined,
url: `https://juejin.cn/post/${v.content.content_id}`,
mobileUrl: `https://juejin.cn/post/${v.content.content_id}`,
})),

75
src/routes/miyoushe.ts Normal file
View File

@@ -0,0 +1,75 @@
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
// 游戏分类
const gameMap: Record<string, string> = {
"1": "崩坏3",
"2": "原神",
"3": "崩坏学园2",
"4": "未定事件簿",
"5": "大别野",
"6": "崩坏:星穹铁道",
"7": "暂无",
"8": "绝区零",
};
// 榜单分类
const typeMap: Record<string, string> = {
"1": "公告",
"2": "活动",
"3": "资讯",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => {
const game = c.req.query("game") || "1";
const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ game, type }, noCache);
const routeData: RouterData = {
name: "miyoushe",
title: `米游社 · ${gameMap[game]}`,
type: `最新${typeMap[type]}`,
params: {
game: {
name: "游戏分类",
type: gameMap,
},
type: {
name: "榜单分类",
type: typeMap,
},
},
link: "https://www.miyoushe.com/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
const { game, type } = options;
const url = `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?client_type=4&gids=${game}&last_id=&page_size=30&type=${type}`;
const result = await get({ url, noCache });
const list = result.data.data.list;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["miyoushe"]) => {
const data = v.post;
return {
id: data.post_id,
title: data.subject,
desc: data.content,
cover: data.cover || data?.images?.[0],
author: v.user?.nickname || null,
timestamp: getTime(data.created_at),
hot: data.view_status || 0,
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
};
}),
};
};

View File

@@ -1,6 +1,8 @@
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { parseStringPromise } from "xml2js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
@@ -33,13 +35,13 @@ const getList = async (noCache: boolean) => {
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v) => ({
data: list.map((v: RouterType["nodeseek"]) => ({
id: v.guid[0]._,
title: v.title[0],
desc: v.description ? v.description[0] : "",
author: v["dc:creator"] ? v["dc:creator"][0] : "unknown",
timestamp: new Date(v.pubDate[0]).getTime(),
hot: null, // NodeSeek RSS 中没有类似于hot的字段
timestamp: getTime(v.pubDate[0]),
hot: undefined,
url: v.link[0],
mobileUrl: v.link[0],
})),

View File

@@ -68,7 +68,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
const routeData: RouterData = {
name: "sina-news",
title: "新浪新闻",
type: listType[type].name,
type: listType[type as keyof typeof listType].name,
params: {
type: {
name: "榜单分类",
@@ -106,7 +106,7 @@ const parseData = (data: string) => {
const jsonData = JSON.parse(jsonString);
return jsonData;
} catch (error) {
throw new Error("Failed to parse JSON: " + error.message);
throw new Error("Failed to parse JSON: " + error);
}
} else {
throw new Error("Invalid JSON format");
@@ -116,7 +116,7 @@ const parseData = (data: string) => {
const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
// 必要数据
const { params, www } = listType[type];
const { params, www } = listType[type as keyof typeof listType];
const { year, month, day } = getCurrentDateTime(true);
const url = `https://top.${www}.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=${params}&top_time=${year + month + day}&top_show_num=50`;
const result = await get({ url, noCache });

View File

@@ -27,7 +27,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
const getList = async (options: Options, noCache: boolean) => {
const { province } = options;
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province)}`;
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province || "")}`;
const result = await get({ url, noCache });
const list = result.data.data.page.list;
return {