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
d7e15a96
authored
Jul 06, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
feat(tokens): add cherryConfig support for URL generation and base64 encoding
parent
b67a4fda
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletions
+22
-1
common/str.go
+5
-0
setting/chat.go
+4
-1
web/src/components/table/TokensTable.js
+13
-0
No files found.
common/str.go
View file @
d7e15a96
package
common
package
common
import
(
import
(
"encoding/base64"
"encoding/json"
"encoding/json"
"math/rand"
"math/rand"
"strconv"
"strconv"
...
@@ -68,3 +69,7 @@ func StringToByteSlice(s string) []byte {
...
@@ -68,3 +69,7 @@ func StringToByteSlice(s string) []byte {
tmp2
:=
[
3
]
uintptr
{
tmp1
[
0
],
tmp1
[
1
],
tmp1
[
1
]}
tmp2
:=
[
3
]
uintptr
{
tmp1
[
0
],
tmp1
[
1
],
tmp1
[
1
]}
return
*
(
*
[]
byte
)(
unsafe
.
Pointer
(
&
tmp2
))
return
*
(
*
[]
byte
)(
unsafe
.
Pointer
(
&
tmp2
))
}
}
func
EncodeBase64
(
str
string
)
string
{
return
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
str
))
}
setting/chat.go
View file @
d7e15a96
...
@@ -6,8 +6,11 @@ import (
...
@@ -6,8 +6,11 @@ import (
)
)
var
Chats
=
[]
map
[
string
]
string
{
var
Chats
=
[]
map
[
string
]
string
{
//{
// "ChatGPT Next Web 官方示例": "https://app.nextchat.dev/#/?settings={\"key\":\"{key}\",\"url\":\"{address}\"}",
//},
{
{
"Ch
atGPT Next Web 官方示例"
:
"https://app.nextchat.dev/#/?settings={
\"
key
\"
:
\"
{key}
\"
,
\"
url
\"
:
\"
{address}
\"
}"
,
"Ch
erry Studio"
:
"cherrystudio://providers/api-keys?v=1&data={cherryConfig
}"
,
},
},
{
{
"Lobe Chat 官方示例"
:
"https://chat-preview.lobehub.com/?settings={
\"
keyVaults
\"
:{
\"
openai
\"
:{
\"
apiKey
\"
:
\"
{key}
\"
,
\"
baseURL
\"
:
\"
{address}/v1
\"
}}}"
,
"Lobe Chat 官方示例"
:
"https://chat-preview.lobehub.com/?settings={
\"
keyVaults
\"
:{
\"
openai
\"
:{
\"
apiKey
\"
:
\"
{key}
\"
,
\"
baseURL
\"
:
\"
{address}/v1
\"
}}}"
,
...
...
web/src/components/table/TokensTable.js
View file @
d7e15a96
...
@@ -432,9 +432,22 @@ const TokensTable = () => {
...
@@ -432,9 +432,22 @@ const TokensTable = () => {
if
(
serverAddress
===
''
)
{
if
(
serverAddress
===
''
)
{
serverAddress
=
window
.
location
.
origin
;
serverAddress
=
window
.
location
.
origin
;
}
}
if
(
url
.
includes
(
'{cherryConfig}'
)
===
true
)
{
let
cherryConfig
=
{
id
:
'new-api'
,
baseUrl
:
serverAddress
,
apiKey
:
'sk-'
+
record
.
key
,
}
// 替换 {cherryConfig} 为base64编码的JSON字符串
let
encodedConfig
=
encodeURIComponent
(
btoa
(
JSON
.
stringify
(
cherryConfig
))
);
url
=
url
.
replaceAll
(
'{cherryConfig}'
,
encodedConfig
);
}
else
{
let
encodedServerAddress
=
encodeURIComponent
(
serverAddress
);
let
encodedServerAddress
=
encodeURIComponent
(
serverAddress
);
url
=
url
.
replaceAll
(
'{address}'
,
encodedServerAddress
);
url
=
url
.
replaceAll
(
'{address}'
,
encodedServerAddress
);
url
=
url
.
replaceAll
(
'{key}'
,
'sk-'
+
record
.
key
);
url
=
url
.
replaceAll
(
'{key}'
,
'sk-'
+
record
.
key
);
}
window
.
open
(
url
,
'_blank'
);
window
.
open
(
url
,
'_blank'
);
};
};
...
...
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