Skip to content

feat(frontend): add AuthenticatedImg component for authorized image requests - #16525

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:feat/frontend-authenticated-image-components
Jul 1, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:feat/frontend-authenticated-image-components

Conversation

@euvre

@euvre euvre commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the frontend image and document preview components with authenticated image request support.

Background: File thumbnails and certain image resources require Authorization headers to be fetched from protected API endpoints. Previously, these resources would fail to load due to missing authentication.

Changes

  • Add AuthenticatedImg component (web/src/components/image/index.tsx)

    • New component that automatically attaches Authorization header when fetching images
    • Uses fetch API with proper auth headers for authenticated requests
  • Update file-icon component (web/src/components/file-icon/index.tsx)

    • Replace standard <img> with <AuthenticatedImg> for document thumbnails
    • Ensures file icons display correctly with authenticated endpoints
  • Update markdown-content components (3 files)

    • Use <AuthenticatedImg> for file thumbnails in:
      • web/src/components/markdown-content/index.tsx
      • web/src/components/next-markdown-content/index.tsx
      • web/src/pages/next-search/markdown-content/index.tsx
  • Improve error handling (web/src/components/document-preview/hooks.ts)

    • Add try-catch for network error handling
    • Properly distinguish between binary (PDF) and JSON responses
    • Prevent false errors when loading binary document data
  • Simplify PDF previewer (web/src/components/document-preview/index.tsx)

    • Clean up conditional rendering logic

Test plan

  • Verify file thumbnails load correctly in knowledge base list view
  • Test document preview works for both PDF and other formats
  • Confirm markdown content renders thumbnails properly in chat/search results
  • Check error states display appropriately for failed/missing documents

…equests

- Add AuthenticatedImg component in image/index.tsx to handle images requiring Authorization headers
- Update file-icon component to use AuthenticatedImg for document thumbnails
- Update markdown-content components to use AuthenticatedImg for file thumbnails
- Improve error handling in document-preview hooks (try-catch for network errors, proper binary/JSON response detection)
- Simplify PDF previewer rendering conditions
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code labels Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d6d24c70-8124-47a6-99c4-baedec0aa9b6

📥 Commits

Reviewing files that changed from the base of the PR and between 8114781 and a7ede3d.

📒 Files selected for processing (2)
  • web/src/components/document-preview/hooks.ts
  • web/src/components/image/index.tsx
💤 Files with no reviewable changes (1)
  • web/src/components/image/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/components/document-preview/hooks.ts

📝 Walkthrough

Walkthrough

This PR adds authenticated blob-URL loading for image thumbnails, applies it to file icon and markdown/reference previews, and updates document preview error handling plus PDF preview rendering.

Changes

Authenticated Image Rendering

Layer / File(s) Summary
Authenticated image core
web/src/components/image/index.tsx
Refactors auth-aware image URL handling and adds useAuthenticatedImageUrl plus AuthenticatedImg for blob-URL rendering.
File icon thumbnail loading
web/src/components/file-icon/index.tsx
FileIcon now derives a blob URL from authenticated thumbnails before rendering the image.
Thumbnail rendering updates
web/src/components/floating-chat-widget-markdown.tsx, web/src/components/markdown-content/index.tsx, web/src/components/next-markdown-content/index.tsx, web/src/pages/next-search/markdown-content/index.tsx
Reference thumbnail rendering switches from plain <img> elements to AuthenticatedImg in chat and markdown preview paths.

Document Preview Fixes

Layer / File(s) Summary
Preview fetch and PDF rendering
web/src/components/document-preview/hooks.ts, web/src/components/document-preview/index.tsx
fetchDocument now handles nonstandard error payloads and network failures, and the PDF preview branch now uses an isPdf check.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#16152: Both PRs change web/src/components/image/index.tsx and the authenticated image/blob URL loading path.

Suggested labels: 🐞 bug

Suggested reviewers: cike8899, dcc123456

Poem

A rabbit hopped through preview land,
With blob URLs close at hand 🐇
Thumbnails glowed, the errors tamed,
And PDFs appeared unflamed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding authenticated image support via AuthenticatedImg.
Description check ✅ Passed The description matches the template and includes summary, background, changes, and test plan details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@euvre euvre added the ci Continue Integration label Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/components/file-icon/index.tsx`:
- Around line 5-7: The file icon component is reimplementing authenticated image
URL handling and dropping the cleanup from the effect, so object URLs are never
revoked. Update the component to use the shared useAuthenticatedImageUrl hook
instead of inline auth/file-fetch logic in FileIcon, or extract that hook into
src/hooks/ if it is not already shared. Keep FileIcon lean and ensure URL
creation/revocation is handled by the hook.

In `@web/src/components/image/index.tsx`:
- Around line 171-179: AuthenticatedImg currently returns null when
useAuthenticatedImageUrl(src) yields no usable URL, which leaves protected
thumbnails blank because callers treat fileThumbnail as truthy and skip their
SvgIcon fallback. Update AuthenticatedImg (and the thumbnail branch that
consumes it) to expose a fallback path for failed/empty authenticated image
loading, so a broken blob URL can still render the existing icon/placeholder
instead of rendering nothing.
- Around line 86-88: The auth check in isAuthRequiredUrl is too broad because it
marks any URL containing /documents/images/ as authenticated, even cross-origin
URLs. Update the logic in isAuthRequiredUrl to require same-origin before
returning true for image/document URLs, so getAuthorization() is only used for
requests to the app’s own API or same-origin image endpoints. Keep the /api/v1/
handling, but gate the /documents/images/ case behind an origin check using the
URL parsing logic already available in this component.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c055f04a-b92f-4f30-9352-561298aa4974

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf5760 and a9a6dc6.

📒 Files selected for processing (8)
  • web/src/components/document-preview/hooks.ts
  • web/src/components/document-preview/index.tsx
  • web/src/components/file-icon/index.tsx
  • web/src/components/floating-chat-widget-markdown.tsx
  • web/src/components/image/index.tsx
  • web/src/components/markdown-content/index.tsx
  • web/src/components/next-markdown-content/index.tsx
  • web/src/pages/next-search/markdown-content/index.tsx

Comment thread web/src/components/file-icon/index.tsx Resolved
Comment thread web/src/components/image/index.tsx Resolved
Comment thread web/src/components/image/index.tsx Resolved
euvre added 2 commits July 1, 2026 14:55
- Security: Add same-origin check in isAuthRequiredUrl to prevent token leakage
- Fix memory leak: Refactor file-icon to use shared useAuthenticatedImageUrl hook
  instead of reimplementing auth fetch logic without proper cleanup
- UX: Add fallback prop to AuthenticatedImg for degraded UI on load failure
- Remove unused 'getSearchValue' import from image/index.tsx
- Suppress no-console warning in document-preview hooks.ts
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (9bf5760) to head (a7ede3d).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16525   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 requested a review from dcc123456 July 1, 2026 08:32
@wangq8
wangq8 merged commit 81cfcdf into infiniflow:main Jul 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants