From a6c84ceb6117d14a1352cf8861a65e9e4f4c7863 Mon Sep 17 00:00:00 2001 From: benarc Date: Sat, 16 Apr 2022 11:14:34 +0100 Subject: [PATCH] Geberic QRcode maker Added generic qrcode maker endpoint extensions can use to make embedable qrcodes --- lnbits/core/views/api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 0e88b5c8..b147c212 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -7,6 +7,7 @@ from typing import Dict, List, Optional, Union from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse import httpx +import pyqrcode from fastapi import Query, Request, Header from fastapi.exceptions import HTTPException from fastapi.param_functions import Depends @@ -580,3 +581,23 @@ async def api_fiat_as_sats(data: ConversionData): output["sats"] = await fiat_amount_as_satoshis(data.amount, data.from_) output["BTC"] = output["sats"] / 100000000 return output + +@withdraw_ext.get("/api/v1/qrcode/{data}", response_class=StreamingResponse) +async def img(request: Request, data): + qr = pyqrcode.create(data) + stream = BytesIO() + qr.svg(stream, scale=3) + stream.seek(0) + + async def _generator(stream: BytesIO): + yield stream.getvalue() + + return StreamingResponse( + _generator(stream), + headers={ + "Content-Type": "image/svg+xml", + "Cache-Control": "no-cache, no-store, must-revalidate", + "Pragma": "no-cache", + "Expires": "0", + }, + )