Skip to content

Wire imageFetcher through CLI docs export pipeline#185

Merged
hackerwins merged 1 commit into
mainfrom
cli-docs-export-imagefetcher
May 5, 2026
Merged

Wire imageFetcher through CLI docs export pipeline#185
hackerwins merged 1 commit into
mainfrom
cli-docs-export-imagefetcher

Conversation

@hackerwins

@hackerwins hackerwins commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • wafflebase docs export <id> <file> failed for any document with an image inline because the CLI never built an imageFetcher to pass to exportPdf / exportDocx. The exporters intentionally throw imageFetcher required: document contains N image inline(s); first: <url> rather than silently dropping image content.
  • Added createImageFetcher({ serverBase }) (parallel to the frontend's docsImageFetcher): absolute URLs pass through, relative /images/<id> paths resolve against the configured server, public GET /images/:id so no auth header is needed.
  • Plumbed the fetcher into CliPdfExportOptions.imageFetcher and the docs export action so both PDF and DOCX paths get one for free.

Test plan

  • pnpm verify:fast (cli + docs + sheets — 2153 tests, all green)
  • New image-fetcher.test.ts covers URL resolution rules and fetch success/404 mapping with an injected fetch stub.
  • docs-export.test.ts regression test reproduces the original error message verbatim against a doc with an https://api.wafflebase.io/images/<uuid>.png inline.
  • docs-export.test.ts embed test exercises the full exportPdf pipeline with a 1×1 PNG stub fetcher and confirms the call resolves to a valid PDF (%PDF- header, fetcher invoked once with the absolute URL).
  • Manual smoke: wafflebase docs export <id> out.pdf against a workspace doc that contains one or more inline images.

🤖 Generated with Claude Code

`wafflebase docs export <id> <file>` previously called `exportPdf`
and `exportDocx` with no `imageFetcher`, so any document containing
even one image inline rejected the export with:

  imageFetcher required: document contains 1 image inline(s);
  first: https://api.wafflebase.io/images/<uuid>.png

That guard lives in `pdf-image-painter.ts` (and a sibling check in
`docx-exporter.ts`) and is intentional — silently dropping image
content would change the visible output without warning. The CLI
just never built a fetcher.

Add `createImageFetcher({ serverBase })` that mirrors the frontend's
`docsImageFetcher`: absolute URLs (`http(s):`, `data:`, `blob:`,
`file:`) pass through untouched, and server-relative paths
(`/images/<id>`) resolve against the CLI's configured server. The
backend `GET /images/:id` route is publicly readable so no auth
header is needed; the fetcher returns a `Blob` the exporter embeds
directly.

Plumb the fetcher into `CliPdfExportOptions.imageFetcher`,
`CliDocxExportOptions.imageFetcher` (already supported), and the
`docs export` action so both PDF and DOCX paths get one for free.

Tests:
- New `image-fetcher.test.ts` covers URL resolution rules and the
  fetcher's success/error mapping with an injected fetch stub.
- `docs-export.test.ts` adds a regression test that reproduces the
  reported error message verbatim, plus an embed test that exercises
  the full PDF pipeline with a 1×1 PNG stub fetcher. The DOCX
  symmetric regression is deliberately not duplicated here because a
  failing `DocxExporter.export` invocation perturbs JSZip's Blob
  support state in pure-Node tests; that path is already covered in
  the docs package's jsdom-env suite.
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@hackerwins has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 45 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc81f37c-d1f5-4c36-b929-21a6d5ca8c48

📥 Commits

Reviewing files that changed from the base of the PR and between 948c276 and 0945cb3.

📒 Files selected for processing (5)
  • packages/cli/src/commands/docs.ts
  • packages/cli/src/docs/image-fetcher.ts
  • packages/cli/src/docs/pdf-export.ts
  • packages/cli/test/docs-export.test.ts
  • packages/cli/test/image-fetcher.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli-docs-export-imagefetcher

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 137.8s

Lane Status Duration
sheets:build ✅ pass 12.6s
docs:build ✅ pass 12.2s
verify:fast ✅ pass 70.6s
frontend:build ✅ pass 18.1s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.8s
cli:build ✅ pass 2.1s
verify:entropy ✅ pass 17.3s

Verification: verify:integration

Result: ✅ PASS

@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/commands/docs.ts 12.50% 7 Missing ⚠️
packages/cli/src/docs/image-fetcher.ts 94.73% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@hackerwins
hackerwins merged commit 63fab16 into main May 5, 2026
4 checks passed
@hackerwins
hackerwins deleted the cli-docs-export-imagefetcher branch May 5, 2026 09:07
@hackerwins hackerwins mentioned this pull request May 11, 2026
6 tasks
hackerwins added a commit that referenced this pull request May 11, 2026
Adds @wafflebase/slides as a third surface alongside Sheets and Docs,
plus 53-shape library (Phase 1+2), adjustment handles for 9 pilot
shapes (P3-A.1), live snap guides, align/distribute toolbar, themed
authoring, and layout-change UI. Also ships Sheets cell comments
(Phase B), docs peer-avatar caret jump, yorkie-js-sdk 0.7.8 upgrade,
and CLI/REST API improvements (docs export imageFetcher, expired
session refresh, REST docs split). Minor bump because slides is a
new top-level package.

Highlights: #184 #185 #186 #187 #188 #189 #190 #191 #192 #197 #198
#201 #202 #203 #204 #205 #206 #207 #209 #210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant