From 4e9cc4a36c388422e706452e66aa815e022a9dfe Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Tue, 4 Nov 2025 09:56:24 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`hotfix/?= =?UTF-8?q?analytic`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @wzxjohn. * https://github.com/QuantumNous/new-api/pull/2133#issuecomment-3484993715 The following files were modified: * `common/embed-file-system.go` --- common/embed-file-system.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/common/embed-file-system.go b/common/embed-file-system.go index d7bd2d5bd..d1a9af03d 100644 --- a/common/embed-file-system.go +++ b/common/embed-file-system.go @@ -4,6 +4,7 @@ import ( "embed" "io/fs" "net/http" + "os" "github.com/gin-contrib/static" ) @@ -14,7 +15,7 @@ type embedFileSystem struct { http.FileSystem } -func (e embedFileSystem) Exists(prefix string, path string) bool { +func (e *embedFileSystem) Exists(prefix string, path string) bool { _, err := e.Open(path) if err != nil { return false @@ -22,12 +23,22 @@ func (e embedFileSystem) Exists(prefix string, path string) bool { return true } +func (e *embedFileSystem) Open(name string) (http.File, error) { + if name == "/" { + // This will make sure the index page goes to NoRouter handler, + // which will use the replaced index bytes with analytic codes. + return nil, os.ErrNotExist + } + return e.FileSystem.Open(name) +} + +// requested subtree cannot be opened. func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem { efs, err := fs.Sub(fsEmbed, targetPath) if err != nil { panic(err) } - return embedFileSystem{ + return &embedFileSystem{ FileSystem: http.FS(efs), } -} +} \ No newline at end of file