rsshub
Version:
Make RSS Great Again!
55 lines (54 loc) • 1.82 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
//#region lib/routes/youdao/xueba.ts
const route = {
path: "/xueba",
categories: ["study"],
example: "/youdao/xueba",
name: "学霸感悟",
maintainers: ["nczitzk"],
handler
};
async function handler() {
const rootUrl = "https://xueba.youdao.com";
const response = await rofetch(`${rootUrl}/yws/mapi/xueba/library?method=search`, {
method: "POST",
headers: { Referer: `${rootUrl}/web/index.html` },
parseResponse: JSON.parse,
body: new URLSearchParams({
keyword: "",
begin: "0",
count: "9",
primary_category: "4"
})
});
const authors = {};
for (const author of response.xuebas) authors[author.uid] = author.name;
const list = response.notes.map((item) => ({
type: item.type,
title: item.title,
author: item.userId,
description: item.description,
pubDate: parseDate(item.upt),
link: `http://note.youdao.com/publicshare/?type=${item.type}&id=${item.id}`
}));
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
try {
const id = item.link.split("&id=", 2)[1];
const contentResponse = await rofetch(`http://note.youdao.com/yws/public/${item.type}/${id}`, { parseResponse: JSON.parse });
if (item.type === "note") item.description = contentResponse.content;
else item.description = contentResponse[2].map((note) => `<h3><a href="http://note.youdao.com/publicshare?id=${id}#${note.p}">${note.tl}</a></h3>`).join("");
} catch {} finally {
item.author = authors[item.author];
}
return item;
})));
return {
title: "学霸感悟 - 有道云笔记",
link: `${rootUrl}/web/index.html#4`,
item: items
};
}
//#endregion
export { route };