From 7b4bf3cdc04c7168698365dac9251ada67e405ee Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Fri, 16 Apr 2021 20:42:37 +0100 Subject: [PATCH] Lnurl all-father, please let this work --- lnbits/extensions/copilot/lnurl.py | 7 ++--- lnbits/extensions/copilot/views.py | 33 +++++++++++++++++++++- lnbits/extensions/copilot/views_api.py | 39 +------------------------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index 69bba5ac..dea70567 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -66,10 +66,9 @@ async def lnurl_callback(cp_id): wallet_id=cp.wallet, amount=int(amount_received / 1000), memo=cp.lnurl_title, - webhook="/copilot/api/v1/copilot/hook/" + cp_id, + webhook=url_for("copilot.api_copilot_hooker", cp_id=cp_id, amount=int(amount_received / 1000), _external=True), description_hash=hashlib.sha256((cp.lnurl_title).encode("utf-8")).digest(), extra={"tag": "copilot", "comment": comment}, ) - print(jsonify(pr=payment_request, success_action=None, routes=[], disposable=None)) - print(["pr"=payment_request, "success_action"=None, "routes"=[], "disposable"=None]) - return jsonify(pr=payment_request, success_action=None, routes=[], disposable=None) \ No newline at end of file + + return jsonify(pr=payment_request, success_action=None, routes=[]) \ No newline at end of file diff --git a/lnbits/extensions/copilot/views.py b/lnbits/extensions/copilot/views.py index d25416ff..49f58594 100644 --- a/lnbits/extensions/copilot/views.py +++ b/lnbits/extensions/copilot/views.py @@ -22,7 +22,6 @@ async def ws_panel(copilot_id): data = await websocket.receive() connected_websockets[copilot_id] = shortuuid.uuid() + "-" + data - @copilot_ext.websocket("/ws/compose/") async def ws_compose(copilot_id): global connected_websockets @@ -61,3 +60,35 @@ async def panel(copilot_id): HTTPStatus.NOT_FOUND, "Copilot link does not exist." ) return await render_template("copilot/panel.html", copilot=copilot) + + +@copilot_ext.route("/api/v1/copilot/hook//", methods=["GET"]) +async def api_copilot_hooker(copilot_id, amount): + copilot = await get_copilot(copilot_id) + + if not copilot: + return ( + jsonify({"message": "Copilot link link does not exist."}), + HTTPStatus.NOT_FOUND, + ) + if ( + copilot.animation1threshold + and int(amount) > copilot.animation1threshold + ): + data = copilot.animation1 + if ( + copilot.animation2threshold + and int(amount) > copilot.animation2threshold + ): + data = copilot.animation2 + if ( + copilot.animation3threshold + and int(amount) > copilot.animation3threshold + ): + data = copilot.animation3 + async with websocket( + "/ws/compose/" + copilot_id + ) as the_websocket: + await the_websocket.send(data) + + return "", HTTPStatus.OK \ No newline at end of file diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py index eb502599..ce3d40ca 100644 --- a/lnbits/extensions/copilot/views_api.py +++ b/lnbits/extensions/copilot/views_api.py @@ -90,41 +90,4 @@ async def api_copilot_delete(copilot_id): await delete_copilot(copilot_id) - return "", HTTPStatus.NO_CONTENT - - -#############################PAYMENTHOOKER########################## - - -@copilot_ext.route("/api/v1/copilot/hook/", methods=["POST"]) -async def api_copilot_hooker(copilot_id, trigger): - copilot = await get_copilot(copilot_id) - - if not copilot: - return ( - jsonify({"message": "Copilot link link does not exist."}), - HTTPStatus.NOT_FOUND, - ) - - socket_sendererer = app.socket_sendererer() - if ( - copilot.animation1threshold - and int(g.data["amount"]) > copilot.animation1threshold - ): - data = copilot.animation1 - if ( - copilot.animation2threshold - and int(g.data["amount"]) > copilot.animation2threshold - ): - data = copilot.animation2 - if ( - copilot.animation3threshold - and int(g.data["amount"]) > copilot.animation3threshold - ): - data = copilot.animation3 - async with socket_sendererer.websocket( - "/ws/compose/" + copilot_id - ) as the_websocket: - await the_websocket.send(data) - - return "", HTTPStatus.OK + return "", HTTPStatus.NO_CONTENT \ No newline at end of file