-
Notifications
You must be signed in to change notification settings - Fork 7
/
views.py
41 lines (29 loc) · 1.3 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer
from .crud import get_public_relay
from .helpers import relay_info_response
nostrrelay_generic_router: APIRouter = APIRouter()
def nostrrelay_renderer():
return template_renderer(["nostrrelay/templates"])
@nostrrelay_generic_router.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return nostrrelay_renderer().TemplateResponse(
"nostrrelay/index.html", {"request": request, "user": user.json()}
)
@nostrrelay_generic_router.get("/{relay_id}")
async def nostrrelay(request: Request, relay_id: str):
relay_public_data = await get_public_relay(relay_id)
if not relay_public_data:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND,
detail="Cannot find relay",
)
if request.headers.get("accept") == "application/nostr+json":
return relay_info_response(relay_public_data)
return nostrrelay_renderer().TemplateResponse(
"nostrrelay/public.html", {"request": request, "relay": relay_public_data}
)