fix(runtime-config): resolver MUSIC_DIR en tiempo de ejecución y no hornearlo en build; endpoints usan env absoluto o public fallback
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { join, resolve, isAbsolute } from 'path'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
@@ -9,10 +9,12 @@ export default defineEventHandler(async (event) => {
|
||||
console.log(`[MUSIC API] Music list request from ${realIP}`)
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
// Prefer absolute dir computed at build time; fallback to env or public path
|
||||
const defaultPublicPath = config.public?.musicPath || '/music'
|
||||
const publicRel = defaultPublicPath.replace(/^\//, '')
|
||||
const musicDir = config.musicDirAbs || process.env.MUSIC_DIR || join(process.cwd(), 'public', publicRel)
|
||||
const envDir = process.env.MUSIC_DIR
|
||||
const musicDir = envDir
|
||||
? (isAbsolute(envDir) ? envDir : resolve(process.cwd(), envDir))
|
||||
: join(process.cwd(), 'public', publicRel)
|
||||
|
||||
// Check if music directory exists
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user