forked from lnbits/nostrrelay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
40 lines (29 loc) · 1.27 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
from http import HTTPStatus
from fastapi import Depends, Request
from fastapi.exceptions import HTTPException
from fastapi.templating import Jinja2Templates
from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from . import nostrrelay_ext, nostrrelay_renderer
from .crud import get_public_relay
from .helpers import relay_info_response
templates = Jinja2Templates(directory="templates")
@nostrrelay_ext.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.dict()}
)
@nostrrelay_ext.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}
)