Skip to content

fix: root page does not have analytic code - #2261

Merged
seefs001 merged 2 commits into
QuantumNous:mainfrom
wzxjohn:hotfix/analytic
Nov 24, 2025
Merged

fix: root page does not have analytic code#2261
seefs001 merged 2 commits into
QuantumNous:mainfrom
wzxjohn:hotfix/analytic

Conversation

@wzxjohn

@wzxjohn wzxjohn commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

当前主页(index.html)是直接从 embed fs 内读取的,这导致 umami 和 GA 的替换逻辑未替换主页。
这个 PR 修改了主页的读取逻辑,强制使用替换逻辑替换后的主页,保证统计代码生效。

The root page https://xxx.xxx/ is served directly from the embed file system, which always delivers the original version of the index file — one that hasn’t been patched with the analytics code.

This PR prevents the static file system from serving the root page directly, ensuring that the version with the analytics code is always used.

Summary by CodeRabbit

  • Chores
    • Improved internal file system handling architecture for better code maintainability and stability.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The embedFileSystem type is refactored to conform to the http.FileSystem interface by adding an Open method and converting it to use pointer receivers. The EmbedFolder function now returns a pointer to embedFileSystem instead of a value, with the Open method handling root path requests by returning an error.

Changes

Cohort / File(s) Change Summary
Embed File System Interface Implementation
common/embed-file-system.go
Changed Exists method from value receiver to pointer receiver; added new Open(name string) (http.File, error) method with special handling for root path "/"; updated EmbedFolder to return *embedFileSystem instead of value type.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Single-file modification with straightforward interface conformance changes
  • New Open method contains minimal logic with a single conditional branch
  • Pointer receiver changes are mechanical and low-risk
  • Consider verifying that the http.File return type satisfies all required interface methods

Poem

🐰 A rabbit hops through file systems grand,
With pointers now to better understand,
The Open method takes its rightful place,
Interface conformance wins the race! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes fixing analytics code on the root page, but the changeset modifies embed-file-system.go to change method receivers and add an Open method—implementation details that don't directly convey the analytics fix objective. Revise the title to reflect the actual code changes, e.g., 'fix: Make root page use patched analytics code by disabling direct embedded file serving' or simply 'Prevent embedded filesystem from serving root page directly'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b899122 and 2a62aea.

📒 Files selected for processing (1)
  • common/embed-file-system.go (2 hunks)
🔇 Additional comments (4)
common/embed-file-system.go (4)

7-7: LGTM!

The os import is necessary for os.ErrNotExist used in the new Open method.


18-24: LGTM!

The change to a pointer receiver is necessary for consistency with the EmbedFolder return type. Note that Exists("/") will now return false due to the special handling in Open, which correctly prevents the embedded filesystem from serving the root page directly.


40-42: Pointer return type is correct and necessary.

The interface compliance is verified: static.ServeFileSystem requires the Exists and Open methods. Since these are defined with pointer receivers on embedFileSystem, only the pointer type &embedFileSystem satisfies the interface. The return statement is correct and required for the code to compile and function properly.


26-33: Verified: Implementation correctly implements the required interface and achieves the PR objective.

The code properly implements the ServeFileSystem interface with both required methods:

  • The ServeFileSystem interface embeds http.FileSystem and adds an Exists(prefix string, path string) bool method
  • embedFileSystem implements both Open() and Exists() methods
  • The special case for "/" returning os.ErrNotExist ensures the gin-contrib/static middleware cannot serve the root path
  • This forces the request through to the NoRoute handler at router/web-router.go:21, which serves the custom index with analytics patching

No issues found. The implementation correctly achieves the stated objective.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@seefs001
seefs001 merged commit 2f80e3f into QuantumNous:main Nov 24, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
fix: root page does not have analytic code
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.

2 participants