Skip to content

Commit

Permalink
fix: config
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 committed Oct 31, 2024
1 parent dcf9086 commit 20931cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 9 additions & 6 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@ 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
""",
{"owner_id": owner_id},
model=UserConfig,
)
if user_config:
return user_config.extra
return None
4 changes: 1 addition & 3 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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()

0 comments on commit 20931cc

Please sign in to comment.