diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-27 08:49:13 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-27 08:49:13 +0300 |
| commit | dee27d8f2805c9e409853462d35f9103e1a8c53e (patch) | |
| tree | 3b7f7593b7481e012801dbf44961883407833d9e /internal/processor/audio.go | |
| parent | ad0cc92e16aa98ee10bead846c0ff4c74c5244d6 (diff) | |
processor: refactor to two-phase commit for inbox processing
Introduce postPlan to capture everything validated in Phase 1 before
any filesystem mutation occurs. Phase 1 scans the inbox, validates all
source files (parses text, markdown, image, audio), checks markdown
image claims for conflicts, and collects a plan per item. Phase 2
commits mutations only after every plan is validated: creates post
directories, writes assets, persists post.json, and removes sources.
If Phase 1 fails (e.g. unsupported file, missing markdown image, claim
conflict), no mutations occur and the inbox is left untouched. Roll
back the partial post directory if a mutation fails during commit.
Also refactor image and audio sub-processors into validation-only and
write-only parts (validateImage/writeImageAsset, validateAudio/copyFile)
so that Phase 1 is strictly read-only.
All existing tests pass.
Diffstat (limited to 'internal/processor/audio.go')
| -rw-r--r-- | internal/processor/audio.go | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/internal/processor/audio.go b/internal/processor/audio.go index 98aedcf..68938cf 100644 --- a/internal/processor/audio.go +++ b/internal/processor/audio.go @@ -4,27 +4,15 @@ import ( "fmt" "io" "os" - "path/filepath" ) -// processAudio copies an .mp3 file into destDir and returns an HTML <audio> snippet. -// The audio element has controls enabled so visitors can play it inline. -func processAudio(srcPath, destDir, postID string) (filename, htmlContent string, err error) { - outName := filepath.Base(srcPath) - outPath := filepath.Join(destDir, outName) - - if err := copyFile(srcPath, outPath); err != nil { - return "", "", err +// validateAudio confirms the audio source file exists and is readable. +func validateAudio(srcPath string) error { + f, err := os.Open(srcPath) + if err != nil { + return fmt.Errorf("open audio %s: %w", srcPath, err) } - - // The src attribute is relative to the site root. - src := fmt.Sprintf("posts/%s/%s", postID, outName) - html := fmt.Sprintf( - `<audio controls class="post-audio"><source src="%s" type="audio/mpeg">Your browser does not support audio.</audio>`, - src, - ) - - return outName, html, nil + return f.Close() } // copyFile copies the file at src to dst, creating dst if it does not exist. |
