fix: 修复问题

This commit is contained in:
耗子
2026-03-25 01:17:05 +08:00
parent 455f6c061d
commit b952ebf5ad
3 changed files with 12 additions and 4 deletions
+8 -1
View File
@@ -266,7 +266,14 @@ func (s *App) UpdateDataSource(w http.ResponseWriter, r *http.Request) {
for i, item := range list {
if ds, ok := item.(map[string]any); ok && ds["name"] == oldName {
found = true
list[i] = s.buildDatasourceMap(req)
newDs := s.buildDatasourceMap(req)
// 密码为空时保留原有 secureJsonData
if req.Password == "" {
if sec, exists := ds["secureJsonData"]; exists {
newDs["secureJsonData"] = sec
}
}
list[i] = newDs
break
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ type ConfigTune struct {
// DataSource 数据源
type DataSource struct {
Name string `form:"name" json:"name" validate:"required"`
Type string `form:"type" json:"type" validate:"required"`
Type string `form:"type" json:"type" validate:"required|in:prometheus,mysql,postgres,influxdb,loki,elasticsearch"`
URL string `form:"url" json:"url" validate:"required"`
Access string `form:"access" json:"access"`
IsDefault bool `form:"is_default" json:"is_default"`
+3 -2
View File
@@ -15,6 +15,7 @@ export default {
datasources: (): any => http.Get('/apps/grafana/datasources'),
createDatasource: (data: any): any => http.Post('/apps/grafana/datasources', data),
updateDatasource: (name: string, data: any): any =>
http.Post(`/apps/grafana/datasources/${name}`, data),
deleteDatasource: (name: string): any => http.Delete(`/apps/grafana/datasources/${name}`)
http.Post(`/apps/grafana/datasources/${encodeURIComponent(name)}`, data),
deleteDatasource: (name: string): any =>
http.Delete(`/apps/grafana/datasources/${encodeURIComponent(name)}`)
}