* refactor: use patchwright * refactor: migrate setRequestInterception and waitUntil * fix: overwrite ua * refactor: drop puppeteer cookie/requestfinished shims Migrate page.cookies/setCookie and browser.cookies/setCookie call sites to the native context APIs (page.context().cookies/addCookies), rewrite requestfinished handlers to await request.response() instead of consuming the synchronous puppeteer-shaped payload, and remove the now-redundant browser.close context-cleanup wrapper. Playwright already handles all of these natively; the shims existed only for the puppeteer -> playwright migration. * refactor: remove page.authenticate, page.setUserAgent, browser.newPage(), browser.userAgent() shims update cookie utility tests * refactor: replace browser instance with context in Playwright usage across multiple routes - Updated all instances of `browser` to `context` in Playwright-related functions for consistency and improved resource management. - Ensured proper closure of context after operations to prevent memory leaks. - Adjusted request interception methods to utilize the new context variable. * fix: direct type import * refactor: remove Puppeteer compatibility layers and unify page handling with Playwright * fix: test case * chore: bump patchright to v1.60.0 * chore: pin patchright to 1.59.1 nft can't resolve browser.json due to https://github.com/microsoft/playwright/pull/40093 * chore: pin to node 24.15 for playwright browser install on node 24.16 stucks due to https://github.com/microsoft/playwright/issues/40724 * fix: update patchright and patchright-core to version 1.60.2 and adjust minify-docker.js for compatibility * fix: import BrowserContext from patchright
82 lines
3.2 KiB
TypeScript
82 lines
3.2 KiB
TypeScript
// journals form AAAS publishing group
|
|
//
|
|
// science: Science
|
|
// sciadv: Science Advances
|
|
// sciimmunol: Science Immunology
|
|
// scirobotics: Science Robotics
|
|
// signaling: Science Signaling
|
|
// stm: Science Translational Medicine
|
|
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import playwright from '@/utils/playwright';
|
|
|
|
import { baseUrl, fetchDesc, getItem } from './utils';
|
|
|
|
export const route: Route = {
|
|
path: '/current/:journal?',
|
|
categories: ['journal'],
|
|
example: '/science/current/science',
|
|
parameters: { journal: 'Short name for a journal' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: true,
|
|
antiCrawler: true,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: true,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['science.org/journal/:journal', 'science.org/toc/:journal/current'],
|
|
target: '/current/:journal',
|
|
},
|
|
],
|
|
name: 'Current Issue',
|
|
maintainers: ['y9c', 'TonyRL'],
|
|
handler,
|
|
description: `| Short name | Full name of the journal | Route |
|
|
| :---------: | :----------------------------: | ------------------------------------------------------------------------------ |
|
|
| science | Science | [/science/current/science](https://rsshub.app/science/current/science) |
|
|
| sciadv | Science Advances | [/science/current/sciadv](https://rsshub.app/science/current/sciadv) |
|
|
| sciimmunol | Science Immunology | [/science/current/sciimmunol](https://rsshub.app/science/current/sciimmunol) |
|
|
| scirobotics | Science Robotics | [/science/current/scirobotics](https://rsshub.app/science/current/scirobotics) |
|
|
| signaling | Science Signaling | [/science/current/signaling](https://rsshub.app/science/current/signaling) |
|
|
| stm | Science Translational Medicine | [/science/current/stm](https://rsshub.app/science/current/stm) |
|
|
|
|
- Using route (\`/science/current/\` + "short name for a journal") to get current issue of a journal from AAAS.
|
|
- Leaving it empty (\`/science/current\`) to get update from Science.`,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const { journal = 'science' } = ctx.req.param();
|
|
const pageURL = `${baseUrl}/toc/${journal}/current`;
|
|
|
|
const { data: pageResponse } = await got(pageURL, {
|
|
headers: {
|
|
cookie: 'cookiePolicy=iaccept;',
|
|
},
|
|
});
|
|
const $ = load(pageResponse);
|
|
const pageTitleName = $('head > title').text();
|
|
|
|
const list = $('.toc__section .card')
|
|
.toArray()
|
|
.map((item) => getItem(item, $));
|
|
|
|
const context = await playwright();
|
|
const items = await fetchDesc(list, context, cache.tryGet);
|
|
await context.close();
|
|
|
|
return {
|
|
title: `${pageTitleName} | Current Issue`,
|
|
description: `Current Issue of ${pageTitleName}`,
|
|
image: `${baseUrl}/apple-touch-icon.png`,
|
|
link: pageURL,
|
|
language: 'en-US',
|
|
item: items,
|
|
};
|
|
}
|