From 799c944e01f5c533a614ab594ae82f984b2cbd13 Mon Sep 17 00:00:00 2001 From: valere Date: Mon, 28 Oct 2024 13:42:55 +0100 Subject: [PATCH] FEAT: api for playlists v0.1 --- docker-compose.yml | 4 +++- server/api/playlists.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 server/api/playlists.ts diff --git a/docker-compose.yml b/docker-compose.yml index ac3e4aa..8b3e03d 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,8 +11,10 @@ services: LETSENCRYPT_HOST: "${DOMAIN}" PUID: "${PUID}" PGID: "${PGID}" + volumes: + - "${MEDIA_DIR}:/app/media" networks: default: name: dockerweb - external: true + external: true \ No newline at end of file diff --git a/server/api/playlists.ts b/server/api/playlists.ts new file mode 100644 index 0000000..e3e5497 --- /dev/null +++ b/server/api/playlists.ts @@ -0,0 +1,21 @@ +import fs from 'fs' +import path from 'path' + +export default eventHandler(async (event) => { + const directoryPath = path.join(process.cwd(), '/app/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 + } + } +})