UI mejorada

This commit is contained in:
2025-08-10 00:45:59 -06:00
parent 2f878a857a
commit 493d236dc4
8 changed files with 56 additions and 25 deletions

View File

@@ -16,18 +16,23 @@ export default defineEventHandler(async (event) => {
const headers = getHeaders(event)
const realIP = headers['x-real-ip'] || headers['x-forwarded-for'] || 'unknown'
console.log(`[MUSIC API] Request from ${realIP} for file: ${filename}`)
console.log('Original filename bytes:', [...filename].map(c => c.charCodeAt(0)))
// Decode the filename
try {
filename = decodeURIComponent(filename)
console.log('Decoded filename:', filename)
console.log('Decoded filename bytes:', [...filename].map(c => c.charCodeAt(0)))
} catch (error) {
console.error('Error decoding filename:', error)
// If decoding fails, use original filename
}
try {
const musicDir = join(process.cwd(), 'public', 'music')
const config = useRuntimeConfig()
const defaultPublicPath = config.public?.musicPath || '/music'
const publicRel = defaultPublicPath.replace(/^\//, '')
const musicDir = process.env.MUSIC_DIR || join(process.cwd(), 'public', publicRel)
const filePath = join(musicDir, filename)
// Security check: ensure the file is within the music directory
@@ -41,7 +46,16 @@ export default defineEventHandler(async (event) => {
// Check if file exists
try {
await fs.access(filePath)
} catch {
console.log('File found successfully:', filePath)
} catch (error) {
console.log('File NOT found:', filePath)
console.log('Directory contents:')
try {
const files = await fs.readdir(musicDir)
files.forEach(file => console.log(' -', file))
} catch (e) {
console.log('Cannot read directory:', e)
}
throw createError({
statusCode: 404,
statusMessage: 'File not found'
@@ -100,4 +114,4 @@ export default defineEventHandler(async (event) => {
statusMessage: 'Failed to serve music file'
})
}
})
})