Fix empty API results: switch CIE source to papersdaddy with download proxy#6
Merged
Conversation
The previous upstreams (pastpapers.papacambridge.com, pastpapers.co) moved behind Cloudflare Managed Challenge — the legacy crawler couldn't solve the JS challenge, returned empty arrays, and those empties were cached in Redis for a month. Replace them with papersdaddy.com (active, has 2002-2026, no anti-bot wall), route paper downloads through a server proxy that strips the per-page watermark, and harden the cache so a transient upstream failure can't poison it again. - routes/papacambridge_com.js, routes/years.js, routes/cates.js — ppca papers/years/cates now go to papersdaddy via the new wrapper - utils/papersdaddy_wrapper.js — fetchYears/fetchPapers/fetchCates + resolveDownload (extracts the short-lived tokenized PDF URL from papersdaddy's viewer page) - routes/download.js — buffers the upstream PDF, runs stripWatermark, serves with proper Content-Disposition, ?download=1 for forced save, Range request support, and HEAD; non-PDF assets still pipe-stream - utils/watermark_stripper.js — empties the standalone "PapersDaddy" and "Downloaded for free from www.papersdaddy.com" content streams via pdf-lib (matches the 22-byte hex sequences of the watermark text) - app.js — apicache now skips /api/download and only stores 200s, so multi-MB binaries and error responses can't end up in Redis - utils/redis_wrapper.js — Redis connection errors no longer crash the process; caching just disables instead - config/cors.config.js — expose Content-Disposition, Content-Length, Content-Range, Accept-Ranges so cross-origin fetch() can read them Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fly terminates TLS and forwards as plain HTTP to the app, so req.protocol was "http" and the /api/papers response built http://node.snapaper.com/api/download/... URLs. The frontend runs on https://snapaper.com, so clicking those links triggers mixed-content blocks in modern browsers. With trust proxy on, Express honors X-Forwarded-Proto and req.protocol returns "https". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pastpapers.papacambridge.comandpastpapers.comoved behind Cloudflare's Managed Challenge — the legacycrawlerlibrary couldn't solve the JS challenge, returned empty arrays, and those got cached in Redis for a month. The historical fallback sources (gceguide.cc/.xyz/.com) are dead or domain-parked.ppcapapers/years/cates topapersdaddy.com(active, 2002–2026, no anti-bot wall) via a new wrapper. Paper download URLs route through a server-side/api/download/*proxy that resolves papersdaddy's short-lived tokenized URL, strips the per-pagePapersDaddy/Downloaded for free from www.papersdaddy.comwatermarks viapdf-lib, and serves the cleaned PDF with properContent-Disposition,Range, and CORS exposure.apicacheno longer caches non-200 responses (so a transient upstream failure can't poison the 1-month TTL again) and skips the/api/downloadpath entirely (no multi-MB binaries in Redis). Redis connection errors no longer crash the process.trust proxyis on so paper URLs are correctlyhttps://behind Fly's edge.Production verification (https://node.snapaper.com)
/api/years/ppca/as-and-a-level/mathematics-(9709)→ 60 sessions, newest2026-Oct-Nov✓/api/papers/ppca/as-and-a-level/mathematics-(9709)/2025-May-Jun→ 50 papers, URLs arehttps://node.snapaper.com/api/download/...✓/api/cates/ppca/as-and-a-level→ 120 subjects ✓GET /api/download/.../9709_s25_qp_11.pdf→ 200application/pdf,%PDFheader,pdftotext | grep PapersDaddy= 0 ✓Range: bytes=0-99→ 206 Partial Content, exactly 100 bytes,Content-Range: bytes 0-99/411664✓?download=1→Content-Disposition: attachment✓/api/papers/ppca/as-and-a-level/economics-(9708)/2001-Novand/api/years/ppca/as-and-a-level/mathematics-(9709)) now resolve — the latter returns full data, the former returns502 upstream 404because papersdaddy data starts at 2002 for Economics (semantic, not a bug)Test plan
/api/cates/ppca/{as-and-a-level,igcse,o-level}return their expected subject lists in the production environment/api/years/ppca/...returns newest-first sessions including the just-released 2026 entries/api/papers/ppca/.../{year}returns paper objects withhttps://URLs pointing at our/api/downloadproxy/api/download/...serves a watermark-free PDF (cross-checked withpdftotext)Content-Range?download=1switchesContent-DispositiontoattachmentContent-Disposition,Content-Length,Content-Range,Accept-RangesNotes for reviewers
statusCodes: { include: [200] }apicache config prevents this from recurring./api/download/cambridge/...). The frontend treats them as plain<a href>targets so no frontend change is needed.9709_s25_qp_11.pdf) is preserved end-to-end so students can still recognize the standard CAIE naming.🤖 Generated with Claude Code