diff --git a/internal/storage/assets_repo.go b/internal/storage/assets_repo.go index 5997221..6f75603 100644 --- a/internal/storage/assets_repo.go +++ b/internal/storage/assets_repo.go @@ -120,8 +120,13 @@ func (r *AssetsRepo) SaveVideoSource(id int, name string, sourceType string, are } now := time.Now().Format(time.RFC3339) if id > 0 { - // Update existing by ID - _, err := r.db.Exec(` + // Check name uniqueness before update + var existingID int + err := r.db.QueryRow(`SELECT id FROM video_sources WHERE name = ? AND id != ?`, name, id).Scan(&existingID) + if err == nil { + return fmt.Errorf("视频源名称 %q 已存在", name) + } + _, err = r.db.Exec(` UPDATE video_sources SET name=?, source_type=?, area=?, description=?, body_json=?, updated_at=? WHERE id=?`, name, sourceType, area, description, bodyJSON, now, id) return err diff --git a/internal/web/ui/templates/assets.html b/internal/web/ui/templates/assets.html index 9389a2c..5f81df5 100644 --- a/internal/web/ui/templates/assets.html +++ b/internal/web/ui/templates/assets.html @@ -232,7 +232,8 @@ toggleIntegrationFields('{{.AssetIntegration.Type}}'); {{if .AssetVideoSource}}