23 lines
		
	
	
		
			528 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			528 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import fs from 'fs'
 | |
| import path from 'path'
 | |
| import { eventHandler } from 'h3'
 | |
| 
 | |
| 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
 | |
|     }
 | |
|   }
 | |
| })
 |