Skip to content

Commit 150d771

Browse files
committed
Bug fix.
1 parent 799c23b commit 150d771

6 files changed

Lines changed: 18 additions & 13 deletions

File tree

cmd/dashboard/controller/common_page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ func (cp *commonPage) ws(c *gin.Context) {
12291229
log.Printf("WebSocket连接建立: %s", connID)
12301230

12311231
// 使用Context来统一控制此连接所有Goroutine的生命周期
1232-
ctx, cancel := context.WithCancel(c.Request.Context())
1232+
ctx, cancel := context.WithCancel(c.Request.Context()) // #nosec G118 -- cancel is deferred below
12331233

12341234
// defer确保在函数退出时,无论任何原因,都能调用cancel()来清理所有goroutine
12351235
defer func() {

cmd/dashboard/controller/oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (oa *oauth2controller) getCommonOauth2Config(c *gin.Context) *oauth2.Config
4646
ClientID: singleton.Conf.Oauth2.ClientID,
4747
ClientSecret: singleton.Conf.Oauth2.ClientSecret,
4848
Scopes: []string{},
49-
Endpoint: oauth2.Endpoint{
49+
Endpoint: oauth2.Endpoint{ // #nosec G101 -- OAuth2 endpoint URLs, not credentials
5050
AuthURL: "https://gitee.com/oauth/authorize",
5151
TokenURL: "https://gitee.com/oauth/token",
5252
},
@@ -65,7 +65,7 @@ func (oa *oauth2controller) getCommonOauth2Config(c *gin.Context) *oauth2.Config
6565
ClientID: singleton.Conf.Oauth2.ClientID,
6666
ClientSecret: singleton.Conf.Oauth2.ClientSecret,
6767
Scopes: []string{"read_user", "read_api"},
68-
Endpoint: oauth2.Endpoint{
68+
Endpoint: oauth2.Endpoint{ // #nosec G101 -- OAuth2 endpoint URLs, not credentials
6969
AuthURL: "https://jihulab.com/oauth/authorize",
7070
TokenURL: "https://jihulab.com/oauth/token",
7171
},

cmd/dashboard/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func main() {
132132

133133
singleton.InitLocalizer()
134134

135+
// 初始化 GeoIP 数据库(在 RPC 服务启动前完成)
136+
singleton.InitGeoIP()
137+
135138
// 初始化Goroutine池,防止内存泄漏
136139
singleton.InitGoroutinePools()
137140

db/migration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func (m *Migration) migrateServers() error {
536536
if err := validateID(progress.LastProcessed); err != nil {
537537
return fmt.Errorf("invalid LastProcessed ID: %w", err)
538538
}
539-
query += fmt.Sprintf(" AND id > %s", progress.LastProcessed)
539+
query += fmt.Sprintf(" AND id > %s", progress.LastProcessed) // #nosec G202 -- validated by validateID
540540
}
541541
query += " ORDER BY id"
542542

@@ -1202,7 +1202,7 @@ func (m *Migration) migrateMonitorHistories() error {
12021202
}
12031203
query += fmt.Sprintf(" LIMIT %d", batchSize)
12041204
} else if m.config.BatchSize > 0 {
1205-
query += fmt.Sprintf(" LIMIT %d", m.config.BatchSize)
1205+
query += fmt.Sprintf(" LIMIT %d", m.config.BatchSize) // #nosec G202 -- BatchSize is a typed int, not user input
12061206
}
12071207
} else {
12081208
// 如果不支持恢复,直接退出
@@ -1574,7 +1574,7 @@ func (m *Migration) migrateTransfers() error {
15741574
}
15751575
query = fmt.Sprintf("SELECT * FROM transfers WHERE id > %s ORDER BY id", lastID)
15761576
if m.config.BatchSize > 0 {
1577-
query += fmt.Sprintf(" LIMIT %d", m.config.BatchSize)
1577+
query += fmt.Sprintf(" LIMIT %d", m.config.BatchSize) // #nosec G202 -- BatchSize is a typed int, not user input
15781578
}
15791579
} else {
15801580
// 如果不支持恢复,直接退出

service/rpc/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ func (s *ServerHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rec
747747
host.IP, len(providers))
748748
for _, provider := range providers {
749749
go func(provider *ddns.Provider) {
750-
provider.UpdateDomain(context.Background())
750+
provider.UpdateDomain(c) // #nosec G118 -- use request context for DDNS update
751751
}(provider)
752752
}
753753
} else {

service/singleton/singleton.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,6 @@ func LoadSingleton() {
239239
}
240240
}()
241241

242-
// 初始化 GeoIP 数据库
243-
log.Println("正在初始化 GeoIP 数据库...")
244-
if err := geoip.Init(Conf.GeoIPDB); err != nil {
245-
log.Printf("GeoIP 数据库初始化失败: %v", err)
246-
}
247-
248242
// 加载通知服务
249243
log.Println("正在加载通知服务...")
250244
func() {
@@ -451,6 +445,14 @@ func LoadSingleton() {
451445
validateAndFixDataIntegrity()
452446
}
453447

448+
// InitGeoIP 初始化 GeoIP 数据库
449+
func InitGeoIP() {
450+
log.Println("正在初始化 GeoIP 数据库...")
451+
if err := geoip.Init(Conf.GeoIPDB); err != nil {
452+
log.Printf("GeoIP 数据库初始化失败: %v", err)
453+
}
454+
}
455+
454456
// InitConfigFromPath 从给出的文件路径中加载配置
455457
func InitConfigFromPath(path string) {
456458
Conf = &model.Config{}

0 commit comments

Comments
 (0)