rsshub
Version:
Make RSS Great Again!
104 lines (102 loc) • 3.76 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import path from "node:path";
import crypto from "node:crypto";
//#region lib/routes/linkresearcher/index.ts
init_esm_shims();
const templatePath = path.join(__dirname, "templates/bilingual-537f83c2.art");
const baseURL = "https://www.linkresearcher.com";
const apiURL = `${baseURL}/api`;
const route = {
name: "Articles",
path: "/:params",
example: "/linkresearcher/category=theses&columns=Nature%20导读&subject=生物",
maintainers: ["y9c", "KarasuShin"],
handler,
view: ViewType.Articles,
categories: ["journal"],
parameters: { params: { description: "search parameters, support `category`, `subject`, `columns`, `query`" } },
zh: { name: "文章" },
"zh-TW": { name: "文章" }
};
async function handler(ctx) {
const categoryMap = {
theses: "论文",
information: "新闻",
careers: "职业"
};
const params = ctx.req.param("params");
const filters = new URLSearchParams(params);
const subject = filters.get("subject");
const columns = filters.get("columns");
const query = filters.get("query") ?? "";
const category = filters.get("category") ?? "theses";
if (!(category in categoryMap)) throw new invalid_parameter_default("Invalid category");
let title = categoryMap[category];
const token = crypto.randomUUID();
const data = { filters: { status: true } };
if (subject) {
data.filters.subject = subject;
title = `${title}「${subject}」`;
}
if (columns) {
data.filters.columns = columns;
title = `${title}「${columns}」`;
}
const pageResponse = await ofetch_default(`${baseURL}/api/${category === "careers" ? "articles" : category}/search`, {
method: "POST",
headers: {
"content-type": "application/json; charset=UTF-8",
"x-xsrf-token": token,
cookie: `XSRF-TOKEN=${token}`
},
params: {
from: 0,
size: 20,
type: category === "careers" ? "CAREER" : "SEARCH"
},
body: {
...data,
query
}
});
const items = await Promise.all(pageResponse.hits.map((item) => {
const link = `${baseURL}/${category}/${item.id}`;
return cache_default.tryGet(link, async () => {
const response = await ofetch_default(`${apiURL}/${category === "theses" ? "theses" : "information"}/${item.id}`, { responseType: "json" });
const dataItem = {
title: response.title,
pubDate: parseDate(response.onlineTime),
link,
image: response.cover,
description: "zhTextList" in response && "enTextList" in response ? art(templatePath, {
zh: response.zhTextList,
en: response.enTextList
}) : response.content
};
if ("paperList" in response) {
const { doi, authors } = response.paperList[0];
dataItem.doi = doi;
dataItem.author = authors.map((author) => ({ name: author }));
}
return dataItem;
});
}));
return {
title: `领研 | ${title}`,
description: "领研是链接华人学者的人才及成果平台。领研为国内外高校、科研机构及科技企业提供科研人才招聘服务,也是青年研究者的职业发展指导及线上培训平台;研究者还可将自己的研究论文上传至领研,与超过五十万华人学者分享工作的最新进展。",
image: `${baseURL}/assets/images/logo-app.png`,
link: baseURL,
item: items
};
}
//#endregion
export { route };