Fix music directory path to match Docker mount point
All checks were successful
build-and-deploy / build (push) Successful in 19s
build-and-deploy / deploy (push) Successful in 2s

This commit is contained in:
2025-08-04 14:50:47 -06:00
parent c2ac2f02fd
commit f756457ea9

View File

@@ -0,0 +1,57 @@
import { promises as fs } from 'fs'
import { join } from 'path'
export default defineEventHandler(async (event) => {
try {
// Log incoming request for debugging proxy issues
const headers = getHeaders(event)
const realIP = headers['x-real-ip'] || headers['x-forwarded-for'] || 'unknown'
console.log(`[MUSIC API] Music list request from ${realIP}`)
const musicDir = join(process.cwd(), 'public', 'music')
// Check if music directory exists
try {
await fs.access(musicDir)
} catch {
// Create music directory if it doesn't exist
await fs.mkdir(musicDir, { recursive: true })
return { tracks: [] }
}
// Read music directory
const files = await fs.readdir(musicDir)
// Filter audio files
const audioExtensions = ['.mp3', '.wav', '.flac', '.m4a', '.ogg', '.aac']
const musicFiles = files.filter(file =>
audioExtensions.some(ext => file.toLowerCase().endsWith(ext))
)
// Get file stats and create track objects
const tracks = await Promise.all(
musicFiles.map(async (file) => {
const filePath = join(musicDir, file)
const stats = await fs.stat(filePath)
return {
name: file,
size: stats.size,
modified: stats.mtime,
duration: null // We'll set this on the client side when the audio loads
}
})
)
// Sort by name
tracks.sort((a, b) => a.name.localeCompare(b.name))
return { tracks }
} catch (error) {
console.error('Error reading music directory:', error)
throw createError({
statusCode: 500,
statusMessage: 'Failed to load music files'
})
}
})