2020-09-13 21:31:05 -03:00
|
|
|
from quart import g, abort, render_template
|
2020-05-03 15:57:05 +02:00
|
|
|
from http import HTTPStatus
|
2020-01-31 21:07:05 +01:00
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
from lnbits.decorators import check_user_exists, validate_uuids
|
2020-01-31 21:07:05 +01:00
|
|
|
|
2020-11-21 18:04:39 -03:00
|
|
|
from . import withdraw_ext
|
2020-07-20 21:03:23 +01:00
|
|
|
from .crud import get_withdraw_link, chunks
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
@withdraw_ext.route("/")
|
2020-04-16 17:07:53 +02:00
|
|
|
@validate_uuids(["usr"], required=True)
|
|
|
|
@check_user_exists()
|
2020-09-13 21:31:05 -03:00
|
|
|
async def index():
|
|
|
|
return await render_template("withdraw/index.html", user=g.user)
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
@withdraw_ext.route("/<link_id>")
|
2020-09-13 21:31:05 -03:00
|
|
|
async def display(link_id):
|
2020-11-21 18:04:39 -03:00
|
|
|
link = await get_withdraw_link(link_id, 0) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-09-13 21:31:05 -03:00
|
|
|
return await render_template("withdraw/display.html", link=link, unique=True)
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
@withdraw_ext.route("/print/<link_id>")
|
2020-09-13 21:31:05 -03:00
|
|
|
async def print_qr(link_id):
|
2020-11-21 18:04:39 -03:00
|
|
|
link = await get_withdraw_link(link_id) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-07-20 21:03:23 +01:00
|
|
|
if link.uses == 0:
|
2020-09-13 21:31:05 -03:00
|
|
|
return await render_template("withdraw/print_qr.html", link=link, unique=False)
|
2020-07-20 21:03:23 +01:00
|
|
|
links = []
|
2020-08-19 08:49:52 +01:00
|
|
|
count = 0
|
2020-07-20 21:03:23 +01:00
|
|
|
for x in link.usescsv.split(","):
|
2020-11-21 18:04:39 -03:00
|
|
|
linkk = await get_withdraw_link(link_id, count) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-08-19 08:49:52 +01:00
|
|
|
links.append(str(linkk.lnurl))
|
|
|
|
count = count + 1
|
2020-08-10 19:44:55 +01:00
|
|
|
page_link = list(chunks(links, 2))
|
|
|
|
linked = list(chunks(page_link, 5))
|
2020-09-13 21:31:05 -03:00
|
|
|
return await render_template("withdraw/print_qr.html", link=linked, unique=True)
|