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, resolve, sep } from 'path'
|
||||
import { join, resolve, sep, isAbsolute } from 'path'
|
||||
import { createReadStream } from 'fs'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
@@ -30,9 +30,9 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
// Determine the music directory path
|
||||
let musicDir: string
|
||||
if (config.musicDirAbs || process.env.MUSIC_DIR) {
|
||||
// Prefer absolute dir from runtimeConfig; fallback to env (resolved relative to repo root at build time)
|
||||
musicDir = (config.musicDirAbs as string) || resolve(process.cwd(), process.env.MUSIC_DIR!)
|
||||
if (process.env.MUSIC_DIR) {
|
||||
// Resolve env to absolute
|
||||
musicDir = isAbsolute(process.env.MUSIC_DIR) ? process.env.MUSIC_DIR : resolve(process.cwd(), process.env.MUSIC_DIR)
|
||||
} else {
|
||||
// Fallback to public/music
|
||||
const defaultPublicPath = config.public?.musicPath || '/music'
|
||||
|
||||
@@ -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