fix(ieee): Restore author.ts (#17688)
* fix(ieee): Restore author.ts * change function * I have addressed and implemented all suggestions and recommendations. * docs * Update lib/routes/ieee/author.ts
This commit is contained in:
@@ -874,9 +874,6 @@ router.get('/guet/xwzx/:type?', lazyloadRouteHandler('./routes/guet/news'));
|
||||
// はてな匿名ダイアリー
|
||||
router.get('/hatena/anonymous_diary/archive', lazyloadRouteHandler('./routes/hatena/anonymous_diary/archive'));
|
||||
|
||||
// IEEE Xplore [Sci Journal]
|
||||
router.get('/ieee/author/:aid/:sortType/:count?', lazyloadRouteHandler('./routes/ieee/author'));
|
||||
|
||||
// PNAS [Sci Journal]
|
||||
// router.get('/pnas/:topic?', lazyloadRouteHandler('./routes/pnas/index'));
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { aid, sortType, count = 10 } = ctx.params;
|
||||
|
||||
const response = await got(`https://ieeexplore.ieee.org/rest/author/${aid}`);
|
||||
const author = response.data[0];
|
||||
|
||||
const { data: papers } = await got.post('https://ieeexplore.ieee.org/rest/search', {
|
||||
json: {
|
||||
rowsPerPage: count,
|
||||
searchWithin: [`"Author Ids": ${aid}`],
|
||||
sortType,
|
||||
},
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${author.preferredName} on IEEE Xplore`,
|
||||
link: `https://ieeexplore.ieee.org/author/${aid}`,
|
||||
description: author.bioParagraphs.join('<br/>'),
|
||||
item: papers.records.map((item) => ({
|
||||
title: item.articleTitle,
|
||||
author: item.authors.map((author) => author.preferredName).join(', '),
|
||||
category: item.articleContentType,
|
||||
description: item.abstract,
|
||||
pubDate: item.publicationDate,
|
||||
link: `https://ieeexplore.ieee.org${item.documentLink}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import path from 'node:path';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { art } from '@/utils/render';
|
||||
import { getCurrentPath } from '@/utils/helpers';
|
||||
const __dirname = getCurrentPath(import.meta.url);
|
||||
|
||||
export const route: Route = {
|
||||
name: 'IEEE Author Articles',
|
||||
maintainers: ['Derekmini'],
|
||||
categories: ['journal'],
|
||||
path: '/author/:aid/:sortType',
|
||||
parameters: {
|
||||
aid: 'Author ID',
|
||||
sortType: 'Sort Type of papers',
|
||||
},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: true,
|
||||
},
|
||||
example: '/ieee/author/37264968900/newest',
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const { aid, sortType } = ctx.req.param();
|
||||
const count = ctx.req.query('limit') || 10;
|
||||
const host = 'https://ieeexplore.ieee.org';
|
||||
|
||||
const res = await ofetch(`${host}/rest/author/${aid}`);
|
||||
const author = res[0];
|
||||
const title = `${author.preferredName} on IEEE Xplore`;
|
||||
const link = `${host}/author/${aid}`;
|
||||
const description = author.bioParagraphs.join(' ');
|
||||
const image = `${host}${author.photoUrl}`;
|
||||
|
||||
const response = await ofetch(`${host}/rest/search`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
rowsPerPage: count,
|
||||
searchWithin: [`"Author Ids": ${aid}`],
|
||||
sortType,
|
||||
},
|
||||
});
|
||||
|
||||
const list = response.records.map((item) => ({
|
||||
title: item.articleTitle,
|
||||
link: item.htmlLink,
|
||||
doi: item.doi,
|
||||
authors: 'authors' in item ? item.authors.map((itemAuth) => itemAuth.preferredName).join('; ') : 'Do not have author',
|
||||
abstract: 'abstract' in item ? item.abstract : '',
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (item.abstract !== '') {
|
||||
const res = await ofetch(`${host}${item.link}`, {
|
||||
parseResponse: (txt) => txt,
|
||||
});
|
||||
const $ = load(res);
|
||||
const metadataMatch = $.html().match(/metadata=(.*);/);
|
||||
const metadata = metadataMatch ? JSON.parse(metadataMatch[1]) : null;
|
||||
item.pubDate = metadata?.insertDate ? parseDate(metadata.insertDate) : undefined;
|
||||
item.abstract = load(metadata?.abstract || '').text();
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
description: renderDescription(item),
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
item: items,
|
||||
image,
|
||||
};
|
||||
}
|
||||
|
||||
function renderDescription(item: { title: string; authors: string; abstract: string; doi: string }) {
|
||||
return art(path.join(__dirname, 'templates/description.art'), {
|
||||
item,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user