diff --git a/app/library/Events.py b/app/library/Events.py index 6a2e176f..8d287fe6 100644 --- a/app/library/Events.py +++ b/app/library/Events.py @@ -11,6 +11,7 @@ from .Singleton import Singleton LOG: logging.Logger = logging.getLogger("Events") + class Events: """ The events that can be emitted. @@ -22,30 +23,32 @@ class Events: SHUTDOWN = "shutdown" ADDED = "added" + UPDATE = "update" UPDATED = "updated" COMPLETED = "completed" CANCELLED = "cancelled" CLEARED = "cleared" - ERROR = "error" + CONNECTED = "connected" + STATUS = "status" + LOG_INFO = "log_info" LOG_WARNING = "log_warning" LOG_ERROR = "log_error" LOG_SUCCESS = "log_success" - INITIAL_DATA = "initial_data" ITEM_DELETE = "item_delete" ITEM_CANCEL = "item_cancel" ITEM_ERROR = "item_error" - STATUS = "status" - CLI_CLOSE = "cli_close" - CLI_OUTPUT = "cli_output" - UPDATE = "update" + TEST = "test" ADD_URL = "add_url" - CLI_POST = "cli_post" PAUSED = "paused" + CLI_POST = "cli_post" + CLI_CLOSE = "cli_close" + CLI_OUTPUT = "cli_output" + TASKS_ADD = "task_add" TASK_DISPATCHED = "task_dispatched" TASK_FINISHED = "task_finished" @@ -53,6 +56,7 @@ class Events: PRESETS_ADD = "presets_add" PRESETS_UPDATE = "presets_update" + SCHEDULE_ADD = "schedule_add" CONDITIONS_ADD = "conditions_add" @@ -82,9 +86,8 @@ class Events: """ return [ - Events.INITIAL_DATA, + Events.CONNECTED, Events.ADDED, - Events.ERROR, Events.LOG_INFO, Events.LOG_WARNING, Events.LOG_ERROR, diff --git a/app/library/Notifications.py b/app/library/Notifications.py index 295daa85..58656a58 100644 --- a/app/library/Notifications.py +++ b/app/library/Notifications.py @@ -92,7 +92,6 @@ class Target: class NotificationEvents: ADDED = Events.ADDED COMPLETED = Events.COMPLETED - ERROR = Events.ERROR CANCELLED = Events.CANCELLED CLEARED = Events.CLEARED LOG_INFO = Events.LOG_INFO @@ -308,10 +307,17 @@ class Notification(metaclass=Singleton): msg = "Invalid notification target. Invalid 'on' event list found." raise ValueError(msg) + removed_events = [] + all_events = NotificationEvents.get_events().values() for e in target["on"]: - if e not in NotificationEvents.get_events().values(): - msg = f"Invalid notification target. Invalid event '{e}' found." - raise ValueError(msg) + if e not in all_events: + removed_events.append(e) + target["on"].remove(e) + continue + + if len(removed_events) > 0 and len(target["on"]) < 1: + msg: str = f"Invalid notification target. Invalid events '{', '.join(removed_events)}' found." + raise ValueError(msg) if "headers" in target["request"]: if not isinstance(target["request"]["headers"], list): diff --git a/app/routes/socket/connection.py b/app/routes/socket/connection.py index bb2d0b7f..28407a4d 100644 --- a/app/routes/socket/connection.py +++ b/app/routes/socket/connection.py @@ -31,7 +31,13 @@ async def connect(config: Config, queue: DownloadQueue, notify: EventBus, sid: s data["folders"] = [folder.name for folder in Path(config.download_path).iterdir() if folder.is_dir()] - await notify.emit(Events.INITIAL_DATA, data=data, to=sid) + await notify.emit( + Events.CONNECTED, + data=data, + title="Client connected", + message=f"Client '{sid}' connected.", + to=sid, + ) @route(RouteType.SOCKET, "disconnect", "socket_disconnect") @@ -67,7 +73,7 @@ async def subscribe(config: Config, notify: EventBus, sio: socketio.AsyncServer, """ if not isinstance(data, str) or not data: await notify.emit( - Events.ERROR, + Events.LOG_ERROR, title="Subscription Error", message="Invalid event type was expecting a string.", to=sid, diff --git a/app/routes/socket/history.py b/app/routes/socket/history.py index 096fe121..77ada6fa 100644 --- a/app/routes/socket/history.py +++ b/app/routes/socket/history.py @@ -80,7 +80,9 @@ async def item_cancel(queue: DownloadQueue, notify: EventBus, sid: str, data: st status = await queue.cancel([data]) status.update({"identifier": data}) - await notify.emit(Events.ITEM_CANCEL, data=status) + await notify.emit( + Events.ITEM_CANCEL, data=status, title="Item Cancelled", message=f"Item '{data}': has been cancelled." + ) @route(RouteType.SOCKET, "item_delete", "item_delete") diff --git a/ui/stores/SocketStore.ts b/ui/stores/SocketStore.ts index a966595d..b430a5d2 100644 --- a/ui/stores/SocketStore.ts +++ b/ui/stores/SocketStore.ts @@ -30,7 +30,7 @@ export const useSocketStore = defineStore('socket', () => { socket.value.on('connect', () => isConnected.value = true); socket.value.on('disconnect', () => isConnected.value = false); - socket.value.on('initial_data', stream => { + socket.value.on('connected', stream => { const json = JSON.parse(stream) config.setAll({ @@ -51,11 +51,6 @@ export const useSocketStore = defineStore('socket', () => { toast.success(`Item queued: ${ag(stateStore.get('queue', json.data._id, {}), 'title')}`); }); - socket.value.on('error', stream => { - const json = JSON.parse(stream); - toast.error(`${json.data?.id}: ${json?.message || json?.data?.message}`, json.data || {}); - }); - ['log_info', 'log_success', 'log_warning', 'log_error'].forEach(event => socket.value?.on(event, stream => { const json = JSON.parse(stream); const message = json?.message || json?.data?.message;