mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-25 23:21:21 +01:00
Working, looking good
This commit is contained in:
parent
4e65c39b36
commit
dbc47332ee
4 changed files with 53 additions and 25 deletions
|
@ -30,6 +30,7 @@ class nostrCreateConnections(BaseModel):
|
|||
class nostrRelays(BaseModel):
|
||||
id: Optional[str]
|
||||
relay: Optional[str]
|
||||
status: Optional[bool] = False
|
||||
|
||||
class nostrRelayList(BaseModel):
|
||||
id: str
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<q-table
|
||||
flat
|
||||
dense
|
||||
:data="nostrLinks"
|
||||
:data="nostrrelayLinks"
|
||||
row-key="id"
|
||||
:columns="nostrTable.columns"
|
||||
:pagination.sync="nostrTable.pagination"
|
||||
|
@ -38,9 +38,6 @@
|
|||
{% raw %}
|
||||
<template v-slot:header="props">
|
||||
<q-tr :props="props">
|
||||
<q-th style="width: 5%"></q-th>
|
||||
<q-th style="width: 5%"></q-th>
|
||||
|
||||
<q-th
|
||||
v-for="col in props.cols"
|
||||
:key="col.name"
|
||||
|
@ -63,7 +60,12 @@
|
|||
auto-width
|
||||
>
|
||||
<div v-if="col.name == 'id'"></div>
|
||||
<div v-else>{{ col.value }}</div>
|
||||
<div v-else>
|
||||
<div v-if="col.value == true" style="background-color: green">
|
||||
{{ col.value }}
|
||||
</div>
|
||||
<div v-else>{{ col.value }}</div>
|
||||
</div>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
|
@ -143,7 +145,7 @@
|
|||
<h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} Nostr Extension</h6>
|
||||
<p>Only Admin users can manage this extension</p>
|
||||
|
||||
<q-card-section>Okay </q-card-section>
|
||||
<q-card-section></q-card-section>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
|
@ -153,7 +155,7 @@
|
|||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
var maplnurldevice = obj => {
|
||||
var maplrelays = obj => {
|
||||
obj._data = _.clone(obj)
|
||||
obj.theTime = obj.time * 60 - (Date.now() / 1000 - obj.timestamp)
|
||||
obj.time = obj.time + 'mins'
|
||||
|
@ -179,10 +181,16 @@
|
|||
allowlist: '',
|
||||
denylist: ''
|
||||
},
|
||||
nostrLinks: [],
|
||||
nostrrelayLinks: [],
|
||||
filter: '',
|
||||
nostrTable: {
|
||||
columns: [
|
||||
{
|
||||
name: 'wah',
|
||||
align: 'left',
|
||||
label: 'id',
|
||||
field: 'id'
|
||||
},
|
||||
{
|
||||
name: 'relay',
|
||||
align: 'left',
|
||||
|
@ -190,10 +198,10 @@
|
|||
field: 'relay'
|
||||
},
|
||||
{
|
||||
name: 'connected',
|
||||
name: 'status',
|
||||
align: 'left',
|
||||
label: 'connected',
|
||||
field: 'connected'
|
||||
label: 'status',
|
||||
field: 'status'
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
|
@ -203,7 +211,7 @@
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
getrelays: function () {
|
||||
getRelays: function () {
|
||||
var self = this
|
||||
LNbits.api
|
||||
.request(
|
||||
|
@ -213,7 +221,10 @@
|
|||
)
|
||||
.then(function (response) {
|
||||
if (response.data) {
|
||||
self.nostrrelayLinks = response.data.map(maprelays)
|
||||
console.log(response.data)
|
||||
response.data.map(maplrelays)
|
||||
self.nostrrelayLinks = response.data
|
||||
console.log(self.nostrrelayLinks)
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
|
@ -284,7 +295,7 @@
|
|||
},
|
||||
created: function () {
|
||||
var self = this
|
||||
this.getrelays()
|
||||
this.getRelays()
|
||||
this.getLists()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from http import HTTPStatus
|
||||
import asyncio
|
||||
import asyncio
|
||||
from fastapi import Request
|
||||
from fastapi.param_functions import Query
|
||||
from fastapi.params import Depends
|
||||
|
@ -8,14 +7,17 @@ from fastapi.templating import Jinja2Templates
|
|||
from starlette.exceptions import HTTPException
|
||||
from starlette.responses import HTMLResponse
|
||||
from . import nostradmin_ext, nostr_renderer
|
||||
# FastAPI good for incoming
|
||||
from fastapi import Request, WebSocket, WebSocketDisconnect
|
||||
# Websockets needed for outgoing
|
||||
import websockets
|
||||
|
||||
from lnbits.core.crud import update_payment_status
|
||||
from lnbits.core.models import User
|
||||
from lnbits.core.views.api import api_payment
|
||||
from lnbits.decorators import check_user_exists
|
||||
|
||||
from .crud import get_nostrkeys
|
||||
from .crud import get_nostrkeys, get_nostrrelay
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
@ -74,8 +76,8 @@ class ConnectionManager:
|
|||
manager = ConnectionManager()
|
||||
|
||||
|
||||
@nostradmin_ext.websocket("/nostradmin/ws/{nostr_id}", name="nostr_id.websocket_by_id")
|
||||
async def websocket_endpoint(websocket: WebSocket, copilot_id: str):
|
||||
@nostradmin_ext.websocket("/nostradmin/ws/relayevents/{nostr_id}", name="nostr_id.websocket_by_id")
|
||||
async def websocket_endpoint(websocket: WebSocket, nostr_id: str):
|
||||
await manager.connect(websocket, nostr_id)
|
||||
try:
|
||||
while True:
|
||||
|
@ -88,4 +90,13 @@ async def updater(nostr_id, message):
|
|||
copilot = await get_copilot(nostr_id)
|
||||
if not copilot:
|
||||
return
|
||||
await manager.send_personal_message(f"{message}", nostr_id)
|
||||
await manager.send_personal_message(f"{message}", nostr_id)
|
||||
|
||||
|
||||
async def relay_check(relay: str):
|
||||
async with websockets.connect(relay) as websocket:
|
||||
if str(websocket.state) == "State.OPEN":
|
||||
print(str(websocket.state))
|
||||
return True
|
||||
else:
|
||||
return False
|
|
@ -24,11 +24,10 @@ from .crud import (
|
|||
get_nostrconnections,
|
||||
)
|
||||
from .models import nostrKeys, nostrCreateRelays, nostrRelaySetList
|
||||
|
||||
from .views import relay_check
|
||||
|
||||
@nostradmin_ext.get("/api/v1/relays")
|
||||
async def api_relays_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
|
||||
relays = await get_nostrrelays()
|
||||
if not relays:
|
||||
await create_nostrrelays(nostrCreateRelays(relay="wss://relayer.fiatjaf.com"))
|
||||
|
@ -36,10 +35,16 @@ async def api_relays_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
|
|||
nostrCreateRelays(relay="wss://nostr-pub.wellorder.net")
|
||||
)
|
||||
relays = await get_nostrrelays()
|
||||
try:
|
||||
return [{**relays.dict()} for relays in await relays]
|
||||
except:
|
||||
None
|
||||
if not relays:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
||||
)
|
||||
else:
|
||||
for relay in relays:
|
||||
relay.status = await relay_check(relay.relay)
|
||||
return relays
|
||||
|
||||
|
||||
|
||||
@nostradmin_ext.get("/api/v1/relaylist")
|
||||
async def api_relaylist(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
|
|
Loading…
Add table
Reference in a new issue