Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e81005d1
authored
Sep 27, 2025
by
Seefs
Committed by
GitHub
Sep 27, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1070 from wzxjohn/feature/umami
feat: support UMAMI analytics
parents
83fc8cf8
0a858460
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
main.go
+18
-0
web/index.html
+1
-0
No files found.
main.go
View file @
e81005d1
package
main
package
main
import
(
import
(
"bytes"
"embed"
"embed"
"fmt"
"fmt"
"log"
"log"
...
@@ -16,6 +17,7 @@ import (
...
@@ -16,6 +17,7 @@ import (
"one-api/setting/ratio_setting"
"one-api/setting/ratio_setting"
"os"
"os"
"strconv"
"strconv"
"strings"
"github.com/bytedance/gopkg/util/gopool"
"github.com/bytedance/gopkg/util/gopool"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions"
...
@@ -145,6 +147,22 @@ func main() {
...
@@ -145,6 +147,22 @@ func main() {
})
})
server
.
Use
(
sessions
.
Sessions
(
"session"
,
store
))
server
.
Use
(
sessions
.
Sessions
(
"session"
,
store
))
analyticsInjectBuilder
:=
&
strings
.
Builder
{}
if
os
.
Getenv
(
"UMAMI_WEBSITE_ID"
)
!=
""
{
umamiSiteID
:=
os
.
Getenv
(
"UMAMI_WEBSITE_ID"
)
umamiScriptURL
:=
os
.
Getenv
(
"UMAMI_SCRIPT_URL"
)
if
umamiScriptURL
==
""
{
umamiScriptURL
=
"https://analytics.umami.is/script.js"
}
analyticsInjectBuilder
.
WriteString
(
"<script defer src=
\"
"
)
analyticsInjectBuilder
.
WriteString
(
umamiScriptURL
)
analyticsInjectBuilder
.
WriteString
(
"
\"
data-website-id=
\"
"
)
analyticsInjectBuilder
.
WriteString
(
umamiSiteID
)
analyticsInjectBuilder
.
WriteString
(
"
\"
></script>"
)
}
analyticsInject
:=
analyticsInjectBuilder
.
String
()
indexPage
=
bytes
.
ReplaceAll
(
indexPage
,
[]
byte
(
"<analytics></analytics>
\n
"
),
[]
byte
(
analyticsInject
))
router
.
SetRouter
(
server
,
buildFS
,
indexPage
)
router
.
SetRouter
(
server
,
buildFS
,
indexPage
)
var
port
=
os
.
Getenv
(
"PORT"
)
var
port
=
os
.
Getenv
(
"PORT"
)
if
port
==
""
{
if
port
==
""
{
...
...
web/index.html
View file @
e81005d1
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
content=
"OpenAI 接口聚合管理,支持多种渠道包括 Azure,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用"
content=
"OpenAI 接口聚合管理,支持多种渠道包括 Azure,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用"
/>
/>
<title>
New API
</title>
<title>
New API
</title>
<analytics></analytics>
</head>
</head>
<body>
<body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment