feat: 视频源改名,同步更新识别单元引用

This commit is contained in:
tian 2026-07-26 12:28:17 +08:00
parent 30a93d1c84
commit a4e0d1316f
4 changed files with 32 additions and 0 deletions

View File

@ -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("基础配置仓库未初始化")

View File

@ -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)
}

View File

@ -232,6 +232,7 @@ toggleIntegrationFields('{{.AssetIntegration.Type}}');
</div>
{{if .AssetVideoSource}}
<form method="post" action="/assets/video-sources">
{{if .AssetVideoSource.Name}}<input type="hidden" name="original_name" value="{{.AssetVideoSource.Name}}">{{end}}
<div class="card editor-state {{if .AssetVideoSourceEditing}}editing{{else}}readonly{{end}}">
<div class="section-title">
<div>

Binary file not shown.