rsshub
Version:
Make RSS Great Again!
112 lines (109 loc) • 4.02 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
//#region lib/routes/buaa/lib/space/newbook.ts
init_esm_shims();
const route = {
path: String.raw`/lib/space/:path{newbook.*}`,
name: "图书馆 - 新书速递",
url: "space.lib.buaa.edu.cn/mspace/newBook",
maintainers: ["OverflowCat"],
example: "/buaa/lib/space/newbook/",
handler,
description: `可通过参数进行筛选:\`/buaa/lib/space/newbook/key1=value1&key2=value2...\`
- \`dcpCode\`:学科分类代码
- 例:
- 工学:\`08\`
- 工学 > 计算机 > 计算机科学与技术:\`080901\`
- 默认值:\`nolimit\`
- 注意事项:不可与 \`clsNo\` 同时使用。
- \`clsNo\`:中图分类号
- 例:
- 计算机科学:\`TP3\`
- 默认值:无
- 注意事项
- 不可与 \`dcpCode\` 同时使用。
- 此模式下获取不到上架日期。
- \`libCode\`:图书馆代码
- 例:
- 本馆:\`00000\`
- 默认值:无
- 注意事项:只有本馆一个可选值。
- \`locaCode\`:馆藏地代码
- 例:
- 五层西-中文新书借阅室(A-Z类):\`02503\`
- 默认值:无
- 注意事项:必须与 \`libCode\` 同时使用。
示例:
- \`buaa/lib/space/newbook\` 为所有新书
- \`buaa/lib/space/newbook/clsNo=U&libCode=00000&locaCode=60001\` 为沙河教2图书馆所有中图分类号为 U(交通运输)的书籍
`,
categories: ["university"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
}
};
async function handler(ctx) {
const path$1 = ctx.req.param("path");
const i = path$1.indexOf("/");
const params = i === -1 ? "" : path$1.slice(i + 1);
const searchParams = new URLSearchParams(params);
const dcpCode = searchParams.get("dcpCode");
const clsNo = searchParams.get("clsNo");
if (dcpCode && clsNo) throw new Error("dcpCode and clsNo cannot be used at the same time");
searchParams.set("pageSize", "100");
searchParams.set("page", "1");
!dcpCode && !clsNo && searchParams.set("dcpCode", "nolimit");
const { data } = await got_default(`https://space.lib.buaa.edu.cn/meta-local/opac/new/100/${clsNo ? "byclass" : "bysubject"}?${searchParams.toString()}`);
const list = data?.data?.dataList || [];
return {
title: "北航图书馆 - 新书速递",
item: await Promise.all(list.map(async (item) => await getItem(item))),
description: "北京航空航天大学图书馆新书速递",
language: "zh-CN",
link: "https://space.lib.buaa.edu.cn/space/newBook",
author: "北京航空航天大学图书馆",
allowEmpty: true,
image: "https://lib.buaa.edu.cn/apple-touch-icon.png"
};
}
async function getItem(item) {
return await cache_default.tryGet(item.isbn, async () => {
const info = await getItemInfo(item.isbn);
const holdings = JSON.parse(item.holdings);
const link = `https://space.lib.buaa.edu.cn/space/searchDetailLocal/${item.bibId}`;
const content = art(path.join(__dirname, "templates/newbook-d3aea22a.art"), {
item,
info,
holdings
});
return {
language: item.language === "eng" ? "en" : "zh-CN",
title: item.title,
pubDate: item.onSelfDate ? timezone(parseDate(item.onSelfDate), 8) : void 0,
description: content,
link
};
});
}
async function getItemInfo(isbn) {
const response = await got_default(`https://space.lib.buaa.edu.cn/meta-local/opac/third_api/douban/${isbn}/info`);
return JSON.parse(response.body).data;
}
//#endregion
export { route };