Skip to content

Go: show model and list all models - #16272

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix484
Jun 23, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix484

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(admin)> show model 'abc';
+------------+----------------------------------------------------------------+
| field      | value                                                          |
+------------+----------------------------------------------------------------+
| command    | get_model_by_model_name                                        |
| error      | 'get model by model name' is implemented in enterprise edition |
| model_name | abc                                                            |
+------------+----------------------------------------------------------------+

RAGFlow(admin)> list models;
+-----------------+--------------------------------------------------------+
| command         | error                                                  |
+-----------------+--------------------------------------------------------+
| list_all_models | 'list all models' is implemented in enterprise edition |
+-----------------+--------------------------------------------------------+

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Renames EncodeEmail/DecodeEmail to EncodeToBase64/DecodeFromBase64 in internal/common/format.go. Splits the combined ListModelsOrShowModel handler into ListAllModels and a new ShowModel (base64 path param), renames the provider-scoped ShowModel to ShowProviderModel, fixes instance deletion routing, and propagates the renamed functions across all admin handlers and CLI commands.

Changes

Base64 Rename, Model Endpoint Split, and Username Decoding Update

Layer / File(s) Summary
Base64 helper function rename
internal/common/format.go
Renames EncodeEmail → EncodeToBase64 and DecodeEmail → DecodeFromBase64 with no behavioral change.
Model endpoint split and router rewiring
internal/admin/enterprise_handler.go, internal/admin/router.go
Removes ListModelsOrShowModelRequest and ListModelsOrShowModel; adds ListAllModels and a base64-decoding ShowModel; renames provider-scoped ShowModel to ShowProviderModel; fixes DeleteModelInstance route to target /instances/:instance_name; wires GET /all-models and GET /all-models/:model_name to new handlers.
Username path parameter decoding in admin handlers
internal/admin/handler.go, internal/admin/enterprise_handler.go
Replaces all common.DecodeEmail(encodedUsername) calls with common.DecodeFromBase64(encodedUsername) across GetUser, DeleteUser, ChangePassword, UpdateUserActivateStatus, GrantAdmin, RevokeAdmin, token handlers, dataset/summary/quota/index/permission/listing handlers, PurgeUserData, and API-key handlers.
CLI command encoding update
internal/cli/admin_command.go, internal/cli/common_command.go
Replaces all common.EncodeEmail calls with common.EncodeToBase64 for username path segments across all admin CLI commands; updates CommonShowModel to base64-encode the model name and append it as a URL path segment instead of sending it in a request body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#16119: Introduces the enterprise admin statistics/purge handlers in enterprise_handler.go that this PR updates to use DecodeFromBase64.
  • infiniflow/ragflow#16240: Modifies the provider/model lookup handler naming in enterprise_handler.go/router.go directly adjacent to this PR's ShowProviderModel rename.
  • infiniflow/ragflow#16226: Renames CreateUserAPIKey to GenerateUserAPIKey, which is one of the handlers this PR updates to use DecodeFromBase64.

Suggested labels

☯️ refactor, 💞 feature

🐇 A rabbit hops through paths encoded right,
No more email tricks — just base64's light!
The models split clean, each route finds its place,
/all-models/:name now shows each one's face.
From CLI to handler, the same key applies —
One rename to rule them, no more disguise! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: show model and list all models' clearly references the main changes to implement show model and list all models functionality.
Description check ✅ Passed The description includes the required 'What problem does this PR solve?' section with context about the enterprise edition errors, and specifies 'Refactoring' as the type of change, but omits a substantive explanation of the solution approach.
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.

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


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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 23, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 23, 2026 10:22
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 23, 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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/common/format.go (1)

77-87: 🎯 Functional Correctness | 🟠 Major

Switch to base64.URLEncoding for values embedded in URL path segments.

These helpers back username and model-name values embedded in request paths (e.g., /admin/users/:username, /admin/users/:username/keys). base64.StdEncoding emits +, /, and =. A / in the encoded output is interpreted as a path separator by Gin and will not be captured by a single-segment :param, so encode→path→decode round-trips fail for any input whose base64 contains / (and +/= add further escaping hazards). Switch both functions to base64.URLEncoding (alphabet -/_, no /) to keep encoding/decoding symmetric and path-safe.

Proposed fix
-func EncodeToBase64(email string) string {
-	return base64.StdEncoding.EncodeToString([]byte(email))
+func EncodeToBase64(s string) string {
+	return base64.URLEncoding.EncodeToString([]byte(s))
 }
 
 func DecodeFromBase64(encoded string) (string, error) {
-	decoded, err := base64.StdEncoding.DecodeString(encoded)
+	decoded, err := base64.URLEncoding.DecodeString(encoded)
 	if err != nil {
 		return "", err
 	}
 	return string(decoded), nil
 }
🤖 Prompt for 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.

In `@internal/common/format.go` around lines 77 - 87, The EncodeToBase64 and
DecodeFromBase64 functions use base64.StdEncoding which produces characters like
slash, plus, and equals that cause path parsing issues when embedded in URL
segments (e.g., /admin/users/:username). Replace base64.StdEncoding with
base64.URLEncoding in both functions to use URL-safe alphabet characters (dash
and underscore instead of plus and slash) that remain safe in path parameters
and preserve encoding-decoding symmetry.
🤖 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 `@internal/admin/router.go`:
- Line 187: The DELETE route for DeleteModelInstance handler in the provider
router is currently bound to the collection path `/:provider_name/instances`
without an instance identifier. Change this route to include an instance_name
parameter so it becomes instance-scoped, allowing the handler to target and
delete a specific instance rather than operating at the collection level. This
will enable the DeleteModelInstance handler to properly access the instance_name
from the route parameters.

In `@internal/cli/common_command.go`:
- Around line 1432-1445: The EncodeToBase64 function in
internal/common/format.go is using base64.StdEncoding which produces URL-unsafe
characters like forward slashes and plus signs that break URL path matching when
the encoded values are used in route paths like
/admin/all-models/{encoded_name}. Replace the
base64.StdEncoding.EncodeToString() call with
base64.URLEncoding.EncodeToString() (or base64.RawURLEncoding if padding is not
needed) to ensure the encoded values are safe for use as URL path segments
across all handlers that use this helper function.

---

Outside diff comments:
In `@internal/common/format.go`:
- Around line 77-87: The EncodeToBase64 and DecodeFromBase64 functions use
base64.StdEncoding which produces characters like slash, plus, and equals that
cause path parsing issues when embedded in URL segments (e.g.,
/admin/users/:username). Replace base64.StdEncoding with base64.URLEncoding in
both functions to use URL-safe alphabet characters (dash and underscore instead
of plus and slash) that remain safe in path parameters and preserve
encoding-decoding symmetry.
🪄 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: 318291d3-2c12-4535-a940-d93bfb23beb7

📥 Commits

Reviewing files that changed from the base of the PR and between 643cb47 and 4983bb3.

📒 Files selected for processing (6)
  • internal/admin/enterprise_handler.go
  • internal/admin/handler.go
  • internal/admin/router.go
  • internal/cli/admin_command.go
  • internal/cli/common_command.go
  • internal/common/format.go

Comment thread internal/admin/router.go

provider.POST("/:provider_name/instances", r.handler.AddModelInstance)
provider.GET("/:provider_name/instances", r.handler.ListModelInstances)
provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance)

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use an instance-scoped delete route for DeleteModelInstance.

Line 187 still binds deletion to /providers/:provider_name/instances (collection path). This prevents targeting a specific instance via route param and can break handlers expecting instance_name.

Proposed fix
-				provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance)
+				provider.DELETE("/:provider_name/instances/:instance_name", r.handler.DeleteModelInstance)
📝 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
provider.DELETE("/:provider_name/instances", r.handler.DeleteModelInstance)
provider.DELETE("/:provider_name/instances/:instance_name", r.handler.DeleteModelInstance)
🤖 Prompt for 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.

In `@internal/admin/router.go` at line 187, The DELETE route for
DeleteModelInstance handler in the provider router is currently bound to the
collection path `/:provider_name/instances` without an instance identifier.
Change this route to include an instance_name parameter so it becomes
instance-scoped, allowing the handler to target and delete a specific instance
rather than operating at the collection level. This will enable the
DeleteModelInstance handler to properly access the instance_name from the route
parameters.

Comment on lines +1432 to +1445
encodedModelName := common.EncodeToBase64(modelName)

var resp *Response
var err error
var httpClient *HTTPClient
switch c.Config.CLIMode {
case AdminMode:
baseURL := fmt.Sprintf("/admin/all-models/%s", encodedModelName)
httpClient = c.AdminServerClient
resp, err = httpClient.Request("GET", "/admin/all-models", "web", nil, payload)
resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)
case APIMode:
baseURL := fmt.Sprintf("/all-models/%s", encodedModelName)
httpClient = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
resp, err = httpClient.Request("GET", "/all-models", "web", nil, payload)
resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)

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.

🎯 Functional Correctness | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate base64 helpers =="
fd -p 'format.go' internal/common | while read -r f; do
  echo "-- $f --"
  rg -n 'func (EncodeToBase64|DecodeFromBase64)|StdEncoding|URLEncoding|RawURLEncoding|RawStdEncoding' "$f" -C2
done

echo
echo "== Locate model-name param decoding in admin handlers =="
fd -p 'enterprise_handler.go' internal/admin | while read -r f; do
  echo "-- $f --"
  rg -n 'ShowModel|ListAllModels|Param\("model_name"\)|DecodeFromBase64' "$f" -C2
done

Repository: infiniflow/ragflow

Length of output: 6295


Replace base64.StdEncoding with base64.URLEncoding in EncodeToBase64() helper.

The helper at internal/common/format.go:77–79 currently uses base64.StdEncoding.EncodeToString(), which produces characters like / and + that are unsafe in URL path segments. Since encoded model names (and usernames) are placed directly in routes like /admin/all-models/{encoded_name}, any encoded / will be interpreted as a path delimiter and break route matching.

Replace with base64.URLEncoding (or base64.RawURLEncoding if padding is unnecessary) to ensure path-segment safety across all affected handlers.

🤖 Prompt for 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.

In `@internal/cli/common_command.go` around lines 1432 - 1445, The EncodeToBase64
function in internal/common/format.go is using base64.StdEncoding which produces
URL-unsafe characters like forward slashes and plus signs that break URL path
matching when the encoded values are used in route paths like
/admin/all-models/{encoded_name}. Replace the
base64.StdEncoding.EncodeToString() call with
base64.URLEncoding.EncodeToString() (or base64.RawURLEncoding if padding is not
needed) to ensure the encoded values are safe for use as URL path segments
across all handlers that use this helper function.

@JinHai-CN
JinHai-CN marked this pull request as draft June 23, 2026 10:40
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 23, 2026 10:40
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (643cb47) to head (4983bb3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16272   +/-   ##
=======================================
  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.

@JinHai-CN
JinHai-CN merged commit 4f02ba4 into infiniflow:main Jun 23, 2026
12 of 15 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 26, 2026
1 task done
@coderabbitai coderabbitai Bot mentioned this pull request Jul 3, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant