From 20931ccfe65fb173003ef01b1ee460bf3a3663f0 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 31 Oct 2024 13:13:48 +0200 Subject: [PATCH] fix: config --- crud.py | 15 +++++++++------ views_api.py | 4 +--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crud.py b/crud.py index 5ee1282..f7ef76c 100644 --- a/crud.py +++ b/crud.py @@ -28,20 +28,20 @@ async def delete_relay(relay: Relay) -> None: ######################CONFIG####################### -async def create_config(owner_id: str) -> UserConfig: +async def create_config(owner_id: str) -> Config: admin_config = UserConfig(owner_id=owner_id) await db.insert("nostrclient.config", admin_config) - return admin_config + return admin_config.extra -async def update_config(owner_id: str, config: Config) -> UserConfig: +async def update_config(owner_id: str, config: Config) -> Config: user_config = UserConfig(owner_id=owner_id, extra=config) await db.update("nostrclient.config", user_config, "WHERE owner_id = :owner_id") - return user_config + return user_config.extra -async def get_config(owner_id: str) -> Optional[UserConfig]: - return await db.fetchone( +async def get_config(owner_id: str) -> Optional[Config]: + user_config: UserConfig = await db.fetchone( """ SELECT * FROM nostrclient.config WHERE owner_id = :owner_id @@ -49,3 +49,6 @@ async def get_config(owner_id: str) -> Optional[UserConfig]: {"owner_id": owner_id}, model=UserConfig, ) + if user_config: + return user_config.extra + return None diff --git a/views_api.py b/views_api.py index 330716e..925e48b 100644 --- a/views_api.py +++ b/views_api.py @@ -122,8 +122,6 @@ async def ws_relay(ws_id: str, websocket: WebSocket) -> None: config = await get_config(owner_id="admin") assert config, "Failed to get config" - config.public_ws = True - if not config.private_ws and not config.public_ws: raise ValueError("Websocket connections not accepted.") @@ -178,4 +176,4 @@ async def api_get_config() -> Config: async def api_update_config(data: Config): config = await update_config(owner_id="admin", config=data) assert config - return config.extra.dict() + return config.dict()