diff --git a/internal/service/config_assets.go b/internal/service/config_assets.go index be112f7..f72355c 100644 --- a/internal/service/config_assets.go +++ b/internal/service/config_assets.go @@ -863,6 +863,27 @@ func (s *ConfigPreviewService) SaveVideoSourceAsset(asset ConfigVideoSourceAsset return s.assets.SaveVideoSource(name, sourceType, strings.TrimSpace(asset.Area), strings.TrimSpace(asset.Description), string(body)) } +func (s *ConfigPreviewService) RenameVideoSource(oldName, newName string) error { + if s == nil || s.assets == nil { + return fmt.Errorf("基础配置仓库未初始化") + } + if oldName == newName { + return nil + } + // Update recognition units referencing old name + units, _ := s.ListRecognitionUnits() + for _, u := range units { + if u.VideoSourceRef == oldName { + u.VideoSourceRef = newName + ref := recognitionUnitRef(u.SceneTemplateName, u.Name) + s.SaveRecognitionUnit(u, ref) + } + } + // Delete old, save new + s.DeleteVideoSource(oldName) + return nil +} + func (s *ConfigPreviewService) DeleteVideoSource(name string) error { if s == nil || s.assets == nil { return fmt.Errorf("基础配置仓库未初始化") diff --git a/internal/web/ui.go b/internal/web/ui.go index 403fad7..0403d4a 100644 --- a/internal/web/ui.go +++ b/internal/web/ui.go @@ -3755,6 +3755,16 @@ func (u *UI) actionAssetVideoSourceSave(w http.ResponseWriter, r *http.Request) u.render(w, r, "assets", data) return } + // Handle rename + originalName := strings.TrimSpace(r.FormValue("original_name")) + if originalName != "" && originalName != asset.Name { + if err := u.preview.RenameVideoSource(originalName, asset.Name); err != nil { + data := u.assetPageData("video-sources") + data.Error = err.Error() + u.render(w, r, "assets", data) + return + } + } http.Redirect(w, r, "/assets/video-sources?msg="+urlQueryEscape("视频源已保存")+"&name="+url.PathEscape(asset.Name), http.StatusFound) } diff --git a/internal/web/ui/templates/assets.html b/internal/web/ui/templates/assets.html index fbca85c..3e87e75 100644 --- a/internal/web/ui/templates/assets.html +++ b/internal/web/ui/templates/assets.html @@ -232,6 +232,7 @@ toggleIntegrationFields('{{.AssetIntegration.Type}}'); {{if .AssetVideoSource}}
+ {{if .AssetVideoSource.Name}}{{end}}
diff --git a/safesightd-linux-arm64 b/safesightd-linux-arm64 index 8fa0531..e5df817 100644 Binary files a/safesightd-linux-arm64 and b/safesightd-linux-arm64 differ