pass custom_directories from server to client
This commit is contained in:
parent
4a9f55adda
commit
f79c8fa754
15
app/main.py
15
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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue