mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 12:26:19 +02:00
fix: embeddable img link in withdraw extension
This commit is contained in:
@@ -10,7 +10,7 @@ from fastapi.params import Depends
|
|||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse, StreamingResponse
|
||||||
from lnbits.core.models import User
|
from lnbits.core.models import User
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
templates = Jinja2Templates(directory="templates")
|
||||||
@@ -36,7 +36,7 @@ async def display(request: Request, link_id):
|
|||||||
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":{**link.dict(), "lnurl": link.lnurl(request)}, "unique":True})
|
return withdraw_renderer().TemplateResponse("withdraw/display.html", {"request":request,"link":{**link.dict(), "lnurl": link.lnurl(request)}, "unique":True})
|
||||||
|
|
||||||
|
|
||||||
@withdraw_ext.get("/img/{link_id}", response_class=HTMLResponse)
|
@withdraw_ext.get("/img/{link_id}", response_class=StreamingResponse)
|
||||||
async def img(request: Request, link_id):
|
async def img(request: Request, link_id):
|
||||||
link = await get_withdraw_link(link_id, 0)
|
link = await get_withdraw_link(link_id, 0)
|
||||||
if not link:
|
if not link:
|
||||||
@@ -50,16 +50,19 @@ async def img(request: Request, link_id):
|
|||||||
print(qr)
|
print(qr)
|
||||||
stream = BytesIO()
|
stream = BytesIO()
|
||||||
qr.svg(stream, scale=3)
|
qr.svg(stream, scale=3)
|
||||||
return (
|
stream.seek(0)
|
||||||
stream.getvalue(),
|
|
||||||
200,
|
async def _generator(stream: BytesIO):
|
||||||
{
|
yield stream.getvalue()
|
||||||
|
|
||||||
|
return StreamingResponse(
|
||||||
|
_generator(stream),
|
||||||
|
headers={
|
||||||
"Content-Type": "image/svg+xml",
|
"Content-Type": "image/svg+xml",
|
||||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Expires": "0",
|
"Expires": "0",
|
||||||
},
|
})
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@withdraw_ext.get("/print/{link_id}", response_class=HTMLResponse)
|
@withdraw_ext.get("/print/{link_id}", response_class=HTMLResponse)
|
||||||
|
Reference in New Issue
Block a user