fix(media): metadata editor save no longer wipes audio_metadata

PUT /api/media-items/:id (the metadata editor) writes the FULL row via
UpdateMediaItem, whose query sets audio_metadata unconditionally — and
audio_metadata has no editor field, so the params literal left it nil
and every save NULLed the payload. A plain metadata edit (genre tweak,
title rename) dropped any audiobook back to "1 second long" with no
track manifest: the same incident class as the scanner wipe, sitting
on the most-used admin path in the app.

Carry existing.AudioMetadata through the write. Write-after-success:
only the audio chain (probe-backed extraction /
UpdateMediaItemAudioBookPayload) ever replaces that column.
This commit is contained in:
John O'Keefe committed 2026-10-21 20:23:42 -04:00
1 parent 80bfc1a77b
commit 35d8ba32e5
1 file changed
+8
+8
View File
@@ -1610,6 +1610,14 @@ func (mh *MediaHandler) UpdateMediaItem(c *echo.Context) error {
Summary: pgtype.Text{String: req.Summary, Valid: req.Summary != ""}, Summary: pgtype.Text{String: req.Summary, Valid: req.Summary != ""},
} }
// audio_metadata is scan-owned (track manifest, chapters, duration)
// and has no editor field: the full-row update writes it
// unconditionally, so an unguarded save NULLed every audiobook's
// payload — books dropped back to "1 second long" on a plain
// metadata edit (2026-10-21 incident class). Write-after-success:
// carry the existing bytes; only the audio chain replaces them.
params.AudioMetadata = existing.AudioMetadata
// Fields the user actually changed become overrides so future scans keep // Fields the user actually changed become overrides so future scans keep
// the custom values. An explicit cover upload/removal always overrides. // the custom values. An explicit cover upload/removal always overrides.
overrides := utils.DetectMetadataOverrides(params, existing) overrides := utils.DetectMetadataOverrides(params, existing)