update
This commit is contained in:
parent
f03284d4ea
commit
4feb366493
18 changed files with 10 additions and 7 deletions
6
crud.py
6
crud.py
|
|
@ -7,14 +7,14 @@ from .models import Relay, RelayList
|
||||||
|
|
||||||
|
|
||||||
async def get_relays() -> RelayList:
|
async def get_relays() -> RelayList:
|
||||||
row = await db.fetchall("SELECT * FROM nostradmin.relays")
|
row = await db.fetchall("SELECT * FROM nostrclient.relays")
|
||||||
return RelayList(__root__=row)
|
return RelayList(__root__=row)
|
||||||
|
|
||||||
|
|
||||||
async def add_relay(relay: Relay) -> None:
|
async def add_relay(relay: Relay) -> None:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO nostradmin.relays (
|
INSERT INTO nostrclient.relays (
|
||||||
id,
|
id,
|
||||||
url,
|
url,
|
||||||
active
|
active
|
||||||
|
|
@ -26,4 +26,4 @@ async def add_relay(relay: Relay) -> None:
|
||||||
|
|
||||||
|
|
||||||
async def delete_relay(relay: Relay) -> None:
|
async def delete_relay(relay: Relay) -> None:
|
||||||
await db.execute("DELETE FROM nostradmin.relays WHERE id = ?", (relay.id,))
|
await db.execute("DELETE FROM nostrclient.relays WHERE url = ?", (relay.url,))
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -21,10 +21,10 @@ from . import cbc
|
||||||
|
|
||||||
class NostrClient:
|
class NostrClient:
|
||||||
relays = [
|
relays = [
|
||||||
"wss://lnbits.link/nostrrelay/client",
|
|
||||||
"wss://nostr-pub.wellorder.net",
|
"wss://nostr-pub.wellorder.net",
|
||||||
"wss://nostr.zebedee.cloud",
|
"wss://nostr.zebedee.cloud",
|
||||||
"wss://nodestr.fmt.wiz.biz",
|
"wss://nodestr.fmt.wiz.biz",
|
||||||
|
"wss://nostr.oxtr.dev",
|
||||||
] # ["wss://nostr.oxtr.dev"] # ["wss://relay.nostr.info"] "wss://nostr-pub.wellorder.net" "ws://91.237.88.218:2700", "wss://nostrrr.bublina.eu.org", ""wss://nostr-relay.freeberty.net"", , "wss://nostr.oxtr.dev", "wss://relay.nostr.info", "wss://nostr-pub.wellorder.net" , "wss://relayer.fiatjaf.com", "wss://nodestr.fmt.wiz.biz/", "wss://no.str.cr"
|
] # ["wss://nostr.oxtr.dev"] # ["wss://relay.nostr.info"] "wss://nostr-pub.wellorder.net" "ws://91.237.88.218:2700", "wss://nostrrr.bublina.eu.org", ""wss://nostr-relay.freeberty.net"", , "wss://nostr.oxtr.dev", "wss://relay.nostr.info", "wss://nostr-pub.wellorder.net" , "wss://relayer.fiatjaf.com", "wss://nodestr.fmt.wiz.biz/", "wss://no.str.cr"
|
||||||
relay_manager = RelayManager()
|
relay_manager = RelayManager()
|
||||||
private_key: PrivateKey
|
private_key: PrivateKey
|
||||||
|
|
|
||||||
5
tasks.py
5
tasks.py
|
|
@ -34,7 +34,7 @@ from .crud import get_relays
|
||||||
|
|
||||||
async def init_relays():
|
async def init_relays():
|
||||||
relays = await get_relays()
|
relays = await get_relays()
|
||||||
client.relays = [r.url for r in relays.__root__]
|
client.relays = set([r.url for r in relays.__root__])
|
||||||
client.connect()
|
client.connect()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -73,8 +73,7 @@ async def init_relays():
|
||||||
|
|
||||||
async def subscribe_events():
|
async def subscribe_events():
|
||||||
while not any([r.connected for r in client.relay_manager.relays.values()]):
|
while not any([r.connected for r in client.relay_manager.relays.values()]):
|
||||||
print("no relays connected yet")
|
await asyncio.sleep(2)
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
def callback(event: Event):
|
def callback(event: Event):
|
||||||
print(f"From {event.public_key[:3]}..{event.public_key[-3:]}: {event.content}")
|
print(f"From {event.public_key[:3]}..{event.public_key[-3:]}: {event.content}")
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ async def api_get_relays(): # type: ignore
|
||||||
@nostrclient_ext.post("/api/v1/relay")
|
@nostrclient_ext.post("/api/v1/relay")
|
||||||
async def api_add_relay(relay: Relay): # type: ignore
|
async def api_add_relay(relay: Relay): # type: ignore
|
||||||
assert relay.url, "no URL"
|
assert relay.url, "no URL"
|
||||||
|
if relay.url in client.relay_manager.relays:
|
||||||
|
return
|
||||||
relay.id = urlsafe_short_hash()
|
relay.id = urlsafe_short_hash()
|
||||||
await add_relay(relay)
|
await add_relay(relay)
|
||||||
await init_relays()
|
await init_relays()
|
||||||
|
|
@ -67,6 +69,8 @@ async def api_add_relay(relay: Relay): # type: ignore
|
||||||
|
|
||||||
@nostrclient_ext.delete("/api/v1/relay")
|
@nostrclient_ext.delete("/api/v1/relay")
|
||||||
async def api_delete_relay(relay: Relay): # type: ignore
|
async def api_delete_relay(relay: Relay): # type: ignore
|
||||||
|
assert relay.url
|
||||||
|
client.relay_manager.remove_relay(relay.url)
|
||||||
await delete_relay(relay)
|
await delete_relay(relay)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue