From 7f8ed0e8a0f1e9007552fc069558b140c84dad17 Mon Sep 17 00:00:00 2001 From: valere Date: Fri, 1 Nov 2024 13:15:23 +0100 Subject: [PATCH] FEAT: playlists player v1 --- components/playlists-list.vue | 14 ++++++++++ components/zero-b.vue | 28 ------------------- pages/index.vue | 3 +- pages/playlists/[id].vue | 52 +++++++++++++++++++++++++++++++++++ server/api/playlists/[id].ts | 23 ++++++++++++++++ server/api/playlists/index.ts | 21 ++++++++++++++ 6 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 components/playlists-list.vue delete mode 100644 components/zero-b.vue create mode 100644 pages/playlists/[id].vue create mode 100644 server/api/playlists/[id].ts create mode 100644 server/api/playlists/index.ts diff --git a/components/playlists-list.vue b/components/playlists-list.vue new file mode 100644 index 0000000..79e1255 --- /dev/null +++ b/components/playlists-list.vue @@ -0,0 +1,14 @@ + + + diff --git a/components/zero-b.vue b/components/zero-b.vue deleted file mode 100644 index 1278b6c..0000000 --- a/components/zero-b.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/pages/index.vue b/pages/index.vue index 177f5fd..2e8fc6d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -27,8 +27,9 @@
-
+
+
diff --git a/pages/playlists/[id].vue b/pages/playlists/[id].vue new file mode 100644 index 0000000..3f86d43 --- /dev/null +++ b/pages/playlists/[id].vue @@ -0,0 +1,52 @@ + + + + + \ No newline at end of file diff --git a/server/api/playlists/[id].ts b/server/api/playlists/[id].ts new file mode 100644 index 0000000..c72f80d --- /dev/null +++ b/server/api/playlists/[id].ts @@ -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 + } + } +}) diff --git a/server/api/playlists/index.ts b/server/api/playlists/index.ts new file mode 100644 index 0000000..20ef77f --- /dev/null +++ b/server/api/playlists/index.ts @@ -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 + } + } +})