diff options
author | James Woglom <j@wogloms.net> | 2022-08-29 20:41:21 -0400 |
---|---|---|
committer | James Woglom <j@wogloms.net> | 2022-08-29 20:41:21 -0400 |
commit | f79c8fa7542822cd3edd542d646fc5881d3bb80e (patch) | |
tree | 286b2562995d0d5a8fd05fb13e678725266fa719 | |
parent | Propagate configuration on load via downloads socket (diff) | |
download | metube-f79c8fa7542822cd3edd542d646fc5881d3bb80e.tar.gz metube-f79c8fa7542822cd3edd542d646fc5881d3bb80e.tar.bz2 metube-f79c8fa7542822cd3edd542d646fc5881d3bb80e.zip |
pass custom_directories from server to client
-rw-r--r-- | app/main.py | 15 | ||||
-rw-r--r-- | ui/src/app/app.component.sass | 3 | ||||
-rw-r--r-- | ui/src/app/downloads.service.ts | 10 |
3 files changed, 25 insertions, 3 deletions
diff --git a/app/main.py b/app/main.py index bbdfc87..56adc00 100644 --- a/app/main.py +++ b/app/main.py @@ -7,6 +7,7 @@ from aiohttp import web import socketio
import logging
import json
+import pathlib
from ytdl import DownloadQueueNotifier, DownloadQueue
@@ -100,6 +101,18 @@ async def delete(request): async def connect(sid, environ):
await sio.emit('all', serializer.encode(dqueue.get()), to=sid)
await sio.emit('configuration', serializer.encode(config), to=sid)
+ if config.CUSTOM_DIR:
+ await sio.emit('custom_directories', serializer.encode(get_custom_directories()), to=sid)
+
+def get_custom_directories():
+ path = pathlib.Path(config.DOWNLOAD_DIR)
+ # Recursively lists all subdirectories, and converts PosixPath objects to string
+ dirs = list(map(str, path.glob('**')))
+
+ if '.' in dirs:
+ dirs.remove('.')
+
+ return {"directories": dirs}
@routes.get(config.URL_PREFIX)
def index(request):
@@ -121,7 +134,7 @@ try: app.add_routes(routes)
except ValueError as e:
if 'ui/dist/metube' in str(e):
- raise RuntimeError('Could not find the frontend UI static assets. Please run `node_modules/.bin/ng build`') from e
+ raise RuntimeError('Could not find the frontend UI static assets. Please run `node_modules/.bin/ng build` inside the ui folder') from e
raise e
diff --git a/ui/src/app/app.component.sass b/ui/src/app/app.component.sass index 656fac2..d95fc0d 100644 --- a/ui/src/app/app.component.sass +++ b/ui/src/app/app.component.sass @@ -15,6 +15,9 @@ button.add-url
width: 100%
+.folder-dropdown-menu
+ width: 500px
+
$metube-section-color-bg: rgba(0,0,0,.07)
.metube-section-header
diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts index eb7bac3..018f225 100644 --- a/ui/src/app/downloads.service.ts +++ b/ui/src/app/downloads.service.ts @@ -34,6 +34,7 @@ export class DownloadsService { queueChanged = new Subject(); doneChanged = new Subject(); configuration = {}; + custom_directories = {}; constructor(private http: HttpClient, private socket: MeTubeSocket) { socket.fromEvent('all').subscribe((strdata: string) => { @@ -76,10 +77,15 @@ export class DownloadsService { this.doneChanged.next(null); }); socket.fromEvent('configuration').subscribe((strdata: string) => { - let data: string = JSON.parse(strdata); + let data = JSON.parse(strdata); console.debug("got configuration:", data); this.configuration = data; - }) + }); + socket.fromEvent('custom_directories').subscribe((strdata: string) => { + let data = JSON.parse(strdata); + console.debug("got custom_directories:", data); + this.custom_directories = data["directories"]; + }); } handleHTTPError(error: HttpErrorResponse) { |