Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(route/ieee): fix journal.ts, author.ts and earlyaccess.ts #15120

Closed
wants to merge 15 commits into from
3 changes: 0 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,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'));

Expand Down
30 changes: 0 additions & 30 deletions lib/routes-deprecated/ieee/author.js

This file was deleted.

17 changes: 14 additions & 3 deletions lib/routes/ieee/recent.ts → lib/routes-deprecated/ieee/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ import { CookieJar } from 'tough-cookie';
const cookieJar = new CookieJar();

export const route: Route = {
path: ['/:journal/latest/date/:sortType?', '/journal/:journal/recent/:sortType?'],
name: 'Unknown',
maintainers: [],
path: ['/journal/:journal/recent/:sortType?', '/:journal/latest/date/:sortType?'],
categories: ['journal'],
example: '/ieee/journal/6287639/recent',
parameters: { journal: 'Issue code, the number of the `isnumber` in the URL', sortType: 'Sort Type, default: `vol-only-seq`, the part of the URL after `sortType`' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: true,
},
name: 'Recent Articles',
maintainers: ['Derekmini'],
handler,
};

Expand Down
101 changes: 101 additions & 0 deletions lib/routes/ieee/author.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import path from 'node:path';
import { art } from '@/utils/render';

export const route: Route = {
path: '/author/:aid/:sortType?/:count?',
categories: ['journal'],
example: '/ieee/author/37281702200',
parameters: { aid: 'Author ID', sortType: 'Sort Type of papers', count: 'Number of papers to show' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: true,
},
name: 'Author',
maintainers: ['Derekmini'],
handler,
};

const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
item,
});

async function handler(ctx) {
const { aid, sortType, count = 10 } = ctx.req.param();
const host = 'https://ieeexplore.ieee.org';

const author = await ofetch(`${host}/rest/author/${aid}`).then((res) => res[0]);
const title = `${author.preferredName} on IEEE Xplore`;
const link = `${host}/author/${aid}`;
const description = author.bioParagraphs.join('<br/>');

const response = await ofetch(`${host}/rest/search`, {
method: 'POST',
body: {
rowsPerPage: count,
searchWithin: [`"Author Ids": ${aid}`],
sortType,
},
});
let list = response.records.map((item) => {
const $ = load(item.articleTitle);
const title = $.text();
const link = item.htmlLink;
const doi = item.doi;
let authors = 'Do not have author';
if (Object.hasOwn(item, 'authors')) {
authors = item.authors.map((itemAuth) => itemAuth.preferredName).join('; ');
}
const abstract = Object.hasOwn(item, 'abstract') ? item.abstract : '';
// const pubDate = item.publicationDate;
// const category = item.articleContentType;
// const description = item.abstract;
return {
title,
link,
authors,
doi,
abstract,
// pubDate,
// category,
// description,
};
});

list = 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;
const $2 = load(metadata?.abstract || '');
item.abstract = $2.text();
item.description = renderDesc(item);
}
return item;
})
)
);

return {
title,
link,
description,
item: list,
};
}
86 changes: 51 additions & 35 deletions lib/routes/ieee/earlyaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import path from 'node:path';
import { art } from '@/utils/render';
Expand All @@ -15,7 +15,7 @@ export const route: Route = {
path: '/journal/:journal/earlyaccess/:sortType?',
categories: ['journal'],
example: '/ieee/journal/5306045/earlyaccess',
parameters: { journal: 'Issue code, the number of the `isnumber` in the URL', sortType: 'Sort Type, default: `vol-only-seq`, the part of the URL after `sortType`' },
parameters: { journal: 'Issue code, the number of the `isnumber` in the link', sortType: 'Sort Type, default: `vol-only-seq`, the part of the link after `sortType`' },
features: {
requireConfig: false,
requirePuppeteer: false,
Expand All @@ -25,37 +25,53 @@ export const route: Route = {
supportScihub: false,
},
name: 'Early Access Journal',
maintainers: ['5upernova-heng'],
maintainers: ['5upernova-heng', 'Derekmini'],
handler,
};

const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
item,
});

async function handler(ctx) {
const isnumber = ctx.req.param('journal');
const sortType = ctx.req.param('sortType') ?? 'vol-only-seq';
const host = 'https://ieeexplore.ieee.org';
const jrnlUrl = `${host}/xpl/tocresult.jsp?isnumber=${isnumber}`;
const link = `${host}/xpl/tocresult.jsp?isnumber=${isnumber}`;

const response = await got(`${host}/rest/publication/home/metadata?issueid=${isnumber}`, {
cookieJar,
}).json();
const punumber = response.publicationNumber;
const volume = response.currentIssue.volume;
const jrnlName = response.displayTitle;
const { title, punumber, volume } = await ofetch(`${host}/rest/publication/home/metadata?issueid=${isnumber}`, {
parseResponse: JSON.parse,
headers: {
cookie: cookieJar.getCookieStringSync(host),
},
}).then((res) => {
const title = res.displayTitle;
const punumber = res.publicationNumber;
const volume = res.currentIssue.volume;
return {
title,
punumber,
volume,
};
});

const response2 = await got
.post(`${host}/rest/search/pub/${punumber}/issue/${isnumber}/toc`, {
cookieJar,
json: {
punumber,
isnumber,
sortType,
rowsPerPage: '100',
},
})
.json();
let list = response2.records.map((item) => {
const $2 = load(item.articleTitle);
const title = $2.text();
const response = await ofetch(`${host}/rest/search/pub/${punumber}/issue/${isnumber}/toc`, {
method: 'POST',
parseResponse: JSON.parse,
headers: {
cookie: cookieJar.getCookieStringSync(host),
},
body: {
punumber,
isnumber,
sortType,
rowsPerPage: '100',
},
});
let list = response.records.map((item) => {
const $ = load(item.articleTitle);
const title = $.text();
const link = item.htmlLink;
const doi = item.doi;
let authors = 'Do not have author';
Expand All @@ -73,18 +89,18 @@ async function handler(ctx) {
};
});

const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
item,
});
list = await Promise.all(
list.map((item) =>
list.map((item: any) =>
cache.tryGet(item.link, async () => {
if (item.abstract !== '') {
const response3 = await got(`${host}${item.link}`);
const { abstract } = JSON.parse(response3.body.match(/metadata=(.*);/)[1]);
const $3 = load(abstract);
item.abstract = $3.text();
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;
const $2 = load(metadata?.abstract || '');
item.abstract = $2.text();
item.description = renderDesc(item);
}
return item;
Expand All @@ -93,8 +109,8 @@ async function handler(ctx) {
);

return {
title: jrnlName,
link: jrnlUrl,
title,
link,
item: list,
};
}