From 8ed1a6da2202bb13fcbc4f882a9a0ceb5c38079c Mon Sep 17 00:00:00 2001 From: dzx-dzx Date: Fri, 28 Nov 2025 15:14:46 +0800 Subject: [PATCH 1/7] feat(route/sjtu): Add route for Public OA --- lib/config.ts | 9 +++- lib/routes/sjtu/publicoa.ts | 93 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 lib/routes/sjtu/publicoa.ts diff --git a/lib/config.ts b/lib/config.ts index 261d3646f97d..c1aa101d1908 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -234,7 +234,8 @@ type ConfigEnvKeys = | 'ZSXQ_ACCESS_TOKEN' | 'SMZDM_COOKIE' | 'REMOTE_CONFIG' - | 'REMOTE_CONFIG_AUTH'; + | 'REMOTE_CONFIG_AUTH' + | 'JAAuthCookie'; export type ConfigEnv = Partial>; @@ -570,6 +571,9 @@ export type Config = { sis001: { baseUrl?: string; }; + sjtu: { + JAAuthCookie?: string; + }; skeb: { bearerToken?: string; }; @@ -1048,6 +1052,9 @@ const calculateValue = () => { sis001: { baseUrl: envs.SIS001_BASE_URL || 'https://sis001.com', }, + sjtu: { + JAAuthCookie: envs.JAAuthCookie, + }, skeb: { bearerToken: envs.SKEB_BEARER_TOKEN, }, diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts new file mode 100644 index 000000000000..0a25a0d40ff7 --- /dev/null +++ b/lib/routes/sjtu/publicoa.ts @@ -0,0 +1,93 @@ +import { CookieJar } from 'tough-cookie'; + +import { config } from '@/config'; +import type { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const urlRoot = 'https://publicoa.sjtu.edu.cn'; + +export const route: Route = { + path: '/publicoa', + categories: ['university'], + example: '/sjtu/publicoa', + parameters: {}, + features: { + requireConfig: [ + { + name: 'JAAuthCookie', + description: 'JAAuthCookie, 登陆后提取自jaccount.sjtu.edu.cn', + }, + ], + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '上海交通大学公文系统', + maintainers: [''], + handler, + description: `需要用户认证`, +}; + +const cookieJar = new CookieJar(); + +async function handler() { + if (!config.sjtu?.JAAuthCookie) { + throw '请先在配置文件中填写上海交通大学教务处的JAAuthCookie'; + } + + cookieJar.setCookieSync(`JAAuthCookie=${config.sjtu.JAAuthCookie}; Domain=.jaccount.sjtu.edu.cn; Path=/`, 'https://jaccount.sjtu.edu.cn'); + async function getPublicOAList() { + return await ofetch(`${urlRoot}/api/doc/list`, { + headers: { + cookie: (await cookieJar.getCookieString(urlRoot)) as string, + }, + }); + } + const list: any = await new Promise((resolve) => { + resolve( + getPublicOAList().catch(async (error) => { + if (error.response?.status === 401) { + let requestUrl = urlRoot; + while (true) { + // eslint-disable-next-line no-await-in-loop + const res = await ofetch.raw(requestUrl, { + headers: { + // eslint-disable-next-line no-await-in-loop + cookie: (await cookieJar.getCookieString(requestUrl)) as string, + }, + redirect: 'manual', + }); + const setCookies = res.headers.getSetCookie(); + for (const c of setCookies) { + cookieJar.setCookieSync(c, requestUrl); + } + + if (res.status >= 300 && res.status < 400) { + const location = res.headers.get('location'); + if (typeof location === 'string') { + requestUrl = new URL(location, requestUrl).href; + } + } else { + break; + } + } + return await getPublicOAList(); + } + }) + ); + }); + + return { + title: '上海交通大学公文系统', + item: list.entities.map((item) => ({ + title: item.title, + author: item.doccode, + pubDate: timezone(parseDate(item.qfdate), +8), + link: item.pdfpath, + })), + }; +} From cf622cd8d6ba0049ce8f840ef595ea118b2d7d3d Mon Sep 17 00:00:00 2001 From: dzx-dzx Date: Fri, 28 Nov 2025 15:19:29 +0800 Subject: [PATCH 2/7] . --- lib/routes/sjtu/publicoa.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index 0a25a0d40ff7..2d82379c411d 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -89,5 +89,6 @@ async function handler() { pubDate: timezone(parseDate(item.qfdate), +8), link: item.pdfpath, })), + link: urlRoot, }; } From 91591e9386f13c4682940add8bd2b5a74b5485e3 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sun, 30 Nov 2025 11:39:35 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20publicoa.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/sjtu/publicoa.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index 2d82379c411d..d801719cdd75 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -36,7 +36,7 @@ const cookieJar = new CookieJar(); async function handler() { if (!config.sjtu?.JAAuthCookie) { - throw '请先在配置文件中填写上海交通大学教务处的JAAuthCookie'; + throw 'JAAuthCookie needs to be set to use this route.'; } cookieJar.setCookieSync(`JAAuthCookie=${config.sjtu.JAAuthCookie}; Domain=.jaccount.sjtu.edu.cn; Path=/`, 'https://jaccount.sjtu.edu.cn'); From a44bd9bbe0d616cc5a28e4e89737134db8f7dacf Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:53:48 +0800 Subject: [PATCH 4/7] Update lib/routes/sjtu/publicoa.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/routes/sjtu/publicoa.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index d801719cdd75..843dd911e5d0 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -27,7 +27,7 @@ export const route: Route = { supportScihub: false, }, name: '上海交通大学公文系统', - maintainers: [''], + maintainers: ['dzx-dzx'], handler, description: `需要用户认证`, }; From 17f3175c08966242e4677224a54fa501beb78a2f Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Mon, 2 Feb 2026 13:47:11 +0800 Subject: [PATCH 5/7] Update publicoa.ts --- lib/routes/sjtu/publicoa.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index 843dd911e5d0..a59c7f8b40d8 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -5,6 +5,7 @@ import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; import timezone from '@/utils/timezone'; +import ConfigNotFoundError from '@/errors/types/config-not-found'; const urlRoot = 'https://publicoa.sjtu.edu.cn'; @@ -36,7 +37,7 @@ const cookieJar = new CookieJar(); async function handler() { if (!config.sjtu?.JAAuthCookie) { - throw 'JAAuthCookie needs to be set to use this route.'; + throw new ConfigNotFoundError('JAAuthCookie needs to be set to use this route.'); } cookieJar.setCookieSync(`JAAuthCookie=${config.sjtu.JAAuthCookie}; Domain=.jaccount.sjtu.edu.cn; Path=/`, 'https://jaccount.sjtu.edu.cn'); From dc116254b35286f97e43df3be28a1b3fdc85eb4a Mon Sep 17 00:00:00 2001 From: dzx-dzx Date: Wed, 4 Feb 2026 20:55:36 +0800 Subject: [PATCH 6/7] . --- lib/routes/sjtu/publicoa.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index a59c7f8b40d8..e4ed05bced72 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -1,11 +1,11 @@ import { CookieJar } from 'tough-cookie'; import { config } from '@/config'; +import ConfigNotFoundError from '@/errors/types/config-not-found'; import type { Route } from '@/types'; import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; import timezone from '@/utils/timezone'; -import ConfigNotFoundError from '@/errors/types/config-not-found'; const urlRoot = 'https://publicoa.sjtu.edu.cn'; @@ -53,7 +53,7 @@ async function handler() { getPublicOAList().catch(async (error) => { if (error.response?.status === 401) { let requestUrl = urlRoot; - while (true) { + for (let iteration = 10; iteration > 0; iteration--) { // eslint-disable-next-line no-await-in-loop const res = await ofetch.raw(requestUrl, { headers: { @@ -78,6 +78,7 @@ async function handler() { } return await getPublicOAList(); } + throw error; }) ); }); From 3e17921d830c301a872bebbe4e74152ad8df4f01 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sun, 1 Mar 2026 16:50:18 +0800 Subject: [PATCH 7/7] Update lib/routes/sjtu/publicoa.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/routes/sjtu/publicoa.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/sjtu/publicoa.ts b/lib/routes/sjtu/publicoa.ts index e4ed05bced72..52f6f317777c 100644 --- a/lib/routes/sjtu/publicoa.ts +++ b/lib/routes/sjtu/publicoa.ts @@ -18,7 +18,7 @@ export const route: Route = { requireConfig: [ { name: 'JAAuthCookie', - description: 'JAAuthCookie, 登陆后提取自jaccount.sjtu.edu.cn', + description: '登录 jaccount.sjtu.edu.cn 后的 JAAuthCookie 值,可在浏览器开发工具的 Cookie 中找到', }, ], requirePuppeteer: false,