Improve stability (#25)
* chore: increase log level * feat: secure relays endpoint * feat: add config for the extension * chore: update `min_lnbits_version` * chore: improve logging * fix: decrypt logic * chore: improve logs
This commit is contained in:
parent
16ae9d15a1
commit
a119c3836a
8 changed files with 220 additions and 193 deletions
40
crud.py
40
crud.py
|
|
@ -1,7 +1,9 @@
|
|||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
import json
|
||||
|
||||
from . import db
|
||||
from .models import Relay
|
||||
from .models import Config, Relay
|
||||
|
||||
|
||||
async def get_relays() -> List[Relay]:
|
||||
|
|
@ -25,3 +27,37 @@ async def add_relay(relay: Relay) -> None:
|
|||
|
||||
async def delete_relay(relay: Relay) -> None:
|
||||
await db.execute("DELETE FROM nostrclient.relays WHERE url = ?", (relay.url,))
|
||||
|
||||
|
||||
######################CONFIG#######################
|
||||
async def create_config() -> Config:
|
||||
config = Config()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO nostrclient.config (json_data)
|
||||
VALUES (?)
|
||||
""",
|
||||
(json.dumps(config.dict())),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
)
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d))
|
||||
|
||||
|
||||
async def update_config(config: Config) -> Optional[Config]:
|
||||
await db.execute(
|
||||
"""UPDATE nostrclient.config SET json_data = ?""",
|
||||
(json.dumps(config.dict())),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
)
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d))
|
||||
|
||||
|
||||
async def get_config() -> Optional[Config]:
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
)
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d)) if row else None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue