From f756457ea996843e415ffe0383c8afd02ef417f4 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Mon, 4 Aug 2025 14:50:47 -0600 Subject: [PATCH] Fix music directory path to match Docker mount point --- server/api/music/index.get.ts | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 server/api/music/index.get.ts diff --git a/server/api/music/index.get.ts b/server/api/music/index.get.ts new file mode 100644 index 0000000..ed5a227 --- /dev/null +++ b/server/api/music/index.get.ts @@ -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' + }) + } +}) \ No newline at end of file