Fix Nuggets workflow audio: serve with audio content type (nosniff blocked octet-stream), show playback errors; v2.17.1
Publish Container / build (push) Successful in 16m34s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 5.5 committed 2026-10-12 08:56:41 -04:00
1 parent 326838e5bc
commit 11f3d76e9b
4 files changed
+34 -7

No files matched your search

+18 -3
View File
@@ -15,6 +15,15 @@ import {
const WORKFLOW_FILE = path.join(DATA_DIR, 'nuggets-workflow.json')
const AUDIO_TYPES = {
'.mp3': 'audio/mpeg',
'.wav': 'audio/wav',
'.m4a': 'audio/mp4',
'.aac': 'audio/aac',
'.ogg': 'audio/ogg',
'.flac': 'audio/flac',
}
export const WORKFLOW_STEPS = ['listen', 'coldOpen', 'recordColdOpen', 'edit', 'spotify']
async function loadWorkflow() {
@@ -100,6 +109,7 @@ export function register(app) {
{ headers: { Authorization: `Token ${SEAFILE_TOKEN}` }, signal: AbortSignal.timeout(10_000) },
)
if (!linkRes.ok) {
console.error(`[nuggets-workflow] Seafile link lookup for "${filePath}" failed: ${linkRes.status}`)
res.status(404).json({ message: 'Audio file not found in Seafile.' })
return
}
@@ -109,21 +119,26 @@ export function register(app) {
if (req.headers.range) headers.Range = req.headers.range
const upstream = await fetch(downloadUrl, { headers })
if (!upstream.ok && upstream.status !== 206) {
console.error(`[nuggets-workflow] Seafile download failed: ${upstream.status}`)
res.status(502).json({ message: 'Could not fetch audio from Seafile.' })
return
}
res.status(upstream.status)
for (const h of ['content-type', 'content-length', 'content-range', 'accept-ranges']) {
for (const h of ['content-length', 'content-range', 'accept-ranges']) {
const v = upstream.headers.get(h)
if (v) res.setHeader(h, v)
}
if (!upstream.headers.get('content-type')) res.setHeader('content-type', 'audio/mpeg')
// Seafile serves downloads as application/octet-stream, which browsers refuse to play
// (the site sends nosniff), so set the audio type from the file extension.
const ext = path.extname(entry.filename).toLowerCase()
res.setHeader('content-type', AUDIO_TYPES[ext] ?? 'audio/mpeg')
if (!res.getHeader('accept-ranges')) res.setHeader('accept-ranges', 'bytes')
const stream = Readable.fromWeb(upstream.body)
req.on('close', () => stream.destroy())
stream.on('error', () => res.end())
stream.pipe(res)
} catch (err) {
console.error('[nuggets-workflow] audio error:', err.message)
console.error('[nuggets-workflow] audio error:', err.message, err.cause?.message ?? '')
if (!res.headersSent) res.status(500).json({ message: 'Audio stream failed.' })
}
})