fix: id和original_name隐藏字段分开判断,避免空id导致新增
This commit is contained in:
parent
04908155a4
commit
873cc3e1a4
@ -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
|
||||
|
||||
@ -232,7 +232,8 @@ toggleIntegrationFields('{{.AssetIntegration.Type}}');
|
||||
</div>
|
||||
{{if .AssetVideoSource}}
|
||||
<form method="post" action="/assets/video-sources">
|
||||
{{if .AssetVideoSource}}<input type="hidden" name="id" value="{{.AssetVideoSource.ID}}"><input type="hidden" name="original_name" value="{{.AssetVideoSource.Name}}">{{end}}
|
||||
{{if .AssetVideoSource.ID}}<input type="hidden" name="id" value="{{.AssetVideoSource.ID}}">{{end}}
|
||||
{{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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user