mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-22 22:25:47 +01:00
copilot starts, templates need adjusting
This commit is contained in:
parent
1346ad12f1
commit
e1b4df869f
4 changed files with 36 additions and 25 deletions
|
@ -17,7 +17,6 @@ from .crud import get_copilot
|
|||
from typing import Optional
|
||||
from fastapi.params import Depends
|
||||
from fastapi.param_functions import Query
|
||||
from .models import CreateJukeLinkData, CreateJukeboxPayment
|
||||
|
||||
|
||||
@copilot_ext.get("/lnurl/{cp_id}", response_class=HTMLResponse)
|
||||
|
|
|
@ -73,3 +73,15 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
await updater(copilot.id, data, payment.extra.get("comment"))
|
||||
else:
|
||||
await updater(copilot.id, data, "none")
|
||||
|
||||
|
||||
async def mark_webhook_sent(payment: Payment, status: int) -> None:
|
||||
payment.extra["wh_status"] = status
|
||||
|
||||
await core_db.execute(
|
||||
"""
|
||||
UPDATE apipayments SET extra = ?
|
||||
WHERE hash = ?
|
||||
""",
|
||||
(json.dumps(payment.extra), payment.payment_hash),
|
||||
)
|
||||
|
|
|
@ -23,21 +23,21 @@ import base64
|
|||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@copilot_ext.route("/", response_class=HTMLResponse)
|
||||
@copilot_ext.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||
return copilot_renderer().TemplateResponse(
|
||||
"copilot/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
||||
|
||||
|
||||
@copilot_ext.route("/cp/", response_class=HTMLResponse)
|
||||
@copilot_ext.get("/cp/", response_class=HTMLResponse)
|
||||
async def compose(request: Request):
|
||||
return copilot_renderer().TemplateResponse(
|
||||
"copilot/compose.html", {"request": request}
|
||||
)
|
||||
|
||||
|
||||
@copilot_ext.route("/pn/", response_class=HTMLResponse)
|
||||
@copilot_ext.get("/pn/", response_class=HTMLResponse)
|
||||
async def panel(request: Request):
|
||||
return copilot_renderer().TemplateResponse(
|
||||
"copilot/panel.html", {"request": request}
|
||||
|
@ -52,25 +52,25 @@ async def panel(request: Request):
|
|||
connected_websockets = defaultdict(set)
|
||||
|
||||
|
||||
# @copilot_ext.websocket("/ws/{id}/")
|
||||
# async def websocket_endpoint(websocket: WebSocket, id: str = Query(None)):
|
||||
# copilot = await get_copilot(id)
|
||||
# if not copilot:
|
||||
# return "", HTTPStatus.FORBIDDEN
|
||||
# await websocket.accept()
|
||||
# invoice_queue = asyncio.Queue()
|
||||
# connected_websockets[id].add(invoice_queue)
|
||||
# try:
|
||||
# while True:
|
||||
# data = await websocket.receive_text()
|
||||
# await websocket.send_text(f"Message text was: {data}")
|
||||
# finally:
|
||||
# connected_websockets[id].remove(invoice_queue)
|
||||
@copilot_ext.websocket("/ws/{id}/")
|
||||
async def websocket_endpoint(websocket: WebSocket, id: str = Query(None)):
|
||||
copilot = await get_copilot(id)
|
||||
if not copilot:
|
||||
return "", HTTPStatus.FORBIDDEN
|
||||
await websocket.accept()
|
||||
invoice_queue = asyncio.Queue()
|
||||
connected_websockets[id].add(invoice_queue)
|
||||
try:
|
||||
while True:
|
||||
data = await websocket.receive_text()
|
||||
await websocket.send_text(f"Message text was: {data}")
|
||||
finally:
|
||||
connected_websockets[id].remove(invoice_queue)
|
||||
|
||||
|
||||
# async def updater(copilot_id, data, comment):
|
||||
# copilot = await get_copilot(copilot_id)
|
||||
# if not copilot:
|
||||
# return
|
||||
# for queue in connected_websockets[copilot_id]:
|
||||
# await queue.send(f"{data + '-' + comment}")
|
||||
async def updater(copilot_id, data, comment):
|
||||
copilot = await get_copilot(copilot_id)
|
||||
if not copilot:
|
||||
return
|
||||
for queue in connected_websockets[copilot_id]:
|
||||
await queue.send(f"{data + '-' + comment}")
|
||||
|
|
|
@ -76,7 +76,7 @@ async def api_copilot_retrieve(
|
|||
@copilot_ext.delete("/api/v1/copilot/{copilot_id}", response_class=HTMLResponse)
|
||||
async def api_copilot_delete(
|
||||
copilot_id: str = Query(None),
|
||||
wallet: WalletTypeInfo = Depends(WalletAdminKeyChecker()),
|
||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||
):
|
||||
copilot = await get_copilot(copilot_id)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue