admin check and thread as daemon
This commit is contained in:
parent
dfe15f6673
commit
d504146f91
4 changed files with 18 additions and 14 deletions
|
|
@ -41,11 +41,11 @@ class RelayManager:
|
||||||
target=relay.connect,
|
target=relay.connect,
|
||||||
args=(ssl_options, proxy),
|
args=(ssl_options, proxy),
|
||||||
name=f"{relay.url}-thread",
|
name=f"{relay.url}-thread",
|
||||||
|
daemon=True,
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
threading.Thread(
|
threading.Thread(
|
||||||
target=relay.queue_worker,
|
target=relay.queue_worker, name=f"{relay.url}-queue", daemon=True
|
||||||
name=f"{relay.url}-queue",
|
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
def close_connections(self):
|
def close_connections(self):
|
||||||
|
|
|
||||||
3
tasks.py
3
tasks.py
|
|
@ -76,12 +76,13 @@ async def subscribe_events():
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
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}")
|
||||||
asyncio.run(received_event_queue.put(event))
|
asyncio.run(received_event_queue.put(event))
|
||||||
|
|
||||||
t = threading.Thread(
|
t = threading.Thread(
|
||||||
target=client.subscribe,
|
target=client.subscribe,
|
||||||
args=(callback,),
|
args=(callback,),
|
||||||
name="Nostr-event-subscription",
|
name="Nostr-event-subscription",
|
||||||
|
daemon=True,
|
||||||
)
|
)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
|
||||||
|
|
@ -187,8 +187,8 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/nostrclient/api/v1/relays',
|
'/nostrclient/api/v1/relays?usr=' + this.g.user.id,
|
||||||
self.g.user.wallets[0].adminkey
|
this.g.user.wallets[0].adminkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
|
|
@ -202,7 +202,7 @@
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addRelay: function () {
|
addRelay() {
|
||||||
if (!this.relayToAdd.startsWith("wss://")) {
|
if (!this.relayToAdd.startsWith("wss://")) {
|
||||||
this.relayToAdd = ""
|
this.relayToAdd = ""
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
|
|
@ -218,8 +218,8 @@
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/nostrclient/api/v1/relay',
|
'/nostrclient/api/v1/relay?usr=' + this.g.user.id,
|
||||||
self.g.user.wallets[0].adminkey,
|
this.g.user.wallets[0].adminkey,
|
||||||
{url:this.relayToAdd},
|
{url:this.relayToAdd},
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
@ -235,14 +235,13 @@
|
||||||
})
|
})
|
||||||
location.reload();
|
location.reload();
|
||||||
},
|
},
|
||||||
deleteRelay: function (url) {
|
deleteRelay(url) {
|
||||||
console.log("DELETE RELAY " + url)
|
console.log("DELETE RELAY " + url)
|
||||||
var self = this
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/nostrclient/api/v1/relay',
|
'/nostrclient/api/v1/relay?usr=' + this.g.user.id,
|
||||||
self.g.user.wallets[0].adminkey,
|
this.g.user.wallets[0].adminkey,
|
||||||
{url:url},
|
{url:url},
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,9 @@ async def api_get_relays(): # type: ignore
|
||||||
return relays
|
return relays
|
||||||
|
|
||||||
|
|
||||||
@nostrclient_ext.post("/api/v1/relay")
|
@nostrclient_ext.post(
|
||||||
|
"/api/v1/relay", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||||
|
)
|
||||||
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:
|
if relay.url in client.relay_manager.relays:
|
||||||
|
|
@ -67,7 +69,9 @@ async def api_add_relay(relay: Relay): # type: ignore
|
||||||
await init_relays()
|
await init_relays()
|
||||||
|
|
||||||
|
|
||||||
@nostrclient_ext.delete("/api/v1/relay")
|
@nostrclient_ext.delete(
|
||||||
|
"/api/v1/relay", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)]
|
||||||
|
)
|
||||||
async def api_delete_relay(relay: Relay): # type: ignore
|
async def api_delete_relay(relay: Relay): # type: ignore
|
||||||
assert relay.url
|
assert relay.url
|
||||||
client.relay_manager.remove_relay(relay.url)
|
client.relay_manager.remove_relay(relay.url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue