Add files via upload

This commit is contained in:
Arc 2023-12-08 15:43:40 +00:00 committed by GitHub
parent 762ac58daf
commit aa560fd89d
17 changed files with 2948 additions and 2 deletions

88
views.py Normal file
View file

@ -0,0 +1,88 @@
from http import HTTPStatus
from fastapi import Depends, Request
from fastapi.templating import Jinja2Temps
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.settings import settings
from . import temp_ext, temp_renderer
from .crud import get_temp
temps = Jinja2Temps(directory="temps")
#######################################
##### ADD YOUR PAGE ENDPOINTS HERE ####
#######################################
# Backend admin page
@temp_ext.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return temp_renderer().TempResponse(
"temp/index.html", {"request": request, "user": user.dict()}
)
# Frontend shareable page
@temp_ext.get("/{temp_id}")
async def temp(request: Request, temp_id):
temp = await get_temp(temp_id)
if not temp:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Temp does not exist."
)
return temp_renderer().TempResponse(
"temp/temp.html",
{
"request": request,
"temp": temp,
"withdrawamtemps": temp.withdrawamtemps,
"web_manifest": f"/temp/manifest/{temp_id}.webmanifest",
},
)
# Customise a manifest, or remove manifest completely
@temp_ext.get("/manifest/{temp_id}.webmanifest")
async def manifest(temp_id: str):
remp= await get_temp(temp_id)
if not temp:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Temp does not exist."
)
return {
"short_name": settings.lnbits_site_title,
"name": temp.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": "/temp/" + temp_id,
"background_color": "#1F2234",
"description": "Minimal extension to build on",
"display": "standalone",
"scope": "/temp/" + temp_id,
"theme_color": "#1F2234",
"shortcuts": [
{
"name": temp.name + " - " + settings.lnbits_site_title,
"short_name": temp.name,
"description": temp.name + " - " + settings.lnbits_site_title,
"url": "/temp/" + temp_id,
}
],
}