Files
evilspins/server/api/playlists.ts
2024-10-28 13:45:55 +01:00

22 lines
552 B
TypeScript

import fs from 'fs'
import path from 'path'
export default eventHandler(async (event) => {
const directoryPath = path.join(process.cwd(), 'media/files/music') // 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
}
}
})