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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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
72 changes: 46 additions & 26 deletions lib/routes/ieee/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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 @@ -12,9 +12,20 @@
const cookieJar = new CookieJar();

export const route: Route = {
path: ['/:journal/latest/vol/:sortType?', '/journal/:journal/:sortType?'],
name: 'Unknown',
maintainers: [],
path: '/journal/:journal/:sortType?',
categories: ['journal'],
example: '/ieee/journal/8782710',
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: 'Current Issue',
maintainers: ['Derekmini'],
handler,
};

Expand All @@ -24,32 +35,37 @@
const host = 'https://ieeexplore.ieee.org';
const jrnlUrl = `${host}/xpl/mostRecentIssue.jsp?punumber=${punumber}`;

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

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 response2 = 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 = response2.records.map((item: any) => {
const $2 = load(item.articleTitle);
const title = $2.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('; ');
authors = item.authors.map((itemAuth: any) => itemAuth.preferredName).join('; ');
}
let abstract = '';
Object.hasOwn(item, 'abstract') ? (abstract = item.abstract) : (abstract = '');
Expand All @@ -63,18 +79,22 @@
};
});

const renderDesc = (item) =>
const renderDesc = (item: any) =>
Fixed Show fixed Hide fixed
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 response3 = await ofetch(`${host}${item.link}`, {
parseResponse: (txt) => txt,
});
const $3 = load(response3);
const metadataMatch = $3.html().match(/metadata=(.*);/);
const metadata = metadataMatch ? JSON.parse(metadataMatch[1]) : null;
const $4 = load(metadata?.abstract || '');
item.abstract = $4.text();
item.description = renderDesc(item);
}
return item;
Expand Down