Files
evilspins/server/api/playlists/[id].ts
2024-11-01 13:15:23 +01:00

24 lines
603 B
TypeScript

import fs from 'fs'
import path from 'path'
export default eventHandler(async (event) => {
const id = event.context.params?.id || ''
const directoryPath = path.join(process.cwd(), 'media/files/music/' + id) // replace 'your-folder' with the folder you want to list
try {
// Read the directory contents
const files = await fs.promises.readdir(directoryPath)
return {
success: true,
files: files.filter(file => !file.startsWith('.')) // optional: exclude unwanted files
}
} catch (error) {
return {
success: false,
error: error.message
}
}
})