Skip to content

Commit 0f7f22b

Browse files
committed
removed event type ERROR and migrated it's uses to LOG_ERROR
1 parent 138a497 commit 0f7f22b

5 files changed

Lines changed: 34 additions & 22 deletions

File tree

app/library/Events.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
LOG: logging.Logger = logging.getLogger("Events")
1313

14+
1415
class Events:
1516
"""
1617
The events that can be emitted.
@@ -22,37 +23,40 @@ class Events:
2223
SHUTDOWN = "shutdown"
2324

2425
ADDED = "added"
26+
UPDATE = "update"
2527
UPDATED = "updated"
2628
COMPLETED = "completed"
2729
CANCELLED = "cancelled"
2830
CLEARED = "cleared"
29-
ERROR = "error"
31+
CONNECTED = "connected"
32+
STATUS = "status"
33+
3034
LOG_INFO = "log_info"
3135
LOG_WARNING = "log_warning"
3236
LOG_ERROR = "log_error"
3337
LOG_SUCCESS = "log_success"
3438

35-
INITIAL_DATA = "initial_data"
3639
ITEM_DELETE = "item_delete"
3740
ITEM_CANCEL = "item_cancel"
3841
ITEM_ERROR = "item_error"
39-
STATUS = "status"
40-
CLI_CLOSE = "cli_close"
41-
CLI_OUTPUT = "cli_output"
42-
UPDATE = "update"
42+
4343
TEST = "test"
4444
ADD_URL = "add_url"
4545

46-
CLI_POST = "cli_post"
4746
PAUSED = "paused"
4847

48+
CLI_POST = "cli_post"
49+
CLI_CLOSE = "cli_close"
50+
CLI_OUTPUT = "cli_output"
51+
4952
TASKS_ADD = "task_add"
5053
TASK_DISPATCHED = "task_dispatched"
5154
TASK_FINISHED = "task_finished"
5255
TASK_ERROR = "task_error"
5356

5457
PRESETS_ADD = "presets_add"
5558
PRESETS_UPDATE = "presets_update"
59+
5660
SCHEDULE_ADD = "schedule_add"
5761

5862
CONDITIONS_ADD = "conditions_add"
@@ -82,9 +86,8 @@ def frontend() -> list:
8286
8387
"""
8488
return [
85-
Events.INITIAL_DATA,
89+
Events.CONNECTED,
8690
Events.ADDED,
87-
Events.ERROR,
8891
Events.LOG_INFO,
8992
Events.LOG_WARNING,
9093
Events.LOG_ERROR,

app/library/Notifications.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def get(self, key: str, default: Any = None) -> Any:
9292
class NotificationEvents:
9393
ADDED = Events.ADDED
9494
COMPLETED = Events.COMPLETED
95-
ERROR = Events.ERROR
9695
CANCELLED = Events.CANCELLED
9796
CLEARED = Events.CLEARED
9897
LOG_INFO = Events.LOG_INFO
@@ -308,10 +307,17 @@ def validate(target: Target | dict) -> bool:
308307
msg = "Invalid notification target. Invalid 'on' event list found."
309308
raise ValueError(msg)
310309

310+
removed_events = []
311+
all_events = NotificationEvents.get_events().values()
311312
for e in target["on"]:
312-
if e not in NotificationEvents.get_events().values():
313-
msg = f"Invalid notification target. Invalid event '{e}' found."
314-
raise ValueError(msg)
313+
if e not in all_events:
314+
removed_events.append(e)
315+
target["on"].remove(e)
316+
continue
317+
318+
if len(removed_events) > 0 and len(target["on"]) < 1:
319+
msg: str = f"Invalid notification target. Invalid events '{', '.join(removed_events)}' found."
320+
raise ValueError(msg)
315321

316322
if "headers" in target["request"]:
317323
if not isinstance(target["request"]["headers"], list):

app/routes/socket/connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ async def connect(config: Config, queue: DownloadQueue, notify: EventBus, sid: s
3131

3232
data["folders"] = [folder.name for folder in Path(config.download_path).iterdir() if folder.is_dir()]
3333

34-
await notify.emit(Events.INITIAL_DATA, data=data, to=sid)
34+
await notify.emit(
35+
Events.CONNECTED,
36+
data=data,
37+
title="Client connected",
38+
message=f"Client '{sid}' connected.",
39+
to=sid,
40+
)
3541

3642

3743
@route(RouteType.SOCKET, "disconnect", "socket_disconnect")
@@ -67,7 +73,7 @@ async def subscribe(config: Config, notify: EventBus, sio: socketio.AsyncServer,
6773
"""
6874
if not isinstance(data, str) or not data:
6975
await notify.emit(
70-
Events.ERROR,
76+
Events.LOG_ERROR,
7177
title="Subscription Error",
7278
message="Invalid event type was expecting a string.",
7379
to=sid,

app/routes/socket/history.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ async def item_cancel(queue: DownloadQueue, notify: EventBus, sid: str, data: st
8080
status = await queue.cancel([data])
8181
status.update({"identifier": data})
8282

83-
await notify.emit(Events.ITEM_CANCEL, data=status)
83+
await notify.emit(
84+
Events.ITEM_CANCEL, data=status, title="Item Cancelled", message=f"Item '{data}': has been cancelled."
85+
)
8486

8587

8688
@route(RouteType.SOCKET, "item_delete", "item_delete")

ui/stores/SocketStore.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const useSocketStore = defineStore('socket', () => {
3030
socket.value.on('connect', () => isConnected.value = true);
3131
socket.value.on('disconnect', () => isConnected.value = false);
3232

33-
socket.value.on('initial_data', stream => {
33+
socket.value.on('connected', stream => {
3434
const json = JSON.parse(stream)
3535

3636
config.setAll({
@@ -51,11 +51,6 @@ export const useSocketStore = defineStore('socket', () => {
5151
toast.success(`Item queued: ${ag(stateStore.get('queue', json.data._id, {}), 'title')}`);
5252
});
5353

54-
socket.value.on('error', stream => {
55-
const json = JSON.parse(stream);
56-
toast.error(`${json.data?.id}: ${json?.message || json?.data?.message}`, json.data || {});
57-
});
58-
5954
['log_info', 'log_success', 'log_warning', 'log_error'].forEach(event => socket.value?.on(event, stream => {
6055
const json = JSON.parse(stream);
6156
const message = json?.message || json?.data?.message;

0 commit comments

Comments
 (0)