mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-26 23:51:55 +01:00
models decided
This commit is contained in:
parent
29bd8d9ce9
commit
2083ecbc27
7 changed files with 100 additions and 107 deletions
|
@ -5,7 +5,7 @@ from lnbits.helpers import template_renderer
|
||||||
|
|
||||||
db = Database("ext_nostradmin")
|
db = Database("ext_nostradmin")
|
||||||
|
|
||||||
nostr_ext: APIRouter = APIRouter(prefix="/nostradmin", tags=["nostradmin"])
|
nostradmin_ext: APIRouter = APIRouter(prefix="/nostradmin", tags=["nostradmin"])
|
||||||
|
|
||||||
|
|
||||||
def nostr_renderer():
|
def nostr_renderer():
|
||||||
|
|
|
@ -12,6 +12,7 @@ from .models import (
|
||||||
nostrCreateConnections,
|
nostrCreateConnections,
|
||||||
nostrRelayList,
|
nostrRelayList,
|
||||||
)
|
)
|
||||||
|
from .models import nostrKeys, nostrCreateRelays, nostrRelaySetList
|
||||||
|
|
||||||
###############KEYS##################
|
###############KEYS##################
|
||||||
|
|
||||||
|
@ -100,31 +101,20 @@ async def get_nostrrelay(nostrrelay_id: str) -> nostrRelays:
|
||||||
row = await db.fetchone("SELECT * FROM nostradmin.relays WHERE id = ?", (nostrrelay_id,))
|
row = await db.fetchone("SELECT * FROM nostradmin.relays WHERE id = ?", (nostrrelay_id,))
|
||||||
return nostrRelays(**row) if row else None
|
return nostrRelays(**row) if row else None
|
||||||
|
|
||||||
|
async def update_nostrrelaysetlist(data: nostrRelaySetList) -> nostrRelayList:
|
||||||
async def update_nostrrelayallowlist(allowlist: str) -> nostrRelayList:
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE nostradmin.relaylist SET
|
UPDATE nostradmin.relaylists SET
|
||||||
|
denylist = ?,
|
||||||
allowlist = ?
|
allowlist = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""",
|
""",
|
||||||
(allowlist, 1),
|
(data.denylist, data.allowlist, 1),
|
||||||
)
|
|
||||||
return await get_nostrrelaylist()
|
|
||||||
|
|
||||||
async def update_nostrrelaydenylist(denylist: str) -> nostrRelayList:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE nostradmin.relaylist SET
|
|
||||||
denylist = ?
|
|
||||||
WHERE id = ?
|
|
||||||
""",
|
|
||||||
(denylist, 1),
|
|
||||||
)
|
)
|
||||||
return await get_nostrrelaylist()
|
return await get_nostrrelaylist()
|
||||||
|
|
||||||
async def get_nostrrelaylist() -> nostrRelayList:
|
async def get_nostrrelaylist() -> nostrRelayList:
|
||||||
row = await db.fetchone("SELECT * FROM nostradmin.relaylist WHERE id = ?", (1,))
|
row = await db.fetchone("SELECT * FROM nostradmin.relaylists WHERE id = ?", (1,))
|
||||||
return nostrRelayList(**row) if row else None
|
return nostrRelayList(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
from lnbits.db import Database
|
from lnbits.db import Database
|
||||||
|
|
||||||
db2 = Database("ext_nostr")
|
|
||||||
|
|
||||||
|
|
||||||
async def m001_initial(db):
|
async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
Initial nostr table.
|
Initial nostradmin table.
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
|
@ -40,24 +37,23 @@ async def m001_initial(db):
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE nostradmin.relaylists (
|
CREATE TABLE nostradmin.relaylists (
|
||||||
id TEXT NOT NULL PRIMARY KEY DEFAULT 1,
|
id TEXT NOT NULL PRIMARY KEY DEFAULT 1,
|
||||||
allowlist TEXT NOT NULL,
|
allowlist TEXT,
|
||||||
denylist TEXT NOT NULL
|
denylist TEXT
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO nostradmin.relaylist (
|
INSERT INTO nostradmin.relaylists (
|
||||||
id,
|
id,
|
||||||
denylist
|
denylist
|
||||||
)
|
|
||||||
VALUES (?, ?,)
|
|
||||||
""",
|
|
||||||
(1, "\n".join(["wss://zucks-meta-relay.com", "wss://nostradmin.cia.gov"])),
|
|
||||||
)
|
)
|
||||||
except:
|
VALUES (?, ?)
|
||||||
return
|
""",
|
||||||
|
("1", "wss://zucks-meta-relay.com\nwss://nostr.cia.gov",),
|
||||||
|
)
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TABLE nostradmin.connections (
|
CREATE TABLE nostradmin.connections (
|
||||||
|
@ -67,3 +63,12 @@ async def m001_initial(db):
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
await db.execute(
|
||||||
|
f"""
|
||||||
|
CREATE TABLE nostradmin.subscribed (
|
||||||
|
id TEXT NOT NULL PRIMARY KEY,
|
||||||
|
userPubkey TEXT NOT NULL,
|
||||||
|
subscribedPubkey TEXT NOT NULL
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
)
|
|
@ -5,7 +5,7 @@ from typing import Optional
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
|
from fastapi.param_functions import Query
|
||||||
|
|
||||||
class nostrKeys(BaseModel):
|
class nostrKeys(BaseModel):
|
||||||
pubkey: str
|
pubkey: str
|
||||||
|
@ -21,28 +21,31 @@ class nostrNotes(BaseModel):
|
||||||
sig: str
|
sig: str
|
||||||
|
|
||||||
class nostrCreateRelays(BaseModel):
|
class nostrCreateRelays(BaseModel):
|
||||||
relay: str
|
relay: str = Query(None)
|
||||||
|
|
||||||
class nostrCreateConnections(BaseModel):
|
class nostrCreateConnections(BaseModel):
|
||||||
pubkey: str
|
pubkey: str = Query(None)
|
||||||
relayid: str
|
relayid: str = Query(None)
|
||||||
|
|
||||||
class nostrRelays(BaseModel):
|
class nostrRelays(BaseModel):
|
||||||
id: str
|
id: Optional[str]
|
||||||
relay: str
|
relay: Optional[str]
|
||||||
|
|
||||||
class nostrRelayList(BaseModel):
|
class nostrRelayList(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
allowlist: str
|
allowlist: Optional[str]
|
||||||
denylist: str
|
denylist: Optional[str]
|
||||||
|
|
||||||
class nostrRelayDenyList(BaseModel):
|
class nostrRelaySetList(BaseModel):
|
||||||
denylist: str
|
allowlist: Optional[str]
|
||||||
|
denylist: Optional[str]
|
||||||
class nostrRelayAllowList(BaseModel):
|
|
||||||
allowlist: str
|
|
||||||
|
|
||||||
class nostrConnections(BaseModel):
|
class nostrConnections(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
pubkey: str
|
pubkey: Optional[str]
|
||||||
relayid: str
|
relayid: Optional[str]
|
||||||
|
|
||||||
|
class nostrSubscriptions(BaseModel):
|
||||||
|
id: str
|
||||||
|
userPubkey: Optional[str]
|
||||||
|
subscribedPubkey: Optional[str]
|
|
@ -6,7 +6,7 @@
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="row items-center no-wrap q-mb-md">
|
<div class="row items-center no-wrap q-mb-md">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h5 class="text-subtitle1 q-my-none">Nostr</h5>
|
<h5 class="text-subtitle1 q-my-none">NOSTR RELAYS ONLINE</h5>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
<q-table
|
<q-table
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
:data="lnurldeviceLinks"
|
:data="nostrLinks"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
:columns="nostrTable.columns"
|
:columns="nostrTable.columns"
|
||||||
:pagination.sync="nostrTable.pagination"
|
:pagination.sync="nostrTable.pagination"
|
||||||
|
@ -81,21 +81,24 @@
|
||||||
align="justify"
|
align="justify"
|
||||||
narrow-indicator
|
narrow-indicator
|
||||||
>
|
>
|
||||||
<q-tab name="denylist" label="Deny List" />
|
<q-tab name="denylist" label="Deny List"></q-tab>
|
||||||
<q-tab name="allowlist" label="Allow List" />
|
<q-tab name="allowlist" label="Allow List"></q-tab>
|
||||||
</q-tabs>
|
</q-tabs>
|
||||||
|
|
||||||
<q-separator />
|
<q-separator></q-separator>
|
||||||
|
|
||||||
<q-tab-panels v-model="tab" animated>
|
<q-tab-panels v-model="listSelection" animated>
|
||||||
<q-tab-panel name="denylist">
|
<q-tab-panel name="denylist">
|
||||||
<div class="text-h6">
|
<div class="text-h6">Relays in this list will NOT be used</div>
|
||||||
Deny List (denys use of relays in this list)
|
<q-form class="q-gutter-md q-y-md" @submit="setRelayList">
|
||||||
</div>
|
|
||||||
<q-form class="q-gutter-md q-y-md" @submit="setDenyList">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col q-mx-lg">
|
<div class="col q-mx-lg">
|
||||||
<q-input v-model="denyList" dense filled autogrow />
|
<q-input
|
||||||
|
v-model="setList.denylist"
|
||||||
|
dense
|
||||||
|
filled
|
||||||
|
autogrow
|
||||||
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="col q-mx-lg items-align flex items-center justify-center"
|
class="col q-mx-lg items-align flex items-center justify-center"
|
||||||
|
@ -103,22 +106,22 @@
|
||||||
<q-btn unelevated color="primary" type="submit">
|
<q-btn unelevated color="primary" type="submit">
|
||||||
Update Deny List
|
Update Deny List
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn @click="loadShop" flat color="grey" class="q-ml-auto"
|
|
||||||
>Reset</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-tab-panel>
|
</q-tab-panel>
|
||||||
|
|
||||||
<q-tab-panel name="allowlist">
|
<q-tab-panel name="allowlist">
|
||||||
<div class="text-h6">
|
<div class="text-h6">ONLY relays in this list will be used</div>
|
||||||
Allow List (denys any relays not in this list)
|
<q-form class="q-gutter-md q-y-md" @submit="setRelayList">
|
||||||
</div>
|
|
||||||
<q-form class="q-gutter-md q-y-md" @submit="setAllowList">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col q-mx-lg">
|
<div class="col q-mx-lg">
|
||||||
<q-input v-model="allowList" dense filled autogrow />
|
<q-input
|
||||||
|
v-model="setList.allowlist"
|
||||||
|
dense
|
||||||
|
filled
|
||||||
|
autogrow
|
||||||
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="col q-mx-lg items-align flex items-center justify-center"
|
class="col q-mx-lg items-align flex items-center justify-center"
|
||||||
|
@ -126,9 +129,6 @@
|
||||||
<q-btn unelevated color="primary" type="submit">
|
<q-btn unelevated color="primary" type="submit">
|
||||||
Update Allow List
|
Update Allow List
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn @click="loadShop" flat color="grey" class="q-ml-auto"
|
|
||||||
>Reset</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
|
@ -175,8 +175,12 @@
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
listSelection: 'denylist',
|
listSelection: 'denylist',
|
||||||
allowList: [],
|
setList: {
|
||||||
denyList: [],
|
allowlist: '',
|
||||||
|
denylist: ''
|
||||||
|
},
|
||||||
|
nostrLinks: [],
|
||||||
|
filter: '',
|
||||||
nostrTable: {
|
nostrTable: {
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
|
@ -234,18 +238,20 @@
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setDenyList: function () {
|
setRelayList: function () {
|
||||||
var self = this
|
var self = this
|
||||||
|
console.log(self.setList)
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/nostradmin/api/v1/denylist',
|
'/nostradmin/api/v1/setlist',
|
||||||
self.g.user.wallets[0].adminkey,
|
self.g.user.wallets[0].adminkey,
|
||||||
self.allowList
|
self.setList
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
self.denyList = response.data
|
console.log(response.data)
|
||||||
|
// self.denyList = response.data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
@ -262,13 +268,18 @@
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
self.denyList = response.data.denylist
|
console.log(response.data)
|
||||||
self.allowList = response.data.allowlist
|
self.setList.denylist = response.data.denylist
|
||||||
|
self.setList.allowlist = response.data.allowlist
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
exportlnurldeviceCSV: function () {
|
||||||
|
var self = this
|
||||||
|
LNbits.utils.exportCSV(self.nostrTable.columns, this.nostrLinks)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
|
|
|
@ -6,18 +6,19 @@ from fastapi.params import Depends
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
from . import nostradmin_ext, nostr_renderer
|
||||||
|
|
||||||
from lnbits.core.crud import update_payment_status
|
from lnbits.core.crud import update_payment_status
|
||||||
from lnbits.core.models import User
|
from lnbits.core.models import User
|
||||||
from lnbits.core.views.api import api_payment
|
from lnbits.core.views.api import api_payment
|
||||||
from lnbits.decorators import check_user_exists
|
from lnbits.decorators import check_user_exists
|
||||||
|
|
||||||
from . import nostr_ext, nostr_renderer
|
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
|
|
||||||
@nostr_ext.get("/", response_class=HTMLResponse)
|
@nostradmin_ext.get("/", response_class=HTMLResponse)
|
||||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
return nostr_renderer().TemplateResponse(
|
return nostr_renderer().TemplateResponse(
|
||||||
"nostradmin/index.html", {"request": request, "user": user.dict()}
|
"nostradmin/index.html", {"request": request, "user": user.dict()}
|
||||||
|
|
|
@ -7,11 +7,10 @@ from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
|
||||||
from lnbits.extensions.nostr import nostr_ext
|
|
||||||
from lnbits.utils.exchange_rates import currencies
|
from lnbits.utils.exchange_rates import currencies
|
||||||
|
|
||||||
from . import nostr_ext
|
|
||||||
from lnbits.settings import LNBITS_ADMIN_USERS
|
from lnbits.settings import LNBITS_ADMIN_USERS
|
||||||
|
from . import nostradmin_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_nostrkeys,
|
create_nostrkeys,
|
||||||
get_nostrkeys,
|
get_nostrkeys,
|
||||||
|
@ -20,13 +19,11 @@ from .crud import (
|
||||||
create_nostrrelays,
|
create_nostrrelays,
|
||||||
get_nostrrelays,
|
get_nostrrelays,
|
||||||
get_nostrrelaylist,
|
get_nostrrelaylist,
|
||||||
update_nostrrelayallowlist,
|
update_nostrrelaysetlist,
|
||||||
update_nostrrelaydenylist,
|
|
||||||
create_nostrconnections,
|
create_nostrconnections,
|
||||||
get_nostrconnections,
|
get_nostrconnections,
|
||||||
)
|
)
|
||||||
from .models import nostrKeys, nostrCreateRelays, nostrRelayAllowList, nostrRelayDenyList
|
from .models import nostrKeys, nostrCreateRelays, nostrRelaySetList
|
||||||
|
|
||||||
|
|
||||||
# while True:
|
# while True:
|
||||||
async def nostr_subscribe():
|
async def nostr_subscribe():
|
||||||
|
@ -41,13 +38,7 @@ async def nostr_subscribe():
|
||||||
websocket_queue = asyncio.Queue(1000)
|
websocket_queue = asyncio.Queue(1000)
|
||||||
|
|
||||||
|
|
||||||
async def internal_invoice_listener():
|
@nostradmin_ext.get("/api/v1/relays")
|
||||||
while True:
|
|
||||||
checking_id = await internal_invoice_queue.get()
|
|
||||||
asyncio.create_task(invoice_callback_dispatcher(checking_id))
|
|
||||||
|
|
||||||
|
|
||||||
@nostr_ext.get("/api/v1/relays")
|
|
||||||
async def api_relays_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_relays_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
|
|
||||||
relays = await get_nostrrelays()
|
relays = await get_nostrrelays()
|
||||||
|
@ -62,7 +53,7 @@ async def api_relays_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
except:
|
except:
|
||||||
None
|
None
|
||||||
|
|
||||||
@nostr_ext.get("/api/v1/relaylist")
|
@nostradmin_ext.get("/api/v1/relaylist")
|
||||||
async def api_relaylist(wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_relaylist(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -70,18 +61,10 @@ async def api_relaylist(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
)
|
)
|
||||||
return await get_nostrrelaylist()
|
return await get_nostrrelaylist()
|
||||||
|
|
||||||
@nostr_ext.post("/api/v1/allowlist")
|
@nostradmin_ext.post("/api/v1/setlist")
|
||||||
async def api_relaysallowed(data: nostrRelayAllowList, wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_relayssetlist(data: nostrRelaySetList, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
||||||
)
|
)
|
||||||
return await update_nostrrelayallowlist(data)
|
return await update_nostrrelaysetlist(data)
|
||||||
|
|
||||||
@nostr_ext.post("/api/v1/denylist")
|
|
||||||
async def api_relaysdenyed(data: nostrRelayDenyList, wallet: WalletTypeInfo = Depends(get_key_type)):
|
|
||||||
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
|
||||||
)
|
|
||||||
return await update_nostrrelaydenylist(data)
|
|
Loading…
Add table
Reference in a new issue