Skip to content

Refactor variable of front end - #13953

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix370
Apr 7, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix370

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Apr 7, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

api_host -> webAPI
ExternalApi -> restAPIv1

Type of change

  • Refactoring

Summary by CodeRabbit

  • Refactor

    • Updated internal API endpoint configuration to use consolidated base URL constants for improved maintainability and consistency across the application.
  • Chores

    • Updated server-side protocol validation for admin connectivity checks.

@JinHai-CN JinHai-CN added the ci Continue Integration label Apr 7, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review April 7, 2026 05:57
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 7, 2026
Comment thread web/src/utils/api.ts
@@ -1,344 +1,332 @@
const api_host = `/v1`;
const ExternalApi = `/api`;
const webAPI = `/v1`;

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.

const modifies constants, and it's recommended to capitalize the first letter.

Signed-off-by: Jin Hai <[email protected]>
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 7, 2026
Signed-off-by: Jin Hai <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor API base URL constants across the codebase. web/src/utils/api.ts replaces api_host and ExternalApi with webAPI and restAPIv1, updating all endpoint strings accordingly. Multiple web components are updated to use the new constants. Additionally, a CLI ping response validation message is updated.

Changes

Cohort / File(s) Summary
API Base URL Constants Refactoring
web/src/utils/api.ts
Replaced exported constants api_host and ExternalApi with webAPI and restAPIv1. Updated all API endpoint strings throughout the file to use these new base URL constants, affecting chat, knowledge-base, search, admin, and file endpoints.
Component API Endpoint Updates
web/src/components/document-preview/hooks.ts, web/src/components/image/index.tsx, web/src/components/next-message-item/reference-image-list.tsx, web/src/hooks/use-document-request.ts, web/src/pages/document-viewer/index.tsx
Updated API endpoint construction to use webAPI instead of api_host for non-agent document/image URLs, and restAPIv1 instead of ExternalApi + api_host for authenticated paths. Changes apply consistently across document preview, image rendering, and document viewer components.
CLI Ping Validation
internal/cli/common_command.go
Updated admin-mode JSON ping response validation to accept lowercase "pong" instead of uppercase "PONG", with corresponding comment updates.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 The URLs hop and skip with joy,
No more ExternalApi's employ!
WebAPI and restAPIv1 take the lead,
A refactored path for every need!
With "pong" so soft, the endpoints align—
One constant change, a great design! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Refactor variable of front end' is vague and generic, using imprecise language ('variable', 'front end') that doesn't convey the specific changes (api_host/ExternalApi renames). Use a more specific title like 'Refactor API base URL variable names' or 'Rename api_host to webAPI and ExternalApi to restAPIv1' to clearly communicate the main changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description covers required sections (problem statement and type of change) and correctly identifies the refactoring work, though it could provide more context about why these renamings improve the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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: 1

🧹 Nitpick comments (2)
web/src/hooks/use-document-request.ts (1)

467-475: Disambiguate the two useGetDocumentUrl hooks.

web/src/components/document-preview/hooks.ts already exports useGetDocumentUrl, but that version takes isAgent: boolean and returns a string. Reusing the same name here for a callback-producing hook makes imports easy to misread during refactors like this.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/hooks/use-document-request.ts` around lines 467 - 475, The exported
hook name useGetDocumentUrl conflicts with another hook of the same name that
returns a string (the other takes isAgent:boolean), so rename this
callback-producing hook (e.g., useGetDocumentUrlCallback or
useGetDocumentUrlFactory) to avoid ambiguity, update the internal identifier
getDocumentUrl remains the same, change the export and all imports/usages to the
new name, and run a project-wide search to replace any imports of
useGetDocumentUrl that should point to this callback-producing version to ensure
callers still receive the useCallback-returning function.
web/src/components/next-message-item/reference-image-list.tsx (1)

82-82: Share the document-image URL builder.

This duplicates the path logic in web/src/components/image/index.tsx Line 16. A small shared helper would keep PhotoView and <Image /> aligned the next time this route or its cache-busting rules change.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/components/next-message-item/reference-image-list.tsx` at line 82,
Duplicate URL construction for document images exists between the PhotoView
usage in reference-image-list.tsx (PhotoView
src={`${webAPI}/document/image/${id}`}) and the Image component in
web/src/components/image/index.tsx; extract that logic into a single exported
helper (e.g., getDocumentImageUrl or buildDocumentImageUrl) that accepts the
image id and base webAPI and returns the full URL, replace the inline string
interpolation in reference-image-list.tsx (PhotoView) and the Image component to
call this helper, and export/import the helper from a shared module so both
components consume the same URL builder.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/src/components/image/index.tsx`:
- Around line 14-17: The CSS class on the <img> element uses an invalid unit
"40wh" so the max-height is ignored; update the classNames call in
web/src/components/image/index.tsx (the img element rendering, where className
is built) to use a valid viewport height unit such as "max-h-[40vh]" (replace
"40wh" with "40vh") so the image height cap is applied.

---

Nitpick comments:
In `@web/src/components/next-message-item/reference-image-list.tsx`:
- Line 82: Duplicate URL construction for document images exists between the
PhotoView usage in reference-image-list.tsx (PhotoView
src={`${webAPI}/document/image/${id}`}) and the Image component in
web/src/components/image/index.tsx; extract that logic into a single exported
helper (e.g., getDocumentImageUrl or buildDocumentImageUrl) that accepts the
image id and base webAPI and returns the full URL, replace the inline string
interpolation in reference-image-list.tsx (PhotoView) and the Image component to
call this helper, and export/import the helper from a shared module so both
components consume the same URL builder.

In `@web/src/hooks/use-document-request.ts`:
- Around line 467-475: The exported hook name useGetDocumentUrl conflicts with
another hook of the same name that returns a string (the other takes
isAgent:boolean), so rename this callback-producing hook (e.g.,
useGetDocumentUrlCallback or useGetDocumentUrlFactory) to avoid ambiguity,
update the internal identifier getDocumentUrl remains the same, change the
export and all imports/usages to the new name, and run a project-wide search to
replace any imports of useGetDocumentUrl that should point to this
callback-producing version to ensure callers still receive the
useCallback-returning function.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d7d4e9d-cd32-4253-b1de-127d22a5bd45

📥 Commits

Reviewing files that changed from the base of the PR and between 9ac5d28 and 862e0f3.

📒 Files selected for processing (7)
  • internal/cli/common_command.go
  • web/src/components/document-preview/hooks.ts
  • web/src/components/image/index.tsx
  • web/src/components/next-message-item/reference-image-list.tsx
  • web/src/hooks/use-document-request.ts
  • web/src/pages/document-viewer/index.tsx
  • web/src/utils/api.ts

Comment on lines 14 to 17
<img
{...props}
src={`${api_host}/document/image/${id}${t ? `?_t=${t}` : ''}`}
src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`}
className={classNames('max-w-[45vw] max-h-[40wh] block', className)}

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.

⚠️ Potential issue | 🟡 Minor

Fix the invalid max-height unit.

Line 17 uses max-h-[40wh], which is not a valid CSS unit, so the height cap is ignored.

Proposed fix
-      className={classNames('max-w-[45vw] max-h-[40wh] block', className)}
+      className={classNames('max-w-[45vw] max-h-[40vh] block', className)}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<img
{...props}
src={`${api_host}/document/image/${id}${t ? `?_t=${t}` : ''}`}
src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`}
className={classNames('max-w-[45vw] max-h-[40wh] block', className)}
<img
{...props}
src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`}
className={classNames('max-w-[45vw] max-h-[40vh] block', className)}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/components/image/index.tsx` around lines 14 - 17, The CSS class on
the <img> element uses an invalid unit "40wh" so the max-height is ignored;
update the classNames call in web/src/components/image/index.tsx (the img
element rendering, where className is built) to use a valid viewport height unit
such as "max-h-[40vh]" (replace "40wh" with "40vh") so the image height cap is
applied.

@codecov

codecov Bot commented Apr 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.52%. Comparing base (424aee5) to head (862e0f3).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13953   +/-   ##
=======================================
  Coverage   96.52%   96.52%           
=======================================
  Files          10       10           
  Lines         690      690           
  Branches      108      108           
=======================================
  Hits          666      666           
  Misses          8        8           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 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.

@JinHai-CN
JinHai-CN merged commit 393efa9 into infiniflow:main Apr 7, 2026
1 check passed
JasleenKaurSethi pushed a commit to stackhpc/ragflow that referenced this pull request Apr 28, 2026
### What problem does this PR solve?

api_host -> webAPI
ExternalApi -> restAPIv1

### Type of change

- [x] Refactoring


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Updated internal API endpoint configuration to use consolidated base
URL constants for improved maintainability and consistency across the
application.

* **Chores**
* Updated server-side protocol validation for admin connectivity checks.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants