-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathviews.py
97 lines (76 loc) · 3.06 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Description: Add your page endpoints here.
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 lnbits.settings import settings
from .crud import get_myextension
from .helpers import lnurler
myextension_generic_router = APIRouter()
def myextension_renderer():
return template_renderer(["myextension/templates"])
#######################################
##### ADD YOUR PAGE ENDPOINTS HERE ####
#######################################
# Backend admin page
@myextension_generic_router.get("/", response_class=HTMLResponse)
async def index(req: Request, user: User = Depends(check_user_exists)):
return myextension_renderer().TemplateResponse(
"myextension/index.html", {"request": req, "user": user.json()}
)
# Frontend shareable page
@myextension_generic_router.get("/{myextension_id}")
async def myextension(req: Request, myextension_id):
myex = await get_myextension(myextension_id)
if not myex:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="MyExtension does not exist."
)
return myextension_renderer().TemplateResponse(
"myextension/myextension.html",
{
"request": req,
"myextension_id": myextension_id,
"lnurlpay": lnurler(myex.id, "myextension.api_lnurl_pay", req),
"web_manifest": f"/myextension/manifest/{myextension_id}.webmanifest",
},
)
# Manifest for public page, customise or remove manifest completely
@myextension_generic_router.get("/manifest/{myextension_id}.webmanifest")
async def manifest(myextension_id: str):
myextension = await get_myextension(myextension_id)
if not myextension:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="MyExtension does not exist."
)
return {
"short_name": settings.lnbits_site_title,
"name": myextension.name + " - " + settings.lnbits_site_title,
"icons": [
{
"src": (
settings.lnbits_custom_logo
if settings.lnbits_custom_logo
else "https://cdn.jsdelivr.net/gh/lnbits/lnbits@0.3.0/docs/logos/lnbits.png"
),
"type": "image/png",
"sizes": "900x900",
}
],
"start_url": "/myextension/" + myextension_id,
"background_color": "#1F2234",
"description": "Minimal extension to build on",
"display": "standalone",
"scope": "/myextension/" + myextension_id,
"theme_color": "#1F2234",
"shortcuts": [
{
"name": myextension.name + " - " + settings.lnbits_site_title,
"short_name": myextension.name,
"description": myextension.name + " - " + settings.lnbits_site_title,
"url": "/myextension/" + myextension_id,
}
],
}