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
9a65b864
authored
Dec 26, 2025
by
Seefs
Committed by
GitHub
Dec 26, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2528 from QuantumNous/fix/model-sync-overwrite-empty-missing
parents
c137a6b0
f45e707d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
controller/model_sync.go
+28
-4
service/convert.go
+0
-0
No files found.
controller/model_sync.go
View file @
9a65b864
...
@@ -249,7 +249,9 @@ func ensureVendorID(vendorName string, vendorByName map[string]upstreamVendor, v
...
@@ -249,7 +249,9 @@ func ensureVendorID(vendorName string, vendorByName map[string]upstreamVendor, v
return
0
return
0
}
}
// SyncUpstreamModels 同步上游模型与供应商,仅对「未配置模型」生效
// SyncUpstreamModels 同步上游模型与供应商:
// - 默认仅创建「未配置模型」
// - 可通过 overwrite 选择性覆盖更新本地已有模型的字段(前提:sync_official <> 0)
func
SyncUpstreamModels
(
c
*
gin
.
Context
)
{
func
SyncUpstreamModels
(
c
*
gin
.
Context
)
{
var
req
syncRequest
var
req
syncRequest
// 允许空体
// 允许空体
...
@@ -261,6 +263,28 @@ func SyncUpstreamModels(c *gin.Context) {
...
@@ -261,6 +263,28 @@ func SyncUpstreamModels(c *gin.Context) {
return
return
}
}
// 若既无缺失模型需要创建,也未指定覆盖更新字段,则无需请求上游数据,直接返回
if
len
(
missing
)
==
0
&&
len
(
req
.
Overwrite
)
==
0
{
modelsURL
,
vendorsURL
:=
getUpstreamURLs
(
req
.
Locale
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"data"
:
gin
.
H
{
"created_models"
:
0
,
"created_vendors"
:
0
,
"updated_models"
:
0
,
"skipped_models"
:
[]
string
{},
"created_list"
:
[]
string
{},
"updated_list"
:
[]
string
{},
"source"
:
gin
.
H
{
"locale"
:
req
.
Locale
,
"models_url"
:
modelsURL
,
"vendors_url"
:
vendorsURL
,
},
},
})
return
}
// 2) 拉取上游 vendors 与 models
// 2) 拉取上游 vendors 与 models
timeoutSec
:=
common
.
GetEnvOrDefault
(
"SYNC_HTTP_TIMEOUT_SECONDS"
,
15
)
timeoutSec
:=
common
.
GetEnvOrDefault
(
"SYNC_HTTP_TIMEOUT_SECONDS"
,
15
)
ctx
,
cancel
:=
context
.
WithTimeout
(
c
.
Request
.
Context
(),
time
.
Duration
(
timeoutSec
)
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
c
.
Request
.
Context
(),
time
.
Duration
(
timeoutSec
)
*
time
.
Second
)
...
@@ -307,9 +331,9 @@ func SyncUpstreamModels(c *gin.Context) {
...
@@ -307,9 +331,9 @@ func SyncUpstreamModels(c *gin.Context) {
createdModels
:=
0
createdModels
:=
0
createdVendors
:=
0
createdVendors
:=
0
updatedModels
:=
0
updatedModels
:=
0
var
skipped
[]
string
skipped
:=
make
([]
string
,
0
)
var
createdList
[]
string
createdList
:=
make
([]
string
,
0
)
var
updatedList
[]
string
updatedList
:=
make
([]
string
,
0
)
// 本地缓存:vendorName -> id
// 本地缓存:vendorName -> id
vendorIDCache
:=
make
(
map
[
string
]
int
)
vendorIDCache
:=
make
(
map
[
string
]
int
)
...
...
service/convert.go
View file @
9a65b864
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