papersearch 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +297 -14
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.js +1 -1
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/batchSummary.js +1 -1
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.js +5 -5
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +16 -9
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +64 -54
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.js +61 -56
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +6 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +14 -3
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
- package/dist/infrastructure/school/index.d.ts +1 -1
- package/dist/infrastructure/school/index.d.ts.map +1 -1
- package/dist/infrastructure/school/types.d.ts +10 -3
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/management/failures/index.d.ts +5 -2
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +21 -4
- package/dist/management/failures/index.js.map +1 -1
- package/package.json +1 -1
- package/school/paper_search_school/adapters/base.py +4 -0
- package/school/paper_search_school/adapters/oup/__init__.py +20 -0
- package/school/paper_search_school/adapters/sage/__init__.py +4 -1
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +3 -0
- package/school/paper_search_school/adapters/thieme/__init__.py +4 -2
- package/school/paper_search_school/assets/capsule.html +125 -49
- package/school/paper_search_school/assets/capsule_en.json +32 -54
- package/school/paper_search_school/assets/capsule_fr.json +32 -54
- package/school/paper_search_school/assets/capsule_ja.json +32 -54
- package/school/paper_search_school/assets/capsule_ko.json +32 -54
- package/school/paper_search_school/assets/capsule_zh-Hant.json +27 -53
- package/school/paper_search_school/cold_start.py +22 -11
- package/school/paper_search_school/engine/access_rules.py +3 -2
- package/school/paper_search_school/engine/batch.py +12 -4
- package/school/paper_search_school/engine/batch_access.py +21 -9
- package/school/paper_search_school/engine/batch_capture.py +1 -1
- package/school/paper_search_school/engine/batch_institution.py +130 -29
- package/school/paper_search_school/engine/bridge.py +16 -3
- package/school/paper_search_school/engine/router.py +2 -1
- package/school/paper_search_school/orchestrator.py +44 -18
- package/school/paper_search_school/progress_reporter.py +17 -8
- package/school/paper_search_school/progress_view.py +1 -1
- package/school/paper_search_school/publishers/builtin/sage.json +4 -2
- package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
- package/school/paper_search_school/school_switch.py +34 -52
- package/school/paper_search_school/server.py +10 -8
- package/skills/paper-search/SKILL.md +1 -1
- package/skills/paper-search/references/browser-download.md +7 -9
- package/skills/paper-search/references/publisher-support.md +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../../../src/capabilities/download/batch/batch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAMnE,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":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;AACH,eAAO,MAAM,qBAAqB,QAAc,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AA4F9C,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAEjE;AA8KD,6EAA6E;AAC7E,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE,aAAa,EACvB,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAkD,EACzE,WAAW,GAAE,CAAC,OAAO,CAAC,EAAE,aAAa,KAAK,YAAY,EAA+B,EACrF,KAAK,GAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAQ,EAC3C,MAAM,GAAE,MAAM,OAAO,CAAC,OAAO,CAAoB,GAChD,OAAO,CAAC,mBAAmB,CAAC,CAsG9B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveDownloadPath } from "../../../config/ConfigService.js";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { RunLedger } from "../../../infrastructure/runlog/RunLedger.js";
|
|
4
|
-
import { FAILURE_CLASS_NAMES, } from "../../../infrastructure/runlog/failureClass.js";
|
|
4
|
+
import { classifyFailureCode, FAILURE_CLASS_NAMES, } from "../../../infrastructure/runlog/failureClass.js";
|
|
5
5
|
import { createDefaultDownloadTiers, downloadWithFallback, } from "../content/pdf/OpenAccessFallbackService.js";
|
|
6
6
|
import { schoolAttemptDetails, schoolShortReason } from "../../../infrastructure/school/index.js";
|
|
7
7
|
import { journalOfDoi, takeNext } from "./journalKey.js";
|
|
@@ -192,6 +192,58 @@ const STOP_NOTICE = "[批量] 已在进度窗口终止任务,剩下的篇目
|
|
|
192
192
|
export function batchStopped(result) {
|
|
193
193
|
return !!result.stopped || result.items.some((item) => stoppedByUser(item) || item.attempts.some((attempt) => attempt.code === "login_paused"));
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* 没权限 (FailureClass no_access) at the school's stage: the publisher refused the signed-in school, the school's
|
|
197
|
+
* sign-in is not enabled for the publisher, the publisher has no route for it, or the user marked the journal as
|
|
198
|
+
* without access. Another saved school may have it (没权限时换下一所学校, user 2026-11-22: every paper under 没权限).
|
|
199
|
+
*/
|
|
200
|
+
function withoutAccess(result) {
|
|
201
|
+
if (!result || result.status === "ok")
|
|
202
|
+
return false;
|
|
203
|
+
const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
|
|
204
|
+
return school?.status === "error" && classifyFailureCode(school.code) === "no_access";
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 原因不明 (FailureClass unexplained) at the school's stage: tried once more at the batch's end, with the school it had,
|
|
208
|
+
* before any other school (user, 2026-11-22: "原因不明的也最后再试一次"); not a paper the user stopped.
|
|
209
|
+
*/
|
|
210
|
+
function unexplainedFailure(result) {
|
|
211
|
+
if (!result || result.status === "ok" || stoppedByUser(result))
|
|
212
|
+
return false;
|
|
213
|
+
const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
|
|
214
|
+
return school?.status === "error" && classifyFailureCode(school.code) === "unexplained";
|
|
215
|
+
}
|
|
216
|
+
/** The other saved schools a batch's papers without access go to at its end: none for a batch given its school. */
|
|
217
|
+
async function schoolsAfterDefault(backend, options) {
|
|
218
|
+
if (options.school?.trim() || !backend?.schoolSwitch)
|
|
219
|
+
return [];
|
|
220
|
+
return (await backend.schoolSwitch().catch(() => undefined))?.schools.slice(1) ?? [];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* 没权限时换下一所学校 at a batch's end (PaperSearch Pro; user, 2026-11-22): the papers still without access go to each
|
|
224
|
+
* other saved school in turn, all of them with one before the next, so that the school's login is switched once, not at
|
|
225
|
+
* every paper (switching to and fro had a school's login ask for a picture code, Windows 2026-11-22). ``visit`` tries
|
|
226
|
+
* one paper with a school.
|
|
227
|
+
*/
|
|
228
|
+
async function laterSchools(schools, waiting, announce, visit, stopped) {
|
|
229
|
+
for (const school of schools) {
|
|
230
|
+
const offsets = waiting();
|
|
231
|
+
if (!offsets.length || stopped())
|
|
232
|
+
return;
|
|
233
|
+
await announce(school, offsets.length);
|
|
234
|
+
for (const offset of offsets) {
|
|
235
|
+
if (stopped())
|
|
236
|
+
return;
|
|
237
|
+
await visit(offset, school);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** A paper without access with each of ``count`` schools: its last school stage says so (N 所学校都没有权限). */
|
|
242
|
+
function triedSchools(result, count) {
|
|
243
|
+
const school = [...result.attempts].reverse().find((attempt) => attempt.stage === "entitled_access");
|
|
244
|
+
if (school && count > 1)
|
|
245
|
+
school.schools = count;
|
|
246
|
+
}
|
|
195
247
|
/** The attempt recorded for an item the batch did not reach because the user stopped it. */
|
|
196
248
|
function notReached() {
|
|
197
249
|
return { stage: "entitled_access", status: "skipped", message: "已终止任务,未下载", code: "batch_stopped" };
|
|
@@ -475,17 +527,23 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
|
|
|
475
527
|
let succeeded = 0;
|
|
476
528
|
let failed = 0;
|
|
477
529
|
let away = false;
|
|
530
|
+
// 没权限时换下一所学校 (PaperSearch Pro): papers without access wait for the other saved schools, tried at the end, one
|
|
531
|
+
// school at a time (``laterSchools``, user 2026-11-22).
|
|
532
|
+
let turns;
|
|
533
|
+
const otherSchools = () => (turns ??= schoolsAfterDefault(backend, options));
|
|
534
|
+
const waiting = new Map();
|
|
535
|
+
const schoolsTried = new Map();
|
|
536
|
+
/** Papers failed for a reason not known, waiting for their one more try at the end (user, 2026-11-22). */
|
|
537
|
+
const unexplainedYet = new Map();
|
|
538
|
+
let stopped = false;
|
|
478
539
|
for (const [offset, item] of options.items.entries()) {
|
|
479
540
|
const index = offset + 1;
|
|
480
541
|
const request = itemOptions(item, options);
|
|
481
542
|
const entry = runItem(index, request);
|
|
482
543
|
log(`[批量] 第 ${index}/${total} 篇:${request.doi || request.paperId}`);
|
|
483
|
-
|
|
544
|
+
// Papers waiting for the end (without access, 原因不明) are not done yet: the counts are of those finished.
|
|
545
|
+
const batch = { id: batchId, index, total, done: succeeded + failed, succeeded, failed };
|
|
484
546
|
const result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend)), log, pause, backend), watch);
|
|
485
|
-
if (result.status === "ok")
|
|
486
|
-
succeeded += 1;
|
|
487
|
-
else
|
|
488
|
-
failed += 1;
|
|
489
547
|
if (!away && waitedOutOnUser(result)) {
|
|
490
548
|
away = true;
|
|
491
549
|
log(AWAY_NOTICE);
|
|
@@ -496,13 +554,33 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
|
|
|
496
554
|
if (!stoppedByUser(result)) {
|
|
497
555
|
await markdownPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), searchers, pageVisit(backend, { ...request, batch }, log, pause), watch);
|
|
498
556
|
}
|
|
499
|
-
await reportBatchItem({ ...request, batch }, finished, backend);
|
|
500
|
-
ledger?.item(entry, finished);
|
|
501
557
|
items.push(finished);
|
|
558
|
+
if (withoutAccess(finished) && !stoppedByUser(finished) && (await otherSchools()).length) {
|
|
559
|
+
// Not finished: it waits for the other schools at the end.
|
|
560
|
+
waiting.set(offset, entry);
|
|
561
|
+
papers.set(offset, batchPaper(request, finished, "school", content));
|
|
562
|
+
await papers.send();
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (unexplainedFailure(finished)) {
|
|
566
|
+
// Not finished: once more at the end, with this school.
|
|
567
|
+
unexplainedYet.set(offset, entry);
|
|
568
|
+
papers.set(offset, batchPaper(request, finished, "school", content));
|
|
569
|
+
await papers.send();
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (result.status === "ok")
|
|
573
|
+
succeeded += 1;
|
|
574
|
+
else
|
|
575
|
+
failed += 1;
|
|
576
|
+
// The window's end when the last paper is finished, not the last in the list (some wait for the end).
|
|
577
|
+
await reportBatchItem({ ...request, batch: { ...batch, index: batch.done + 1 } }, finished, backend);
|
|
578
|
+
ledger?.item(entry, finished);
|
|
502
579
|
papers.set(offset, batchPaper(request, finished, undefined, content));
|
|
503
580
|
if (publisherBlocked(result))
|
|
504
581
|
log(blockedNotice(request.doi || request.paperId));
|
|
505
582
|
if (stoppedByUser(finished)) {
|
|
583
|
+
stopped = true;
|
|
506
584
|
for (const [rest, restItem] of options.items.entries()) {
|
|
507
585
|
if (rest <= offset)
|
|
508
586
|
continue;
|
|
@@ -517,6 +595,77 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
|
|
|
517
595
|
}
|
|
518
596
|
await papers.send();
|
|
519
597
|
}
|
|
598
|
+
/** A paper's school stage once more (another saved school when given), its files and Markdown when it comes. */
|
|
599
|
+
const again = async (offset, entry, school) => {
|
|
600
|
+
const request = { ...itemOptions(options.items[offset], options), ...(school ? { school: school.entityId } : {}) };
|
|
601
|
+
const batch = { id: batchId, index: offset + 1, total, done: succeeded + failed, succeeded, failed };
|
|
602
|
+
log(school ? `[批量] 换${school.name}:${request.doi || request.paperId}` : `[批量] 再试一次:${request.doi || request.paperId}`);
|
|
603
|
+
const result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend).filter((tier) => tier.stage === "entitled_access")), log, pause, backend), watch);
|
|
604
|
+
const before = items[offset];
|
|
605
|
+
const finished = itemResult({ ...result, attempts: [...before.attempts, ...result.attempts],
|
|
606
|
+
...(before.markdown ? { markdown: before.markdown } : {}) }, offset + 1, request);
|
|
607
|
+
items[offset] = finished;
|
|
608
|
+
if (result.status === "ok") {
|
|
609
|
+
await filesPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), backend, searchers, watch);
|
|
610
|
+
if (finished.markdown?.status !== "ok") {
|
|
611
|
+
await markdownPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), searchers, pageVisit(backend, { ...request, batch }, log, pause), watch);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (stoppedByUser(result))
|
|
615
|
+
stopped = true;
|
|
616
|
+
return finished;
|
|
617
|
+
};
|
|
618
|
+
/** A paper finished at the end: counted, recorded, shown. */
|
|
619
|
+
const finish = async (offset, entry) => {
|
|
620
|
+
const request = itemOptions(options.items[offset], options);
|
|
621
|
+
const done = succeeded + failed;
|
|
622
|
+
const batch = { id: batchId, index: done + 1, total, done, succeeded, failed };
|
|
623
|
+
if (items[offset].status === "ok")
|
|
624
|
+
succeeded += 1;
|
|
625
|
+
else
|
|
626
|
+
failed += 1;
|
|
627
|
+
await reportBatchItem({ ...request, batch }, items[offset], backend);
|
|
628
|
+
ledger?.item(entry, items[offset]);
|
|
629
|
+
papers.set(offset, batchPaper(request, items[offset], undefined, content));
|
|
630
|
+
await papers.send();
|
|
631
|
+
};
|
|
632
|
+
// 原因不明 once more, with this school, before any other school (user, 2026-11-22).
|
|
633
|
+
if (unexplainedYet.size && !stopped) {
|
|
634
|
+
log(`[批量] 原因不明的 ${unexplainedYet.size} 篇再试一次`);
|
|
635
|
+
ledger?.phase(`原因不明的 ${unexplainedYet.size} 篇再试一次`);
|
|
636
|
+
for (const [offset, entry] of [...unexplainedYet]) {
|
|
637
|
+
if (stopped)
|
|
638
|
+
break;
|
|
639
|
+
const finished = await again(offset, entry);
|
|
640
|
+
unexplainedYet.delete(offset);
|
|
641
|
+
if (!stopped && withoutAccess(finished) && (await otherSchools()).length)
|
|
642
|
+
waiting.set(offset, entry);
|
|
643
|
+
else
|
|
644
|
+
await finish(offset, entry);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
for (const [offset, entry] of unexplainedYet)
|
|
648
|
+
await finish(offset, entry);
|
|
649
|
+
// The papers without access go to the other saved schools, one school at a time.
|
|
650
|
+
if (waiting.size && !stopped) {
|
|
651
|
+
await laterSchools(await otherSchools(), () => [...waiting.keys()], async (school, count) => {
|
|
652
|
+
log(`[批量] 没权限的 ${count} 篇换${school.name}再试`);
|
|
653
|
+
ledger?.phase(`没权限的 ${count} 篇换${school.name}再试`);
|
|
654
|
+
}, async (offset, school) => {
|
|
655
|
+
const entry = waiting.get(offset);
|
|
656
|
+
const finished = await again(offset, entry, school);
|
|
657
|
+
schoolsTried.set(offset, (schoolsTried.get(offset) ?? 1) + 1);
|
|
658
|
+
if (!stopped && withoutAccess(finished)) {
|
|
659
|
+
triedSchools(finished, schoolsTried.get(offset));
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
waiting.delete(offset);
|
|
663
|
+
await finish(offset, entry);
|
|
664
|
+
}, () => stopped);
|
|
665
|
+
}
|
|
666
|
+
// Without access with every school (or the batch stopped first): failed.
|
|
667
|
+
for (const [offset, entry] of waiting)
|
|
668
|
+
await finish(offset, entry);
|
|
520
669
|
await papers.send(true);
|
|
521
670
|
ledger?.close();
|
|
522
671
|
return summary("per_item", batchId, items, {
|
|
@@ -859,9 +1008,19 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
859
1008
|
forward?.(record);
|
|
860
1009
|
} };
|
|
861
1010
|
};
|
|
862
|
-
//
|
|
863
|
-
//
|
|
864
|
-
//
|
|
1011
|
+
// 没权限时换下一所学校 (PaperSearch Pro): the other saved schools, asked once a paper has gone without access (the
|
|
1012
|
+
// backend the batch has by then can say). Such papers wait, not finished, and go to them at the end, all of them with
|
|
1013
|
+
// one school before the next (``laterSchools``, user 2026-11-22).
|
|
1014
|
+
let turns;
|
|
1015
|
+
const otherSchools = () => (turns ??= schoolsAfterDefault(backend, options));
|
|
1016
|
+
/** Papers without access with the schools tried so far, waiting for the next one. */
|
|
1017
|
+
const withoutAccessYet = new Set();
|
|
1018
|
+
/** Papers failed for a reason not known, waiting for their one more try at the end. */
|
|
1019
|
+
const unexplainedYet = new Set();
|
|
1020
|
+
/** Each waiting paper's schools tried, the default one counted. */
|
|
1021
|
+
const schoolsTried = new Map();
|
|
1022
|
+
// One journal's papers one after another when the backend says so (more than one school taking part, user
|
|
1023
|
+
// 2026-11-21; kept with the switch at the end, user 2026-11-22). Asked until the backend has run a paper and can say.
|
|
865
1024
|
let groupJournals;
|
|
866
1025
|
let lastJournal = "";
|
|
867
1026
|
const entitledLane = async () => {
|
|
@@ -890,15 +1049,21 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
890
1049
|
continue;
|
|
891
1050
|
}
|
|
892
1051
|
const request = requests[offset];
|
|
893
|
-
|
|
1052
|
+
// Papers waiting for the end (without access, 原因不明) counted too: the log goes 1/7, 2/7 … as the window does
|
|
1053
|
+
// (Windows 2026-11-22: every line said 1/7 while the papers waited).
|
|
1054
|
+
const step = succeeded + failed + withoutAccessYet.size + unexplainedYet.size + 1;
|
|
894
1055
|
log(openRunning
|
|
895
1056
|
? `[批量] 机构下载第 ${step} 篇(开放来源还在查):${id(offset)}`
|
|
896
1057
|
: `[批量] 机构下载 ${step}/${missed.length}:${id(offset)}`);
|
|
897
1058
|
const done = settledOk() + failed;
|
|
898
|
-
|
|
1059
|
+
// Its place among the papers gone through, those waiting for the end counted (the window's "k / N" goes on);
|
|
1060
|
+
// the counts are of those finished.
|
|
1061
|
+
const batch = { id: batchId, index: done + withoutAccessYet.size + unexplainedYet.size + 1, total, done,
|
|
1062
|
+
succeeded: settledOk(), failed };
|
|
899
1063
|
let result;
|
|
900
1064
|
try {
|
|
901
|
-
|
|
1065
|
+
// Reported to the window once it is known whether the paper waits for the end (``reportBatchItem`` below).
|
|
1066
|
+
result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]), offset), createTiers(backend).filter((tier) => tier.stage === "entitled_access" || mode !== "entitled_only" && tier.stage === "preprint")), log, pause, backend), watch);
|
|
902
1067
|
}
|
|
903
1068
|
catch (error) {
|
|
904
1069
|
result = laneError("entitled_access", error);
|
|
@@ -934,11 +1099,23 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
934
1099
|
else if (holding) {
|
|
935
1100
|
hold(offset);
|
|
936
1101
|
}
|
|
1102
|
+
else if (withoutAccess(result) && !stoppedByUser(result) && (await otherSchools()).length) {
|
|
1103
|
+
withoutAccessYet.add(offset);
|
|
1104
|
+
settle(offset, "school");
|
|
1105
|
+
}
|
|
1106
|
+
else if (unexplainedFailure(result)) {
|
|
1107
|
+
unexplainedYet.add(offset);
|
|
1108
|
+
settle(offset, "school");
|
|
1109
|
+
}
|
|
937
1110
|
else {
|
|
938
1111
|
failed += 1;
|
|
939
1112
|
record(offset);
|
|
940
1113
|
settle(offset);
|
|
941
1114
|
}
|
|
1115
|
+
// The window's line, not for a paper that waits for the end (it would close the batch early when last).
|
|
1116
|
+
if (!withoutAccessYet.has(offset) && !unexplainedYet.has(offset)) {
|
|
1117
|
+
await reportBatchItem({ ...request, batch: { ...batch, index: batch.done + 1 } }, result, backend);
|
|
1118
|
+
}
|
|
942
1119
|
if (publisherBlocked(result))
|
|
943
1120
|
log(blockedNotice(id(offset)));
|
|
944
1121
|
if (stoppedByUser(result)) {
|
|
@@ -983,6 +1160,112 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
983
1160
|
await entitledLane();
|
|
984
1161
|
}
|
|
985
1162
|
}
|
|
1163
|
+
/** A paper's school stage once more, with another saved school when given; merged into its result. */
|
|
1164
|
+
const visitAgain = async (offset, school) => {
|
|
1165
|
+
const request = { ...requests[offset], ...(school ? { school: school.entityId } : {}) };
|
|
1166
|
+
const done = settledOk() + failed;
|
|
1167
|
+
const batch = { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed };
|
|
1168
|
+
log(school ? `[批量] 换${school.name}:${id(offset)}` : `[批量] 再试一次:${id(offset)}`);
|
|
1169
|
+
let result;
|
|
1170
|
+
try {
|
|
1171
|
+
result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]), offset), createTiers(backend).filter((tier) => tier.stage === "entitled_access")), log, pause, backend), watch);
|
|
1172
|
+
}
|
|
1173
|
+
catch (error) {
|
|
1174
|
+
result = laneError("entitled_access", error);
|
|
1175
|
+
log(`[批量] 机构下载出错(${id(offset)}):${result.attempts[0].message}`);
|
|
1176
|
+
}
|
|
1177
|
+
const before = results[offset];
|
|
1178
|
+
const markdown = result.markdown ?? before.markdown;
|
|
1179
|
+
results[offset] = itemResult({
|
|
1180
|
+
...result,
|
|
1181
|
+
attempts: [...before.attempts, ...result.attempts],
|
|
1182
|
+
...(result.review ?? before.review ? { review: result.review ?? before.review } : {}),
|
|
1183
|
+
...(markdown ? { markdown } : {}),
|
|
1184
|
+
}, offset + 1, requests[offset]);
|
|
1185
|
+
const item = results[offset];
|
|
1186
|
+
// Its Markdown from the page this visit saved, unless the open sources gave it already.
|
|
1187
|
+
if (wantsMarkdown && result.status === "ok" && item.markdown?.status !== "ok") {
|
|
1188
|
+
await markdownPastNetworkLoss(item, recorded({ ...request, batch }, ledger, entries[offset]), searchers, pageVisit(backend, { ...request, batch, ...(away ? { shortUserWait: true } : {}) }, log, pause), watch);
|
|
1189
|
+
}
|
|
1190
|
+
if (stoppedByUser(result))
|
|
1191
|
+
stopped = true;
|
|
1192
|
+
if (publisherBlocked(result))
|
|
1193
|
+
log(blockedNotice(id(offset)));
|
|
1194
|
+
return item;
|
|
1195
|
+
};
|
|
1196
|
+
/** The window's line for a paper finished at the end (the counts before it, as ``reportBatchItem`` takes them). */
|
|
1197
|
+
const reportSettled = async (offset) => {
|
|
1198
|
+
const done = settledOk() + failed;
|
|
1199
|
+
await reportBatchItem({ ...requests[offset], batch: { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed } }, results[offset], backend);
|
|
1200
|
+
};
|
|
1201
|
+
// 原因不明 once more, the default school still signed in, before any other school (user, 2026-11-22).
|
|
1202
|
+
if (unexplainedYet.size && !stopped) {
|
|
1203
|
+
log(`[批量] 原因不明的 ${unexplainedYet.size} 篇再试一次`);
|
|
1204
|
+
ledger?.phase(`原因不明的 ${unexplainedYet.size} 篇再试一次`);
|
|
1205
|
+
for (const offset of [...unexplainedYet]) {
|
|
1206
|
+
if (stopped)
|
|
1207
|
+
break;
|
|
1208
|
+
const item = await visitAgain(offset);
|
|
1209
|
+
unexplainedYet.delete(offset);
|
|
1210
|
+
if (!stopped && item.status !== "ok" && withoutAccess(item) && (await otherSchools()).length) {
|
|
1211
|
+
withoutAccessYet.add(offset);
|
|
1212
|
+
}
|
|
1213
|
+
else {
|
|
1214
|
+
await reportSettled(offset);
|
|
1215
|
+
if (item.status === "ok")
|
|
1216
|
+
succeeded += 1;
|
|
1217
|
+
else
|
|
1218
|
+
failed += 1;
|
|
1219
|
+
record(offset);
|
|
1220
|
+
settle(offset);
|
|
1221
|
+
}
|
|
1222
|
+
await sendPapers();
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
for (const offset of unexplainedYet) {
|
|
1226
|
+
await reportSettled(offset);
|
|
1227
|
+
failed += 1;
|
|
1228
|
+
record(offset);
|
|
1229
|
+
}
|
|
1230
|
+
unexplainedYet.clear();
|
|
1231
|
+
// The papers without access go to the other saved schools, one school at a time.
|
|
1232
|
+
const withSchool = async (offset, school) => {
|
|
1233
|
+
const item = await visitAgain(offset, school);
|
|
1234
|
+
schoolsTried.set(offset, (schoolsTried.get(offset) ?? 1) + 1);
|
|
1235
|
+
if (!stopped && withoutAccess(item)) {
|
|
1236
|
+
triedSchools(item, schoolsTried.get(offset));
|
|
1237
|
+
}
|
|
1238
|
+
else {
|
|
1239
|
+
withoutAccessYet.delete(offset);
|
|
1240
|
+
await reportSettled(offset);
|
|
1241
|
+
if (item.status === "ok")
|
|
1242
|
+
succeeded += 1;
|
|
1243
|
+
else
|
|
1244
|
+
failed += 1;
|
|
1245
|
+
record(offset);
|
|
1246
|
+
settle(offset);
|
|
1247
|
+
}
|
|
1248
|
+
await sendPapers();
|
|
1249
|
+
};
|
|
1250
|
+
if (withoutAccessYet.size && !stopped) {
|
|
1251
|
+
await laterSchools(await otherSchools(), () => [...withoutAccessYet], async (school, count) => {
|
|
1252
|
+
log(`[批量] 没权限的 ${count} 篇换${school.name}再试`);
|
|
1253
|
+
ledger?.phase(`没权限的 ${count} 篇换${school.name}再试`);
|
|
1254
|
+
if (!backend?.reportBatchProgress)
|
|
1255
|
+
return;
|
|
1256
|
+
const update = { id: batchId, total, done: settledOk() + failed, succeeded: settledOk(), failed, current: "",
|
|
1257
|
+
finished: false, phase: `没权限,换${school.name}` };
|
|
1258
|
+
reports = reports.then(() => backend.reportBatchProgress(update)).catch(() => false);
|
|
1259
|
+
await reports;
|
|
1260
|
+
}, withSchool, () => stopped);
|
|
1261
|
+
}
|
|
1262
|
+
// Without access with every school (or the batch stopped first): failed.
|
|
1263
|
+
for (const offset of withoutAccessYet) {
|
|
1264
|
+
await reportSettled(offset);
|
|
1265
|
+
failed += 1;
|
|
1266
|
+
record(offset);
|
|
1267
|
+
}
|
|
1268
|
+
withoutAccessYet.clear();
|
|
986
1269
|
await reports;
|
|
987
1270
|
// Stopped in the window: the items neither lane reached end as not downloaded, the held as paused.
|
|
988
1271
|
if (stopped) {
|