FEAT: playlists player v1

This commit is contained in:
valere
2024-11-01 13:15:23 +01:00
parent 0ca4cc3bfe
commit 7f8ed0e8a0
6 changed files with 112 additions and 29 deletions

View File

@@ -0,0 +1,23 @@
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
}
}
})

View File

@@ -0,0 +1,21 @@
import fs from 'fs'
import path from 'path'
export default eventHandler(async (event) => {
const directoryPath = path.join(process.cwd(), 'media/files/music')
try {
// Read the directory contents
const files = await fs.promises.readdir(directoryPath)
return {
success: true,
files: files.filter(file => !file.startsWith('.')).reverse() // exclude unwanted files
}
} catch (error) {
return {
success: false,
error: error.message
}
}
})