From 8b97dce251982e865a188ba88caf9f357b6df2c5 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 11 Oct 2022 03:37:58 +1100 Subject: [PATCH] fix(route): link research (#11051) --- docs/en/study.md | 8 +++--- docs/study.md | 4 ++- lib/router.js | 2 +- lib/{routes => v2}/linkresearcher/index.js | 29 ++++++++++++---------- lib/v2/linkresearcher/maintainer.js | 3 +++ lib/v2/linkresearcher/radar.js | 19 ++++++++++++++ lib/v2/linkresearcher/router.js | 3 +++ 7 files changed, 49 insertions(+), 19 deletions(-) rename lib/{routes => v2}/linkresearcher/index.js (74%) create mode 100644 lib/v2/linkresearcher/maintainer.js create mode 100644 lib/v2/linkresearcher/radar.js create mode 100644 lib/v2/linkresearcher/router.js diff --git a/docs/en/study.md b/docs/en/study.md index 3c63f16b7..32064d36d 100644 --- a/docs/en/study.md +++ b/docs/en/study.md @@ -35,15 +35,15 @@ pageClass: routes -## LinkResearch +## Link Research -### theses +### Theses - + | `:param` | example | definition | | -------- | --------------- | -------------------------------------- | -| category | category=thesis | **one of**,theses/information/careers | +| category | category=thesis | **one of** theses/information/careers | | subject | subject=生物 | string / undefined | | columns | columns=健康 | string / undefined | | columns | columns=virus | string / undefined | diff --git a/docs/study.md b/docs/study.md index a100c6c66..9800ad553 100644 --- a/docs/study.md +++ b/docs/study.md @@ -317,7 +317,7 @@ path="/ctfhub/upcoming/:limit?" ### 论文 - + | `:param` | 举例 | 定义 | | -------- | --------------- | --------------------------------- | @@ -326,6 +326,8 @@ path="/ctfhub/upcoming/:limit?" | columns | columns = 健康 | 可置空 | | query | query = 病毒 | 可置空 | + + ## 码农周刊 ### issues diff --git a/lib/router.js b/lib/router.js index b324b0e67..321ef60a7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2160,7 +2160,7 @@ router.get('/kaggle/user/:user', lazyloadRouteHandler('./routes/kaggle/user')); // router.get('/pubmed/trending', lazyloadRouteHandler('./routes/pubmed/trending')); // 领科 (linkresearcher.com) -router.get('/linkresearcher/:params', lazyloadRouteHandler('./routes/linkresearcher/index')); +// router.get('/linkresearcher/:params', lazyloadRouteHandler('./routes/linkresearcher/index')); // eLife [Sci Journal] router.get('/elife/:tid', lazyloadRouteHandler('./routes/elife/index')); diff --git a/lib/routes/linkresearcher/index.js b/lib/v2/linkresearcher/index.js similarity index 74% rename from lib/routes/linkresearcher/index.js rename to lib/v2/linkresearcher/index.js index dc5177c0f..40dc5382f 100644 --- a/lib/routes/linkresearcher/index.js +++ b/lib/v2/linkresearcher/index.js @@ -1,6 +1,6 @@ const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const qs = require('querystring'); +const qs = require('query-string'); +const { parseDate } = require('@/utils/parse-date'); const baseURL = 'https://www.linkresearcher.com'; @@ -15,9 +15,8 @@ module.exports = async (ctx) => { // get XSRF token from main page const metaURL = `${baseURL}/${category}`; - const metaResponse = await got.get(metaURL); - const metaCapture = cheerio.load(metaResponse.data); - const xsrf_token = metaCapture('meta[name="_csrf"]').prop('content'); + const metaResponse = await got(metaURL); + const xsrfToken = metaResponse.headers['set-cookie'][0].split(';')[0].split('=')[1]; let data = { filters: { status: false } }; if (typeof query.subject !== 'undefined' && typeof query.columns !== 'undefined') { @@ -31,16 +30,19 @@ module.exports = async (ctx) => { title = `${title}「${query.columns}」`; } data.query = query.query; - const dataURL = `${baseURL}/api/${category}/search?from=0&size=20&type=SEARCH`; - const pageResponse = await got({ - method: 'post', - url: dataURL, + const dataURL = `${baseURL}/api/${category === 'careers' ? 'articles' : category}/search`; + const pageResponse = await got.post(dataURL, { headers: { 'content-type': 'application/json; charset=UTF-8', - 'x-xsrf-token': xsrf_token, - cookie: `XSRF-TOKEN=${xsrf_token}`, + 'x-xsrf-token': xsrfToken, + cookie: `XSRF-TOKEN=${xsrfToken}`, }, - data: JSON.stringify(data), + searchParams: { + from: 0, + size: 20, + type: category === 'careers' ? 'CAREER' : 'SEARCH', + }, + json: data, }); const list = pageResponse.data.hits; @@ -48,7 +50,7 @@ module.exports = async (ctx) => { const out = list.map((item) => ({ title: item.title, description: item.content, - pubDate: new Date(item.createdAt).toUTCString(), + pubDate: parseDate(item.createdAt, 'x'), link: `${metaURL}/${item.id}`, guid: `${metaURL}/${item.id}`, doi: typeof item.identCode !== 'undefined' ? item.identCode : '', @@ -59,6 +61,7 @@ module.exports = async (ctx) => { title: `领研 | ${title}`, description: '领研是链接华人学者的人才及成果平台。领研为国内外高校、科研机构及科技企业提供科研人才招聘服务,也是青年研究者的职业发展指导及线上培训平台;研究者还可将自己的研究论文上传至领研,与超过五十万华人学者分享工作的最新进展。', + image: 'https://www.linkresearcher.com/assets/images/logo-app.png', link: baseURL, item: out, }; diff --git a/lib/v2/linkresearcher/maintainer.js b/lib/v2/linkresearcher/maintainer.js new file mode 100644 index 000000000..052189d56 --- /dev/null +++ b/lib/v2/linkresearcher/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:params': ['yech1990'], +}; diff --git a/lib/v2/linkresearcher/radar.js b/lib/v2/linkresearcher/radar.js new file mode 100644 index 000000000..9af9774e8 --- /dev/null +++ b/lib/v2/linkresearcher/radar.js @@ -0,0 +1,19 @@ +module.exports = { + linkresearcher: { + _name: '领研', + '.': [ + { + title: '论文', + docs: 'https://docs.rsshub.app/study.html#ling-yan', + source: ['/theses', '/information', '/careers'], + target: (_, url) => { + const pathname = new URL(url).pathname; + const searchParams = new URL(url).searchParams; + return `/linkresearcher/theses/${pathname.replace('/', '')}${searchParams.has('filters.subject') ? `&subject=${searchParams.get('filters.subject')}` : ''}${ + searchParams.has('filters.columns') ? `&columns=${searchParams.get('filters.columns')}` : '' + }`; + }, + }, + ], + }, +}; diff --git a/lib/v2/linkresearcher/router.js b/lib/v2/linkresearcher/router.js new file mode 100644 index 000000000..93c9f82db --- /dev/null +++ b/lib/v2/linkresearcher/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:params', require('./index')); +};