papersearch 0.6.10 → 0.7.0
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/LICENSE +661 -21
- package/NOTICE +51 -0
- package/README.en.md +13 -13
- package/README.md +13 -13
- package/assets/federation-map.en.png +0 -0
- package/assets/federation-map.png +0 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.d.ts +27 -17
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.js +440 -278
- package/dist/capabilities/download/batch/batch.js.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts +21 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.js +206 -0
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.d.ts +1 -1
- package/dist/capabilities/download/batch/batchPapers.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchPapers.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchSummary.d.ts +7 -9
- package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchSummary.js +269 -0
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -0
- package/dist/capabilities/download/batch/networkLoss.d.ts +31 -0
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -0
- package/dist/capabilities/download/batch/networkLoss.js +67 -0
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -0
- package/dist/capabilities/download/batch/resume.d.ts +76 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -0
- package/dist/capabilities/download/batch/resume.js +231 -0
- package/dist/capabilities/download/batch/resume.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts +14 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js +52 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts +87 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.js +109 -0
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +34 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.js +99 -0
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.js +39 -0
- package/dist/capabilities/download/content/markdown/stats.js.map +1 -0
- package/dist/capabilities/download/content/markdown/step.d.ts +50 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/step.js +343 -0
- package/dist/capabilities/download/content/markdown/step.js.map +1 -0
- package/dist/capabilities/download/content/markdown/types.d.ts +120 -0
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/types.js +8 -0
- package/dist/capabilities/download/content/markdown/types.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.d.ts +13 -4
- package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/DownloadTier.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.d.ts +5 -5
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.js +26 -14
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -0
- package/dist/capabilities/download/content/pdf/arxiv.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.js +2 -2
- package/dist/capabilities/download/content/pdf/arxiv.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/identity.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/identity.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/pmcCloud.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.js +2 -2
- package/dist/capabilities/download/content/pdf/open/pmcCloud.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/directPdfUrl.js +3 -3
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/preprint.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/unpaywall.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.js.map +1 -0
- package/dist/capabilities/download/content/pdf/school.d.ts +4 -0
- package/dist/capabilities/download/content/pdf/school.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery/tiers/entitledAccess.js → download/content/pdf/school.js} +16 -38
- package/dist/capabilities/download/content/pdf/school.js.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts +27 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.js +150 -0
- package/dist/capabilities/download/content/supplements/fetch.js.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts +11 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.js +24 -0
- package/dist/capabilities/download/content/supplements/shortfall.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/handler.d.ts +12 -4
- package/dist/capabilities/download/handler.d.ts.map +1 -0
- package/dist/capabilities/download/handler.js +275 -0
- package/dist/capabilities/download/handler.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.d.ts +3 -3
- package/dist/capabilities/download/index.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.js +2 -2
- package/dist/capabilities/download/index.js.map +1 -0
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/outputLayout.js +63 -6
- package/dist/capabilities/download/outputLayout.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/schemas.d.ts +143 -18
- package/dist/capabilities/download/schemas.d.ts.map +1 -0
- package/dist/capabilities/download/schemas.js +126 -0
- package/dist/capabilities/download/schemas.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/tools.d.ts +68 -6
- package/dist/capabilities/download/tools.d.ts.map +1 -0
- package/dist/capabilities/download/tools.js +197 -0
- package/dist/capabilities/download/tools.js.map +1 -0
- package/dist/capabilities/download/types.d.ts +222 -0
- package/dist/capabilities/download/types.d.ts.map +1 -0
- package/dist/capabilities/download/types.js +7 -0
- package/dist/capabilities/download/types.js.map +1 -0
- package/dist/cli.js +98 -17
- package/dist/cli.js.map +1 -1
- package/dist/config/edition.d.ts +8 -0
- package/dist/config/edition.d.ts.map +1 -0
- package/dist/config/edition.js +31 -0
- package/dist/config/edition.js.map +1 -0
- package/dist/core/handleToolCall.d.ts +1 -1
- package/dist/core/handleToolCall.d.ts.map +1 -1
- package/dist/core/handleToolCall.js +1 -1
- package/dist/core/handleToolCall.js.map +1 -1
- package/dist/core/schemas.d.ts +1 -1
- package/dist/core/schemas.d.ts.map +1 -1
- package/dist/core/schemas.js +1 -1
- package/dist/core/schemas.js.map +1 -1
- package/dist/core/tools.d.ts +2 -1
- package/dist/core/tools.d.ts.map +1 -1
- package/dist/core/tools.js +8 -2
- package/dist/core/tools.js.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.js +76 -5
- package/dist/infrastructure/pdf/PdfIdentity.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +12 -2
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +39 -11
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +9 -6
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +81 -41
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.js +12 -3
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.d.ts +17 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.js +99 -10
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.d.ts +1 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.js +1 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.d.ts +7 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.js +10 -2
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.js +72 -3
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.d.ts +2 -1
- package/dist/infrastructure/school/index.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.js +3 -2
- package/dist/infrastructure/school/index.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/types.d.ts +85 -5
- package/dist/infrastructure/school/types.d.ts.map +1 -0
- package/dist/infrastructure/school/types.js +5 -0
- package/dist/infrastructure/school/types.js.map +1 -0
- package/dist/management/capability-profile/schoolReadiness.d.ts +1 -1
- package/dist/management/capability-profile/schoolReadiness.d.ts.map +1 -1
- package/dist/management/capability-profile/schoolReadiness.js +1 -1
- package/dist/management/capability-profile/schoolReadiness.js.map +1 -1
- package/dist/management/failures/exportReport.d.ts +6 -0
- package/dist/management/failures/exportReport.d.ts.map +1 -1
- package/dist/management/failures/exportReport.js +28 -18
- package/dist/management/failures/exportReport.js.map +1 -1
- package/dist/management/failures/index.d.ts +3 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +5 -2
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/failures/markdownReport.d.ts +55 -0
- package/dist/management/failures/markdownReport.d.ts.map +1 -0
- package/dist/management/failures/markdownReport.js +96 -0
- package/dist/management/failures/markdownReport.js.map +1 -0
- package/dist/management/pro/install.d.ts +58 -0
- package/dist/management/pro/install.d.ts.map +1 -0
- package/dist/management/pro/install.js +235 -0
- package/dist/management/pro/install.js.map +1 -0
- package/dist/management/reports/index.d.ts.map +1 -1
- package/dist/management/reports/index.js +4 -1
- package/dist/management/reports/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts +4 -3
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +6 -4
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +1 -0
- package/dist/management/school/cliProgress.js.map +1 -1
- package/dist/management/school/host.js +1 -1
- package/dist/management/school/host.js.map +1 -1
- package/dist/management/school/installer.d.ts +1 -2
- package/dist/management/school/installer.d.ts.map +1 -1
- package/dist/management/school/installer.js.map +1 -1
- package/dist/management/school/legacy.js +1 -1
- package/dist/management/school/legacy.js.map +1 -1
- package/dist/management/school/settingsWindow.d.ts +14 -3
- package/dist/management/school/settingsWindow.d.ts.map +1 -1
- package/dist/management/school/settingsWindow.js +14 -4
- package/dist/management/school/settingsWindow.js.map +1 -1
- package/dist/management/skills/autoSync.d.ts +3 -3
- package/dist/management/skills/autoSync.d.ts.map +1 -1
- package/dist/management/skills/autoSync.js +13 -20
- package/dist/management/skills/autoSync.js.map +1 -1
- package/dist/services/OpenAccessFallbackService.d.ts +3 -3
- package/dist/services/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/services/OpenAccessFallbackService.js +1 -1
- package/dist/services/OpenAccessFallbackService.js.map +1 -1
- package/dist/skills/SkillInstaller.d.ts +26 -0
- package/dist/skills/SkillInstaller.d.ts.map +1 -1
- package/dist/skills/SkillInstaller.js +80 -10
- package/dist/skills/SkillInstaller.js.map +1 -1
- package/package.json +10 -2
- package/school/LICENSE +661 -21
- package/school/LICENSE-scansci-pdf +21 -0
- package/school/NOTICE +10 -0
- package/school/README.md +1 -1
- package/school/paper_search_school/_core/__init__.py +2 -1
- package/school/paper_search_school/adapters/__init__.py +3 -3
- package/school/paper_search_school/adapters/acm/__init__.py +7 -1
- package/school/paper_search_school/adapters/acs/__init__.py +4 -0
- package/school/paper_search_school/adapters/aha_journals/__init__.py +5 -1
- package/school/paper_search_school/adapters/aip/__init__.py +17 -0
- package/school/paper_search_school/adapters/ams/__init__.py +36 -0
- package/school/paper_search_school/adapters/annual_reviews/__init__.py +24 -1
- package/school/paper_search_school/adapters/aps/__init__.py +118 -0
- package/school/paper_search_school/adapters/asce/__init__.py +7 -1
- package/school/paper_search_school/adapters/base.py +21 -1
- package/school/paper_search_school/adapters/bmj/__init__.py +54 -0
- package/school/paper_search_school/adapters/copernicus/__init__.py +35 -0
- package/school/paper_search_school/adapters/dovepress/__init__.py +31 -0
- package/school/paper_search_school/adapters/elsevier/__init__.py +33 -0
- package/school/paper_search_school/adapters/frontiers/__init__.py +46 -1
- package/school/paper_search_school/adapters/ieee/__init__.py +94 -2
- package/school/paper_search_school/adapters/iop/__init__.py +65 -0
- package/school/paper_search_school/adapters/jama/__init__.py +4 -0
- package/school/paper_search_school/adapters/karger/__init__.py +6 -1
- package/school/paper_search_school/adapters/lww/__init__.py +3 -0
- package/school/paper_search_school/adapters/lww/ovid.py +28 -0
- package/school/paper_search_school/adapters/mdpi/__init__.py +73 -0
- package/school/paper_search_school/adapters/nejm/__init__.py +5 -1
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -1
- package/school/paper_search_school/adapters/optica/__init__.py +49 -0
- package/school/paper_search_school/adapters/oup/__init__.py +34 -2
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +83 -2
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +0 -3
- package/school/paper_search_school/adapters/platforms/silverchair/__init__.py +76 -0
- package/school/paper_search_school/adapters/plos/__init__.py +85 -2
- package/school/paper_search_school/adapters/pnas/__init__.py +5 -1
- package/school/paper_search_school/adapters/royal_society/__init__.py +17 -0
- package/school/paper_search_school/adapters/rsc/__init__.py +4 -1
- package/school/paper_search_school/adapters/sage/__init__.py +6 -0
- package/school/paper_search_school/adapters/science/__init__.py +5 -1
- package/school/paper_search_school/adapters/springer/__init__.py +102 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +11 -1
- package/school/paper_search_school/adapters/thieme/__init__.py +46 -0
- package/school/paper_search_school/adapters/wiley/__init__.py +28 -0
- package/school/paper_search_school/adapters/world_scientific/__init__.py +15 -4
- package/school/paper_search_school/assets/capsule.html +607 -41
- package/school/paper_search_school/assets/capsule_en.json +314 -5
- package/school/paper_search_school/browser/__init__.py +5 -2
- package/school/paper_search_school/browser/backend.py +161 -9
- package/school/paper_search_school/browser/batch_session.py +76 -2
- package/school/paper_search_school/browser/challenge/__init__.py +13 -0
- package/school/paper_search_school/browser/{challenges.py → challenge/detection.py} +1 -1
- package/school/paper_search_school/browser/{challenge_interaction.py → challenge/interaction.py} +92 -19
- package/school/paper_search_school/browser/challenge/pointer.py +228 -0
- package/school/paper_search_school/browser/challenge/prompt.py +154 -0
- package/school/paper_search_school/browser/challenge/warmup.py +90 -0
- package/school/paper_search_school/browser/driver.py +12 -0
- package/school/paper_search_school/browser/profiles.py +54 -3
- package/school/paper_search_school/browser/watchdog.py +8 -0
- package/school/paper_search_school/cli.py +150 -10
- package/school/paper_search_school/cold_start.py +5 -2
- package/school/paper_search_school/config.py +25 -1
- package/school/paper_search_school/download_diagnostics.py +3 -2
- package/school/paper_search_school/edition.py +22 -0
- package/school/paper_search_school/engine/access_rules.py +62 -2
- package/school/paper_search_school/engine/batch.py +56 -12
- package/school/paper_search_school/engine/batch_access.py +12 -1
- package/school/paper_search_school/engine/batch_capture.py +309 -9
- package/school/paper_search_school/engine/batch_common.py +3 -1
- package/school/paper_search_school/engine/batch_institution.py +145 -21
- package/school/paper_search_school/engine/batch_login.py +554 -21
- package/school/paper_search_school/engine/batch_waits.py +76 -1
- package/school/paper_search_school/engine/bridge.py +139 -7
- package/school/paper_search_school/engine/fulltext_page.py +340 -0
- package/school/paper_search_school/engine/pdf_guard.py +65 -5
- package/school/paper_search_school/engine/router.py +3 -2
- package/school/paper_search_school/engine/supplement_transfer.py +22 -7
- package/school/paper_search_school/engine/supplements.py +5 -8
- package/school/paper_search_school/federations/__init__.py +9 -6
- package/school/paper_search_school/{carsi_schools.py → federations/carsi.py} +1 -1
- package/school/paper_search_school/federations/{builtin → data/asia}/cstcloud.json +2 -2
- package/school/paper_search_school/federations/{builtin → data/europe}/eduidhu.json +2 -2
- package/school/paper_search_school/login_routes.py +45 -0
- package/school/paper_search_school/markdown_report.py +426 -0
- package/school/paper_search_school/orchestrator.py +25 -1
- package/school/paper_search_school/pro_status.py +192 -0
- package/school/paper_search_school/progress_capsule.py +192 -2
- package/school/paper_search_school/progress_reporter.py +100 -16
- package/school/paper_search_school/progress_status.py +1 -1
- package/school/paper_search_school/progress_view.py +171 -26
- package/school/paper_search_school/publishers/profiles.py +6 -0
- package/school/paper_search_school/rate_limit.py +7 -0
- package/school/paper_search_school/report_sanitizer.py +25 -11
- package/school/paper_search_school/school_login.py +373 -0
- package/school/paper_search_school/schools/__init__.py +7 -0
- package/school/paper_search_school/{federations/schools.py → schools/lookup.py} +3 -3
- package/school/paper_search_school/schools/saved.py +111 -0
- package/school/paper_search_school/server.py +53 -9
- package/school/paper_search_school/user_settings.py +14 -0
- package/school/pyproject.toml +3 -2
- package/skills/paper-search/SKILL.md +11 -12
- package/skills/paper-search/references/browser-download.md +20 -15
- package/skills/paper-search/references/capability-routing.md +1 -1
- package/skills/paper-search/references/cli-contract.md +7 -5
- package/skills/paper-search/references/management-layer.md +3 -3
- package/skills/paper-search/references/publisher-support.md +5 -5
- package/skills/paper-search/references/school-setup.md +14 -0
- package/skills/paper-search/references/troubleshooting.md +0 -1
- package/assets/ask-with-skill.png +0 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/DownloadTier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.js +0 -191
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.js +0 -166
- package/dist/capabilities/pdf-discovery/handler.js.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.js.map +0 -1
- package/dist/capabilities/pdf-discovery/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.js.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.js.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.d.ts +0 -22
- package/dist/capabilities/pdf-discovery/resume.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.js +0 -114
- package/dist/capabilities/pdf-discovery/resume.js.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.js +0 -75
- package/dist/capabilities/pdf-discovery/schemas.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.js +0 -2
- package/dist/capabilities/pdf-discovery/school/types.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts +0 -10
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.js +0 -146
- package/dist/capabilities/pdf-discovery/tools.js.map +0 -1
- package/dist/capabilities/pdf-discovery/types.d.ts +0 -102
- package/dist/capabilities/pdf-discovery/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/types.js +0 -2
- package/dist/capabilities/pdf-discovery/types.js.map +0 -1
- /package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/primary.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/scihub.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download}/outputLayout.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.d.ts +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidbf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidma.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidtg.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/fidern.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/garnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/maren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ngrenid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rafiki.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/safire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ternet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/caf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cofre.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/colfire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/fenix.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/incommon.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/minga.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/azsciencenet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/carsi.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/cynet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/gakunin.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/hkaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/infed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/irfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/iucc.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/kafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/liaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/maeen.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/omren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/pkifed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sgaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sifulan.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/tigerfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/yetkim.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaieduhr.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaiedumk.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aconet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/arnesaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/belnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/bif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/dfnaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/edugate.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidcz.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidlu.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/febas.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/feide.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/grnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/haka.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/iamres.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idedume.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idem.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/laife.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/leaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/litnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/peano.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/pionierid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rash.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rctsaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/renater.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ricerkanet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/roedunetid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/safeid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/sir.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/surfconext.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/swamid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/switchaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/taat.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ukfederation.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/wayf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/global}/openathens.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/aaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/tuakiri.json +0 -0
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { resolveDownloadPath } from "
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
import { createOutputLayout, inPaperDir, isInside, lookupOutputMetadata, moveIntoPaperDir, organizeFiles, removeWorkFolder } from "./outputLayout.js";
|
|
1
|
+
import { resolveDownloadPath } from "../../../config/ConfigService.js";
|
|
4
2
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { RunLedger } from "
|
|
6
|
-
import {
|
|
7
|
-
import { createDefaultDownloadTiers, downloadWithFallback, } from "
|
|
8
|
-
import { schoolAttemptDetails, schoolShortReason } from "
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { RunLedger } from "../../../infrastructure/runlog/RunLedger.js";
|
|
4
|
+
import { FAILURE_CLASS_NAMES, } from "../../../infrastructure/runlog/failureClass.js";
|
|
5
|
+
import { createDefaultDownloadTiers, downloadWithFallback, } from "../content/pdf/OpenAccessFallbackService.js";
|
|
6
|
+
import { schoolAttemptDetails, schoolShortReason } from "../../../infrastructure/school/index.js";
|
|
7
|
+
import { downloadSupplementsOnly, filesPastNetworkLoss } from "../content/supplements/fetch.js";
|
|
8
|
+
import { supplementShortfall } from "../content/supplements/shortfall.js";
|
|
9
|
+
import { fulltextPageVisit } from "../content/markdown/pageVisit.js";
|
|
10
|
+
import { fulltextAlone, fulltextForItem, markdownBeside, markdownPastNetworkLoss } from "../content/markdown/step.js";
|
|
11
|
+
import { markdownDoubt, markdownMissing } from "../content/markdown/shortfall.js";
|
|
12
|
+
import { batchPaper, failure, reportBatchResults, stoppedItem } from "./batchSummary.js";
|
|
13
|
+
import { loadMarkdownPro, markdownBlocked } from "../content/markdown/pro.js";
|
|
11
14
|
import { PaperList } from "./batchPapers.js";
|
|
12
|
-
|
|
15
|
+
import { networkReachable, pastNetworkLoss } from "./networkLoss.js";
|
|
16
|
+
import { openBatchFolder } from "./batchFolder.js";
|
|
13
17
|
/** From this many items the progress window opens at the start, in the open-access stretch. */
|
|
14
18
|
export const OPEN_PROGRESS_MIN_ITEMS = 5;
|
|
15
19
|
/** Every source that needs no browser: open access, publisher APIs, Sci-Hub when on (the guide's 开放下载). */
|
|
@@ -61,90 +65,11 @@ function itemOptions(item, options) {
|
|
|
61
65
|
useEntitledAccess: options.useEntitledAccess,
|
|
62
66
|
useSciHub: options.useSciHub,
|
|
63
67
|
...(options.content && options.content !== "main" ? { content: options.content } : {}),
|
|
68
|
+
...(options.fulltext ? { fulltext: true } : {}),
|
|
69
|
+
...(options.fulltext && options.mode === "entitled_only" ? { fulltextPageOnly: true } : {}),
|
|
70
|
+
...(options.school?.trim() ? { school: options.school.trim() } : {}),
|
|
64
71
|
};
|
|
65
72
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Supplementary files only: the entitled-access backend visits the article
|
|
68
|
-
* page for them. An empty completed check is also ok; it is not a failed download,
|
|
69
|
-
* nor is a site without a supplementary-file rule (user, 2026-11-11). Reported to
|
|
70
|
-
* the run ledger through ``request.onStage`` as the "supplements" stage.
|
|
71
|
-
* ``mainPath``: the paper's main text, saved before; once a file is saved it moves
|
|
72
|
-
* into the paper's folder beside them (the returned ``path``).
|
|
73
|
-
*/
|
|
74
|
-
export async function downloadSupplementsOnly(request, backend, searchers, mainPath) {
|
|
75
|
-
request = { ...request, savePath: resolveDownloadPath(request.savePath) };
|
|
76
|
-
const startedAt = Date.now();
|
|
77
|
-
const metadata = searchers ? await lookupOutputMetadata(searchers, request.doi ? "crossref" : request.source, request.doi || request.paperId) : {};
|
|
78
|
-
let layout = createOutputLayout(request.savePath, request.doi || request.paperId, { ...metadata, title: request.title || metadata.title }, false, { diagnosticsDir: request.diagnosticsDir });
|
|
79
|
-
// A main text already in a folder of its own (an earlier download): its files go beside it.
|
|
80
|
-
const mainDir = mainPath ? dirname(mainPath) : "";
|
|
81
|
-
if (mainDir && isInside(mainDir, request.savePath))
|
|
82
|
-
layout = inPaperDir(layout, mainDir);
|
|
83
|
-
let trace;
|
|
84
|
-
const files = await fetchSupplementsOnly(backend, {
|
|
85
|
-
identifier: request.doi || request.paperId,
|
|
86
|
-
outputDir: layout.paperDir,
|
|
87
|
-
diagnosticsDir: layout.workDiagnosticsDir,
|
|
88
|
-
...(request.batch ? { batch: request.batch } : {}),
|
|
89
|
-
...(request.shortUserWait ? { userWait: "short" } : {}),
|
|
90
|
-
}, value => { trace = value; });
|
|
91
|
-
const saved = files?.filter((f) => f.status === "saved").length ?? 0;
|
|
92
|
-
const noneListed = files?.length === 0;
|
|
93
|
-
// No rule for the site's supplementary files: not known whether there are any, and no fault to diagnose.
|
|
94
|
-
const unsupported = !!files?.length && files.every((file) => file.reason === "supplements_not_supported");
|
|
95
|
-
let filingFailed = false;
|
|
96
|
-
let movedMain;
|
|
97
|
-
try {
|
|
98
|
-
const status = files?.every((file) => file.status === "saved") || unsupported ? "ok" : "error";
|
|
99
|
-
if (files)
|
|
100
|
-
organizeFiles({ supplements: files, trace, status }, layout, layout.paperDir, undefined, request.recordsDir);
|
|
101
|
-
if (saved && mainPath) {
|
|
102
|
-
const moved = moveIntoPaperDir(mainPath, layout);
|
|
103
|
-
if (moved !== mainPath)
|
|
104
|
-
movedMain = moved;
|
|
105
|
-
}
|
|
106
|
-
removeWorkFolder(layout);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
filingFailed = true;
|
|
110
|
-
} // Preserve saved files and report filing separately below.
|
|
111
|
-
const attempt = files === undefined
|
|
112
|
-
? { stage: "supplements", status: "skipped", message: "No entitled-access backend for supplementary files." }
|
|
113
|
-
: noneListed
|
|
114
|
-
? { stage: "supplements", status: "skipped", code: "no_supplements",
|
|
115
|
-
message: "Article page checked; no supplementary files were listed." }
|
|
116
|
-
: unsupported
|
|
117
|
-
? { stage: "supplements", status: "skipped", code: "supplements_not_supported",
|
|
118
|
-
message: "No supplementary-file rule for this site yet; get them from the article page by hand." }
|
|
119
|
-
: {
|
|
120
|
-
stage: "supplements",
|
|
121
|
-
status: saved ? "ok" : "error",
|
|
122
|
-
message: `${saved}/${files.length} supplementary files saved.`,
|
|
123
|
-
...(saved ? {} : { code: "supplements_failed" }),
|
|
124
|
-
};
|
|
125
|
-
request.onStage?.({ ...attempt, ...(trace ? { trace } : {}), startedAt: new Date(startedAt).toISOString(), durationMs: Date.now() - startedAt });
|
|
126
|
-
const title = request.title || metadata.title;
|
|
127
|
-
return {
|
|
128
|
-
status: saved || noneListed || unsupported ? "ok" : "error",
|
|
129
|
-
...(movedMain ? { path: movedMain } : {}),
|
|
130
|
-
...(title ? { title } : {}),
|
|
131
|
-
...(metadata.journal ? { journal: metadata.journal } : {}),
|
|
132
|
-
attempts: [attempt, ...(filingFailed ? [{ stage: "output_layout", status: "error",
|
|
133
|
-
code: "output_layout_failed", message: "File organization failed; use the returned file paths." }] : [])],
|
|
134
|
-
...(files ? { supplements: files } : {}),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/** content "both": supplementary files for an item whose main text came from an open stage. */
|
|
138
|
-
async function supplementsForOpenItem(result, request, backend, searchers) {
|
|
139
|
-
if (request.content !== "both" || result.status !== "ok" || result.supplements)
|
|
140
|
-
return;
|
|
141
|
-
const extra = await downloadSupplementsOnly({ ...request, ...(result.publishedDoi ? { doi: result.publishedDoi } : {}) }, backend, searchers, result.path && !result.version ? result.path : undefined);
|
|
142
|
-
if (extra.supplements)
|
|
143
|
-
result.supplements = extra.supplements;
|
|
144
|
-
if (extra.path)
|
|
145
|
-
result.path = extra.path; // moved into its folder beside the files
|
|
146
|
-
return extra;
|
|
147
|
-
}
|
|
148
73
|
/**
|
|
149
74
|
* A school login that lapsed, and nothing else: the paper's wait ran out (login_timeout) on
|
|
150
75
|
* the school's own sign-in page, a password box or the school's sign-in step, as the backend
|
|
@@ -170,14 +95,15 @@ function waitedOutOnUser(result) {
|
|
|
170
95
|
(attempt.code === "login_timeout" || attempt.code === "download_timeout")));
|
|
171
96
|
}
|
|
172
97
|
/**
|
|
173
|
-
*
|
|
174
|
-
* limit was reached before it opened (dependencies section 6, state L).
|
|
98
|
+
* The seconds the backend asked this article to wait, and whose limit it is: the publisher's
|
|
99
|
+
* hourly limit was reached before it opened (dependencies section 6, state L).
|
|
175
100
|
*/
|
|
176
101
|
function rateLimitWait(result) {
|
|
177
102
|
if (result.status === "ok")
|
|
178
|
-
return
|
|
103
|
+
return undefined;
|
|
179
104
|
const attempt = result.attempts.find((a) => a.stage === "entitled_access" && a.code === "rate_limited");
|
|
180
|
-
return attempt ? Math.max(1, Math.min(3600, attempt.retryAfterSec ?? 60))
|
|
105
|
+
return attempt ? { wait: Math.max(1, Math.min(3600, attempt.retryAfterSec ?? 60)),
|
|
106
|
+
...(attempt.hourlyPublisher ? { publisher: attempt.hourlyPublisher } : {}) } : undefined;
|
|
181
107
|
}
|
|
182
108
|
/**
|
|
183
109
|
* How often a batch waiting for the hourly limit keeps the publisher's session alive:
|
|
@@ -185,26 +111,73 @@ function rateLimitWait(result) {
|
|
|
185
111
|
* and the school's login had expired by then too (Windows, 2026-11-12).
|
|
186
112
|
*/
|
|
187
113
|
export const KEEP_SESSION_EVERY_MS = 10 * 60_000;
|
|
114
|
+
/**
|
|
115
|
+
* How often a batch waiting for the hourly limit asks the backend how long it still waits: with
|
|
116
|
+
* the settings window's 马上生效 on, a limit raised there, or none, goes on at once (the user,
|
|
117
|
+
* 2026-11-19). Each ask reads the backend's settings and count only.
|
|
118
|
+
*/
|
|
119
|
+
export const HOURLY_RECHECK_EVERY_MS = 10_000;
|
|
188
120
|
/**
|
|
189
121
|
* Runs the item again after each wait the publisher's hourly limit asks for. During a
|
|
190
|
-
* wait,
|
|
122
|
+
* wait, the backend's keepSession runs every KEEP_SESSION_EVERY_MS.
|
|
191
123
|
*/
|
|
192
|
-
async function pastHourlyLimit(run, log, pause,
|
|
124
|
+
async function pastHourlyLimit(run, log, pause, backend) {
|
|
193
125
|
let result = await run();
|
|
194
|
-
for (let
|
|
195
|
-
|
|
196
|
-
log(`[批量] 这家出版社一小时内的下载已到上限(防止学校被暂停访问),${resume} 继续这一篇`);
|
|
197
|
-
for (let left = wait * 1000; left > 0;) {
|
|
198
|
-
const step = Math.min(left, KEEP_SESSION_EVERY_MS);
|
|
199
|
-
await pause(step);
|
|
200
|
-
left -= step;
|
|
201
|
-
if (left > 0 && keep)
|
|
202
|
-
await keep().catch(() => false);
|
|
203
|
-
}
|
|
126
|
+
for (let held = rateLimitWait(result); held; held = rateLimitWait(result)) {
|
|
127
|
+
await waitOutHour(held.wait, log, pause, backend, held.publisher);
|
|
204
128
|
result = await run();
|
|
205
129
|
}
|
|
206
130
|
return result;
|
|
207
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The wait the publisher's hourly limit asks for, said once, the session kept alive meanwhile.
|
|
134
|
+
* A backend that can say how long ``publisher`` still waits is asked every
|
|
135
|
+
* HOURLY_RECHECK_EVERY_MS: the wait ends as soon as the limit the user set allows the article.
|
|
136
|
+
*/
|
|
137
|
+
async function waitOutHour(wait, log, pause, backend, publisher) {
|
|
138
|
+
const resume = new Date(Date.now() + wait * 1000).toTimeString().slice(0, 5);
|
|
139
|
+
log(`[批量] 这家出版社一小时内的下载已到上限(防止学校被暂停访问),${resume} 继续这一篇`);
|
|
140
|
+
const recheck = publisher && backend?.hourlyWait ? () => backend.hourlyWait(publisher) : undefined;
|
|
141
|
+
let sinceKeep = 0;
|
|
142
|
+
for (let left = wait * 1000; left > 0;) {
|
|
143
|
+
const step = Math.min(left, KEEP_SESSION_EVERY_MS - sinceKeep, recheck ? HOURLY_RECHECK_EVERY_MS : Infinity);
|
|
144
|
+
await pause(step);
|
|
145
|
+
left -= step;
|
|
146
|
+
sinceKeep += step;
|
|
147
|
+
if (left <= 0)
|
|
148
|
+
break;
|
|
149
|
+
const now = recheck ? await recheck().catch(() => undefined) : undefined;
|
|
150
|
+
if (now?.waitSec === 0) {
|
|
151
|
+
log(`[批量] 按现在的每小时上限(${now.limit > 0 ? `${now.limit} 篇` : "不限"})可以接着下这一篇`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (now)
|
|
155
|
+
left = now.waitSec * 1000;
|
|
156
|
+
if (sinceKeep >= KEEP_SESSION_EVERY_MS) {
|
|
157
|
+
sinceKeep = 0;
|
|
158
|
+
await backend?.keepSession?.().catch(() => false);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A batch's visit for an article page alone (its Markdown), waiting out the publisher's
|
|
164
|
+
* hourly limit as a download does: the page reads count toward it, and with no PDF in the
|
|
165
|
+
* Markdown's place there is no download to wait in (user, 2026-11-16).
|
|
166
|
+
*/
|
|
167
|
+
function pageVisit(backend, request, log, pause, seen) {
|
|
168
|
+
const visit = fulltextPageVisit(backend, request);
|
|
169
|
+
if (!visit)
|
|
170
|
+
return undefined;
|
|
171
|
+
return async (doi, outputDir, diagnosticsDir) => {
|
|
172
|
+
let outcome = await visit(doi, outputDir, diagnosticsDir);
|
|
173
|
+
while (outcome?.code === "rate_limited") {
|
|
174
|
+
await waitOutHour(Math.max(1, Math.min(3600, outcome.retryAfterSec ?? 60)), log, pause, backend, outcome.hourlyPublisher);
|
|
175
|
+
outcome = await visit(doi, outputDir, diagnosticsDir);
|
|
176
|
+
}
|
|
177
|
+
seen?.(outcome?.trace);
|
|
178
|
+
return outcome;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
208
181
|
/** The journal's site blocked the current network (state L): a protection page,
|
|
209
182
|
* or the school paused for downloading too much. The backend answers the
|
|
210
183
|
* journal's later items at once; every other item goes on (the user, 2026-11-02). */
|
|
@@ -216,7 +189,7 @@ function stoppedByUser(result) {
|
|
|
216
189
|
const STOP_NOTICE = "[批量] 已在进度窗口终止任务,剩下的篇目不再下载";
|
|
217
190
|
/** The user pressed 终止 in the batch's window (papers not reached, or still paused, show it). */
|
|
218
191
|
export function batchStopped(result) {
|
|
219
|
-
return result.items.some((item) => stoppedByUser(item) || item.attempts.some((attempt) => attempt.code === "login_paused"));
|
|
192
|
+
return !!result.stopped || result.items.some((item) => stoppedByUser(item) || item.attempts.some((attempt) => attempt.code === "login_paused"));
|
|
220
193
|
}
|
|
221
194
|
/** The attempt recorded for an item the batch did not reach because the user stopped it. */
|
|
222
195
|
function notReached() {
|
|
@@ -239,6 +212,15 @@ function runItem(index, request) {
|
|
|
239
212
|
...(request.title ? { title: request.title } : {}),
|
|
240
213
|
};
|
|
241
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* A failed paper's class and reason, as the failed list names them (batchSummary.failure);
|
|
217
|
+
* undefined for a saved paper or one the stop left undone. Every failed paper is in a class: a
|
|
218
|
+
* batch of the Markdown alone counted only those whose step ended in an error, "失败 6" beside
|
|
219
|
+
* classes of 1 (AHA, 2026-11-17).
|
|
220
|
+
*/
|
|
221
|
+
function failedAs(item, content) {
|
|
222
|
+
return item.status === "ok" || stoppedItem(item) ? undefined : failure(item, content ?? "main");
|
|
223
|
+
}
|
|
242
224
|
/** Request options that report each stage of ``item`` to the ledger. */
|
|
243
225
|
function recorded(request, ledger, item) {
|
|
244
226
|
return ledger
|
|
@@ -253,10 +235,13 @@ function openLedger(mode, batchId, options, log) {
|
|
|
253
235
|
total: options.items.length,
|
|
254
236
|
...(options.savePath ? { savePath: options.savePath } : {}),
|
|
255
237
|
content: options.content ?? "main",
|
|
238
|
+
...(options.fulltext ? { fulltext: true } : {}),
|
|
239
|
+
...(options.school?.trim() ? { school: options.school.trim() } : {}),
|
|
256
240
|
...(options.resumeOf ? { resumeOf: options.resumeOf } : {}),
|
|
257
241
|
});
|
|
258
242
|
if (ledger)
|
|
259
243
|
log(`[批量] 运行记录:${ledger.dir}`);
|
|
244
|
+
options.folderRecord?.attach(ledger);
|
|
260
245
|
return ledger;
|
|
261
246
|
}
|
|
262
247
|
function itemResult(result, index, options) {
|
|
@@ -270,13 +255,12 @@ function itemResult(result, index, options) {
|
|
|
270
255
|
function summary(mode, batchId, items, extra = {}) {
|
|
271
256
|
const succeeded = items.filter((item) => item.status === "ok").length;
|
|
272
257
|
const failed = items.length - succeeded;
|
|
258
|
+
const stopped = items.filter(stoppedItem).length;
|
|
273
259
|
const failureClasses = {};
|
|
274
260
|
for (const item of items) {
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
const failureClass = classifyFailureCode(entitled.code);
|
|
279
|
-
failureClasses[failureClass] = (failureClasses[failureClass] ?? 0) + 1;
|
|
261
|
+
const failed = failedAs(item, extra.content);
|
|
262
|
+
if (failed)
|
|
263
|
+
failureClasses[failed.cls] = (failureClasses[failed.cls] ?? 0) + 1;
|
|
280
264
|
}
|
|
281
265
|
return {
|
|
282
266
|
status: failed === 0 ? "ok" : succeeded === 0 ? "error" : "partial",
|
|
@@ -286,27 +270,74 @@ function summary(mode, batchId, items, extra = {}) {
|
|
|
286
270
|
total: items.length,
|
|
287
271
|
succeeded,
|
|
288
272
|
failed,
|
|
273
|
+
...(stopped ? { stoppedItems: stopped } : {}),
|
|
289
274
|
...(Object.keys(failureClasses).length ? { failureClasses } : {}),
|
|
290
275
|
...extra,
|
|
291
276
|
items,
|
|
292
277
|
};
|
|
293
278
|
}
|
|
294
279
|
/** Download a list serially; one batch id ties it to one progress window. */
|
|
295
|
-
export async function downloadBatch(searchers, options, backend, log = (line) => process.stderr.write(`${line}\n`), createTiers = createDefaultDownloadTiers, pause = wait) {
|
|
280
|
+
export async function downloadBatch(searchers, options, backend, log = (line) => process.stderr.write(`${line}\n`), createTiers = createDefaultDownloadTiers, pause = wait, online = networkReachable) {
|
|
296
281
|
options = { ...options, savePath: resolveDownloadPath(options.savePath) };
|
|
282
|
+
// The batch's own folder keeps its records beside its papers (user, 2026-11-17).
|
|
283
|
+
const { folderRecord: _given, ...asked } = options;
|
|
284
|
+
const folderRecord = openBatchFolder(options.savePath, asked);
|
|
285
|
+
if (folderRecord) {
|
|
286
|
+
const out = log;
|
|
287
|
+
log = (line) => {
|
|
288
|
+
out(line);
|
|
289
|
+
folderRecord.log(line);
|
|
290
|
+
};
|
|
291
|
+
options = { ...options, folderRecord };
|
|
292
|
+
}
|
|
297
293
|
const startedAt = Date.now();
|
|
294
|
+
// The Markdown is PaperSearch Pro's (content/markdown/pro.ts): without it, or while it cannot
|
|
295
|
+
// be used, the batch says so once and its papers' Markdown says why.
|
|
296
|
+
const wantsMarkdown = !!options.fulltext || options.content === "markdown";
|
|
297
|
+
const pro = wantsMarkdown ? await loadMarkdownPro() : undefined;
|
|
298
|
+
const blocked = wantsMarkdown ? markdownBlocked(pro) : undefined;
|
|
299
|
+
if (blocked)
|
|
300
|
+
log(`[批量] ${blocked.code === "markdown_pro_required" ? "Markdown 全文是 PaperSearch Pro 的功能,本机没有安装 Pro(设置窗口的“Markdown 全文”页点“安装”,或运行 paper-search pro install)" : `PaperSearch Pro 暂不可用:${blocked.message}`};PDF 和补充材料照常下载`);
|
|
301
|
+
// Each batch tries the sites not yet supported afresh (three failures in a row give one up).
|
|
302
|
+
if (pro && !blocked)
|
|
303
|
+
pro.batchStarted();
|
|
304
|
+
// Their first papers go first, so how they convert shows early (landingScan.ts, user 2026-11-16).
|
|
305
|
+
if (pro && !blocked && backend && options.items.length > pro.triedFirstCount) {
|
|
306
|
+
const dois = options.items.flatMap((item) => (item.doi ? [item.doi] : []));
|
|
307
|
+
const { items, sites } = pro.triedFirst(options.items, await pro.landingHosts(dois));
|
|
308
|
+
if (sites.length) {
|
|
309
|
+
options = { ...options, items };
|
|
310
|
+
log(`[批量] 预查:${sites.map((site) => `${site.host} ${site.papers} 篇`).join("、")},这些网站没有登记 Markdown 规则,`
|
|
311
|
+
+ `各先试前 ${pro.triedFirstCount} 篇(先用出版社的规则);转换完整才保存,前 ${pro.triedFirstCount} 篇都不完整的本批不再尝试`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
298
314
|
const run = async (backend) => {
|
|
299
|
-
const result = await (options.content === "supplements"
|
|
300
|
-
?
|
|
315
|
+
const result = await (options.content === "supplements" || options.content === "markdown"
|
|
316
|
+
? downloadSerialBatch(options, backend, log, searchers, createTiers, pause, online)
|
|
301
317
|
: options.mode === "per_item"
|
|
302
|
-
? downloadPerItem(searchers, options, backend, log, createTiers, pause)
|
|
303
|
-
: downloadTwoPhase(searchers, options, backend, log, createTiers, options.mode === "entitled_only" ? "entitled_only" : "two_phase", pause));
|
|
318
|
+
? downloadPerItem(searchers, options, backend, log, createTiers, pause, online)
|
|
319
|
+
: downloadTwoPhase(searchers, options, backend, log, createTiers, options.mode === "entitled_only" ? "entitled_only" : "two_phase", pause, online));
|
|
304
320
|
await reportBatchResults(result, backend, startedAt, options.savePath);
|
|
305
321
|
return result;
|
|
306
322
|
};
|
|
307
323
|
const result = await (backend?.withBatchSession ? backend.withBatchSession(run) : run(backend));
|
|
324
|
+
// Each class with its reasons: "原因不明 1(PDF 身份未确认 1)", not a class alone beside the
|
|
325
|
+
// list's reason (Windows, 2026-11-17).
|
|
326
|
+
const reasons = new Map();
|
|
327
|
+
for (const item of result.items) {
|
|
328
|
+
const failed = failedAs(item, result.content);
|
|
329
|
+
if (!failed)
|
|
330
|
+
continue;
|
|
331
|
+
const byReason = reasons.get(failed.cls) ?? new Map();
|
|
332
|
+
byReason.set(failed.reason, (byReason.get(failed.reason) ?? 0) + 1);
|
|
333
|
+
reasons.set(failed.cls, byReason);
|
|
334
|
+
}
|
|
308
335
|
const byClass = Object.entries(result.failureClasses ?? {})
|
|
309
|
-
.map(([failureClass, count]) =>
|
|
336
|
+
.map(([failureClass, count]) => {
|
|
337
|
+
const said = [...(reasons.get(failureClass) ?? [])].sort((a, b) => b[1] - a[1]);
|
|
338
|
+
const listed = said.slice(0, 3).map(([reason, n]) => `${reason} ${n}`).join("、") + (said.length > 3 ? " 等" : "");
|
|
339
|
+
return `${FAILURE_CLASS_NAMES[failureClass]} ${count}` + (listed ? `(${listed})` : "");
|
|
340
|
+
})
|
|
310
341
|
.join("、");
|
|
311
342
|
// Main text and supplementary files apart: "附录未下全 2 篇:网站人机验证拦截 2".
|
|
312
343
|
const shortfalls = new Map();
|
|
@@ -318,33 +349,88 @@ export async function downloadBatch(searchers, options, backend, log = (line) =>
|
|
|
318
349
|
shortfalls.set(reason, (shortfalls.get(reason) ?? 0) + 1);
|
|
319
350
|
}
|
|
320
351
|
const missed = [...shortfalls.values()].reduce((sum, n) => sum + n, 0);
|
|
321
|
-
|
|
352
|
+
// The Markdown not saved, by reason: beside the PDF or the files, for a paper saved without
|
|
353
|
+
// it (432 such went unsaid at the end of an ARD batch, user 2026-11-16); in a batch of the
|
|
354
|
+
// Markdown alone, for each paper it failed.
|
|
355
|
+
const noMarkdown = new Map();
|
|
356
|
+
for (const item of result.items) {
|
|
357
|
+
if (!item.markdown || item.markdown.status === "ok" || stoppedItem(item))
|
|
358
|
+
continue;
|
|
359
|
+
if (result.content !== "markdown" && item.status !== "ok")
|
|
360
|
+
continue;
|
|
361
|
+
const { reason } = markdownMissing(item.markdown);
|
|
362
|
+
const site = item.markdown.unverified ? `(${item.markdown.unverified.host})` : "";
|
|
363
|
+
noMarkdown.set(reason + site, (noMarkdown.get(reason + site) ?? 0) + 1);
|
|
364
|
+
}
|
|
365
|
+
const incomplete = [...noMarkdown.values()].reduce((sum, n) => sum + n, 0);
|
|
366
|
+
// Saved, its checks finding something short (a registered site's page, user 2026-11-17).
|
|
367
|
+
const doubts = new Map();
|
|
368
|
+
for (const item of result.items) {
|
|
369
|
+
const doubt = item.status === "ok" ? markdownDoubt(item.markdown) : undefined;
|
|
370
|
+
if (doubt)
|
|
371
|
+
doubts.set(doubt.reason, (doubts.get(doubt.reason) ?? 0) + 1);
|
|
372
|
+
}
|
|
373
|
+
const doubtful = [...doubts.values()].reduce((sum, n) => sum + n, 0);
|
|
374
|
+
// Papers the stop left undone are told apart, not counted as failed (user, 2026-11-16).
|
|
375
|
+
const stopped = result.stoppedItems ?? 0;
|
|
376
|
+
log(`[批量] 完成:成功 ${result.succeeded},失败 ${result.failed - stopped}` + (stopped ? `,已终止 ${stopped}` : "")
|
|
377
|
+
+ `,共 ${result.total} 篇` +
|
|
322
378
|
(byClass ? `。失败分类:${byClass};详情:paper-search failures --format text` : "") +
|
|
323
|
-
(missed ? `。附录未下全 ${missed} 篇:${[...shortfalls].map(([reason, n]) => `${reason} ${n}`).join("、")}` : "")
|
|
379
|
+
(missed ? `。附录未下全 ${missed} 篇:${[...shortfalls].map(([reason, n]) => `${reason} ${n}`).join("、")}` : "") +
|
|
380
|
+
(incomplete ? `。Markdown 未生成 ${incomplete} 篇:${[...noMarkdown].map(([reason, n]) => `${reason} ${n}`).join("、")}` : "") +
|
|
381
|
+
(doubtful ? `。Markdown 可能不全 ${doubtful} 篇(已保存,请核对):${[...doubts].map(([reason, n]) => `${reason} ${n}`).join("、")}` : ""));
|
|
324
382
|
// What is left goes on later with one word (user, 2026-11-15).
|
|
325
|
-
if ((result.failed || missed) && result.runLog) {
|
|
383
|
+
if ((result.failed || missed || incomplete) && result.runLog) {
|
|
326
384
|
log("[批量] 没下全的篇目:回来后对 AI 说“接着下”即可补(download_batch 的 resume: \"latest\",同一套环境变量)");
|
|
327
385
|
}
|
|
386
|
+
folderRecord?.refresh();
|
|
328
387
|
return result;
|
|
329
388
|
}
|
|
330
|
-
/**
|
|
331
|
-
|
|
389
|
+
/**
|
|
390
|
+
* content "supplements" or "markdown": every item, one after another, without the main
|
|
391
|
+
* text's stages: its supplementary files, its Markdown (the full-text package, no PDF in
|
|
392
|
+
* its place: user, 2026-11-16), or both (user, 2026-11-14).
|
|
393
|
+
*/
|
|
394
|
+
async function downloadSerialBatch(options, backend, log, searchers, createTiers, pause, online) {
|
|
395
|
+
const content = options.content === "markdown" ? "markdown" : "supplements";
|
|
332
396
|
const batchId = randomUUID();
|
|
333
397
|
const total = options.items.length;
|
|
334
|
-
const ledger = openLedger(
|
|
398
|
+
const ledger = openLedger(content, batchId, options, log);
|
|
399
|
+
const watch = { log, pause, online };
|
|
335
400
|
// The window's lists (成功, 失败, 剩余 open on a click), as the other batches send them: a
|
|
336
|
-
// batch of the files alone sent none (Windows, 2026-11-15).
|
|
337
|
-
const papers = new PaperList(backend, batchId, options.savePath, options.items.map((item) => batchPaper(itemOptions(item, options), undefined, "open",
|
|
401
|
+
// batch of the Markdown or the files alone sent none (Windows, 2026-11-15).
|
|
402
|
+
const papers = new PaperList(backend, batchId, options.savePath, options.items.map((item) => batchPaper(itemOptions(item, options), undefined, "open", content, item.mainPath)));
|
|
338
403
|
await papers.send();
|
|
339
404
|
const items = [];
|
|
340
405
|
let succeeded = 0;
|
|
341
406
|
let failed = 0;
|
|
407
|
+
let away = false;
|
|
342
408
|
for (const [offset, item] of options.items.entries()) {
|
|
343
409
|
const batch = { id: batchId, index: offset + 1, total, done: offset, succeeded, failed };
|
|
344
|
-
const request = { ...itemOptions(item, options), batch };
|
|
410
|
+
const request = { ...itemOptions(item, options), batch, ...(away ? { shortUserWait: true } : {}) };
|
|
345
411
|
const entry = runItem(offset + 1, request);
|
|
346
|
-
log(`[批量] 补充材料 ${offset + 1}/${total}:${request.doi || request.paperId}`);
|
|
347
|
-
|
|
412
|
+
log(`[批量] ${content === "markdown" ? "Markdown" : options.fulltext ? "补充材料和 Markdown" : "补充材料"} ${offset + 1}/${total}:${request.doi || request.paperId}`);
|
|
413
|
+
// 接着下 (resume.ts): a paper whose PDF a batch saved before gets its Markdown beside it, not the PDF again.
|
|
414
|
+
// Done again after a network loss, from what was there before it (``before`` copied each time).
|
|
415
|
+
const markdown = (before) => pastNetworkLoss(() => {
|
|
416
|
+
const from = { ...before, attempts: [...before.attempts] };
|
|
417
|
+
return item.mainPath
|
|
418
|
+
? markdownBeside(from, item.mainPath, recorded(request, ledger, entry), searchers, pageVisit(backend, request, log, pause))
|
|
419
|
+
: fulltextAlone(from, recorded(request, ledger, entry), searchers, pageVisit(backend, request, log, pause));
|
|
420
|
+
}, watch);
|
|
421
|
+
let result;
|
|
422
|
+
if (content === "markdown") {
|
|
423
|
+
result = await markdown({ status: "error", attempts: [] });
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
result = await pastNetworkLoss(() => downloadSupplementsOnly(recorded(request, ledger, entry), backend, searchers, item.mainPath), watch);
|
|
427
|
+
if (options.fulltext && !stoppedByUser(result))
|
|
428
|
+
result = await markdown(result);
|
|
429
|
+
}
|
|
430
|
+
if (!away && waitedOutOnUser(result)) {
|
|
431
|
+
away = true;
|
|
432
|
+
log(AWAY_NOTICE);
|
|
433
|
+
}
|
|
348
434
|
await reportBatchItem(request, result, backend);
|
|
349
435
|
if (result.status === "ok")
|
|
350
436
|
succeeded += 1;
|
|
@@ -352,17 +438,17 @@ async function downloadSupplementsBatch(options, backend, log, searchers) {
|
|
|
352
438
|
failed += 1;
|
|
353
439
|
ledger?.item(entry, result);
|
|
354
440
|
items.push(itemResult(result, offset + 1, request));
|
|
355
|
-
papers.set(offset, batchPaper(request, items[items.length - 1], undefined,
|
|
441
|
+
papers.set(offset, batchPaper(request, items[items.length - 1], undefined, content, item.mainPath));
|
|
356
442
|
if (stoppedByUser(result)) {
|
|
357
443
|
for (const [rest, item] of options.items.entries()) {
|
|
358
444
|
if (rest <= offset)
|
|
359
445
|
continue;
|
|
360
446
|
const request = itemOptions(item, options);
|
|
361
447
|
const skipped = itemResult({ status: "error", attempts: [notReached()],
|
|
362
|
-
supplements: [{ status: "skipped", label: "", reason: "batch_stopped" }] }, rest + 1, request);
|
|
448
|
+
...(content === "supplements" ? { supplements: [{ status: "skipped", label: "", reason: "batch_stopped" }] } : {}) }, rest + 1, request);
|
|
363
449
|
items.push(skipped);
|
|
364
450
|
ledger?.item(runItem(rest + 1, request), skipped);
|
|
365
|
-
papers.set(rest, batchPaper(request, skipped, undefined,
|
|
451
|
+
papers.set(rest, batchPaper(request, skipped, undefined, content, item.mainPath));
|
|
366
452
|
}
|
|
367
453
|
log(STOP_NOTICE);
|
|
368
454
|
break;
|
|
@@ -372,14 +458,15 @@ async function downloadSupplementsBatch(options, backend, log, searchers) {
|
|
|
372
458
|
await papers.send(true);
|
|
373
459
|
ledger?.close();
|
|
374
460
|
return summary(options.mode ?? "two_phase", batchId, items, {
|
|
375
|
-
content
|
|
461
|
+
content,
|
|
376
462
|
...(ledger ? { runLog: ledger.dir } : {}),
|
|
377
463
|
});
|
|
378
464
|
}
|
|
379
|
-
async function downloadPerItem(searchers, options, backend, log, createTiers, pause) {
|
|
465
|
+
async function downloadPerItem(searchers, options, backend, log, createTiers, pause, online) {
|
|
380
466
|
const batchId = randomUUID();
|
|
381
467
|
const total = options.items.length;
|
|
382
468
|
const ledger = openLedger("per_item", batchId, options, log);
|
|
469
|
+
const watch = { log, pause, online };
|
|
383
470
|
const content = options.content ?? "main";
|
|
384
471
|
const papers = new PaperList(backend, batchId, options.savePath, options.items.map((item) => batchPaper(itemOptions(item, options), undefined, "open", content)));
|
|
385
472
|
await papers.send();
|
|
@@ -393,7 +480,7 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
|
|
|
393
480
|
const entry = runItem(index, request);
|
|
394
481
|
log(`[批量] 第 ${index}/${total} 篇:${request.doi || request.paperId}`);
|
|
395
482
|
const batch = { id: batchId, index, total, done: offset, succeeded, failed };
|
|
396
|
-
const result = await pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend)), log, pause,
|
|
483
|
+
const result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadWithFallback(searchers, recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entry), createTiers(backend)), log, pause, backend), watch);
|
|
397
484
|
if (result.status === "ok")
|
|
398
485
|
succeeded += 1;
|
|
399
486
|
else
|
|
@@ -404,7 +491,10 @@ async function downloadPerItem(searchers, options, backend, log, createTiers, pa
|
|
|
404
491
|
}
|
|
405
492
|
const finished = itemResult(result, index, request);
|
|
406
493
|
if (!stoppedByUser(result))
|
|
407
|
-
await
|
|
494
|
+
await filesPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), backend, searchers, watch);
|
|
495
|
+
if (!stoppedByUser(result)) {
|
|
496
|
+
await markdownPastNetworkLoss(finished, recorded({ ...request, batch }, ledger, entry), searchers, pageVisit(backend, { ...request, batch }, log, pause), watch);
|
|
497
|
+
}
|
|
408
498
|
await reportBatchItem({ ...request, batch }, finished, backend);
|
|
409
499
|
ledger?.item(entry, finished);
|
|
410
500
|
items.push(finished);
|
|
@@ -441,7 +531,7 @@ function laneError(stage, error) {
|
|
|
441
531
|
message: error instanceof Error ? `${error.name}: ${error.message}` : String(error) }],
|
|
442
532
|
};
|
|
443
533
|
}
|
|
444
|
-
async function downloadTwoPhase(searchers, options, backend, log, createTiers, mode = "two_phase", pause = wait) {
|
|
534
|
+
async function downloadTwoPhase(searchers, options, backend, log, createTiers, mode = "two_phase", pause = wait, online = networkReachable) {
|
|
445
535
|
const batchId = randomUUID();
|
|
446
536
|
const total = options.items.length;
|
|
447
537
|
const ledger = openLedger(mode, batchId, options, log);
|
|
@@ -460,19 +550,25 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
460
550
|
};
|
|
461
551
|
const id = (offset) => requests[offset].doi || requests[offset].paperId;
|
|
462
552
|
// Two lanes at once. The open lane checks every item in turn, needing no
|
|
463
|
-
// browser; each item it misses joins the queue of the
|
|
553
|
+
// browser; each item it misses joins the queue of the browser's lane, which
|
|
464
554
|
// starts on the first one at once and takes them one after another (one
|
|
465
|
-
// browser, one school login).
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
|
|
555
|
+
// browser, one school login). Each paper is finished in its turn, its PDF, its
|
|
556
|
+
// supplementary files and its Markdown, never left for a later round (user,
|
|
557
|
+
// 2026-11-15): an open-access paper whose files or page need the browser joins
|
|
558
|
+
// the same queue, to be finished there. A large batch shows the window from the
|
|
559
|
+
// start: one count for the whole batch, where an item counts once it is finished.
|
|
560
|
+
const wantsFiles = options.content === "both";
|
|
561
|
+
const wantsMarkdown = !!options.fulltext;
|
|
562
|
+
/** Open-access papers in the browser's queue for their files or page. */
|
|
563
|
+
const finishing = new Set();
|
|
470
564
|
const openProgress = mode !== "entitled_only" && total >= OPEN_PROGRESS_MIN_ITEMS && !!backend?.reportBatchProgress;
|
|
471
565
|
const missed = [];
|
|
472
566
|
const queue = [];
|
|
473
567
|
let openRunning = mode !== "entitled_only";
|
|
474
568
|
let checked = 0;
|
|
475
569
|
let openFound = 0;
|
|
570
|
+
/** Open-access papers finished (the browser's part done, when they needed one). */
|
|
571
|
+
let openSettled = 0;
|
|
476
572
|
let succeeded = 0;
|
|
477
573
|
let failed = 0;
|
|
478
574
|
/** Of the entitled lane's 成功: arXiv copies, open ones (as the finished card counts them). */
|
|
@@ -485,7 +581,7 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
485
581
|
wake = undefined;
|
|
486
582
|
resume?.();
|
|
487
583
|
};
|
|
488
|
-
const settledOk = () =>
|
|
584
|
+
const settledOk = () => openSettled + succeeded;
|
|
489
585
|
// The window's lines while the lanes run, one report after another so that
|
|
490
586
|
// the counts never go back. Beside a running download only the counts and
|
|
491
587
|
// the lanes lines change (a backend that cannot do that gets none of these).
|
|
@@ -511,6 +607,15 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
511
607
|
return reports;
|
|
512
608
|
};
|
|
513
609
|
const settle = (offset, waiting) => papers.set(offset, batchPaper(requests[offset], results[offset], waiting, content));
|
|
610
|
+
// Without network the window says so, while it is open (a large batch, or the school's lane begun).
|
|
611
|
+
const watch = { log, pause, online, notice: (phase) => {
|
|
612
|
+
if (!backend?.reportBatchProgress || !(openProgress || missed.length))
|
|
613
|
+
return reports;
|
|
614
|
+
const update = { id: batchId, total, done: settledOk() + failed, succeeded: settledOk(), failed, current: "",
|
|
615
|
+
finished: false, phase };
|
|
616
|
+
reports = reports.then(() => backend.reportBatchProgress(update)).catch(() => false);
|
|
617
|
+
return reports;
|
|
618
|
+
} };
|
|
514
619
|
const openLane = async () => {
|
|
515
620
|
try {
|
|
516
621
|
for (const [offset, request] of requests.entries()) {
|
|
@@ -520,7 +625,7 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
520
625
|
const tiers = createTiers(backend).filter((tier) => tier.stage !== "entitled_access" && tier.stage !== "preprint");
|
|
521
626
|
let result;
|
|
522
627
|
try {
|
|
523
|
-
result = await downloadWithFallback(searchers, recorded(request, ledger, entries[offset]), tiers);
|
|
628
|
+
result = await pastNetworkLoss(() => downloadWithFallback(searchers, recorded(request, ledger, entries[offset]), tiers), watch);
|
|
524
629
|
}
|
|
525
630
|
catch (error) {
|
|
526
631
|
result = laneError("open_access", error);
|
|
@@ -528,13 +633,25 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
528
633
|
}
|
|
529
634
|
results[offset] = itemResult(result, offset + 1, request);
|
|
530
635
|
checked = offset + 1;
|
|
531
|
-
settle(offset, result.status === "ok" ? undefined : "school");
|
|
532
636
|
if (result.status === "ok") {
|
|
533
637
|
openFound += 1;
|
|
534
|
-
if
|
|
638
|
+
// Its Markdown from the open sources now; the browser's part, if any, in its queue.
|
|
639
|
+
const later = wantsFiles || wantsMarkdown &&
|
|
640
|
+
await fulltextForItem(results[offset], recorded(request, ledger, entries[offset]), searchers, "later") === "later";
|
|
641
|
+
// The window lists its PDF as saved now, as it did (its files' shortfall, if any, later).
|
|
642
|
+
settle(offset);
|
|
643
|
+
if (later) {
|
|
644
|
+
finishing.add(offset);
|
|
645
|
+
queue.push(offset);
|
|
646
|
+
notify();
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
openSettled += 1;
|
|
535
650
|
record(offset);
|
|
651
|
+
}
|
|
536
652
|
}
|
|
537
653
|
else {
|
|
654
|
+
settle(offset, "school");
|
|
538
655
|
if (!missed.length) {
|
|
539
656
|
log(`[批量] 开放来源没有找到 ${id(offset)},机构下载同时开始`);
|
|
540
657
|
ledger?.phase("机构下载开始,开放来源同时进行");
|
|
@@ -558,26 +675,109 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
558
675
|
ledger?.phase(`开放来源查完:${missed.length} 篇转机构下载`);
|
|
559
676
|
}
|
|
560
677
|
};
|
|
678
|
+
/**
|
|
679
|
+
* The browser's part of an open-access paper: its supplementary files (the visit also
|
|
680
|
+
* saves the page when the Markdown is wanted), then its Markdown.
|
|
681
|
+
*/
|
|
682
|
+
const finishOpenItem = async (offset) => {
|
|
683
|
+
finishing.delete(offset);
|
|
684
|
+
const done = settledOk() + failed;
|
|
685
|
+
const request = { ...requests[offset], batch: { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed },
|
|
686
|
+
...(away ? { shortUserWait: true } : {}) };
|
|
687
|
+
const item = results[offset];
|
|
688
|
+
log(`[批量] ${wantsFiles ? (wantsMarkdown ? "补充材料和 Markdown" : "补充材料") : "Markdown"}(PDF 已从开放来源取得):${id(offset)}`);
|
|
689
|
+
let extra;
|
|
690
|
+
/** Where the visit for the Markdown's page ended its wait on a school login (trace.loginWaitPage). */
|
|
691
|
+
let pageWait;
|
|
692
|
+
let markdownFrom = item.attempts.length;
|
|
693
|
+
try {
|
|
694
|
+
extra = await filesPastNetworkLoss(item, recorded(request, ledger, entries[offset]), backend, searchers, watch);
|
|
695
|
+
markdownFrom = item.attempts.length;
|
|
696
|
+
if (wantsMarkdown && !stoppedByUser(item)) {
|
|
697
|
+
await markdownPastNetworkLoss(item, recorded(request, ledger, entries[offset]), searchers, pageVisit(backend, request, log, pause, (trace) => { pageWait = trace?.loginWaitPage; learnPublisher(offset, trace?.publisher); }), watch);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
log(`[批量] 补充材料或 Markdown 出错(${id(offset)}):${error instanceof Error ? error.message : String(error)}`);
|
|
702
|
+
}
|
|
703
|
+
// Its full text read on the publisher's page in the browser: the school's login worked for
|
|
704
|
+
// this publisher in this batch, as a PDF through it shows (OAC, 2026-11-17: the login
|
|
705
|
+
// lapsed at 02:39 before any of its PDFs had come through the school, and 44 papers each
|
|
706
|
+
// waited it out until the user signed in again at 08:05).
|
|
707
|
+
if (item.markdown?.status === "ok" && item.markdown.source === "publisher_page")
|
|
708
|
+
cameThrough(offset);
|
|
709
|
+
if (item.markdown?.code === LOGIN_LAPSED_CODE) {
|
|
710
|
+
if (!away) {
|
|
711
|
+
away = true;
|
|
712
|
+
log(AWAY_NOTICE);
|
|
713
|
+
}
|
|
714
|
+
// Its page stopped at the school's own sign-in page: held with its publisher, its Markdown
|
|
715
|
+
// fetched again when the user goes on (the files it got stand).
|
|
716
|
+
if (pageWait === SCHOOL_SIGN_IN_PAGE && wentThrough(offset) && !stoppedByUser(item) && await canHold()) {
|
|
717
|
+
item.attempts.length = markdownFrom;
|
|
718
|
+
delete item.markdown;
|
|
719
|
+
finishing.add(offset);
|
|
720
|
+
if (extra)
|
|
721
|
+
await reportBatchItem(request, extra, backend);
|
|
722
|
+
hold(offset);
|
|
723
|
+
settle(offset);
|
|
724
|
+
await sendPapers();
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
openSettled += 1;
|
|
729
|
+
if (extra)
|
|
730
|
+
await reportBatchItem(request, extra, backend);
|
|
731
|
+
record(offset);
|
|
732
|
+
// The window's 失败 list shows a missing supplementary file as it happens (user, 2026-11-11).
|
|
733
|
+
settle(offset);
|
|
734
|
+
if (stoppedByUser(item)) {
|
|
735
|
+
stopped = true;
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (openRunning || queue.length)
|
|
739
|
+
await reportProgress("");
|
|
740
|
+
await sendPapers();
|
|
741
|
+
};
|
|
561
742
|
// A publisher whose school login stops working mid-batch (its papers came through the
|
|
562
|
-
// school, then one stops at the school's own sign-in page): its papers wait,
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
// the
|
|
743
|
+
// school, then one stops at the school's own sign-in page): its papers wait, their PDF, supplementary files
|
|
744
|
+
// and Markdown alike, the others go on, and they go on when the user presses 登录并继续 in
|
|
745
|
+
// the window (the user, 2026-11-15: Science's session lapsed after 84 articles and a
|
|
746
|
+
// misread login page failed the other 540). Publishers by name (user, 2026-11-17: a publisher's
|
|
747
|
+
// journals of other DOI prefixes, Elsevier's 10.1053/ and ARD's 10.1136/ beside 10.1016/, wait
|
|
748
|
+
// with it), each paper's as its school visit named it, else its DOI prefix's as learned so far,
|
|
749
|
+
// else the prefix itself.
|
|
750
|
+
/** Where the school's login worked in this batch: each such paper's publisher and DOI prefix. */
|
|
566
751
|
const viaSchool = new Set();
|
|
752
|
+
/** Each held publisher's papers, open-access ones still to be finished among them. */
|
|
567
753
|
const held = new Map();
|
|
568
754
|
/** Where each paper's wait on a school login ended, as the backend said (trace.loginWaitPage). */
|
|
569
755
|
const waitEnded = new Map();
|
|
570
756
|
const prefixOf = (offset) => (/^10\.\d{4,9}\//.exec(requests[offset].doi.toLowerCase()) ?? [""])[0];
|
|
571
|
-
/**
|
|
572
|
-
const
|
|
757
|
+
/** Each paper's publisher as its own school visit named it. */
|
|
758
|
+
const paperPublishers = new Map();
|
|
759
|
+
/** A paper's publisher: its own visit's, else its DOI prefix's as learned so far, else the prefix. */
|
|
760
|
+
const publisherOf = (offset) => paperPublishers.get(offset) ?? publishers.get(prefixOf(offset)) ?? prefixOf(offset);
|
|
761
|
+
const learnPublisher = (offset, name) => {
|
|
762
|
+
if (typeof name !== "string" || !name)
|
|
763
|
+
return;
|
|
764
|
+
paperPublishers.set(offset, name);
|
|
765
|
+
if (prefixOf(offset))
|
|
766
|
+
publishers.set(prefixOf(offset), name);
|
|
767
|
+
};
|
|
768
|
+
const cameThrough = (offset) => {
|
|
769
|
+
if (prefixOf(offset))
|
|
770
|
+
viaSchool.add(prefixOf(offset));
|
|
771
|
+
viaSchool.add(publisherOf(offset));
|
|
772
|
+
};
|
|
773
|
+
const wentThrough = (offset) => viaSchool.has(publisherOf(offset)) || (!!prefixOf(offset) && viaSchool.has(prefixOf(offset)));
|
|
573
774
|
// Held only where the window can show it with its button; else they fail as before.
|
|
574
775
|
let holdOk;
|
|
575
776
|
const canHold = async () => (holdOk ??= await backend?.holdSupported?.().catch(() => false) ?? false);
|
|
576
|
-
/** Each
|
|
777
|
+
/** Each DOI prefix's publisher as the school's stages named it ("Science"); the last one named. */
|
|
577
778
|
const publishers = new Map();
|
|
578
|
-
const heldList = () => [...
|
|
579
|
-
key, name: publishers.get(key) ?? key,
|
|
580
|
-
count: (held.get(key)?.length ?? 0) + (heldFiles.get(key)?.length ?? 0),
|
|
779
|
+
const heldList = () => [...held.entries()].map(([key, offsets]) => ({
|
|
780
|
+
key, name: publishers.get(key) ?? key, count: offsets.length,
|
|
581
781
|
}));
|
|
582
782
|
/** The window's line and button for the held publishers (none: cleared). */
|
|
583
783
|
const reportHeld = (waiting = false) => {
|
|
@@ -588,6 +788,19 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
588
788
|
reports = reports.then(() => backend.reportBatchProgress(update)).catch(() => false);
|
|
589
789
|
return reports;
|
|
590
790
|
};
|
|
791
|
+
/** ``offset`` stopped at the school's sign-in page: its publisher's papers wait for the user. */
|
|
792
|
+
const hold = (offset) => {
|
|
793
|
+
const key = publisherOf(offset);
|
|
794
|
+
if (held.has(key)) {
|
|
795
|
+
held.get(key).push(offset);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
held.set(key, [offset]);
|
|
799
|
+
log(`[批量] ${key} 的文章前面经学校登录下到了,这一篇停在学校登录页没有完成登录:` +
|
|
800
|
+
"这家出版社的篇目先暂停,其他照常下载;回来后在进度窗口点“登录并继续”");
|
|
801
|
+
ledger?.phase(`暂停 ${key}:学校登录中途失效`);
|
|
802
|
+
void reportHeld();
|
|
803
|
+
};
|
|
591
804
|
/** The user pressed 登录并继续 (or 终止) in the window: held papers go on first. */
|
|
592
805
|
const takeRequests = () => {
|
|
593
806
|
const asked = backend?.takeBatchRequests?.(batchId);
|
|
@@ -609,17 +822,33 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
609
822
|
notify();
|
|
610
823
|
}
|
|
611
824
|
};
|
|
825
|
+
/** The held papers end as paused (the batch stopped): returns them, no longer held. */
|
|
826
|
+
const markPaused = () => {
|
|
827
|
+
const paused = [...held.values()].flat();
|
|
828
|
+
for (const offset of paused) {
|
|
829
|
+
const item = results[offset];
|
|
830
|
+
if (finishing.has(offset)) {
|
|
831
|
+
// Its PDF stands; its browser's part waited for the login.
|
|
832
|
+
if (wantsFiles)
|
|
833
|
+
item.supplements = [{ status: "skipped", label: "", reason: "batch_stopped" }];
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
results[offset] = itemResult({ ...item, status: "error", attempts: [...item.attempts,
|
|
837
|
+
{ stage: "entitled_access", status: "error", ...schoolAttemptDetails("login_paused") }] }, offset + 1, requests[offset]);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
held.clear();
|
|
841
|
+
return paused;
|
|
842
|
+
};
|
|
612
843
|
/**
|
|
613
|
-
* The request, its school stage also naming
|
|
844
|
+
* The request, its school stage also naming its publisher (``learnPublisher``)
|
|
614
845
|
* and where its wait on a school login ended (``waitEnded``).
|
|
615
846
|
*/
|
|
616
|
-
const watchingSchool = (request,
|
|
847
|
+
const watchingSchool = (request, offset) => {
|
|
617
848
|
const forward = request.onStage;
|
|
618
849
|
return { ...request, onStage: (record) => {
|
|
619
850
|
if (record.stage === "entitled_access") {
|
|
620
|
-
|
|
621
|
-
if (prefix && typeof name === "string" && name)
|
|
622
|
-
publishers.set(prefix, name);
|
|
851
|
+
learnPublisher(offset, record.trace?.publisher);
|
|
623
852
|
const page = record.trace?.loginWaitPage;
|
|
624
853
|
if (typeof page === "string")
|
|
625
854
|
waitEnded.set(offset, page);
|
|
@@ -636,9 +865,17 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
636
865
|
const offset = stopped ? undefined : queue.shift();
|
|
637
866
|
if (offset === undefined)
|
|
638
867
|
return;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
868
|
+
if (held.has(publisherOf(offset))) {
|
|
869
|
+
held.get(publisherOf(offset)).push(offset);
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (finishing.has(offset)) {
|
|
873
|
+
await finishOpenItem(offset);
|
|
874
|
+
if (stopped)
|
|
875
|
+
return;
|
|
876
|
+
if (held.size)
|
|
877
|
+
await reportHeld();
|
|
878
|
+
takeRequests();
|
|
642
879
|
continue;
|
|
643
880
|
}
|
|
644
881
|
const request = requests[offset];
|
|
@@ -650,7 +887,7 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
650
887
|
const batch = { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed };
|
|
651
888
|
let result;
|
|
652
889
|
try {
|
|
653
|
-
result = await pastHourlyLimit(() => downloadBatchItem(searchers, watchingSchool(recorded({ ...request, batch, ...(away ? { shortUserWait: true } : {}) }, ledger, entries[offset]),
|
|
890
|
+
result = await pastNetworkLoss(() => pastHourlyLimit(() => downloadBatchItem(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"), backend), log, pause, backend), watch);
|
|
654
891
|
}
|
|
655
892
|
catch (error) {
|
|
656
893
|
result = laneError("entitled_access", error);
|
|
@@ -669,21 +906,22 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
669
906
|
...(result.review ?? open.review ? { review: result.review ?? open.review } : {}),
|
|
670
907
|
}, offset + 1, request);
|
|
671
908
|
const school = result.attempts.find((attempt) => attempt.stage === "entitled_access");
|
|
672
|
-
const
|
|
909
|
+
const holding = result.status !== "ok" && wentThrough(offset) && school?.code === LOGIN_LAPSED_CODE
|
|
673
910
|
&& waitEnded.get(offset) === SCHOOL_SIGN_IN_PAGE && !stoppedByUser(result) && await canHold();
|
|
911
|
+
// Its Markdown now, from the page this visit saved, or the open sources (only these
|
|
912
|
+
// while its school login is in doubt).
|
|
913
|
+
if (wantsMarkdown && !stoppedByUser(result)) {
|
|
914
|
+
await markdownPastNetworkLoss(results[offset], recorded({ ...request, batch }, ledger, entries[offset]), searchers, holding ? undefined : pageVisit(backend, { ...request, batch, ...(away ? { shortUserWait: true } : {}) }, log, pause), watch);
|
|
915
|
+
}
|
|
674
916
|
if (result.status === "ok") {
|
|
675
917
|
succeeded += 1;
|
|
676
918
|
record(offset);
|
|
677
919
|
settle(offset);
|
|
678
|
-
if (school?.status === "ok"
|
|
679
|
-
|
|
920
|
+
if (school?.status === "ok")
|
|
921
|
+
cameThrough(offset);
|
|
680
922
|
}
|
|
681
|
-
else if (
|
|
682
|
-
|
|
683
|
-
log(`[批量] ${prefix} 的文章前面经学校登录下到了,这一篇停在学校登录页没有完成登录:` +
|
|
684
|
-
"这家出版社的篇目先暂停,其他照常下载;回来后在进度窗口点“登录并继续”");
|
|
685
|
-
ledger?.phase(`暂停 ${prefix}:学校登录中途失效`);
|
|
686
|
-
void reportHeld();
|
|
923
|
+
else if (holding) {
|
|
924
|
+
hold(offset);
|
|
687
925
|
}
|
|
688
926
|
else {
|
|
689
927
|
failed += 1;
|
|
@@ -718,35 +956,35 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
718
956
|
ledger?.phase(`开放来源 ${total} 篇`);
|
|
719
957
|
void sendPapers();
|
|
720
958
|
await Promise.all([mode === "entitled_only" ? undefined : openLane(), entitledLane()]);
|
|
721
|
-
|
|
722
|
-
//
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
959
|
+
// The held publishers wait for the user as long as it takes (user, 2026-11-15): the
|
|
960
|
+
// window shows 登录并继续 and 终止. 登录并继续 downloads them, the school's login asking
|
|
961
|
+
// the user where it lapsed; held again, the wait starts over. 终止 ends them as paused.
|
|
962
|
+
if (held.size && !stopped) {
|
|
963
|
+
const waiting = [...held.values()].reduce((sum, offsets) => sum + offsets.length, 0);
|
|
964
|
+
log(`[批量] 其他篇目已完成,暂停的 ${waiting} 篇等你回来:在进度窗口点“登录并继续”,或点“终止”结束`);
|
|
965
|
+
ledger?.phase(`等你回来:暂停的 ${waiting} 篇`);
|
|
966
|
+
}
|
|
967
|
+
while (held.size && !stopped) {
|
|
968
|
+
await reportHeld(true);
|
|
969
|
+
await pause(HOLD_POLL_MS);
|
|
970
|
+
takeRequests();
|
|
971
|
+
if (queue.length && !stopped) {
|
|
972
|
+
await entitledLane();
|
|
734
973
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
// items not reached end as not downloaded, the held as paused.
|
|
740
|
-
let endedStopped = false;
|
|
741
|
-
const endStopped = () => {
|
|
742
|
-
if (endedStopped)
|
|
743
|
-
return;
|
|
744
|
-
endedStopped = true;
|
|
974
|
+
}
|
|
975
|
+
await reports;
|
|
976
|
+
// Stopped in the window: the items neither lane reached end as not downloaded, the held as paused.
|
|
977
|
+
if (stopped) {
|
|
745
978
|
markPaused();
|
|
746
979
|
for (const [offset, request] of requests.entries()) {
|
|
747
980
|
const item = results[offset];
|
|
748
981
|
if (!item)
|
|
749
982
|
results[offset] = itemResult({ status: "error", attempts: [notReached()] }, offset + 1, request);
|
|
983
|
+
else if (finishing.has(offset)) {
|
|
984
|
+
// Its PDF stands; its browser's part was not reached.
|
|
985
|
+
if (wantsFiles)
|
|
986
|
+
item.supplements = [{ status: "skipped", label: "", reason: "batch_stopped" }];
|
|
987
|
+
}
|
|
750
988
|
else if (queue.includes(offset)) {
|
|
751
989
|
results[offset] = itemResult({ ...item, status: "error", attempts: [...item.attempts, notReached()] }, offset + 1, request);
|
|
752
990
|
}
|
|
@@ -756,86 +994,9 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
756
994
|
record(offset);
|
|
757
995
|
}
|
|
758
996
|
log(STOP_NOTICE);
|
|
759
|
-
}
|
|
760
|
-
if (stopped)
|
|
761
|
-
endStopped();
|
|
997
|
+
}
|
|
762
998
|
const items = results;
|
|
763
999
|
const remaining = missed.length;
|
|
764
|
-
// Then supplementary files for the items the open stages already got.
|
|
765
|
-
if (options.content === "both" && !stopped) {
|
|
766
|
-
const open = requests.map((_, offset) => offset).filter((offset) => !missed.includes(offset));
|
|
767
|
-
if (open.length)
|
|
768
|
-
ledger?.phase(`补充材料 ${open.length} 篇`);
|
|
769
|
-
let supplementsSucceeded = 0;
|
|
770
|
-
let supplementsFailed = 0;
|
|
771
|
-
for (const [step, offset] of open.entries()) {
|
|
772
|
-
const prefix = prefixOf(offset);
|
|
773
|
-
if (prefix && held.has(prefix)) {
|
|
774
|
-
heldFiles.set(prefix, [...(heldFiles.get(prefix) ?? []), offset]);
|
|
775
|
-
continue;
|
|
776
|
-
}
|
|
777
|
-
log(`[批量] 补充材料 ${step + 1}/${open.length}:${id(offset)}`);
|
|
778
|
-
// Every item of the entitled lane has settled; these come after them.
|
|
779
|
-
const batch = { id: batchId, index: remaining + step + 1, total, done: remaining + step,
|
|
780
|
-
succeeded: succeeded + supplementsSucceeded, failed: failed + supplementsFailed };
|
|
781
|
-
const request = { ...requests[offset], batch };
|
|
782
|
-
const extra = await supplementsForOpenItem(items[offset], recorded(request, ledger, entries[offset]), backend, searchers);
|
|
783
|
-
if (extra) {
|
|
784
|
-
await reportBatchItem(request, extra, backend);
|
|
785
|
-
if (extra.status === "ok")
|
|
786
|
-
supplementsSucceeded += 1;
|
|
787
|
-
else
|
|
788
|
-
supplementsFailed += 1;
|
|
789
|
-
}
|
|
790
|
-
record(offset);
|
|
791
|
-
// The window's 失败 list shows a missing supplementary file as it happens (user, 2026-11-11).
|
|
792
|
-
settle(offset);
|
|
793
|
-
await sendPapers();
|
|
794
|
-
if (stoppedByUser(items[offset])) {
|
|
795
|
-
stopped = true; // the rest of them end as not reached, below
|
|
796
|
-
break;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
// The held publishers wait for the user as long as it takes (user, 2026-11-15): the
|
|
801
|
-
// window shows 登录并继续 and 终止. 登录并继续 downloads them, the school's login asking
|
|
802
|
-
// the user where it lapsed; held again, the wait starts over. 终止 ends them as paused.
|
|
803
|
-
if ((held.size || heldFiles.size) && !stopped) {
|
|
804
|
-
const waiting = [...held.values(), ...heldFiles.values()].reduce((sum, offsets) => sum + offsets.length, 0);
|
|
805
|
-
log(`[批量] 其他篇目已完成,暂停的 ${waiting} 篇等你回来:在进度窗口点“登录并继续”,或点“终止”结束`);
|
|
806
|
-
ledger?.phase(`等你回来:暂停的 ${waiting} 篇`);
|
|
807
|
-
}
|
|
808
|
-
while ((held.size || heldFiles.size) && !stopped) {
|
|
809
|
-
await reportHeld(true);
|
|
810
|
-
await pause(HOLD_POLL_MS);
|
|
811
|
-
takeRequests();
|
|
812
|
-
if (queue.length && !stopped) {
|
|
813
|
-
await entitledLane();
|
|
814
|
-
}
|
|
815
|
-
// A publisher gone on with: its open-access papers' files too.
|
|
816
|
-
for (const [key, offsets] of [...heldFiles.entries()]) {
|
|
817
|
-
if (held.has(key) || stopped)
|
|
818
|
-
continue;
|
|
819
|
-
heldFiles.delete(key);
|
|
820
|
-
for (const offset of offsets) {
|
|
821
|
-
if (stopped)
|
|
822
|
-
break;
|
|
823
|
-
log(`[批量] 补充材料:${id(offset)}`);
|
|
824
|
-
const done = settledOk() + failed;
|
|
825
|
-
const request = { ...requests[offset], batch: { id: batchId, index: done + 1, total, done, succeeded: settledOk(), failed } };
|
|
826
|
-
const extra = await supplementsForOpenItem(items[offset], recorded(request, ledger, entries[offset]), backend, searchers);
|
|
827
|
-
if (extra)
|
|
828
|
-
await reportBatchItem(request, extra, backend);
|
|
829
|
-
record(offset);
|
|
830
|
-
settle(offset);
|
|
831
|
-
await sendPapers();
|
|
832
|
-
if (stoppedByUser(items[offset]))
|
|
833
|
-
stopped = true;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
if (stopped)
|
|
838
|
-
endStopped();
|
|
839
1000
|
// Every paper as it ended, before the window's finished card.
|
|
840
1001
|
requests.forEach((_, offset) => settle(offset));
|
|
841
1002
|
await sendPapers(true);
|
|
@@ -844,6 +1005,7 @@ async function downloadTwoPhase(searchers, options, backend, log, createTiers, m
|
|
|
844
1005
|
content: options.content ?? "main",
|
|
845
1006
|
entitledAccessItems: remaining,
|
|
846
1007
|
...(ledger ? { runLog: ledger.dir } : {}),
|
|
1008
|
+
...(stopped ? { stopped: true } : {}),
|
|
847
1009
|
});
|
|
848
1010
|
}
|
|
849
1011
|
//# sourceMappingURL=batch.js.map
|