refactor: reload config on websocket connection.

This commit is contained in:
arabcoders 2026-01-28 17:49:26 +03:00
parent d8ccbe00fa
commit 651aa14882
3 changed files with 8 additions and 20 deletions

View file

@ -1,13 +1,16 @@
import logging
from app.library.Events import EventBus, Events
from app.library.router import RouteType, route
LOG: logging.Logger = logging.getLogger(__name__)
@route(RouteType.SOCKET, "connect", "socket_connect")
async def connect(sid: str):
pass
async def connect(notify: EventBus, sid: str):
notify.emit(
Events.CONNECTED, data={"sid": sid}, title="Client connected", message=f"Client '{sid}' connected.", to=sid
)
@route(RouteType.SOCKET, "disconnect", "socket_disconnect")

View file

@ -264,20 +264,9 @@ export const useSocketStore = defineStore('socket', () => {
on('connect', () => config.loadConfig(false))
on('connected', (data: WSEP['connected']) => {
if (!data?.data) {
return
}
if (data.data.folders) {
config.add('folders', data.data.folders)
}
if ('number' === typeof data.data.history_count) {
stateStore.setHistoryCount(data.data.history_count)
}
on('connected', () => {
error.value = null
config.loadConfig(false)
})
on('item_added', (data: WSEP['item_added']) => {

View file

@ -20,11 +20,7 @@ export type WSEP = {
connect: null
disconnect: null
connect_error: { message?: string }
connected: EventPayload<{
folders?: string[]
history_count?: number
queue?: Record<string, StoreItem>
}>
connected: EventPayload<{ sid: string }>
item_added: EventPayload<StoreItem>
item_updated: EventPayload<StoreItem>
item_cancelled: EventPayload<StoreItem>