migrate from flask to quart.
also remove all flaskiness from static file serving. and reference all vendored scripts on the base tempĺate for simplicity.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from flask import Blueprint
|
||||
from quart import Blueprint
|
||||
|
||||
|
||||
withdraw_ext: Blueprint = Blueprint("withdraw", __name__, static_folder="static", template_folder="templates")
|
||||
withdraw_ext: Blueprint = Blueprint(
|
||||
"withdraw", __name__, static_folder="static", template_folder="templates", static_url_path="/static"
|
||||
)
|
||||
|
||||
|
||||
from .views_api import * # noqa
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import url_for
|
||||
from quart import url_for
|
||||
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode
|
||||
from sqlite3 import Row
|
||||
from typing import NamedTuple
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %} {% block scripts %}
|
||||
|
||||
<script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script>
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
|
||||
%} {% block scripts %} {{ window_vars(user) }}
|
||||
<script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script>
|
||||
{% assets filters='rjsmin', output='__bundle__/withdraw/index.js',
|
||||
'withdraw/js/index.js' %}
|
||||
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
|
||||
{% endassets %} {% endblock %} {% block page %}
|
||||
<script type="text/javascript" src="/withdraw/static/js/index.js"></script>
|
||||
{% endblock %} {% block page %}
|
||||
<div class="row q-col-gutter-md">
|
||||
<div class="col-12 col-md-7 q-gutter-y-md">
|
||||
<q-card>
|
||||
@@ -273,7 +270,7 @@
|
||||
color="deep-purple"
|
||||
:disable="
|
||||
simpleformDialog.data.wallet == null ||
|
||||
|
||||
|
||||
simpleformDialog.data.max_withdrawable == null ||
|
||||
simpleformDialog.data.max_withdrawable < 1 ||
|
||||
simpleformDialog.data.uses == null"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
{% block page %}
|
||||
{% extends "print.html" %} {% block page %}
|
||||
|
||||
<div class="row justify-center">
|
||||
<div class="col-12 col-sm-8 col-lg-6 text-center" id="vue">
|
||||
@@ -50,15 +49,6 @@
|
||||
}
|
||||
</style>
|
||||
{% endblock %} {% block scripts %}
|
||||
<script src="{{ url_for('static', filename='vendor/vue@2.6.12/vue.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='vendor/vuex@3.5.1/vuex.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='vendor/vue-router@3.4.3/vue-router.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='vendor/quasar@1.13.2/quasar.umd.js') }}"></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/static/__bundle__/base.js?a52a989e"
|
||||
></script>
|
||||
<script src="{{ url_for('static', filename='vendor/vue-qrcode@1.0.2/vue-qrcode.min.js') }}"></script>
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import g, abort, render_template
|
||||
from quart import g, abort, render_template
|
||||
from http import HTTPStatus
|
||||
|
||||
from lnbits.decorators import check_user_exists, validate_uuids
|
||||
@@ -10,21 +10,21 @@ from .crud import get_withdraw_link, chunks
|
||||
@withdraw_ext.route("/")
|
||||
@validate_uuids(["usr"], required=True)
|
||||
@check_user_exists()
|
||||
def index():
|
||||
return render_template("withdraw/index.html", user=g.user)
|
||||
async def index():
|
||||
return await render_template("withdraw/index.html", user=g.user)
|
||||
|
||||
|
||||
@withdraw_ext.route("/<link_id>")
|
||||
def display(link_id):
|
||||
async def display(link_id):
|
||||
link = get_withdraw_link(link_id, 0) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
||||
return render_template("withdraw/display.html", link=link, unique=True)
|
||||
return await render_template("withdraw/display.html", link=link, unique=True)
|
||||
|
||||
|
||||
@withdraw_ext.route("/print/<link_id>")
|
||||
def print_qr(link_id):
|
||||
async def print_qr(link_id):
|
||||
link = get_withdraw_link(link_id) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
||||
if link.uses == 0:
|
||||
return render_template("withdraw/print_qr.html", link=link, unique=False)
|
||||
return await render_template("withdraw/print_qr.html", link=link, unique=False)
|
||||
links = []
|
||||
count = 0
|
||||
for x in link.usescsv.split(","):
|
||||
@@ -33,4 +33,4 @@ def print_qr(link_id):
|
||||
count = count + 1
|
||||
page_link = list(chunks(links, 2))
|
||||
linked = list(chunks(page_link, 5))
|
||||
return render_template("withdraw/print_qr.html", link=linked, unique=True)
|
||||
return await render_template("withdraw/print_qr.html", link=linked, unique=True)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from flask import g, jsonify, request
|
||||
from quart import g, jsonify, request
|
||||
from http import HTTPStatus
|
||||
from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl
|
||||
import shortuuid # type: ignore
|
||||
@@ -21,7 +21,7 @@ from .crud import (
|
||||
|
||||
@withdraw_ext.route("/api/v1/links", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
def api_links():
|
||||
async def api_links():
|
||||
wallet_ids = [g.wallet.id]
|
||||
|
||||
if "all_wallets" in request.args:
|
||||
@@ -40,7 +40,7 @@ def api_links():
|
||||
|
||||
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["GET"])
|
||||
@api_check_wallet_key("invoice")
|
||||
def api_link_retrieve(link_id):
|
||||
async def api_link_retrieve(link_id):
|
||||
link = get_withdraw_link(link_id, 0)
|
||||
|
||||
if not link:
|
||||
@@ -65,7 +65,7 @@ def api_link_retrieve(link_id):
|
||||
"is_unique": {"type": "boolean", "required": True},
|
||||
}
|
||||
)
|
||||
def api_link_create_or_update(link_id=None):
|
||||
async def api_link_create_or_update(link_id=None):
|
||||
if g.data["max_withdrawable"] < g.data["min_withdrawable"]:
|
||||
return (
|
||||
jsonify({"message": "`max_withdrawable` needs to be at least `min_withdrawable`."}),
|
||||
@@ -95,7 +95,7 @@ def api_link_create_or_update(link_id=None):
|
||||
|
||||
@withdraw_ext.route("/api/v1/links/<link_id>", methods=["DELETE"])
|
||||
@api_check_wallet_key("admin")
|
||||
def api_link_delete(link_id):
|
||||
async def api_link_delete(link_id):
|
||||
link = get_withdraw_link(link_id)
|
||||
|
||||
if not link:
|
||||
@@ -113,7 +113,7 @@ def api_link_delete(link_id):
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurl/<unique_hash>", methods=["GET"])
|
||||
def api_lnurl_response(unique_hash):
|
||||
async def api_lnurl_response(unique_hash):
|
||||
link = get_withdraw_link_by_hash(unique_hash)
|
||||
|
||||
if not link:
|
||||
@@ -134,7 +134,7 @@ def api_lnurl_response(unique_hash):
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurl/<unique_hash>/<id_unique_hash>", methods=["GET"])
|
||||
def api_lnurl_multi_response(unique_hash, id_unique_hash):
|
||||
async def api_lnurl_multi_response(unique_hash, id_unique_hash):
|
||||
link = get_withdraw_link_by_hash(unique_hash)
|
||||
|
||||
if not link:
|
||||
@@ -163,7 +163,7 @@ def api_lnurl_multi_response(unique_hash, id_unique_hash):
|
||||
|
||||
|
||||
@withdraw_ext.route("/api/v1/lnurl/cb/<unique_hash>", methods=["GET"])
|
||||
def api_lnurl_callback(unique_hash):
|
||||
async def api_lnurl_callback(unique_hash):
|
||||
link = get_withdraw_link_by_hash(unique_hash)
|
||||
k1 = request.args.get("k1", type=str)
|
||||
payment_request = request.args.get("pr", type=str)
|
||||
|
||||
Reference in New Issue
Block a user