修复linux.do接口

This commit is contained in:
xuan
2025-12-20 05:33:57 +08:00
parent 7dc310de43
commit 61f89ed13d

View File

@@ -1,16 +1,7 @@
import type { RouterData } from "../types.js"; import type { RouterData } from "../types.js";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
import { parseRSS } from "../utils/parseRSS.js";
interface Topic {
id: number;
title: string;
excerpt: string;
last_poster_username: string;
created_at: string;
views: number;
like_count: number;
}
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache); const listData = await getList(noCache);
@@ -19,7 +10,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
title: "Linux.do", title: "Linux.do",
type: "热门文章", type: "热门文章",
description: "Linux 技术社区热搜", description: "Linux 技术社区热搜",
link: "https://linux.do/hot", link: "https://linux.do/top/weekly",
total: listData.data?.length || 0, total: listData.data?.length || 0,
...listData, ...listData,
}; };
@@ -27,31 +18,34 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
}; };
const getList = async (noCache: boolean) => { const getList = async (noCache: boolean) => {
const url = "https://linux.do/top/weekly.json"; const url = "https://linux.do/top.rss?period=weekly";
const result = await get({ const result = await get({
url, url,
noCache, noCache,
headers: { headers: {
"Accept": "application/json", "Accept": "application/rss+xml, application/xml;q=0.9, */*;q=0.8",
} "User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
},
}); });
const topics = result.data.topic_list.topics as Topic[]; const items = await parseRSS(result.data);
const list = topics.map((topic) => { const list = items.map((item, index) => {
const link = item.link || "";
return { return {
id: topic.id, id: item.guid || link || index,
title: topic.title, title: item.title || "",
desc: topic.excerpt, desc: item.contentSnippet?.trim() || item.content?.trim() || "",
author: topic.last_poster_username, author: item.author,
timestamp: getTime(topic.created_at), timestamp: getTime(item.pubDate || 0),
url: `https://linux.do/t/${topic.id}`, url: link,
mobileUrl: `https://linux.do/t/${topic.id}`, mobileUrl: link,
hot: topic.views || topic.like_count hot: undefined,
}; };
}); });
return { return {
...result, ...result,
data: list data: list,
}; };
}; };