chore: use standard library's HTTP status codes
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from flask import g, jsonify, request
|
||||
from http import HTTPStatus
|
||||
|
||||
from lnbits.core.crud import get_user, get_wallet
|
||||
from lnbits.core.services import create_invoice
|
||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||
from lnbits.helpers import Status
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
from lnbits.extensions.paywall import paywall_ext
|
||||
@@ -18,7 +18,7 @@ def api_paywalls():
|
||||
if "all_wallets" in request.args:
|
||||
wallet_ids = get_user(g.wallet.user).wallet_ids
|
||||
|
||||
return jsonify([paywall._asdict() for paywall in get_paywalls(wallet_ids)]), Status.OK
|
||||
return jsonify([paywall._asdict() for paywall in get_paywalls(wallet_ids)]), HTTPStatus.OK
|
||||
|
||||
|
||||
@paywall_ext.route("/api/v1/paywalls", methods=["POST"])
|
||||
@@ -33,7 +33,7 @@ def api_paywalls():
|
||||
def api_paywall_create():
|
||||
paywall = create_paywall(wallet_id=g.wallet.id, **g.data)
|
||||
|
||||
return jsonify(paywall._asdict()), Status.CREATED
|
||||
return jsonify(paywall._asdict()), HTTPStatus.CREATED
|
||||
|
||||
|
||||
@paywall_ext.route("/api/v1/paywalls/<paywall_id>", methods=["DELETE"])
|
||||
@@ -42,14 +42,14 @@ def api_paywall_delete(paywall_id):
|
||||
paywall = get_paywall(paywall_id)
|
||||
|
||||
if not paywall:
|
||||
return jsonify({"message": "Paywall does not exist."}), Status.NOT_FOUND
|
||||
return jsonify({"message": "Paywall does not exist."}), HTTPStatus.NOT_FOUND
|
||||
|
||||
if paywall.wallet != g.wallet.id:
|
||||
return jsonify({"message": "Not your paywall."}), Status.FORBIDDEN
|
||||
return jsonify({"message": "Not your paywall."}), HTTPStatus.FORBIDDEN
|
||||
|
||||
delete_paywall(paywall_id)
|
||||
|
||||
return "", Status.NO_CONTENT
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
@paywall_ext.route("/api/v1/paywalls/<paywall_id>/invoice", methods=["GET"])
|
||||
@@ -61,9 +61,9 @@ def api_paywall_get_invoice(paywall_id):
|
||||
wallet_id=paywall.wallet, amount=paywall.amount, memo=f"#paywall {paywall.memo}"
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"message": str(e)}), Status.INTERNAL_SERVER_ERROR
|
||||
return jsonify({"message": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.OK
|
||||
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), HTTPStatus.OK
|
||||
|
||||
|
||||
@paywall_ext.route("/api/v1/paywalls/<paywall_id>/check_invoice", methods=["POST"])
|
||||
@@ -72,18 +72,18 @@ def api_paywal_check_invoice(paywall_id):
|
||||
paywall = get_paywall(paywall_id)
|
||||
|
||||
if not paywall:
|
||||
return jsonify({"message": "Paywall does not exist."}), Status.NOT_FOUND
|
||||
return jsonify({"message": "Paywall does not exist."}), HTTPStatus.NOT_FOUND
|
||||
|
||||
try:
|
||||
is_paid = not WALLET.get_invoice_status(g.data["checking_id"]).pending
|
||||
except Exception:
|
||||
return jsonify({"paid": False}), Status.OK
|
||||
return jsonify({"paid": False}), HTTPStatus.OK
|
||||
|
||||
if is_paid:
|
||||
wallet = get_wallet(paywall.wallet)
|
||||
payment = wallet.get_payment(g.data["checking_id"])
|
||||
payment.set_pending(False)
|
||||
|
||||
return jsonify({"paid": True, "url": paywall.url}), Status.OK
|
||||
return jsonify({"paid": True, "url": paywall.url}), HTTPStatus.OK
|
||||
|
||||
return jsonify({"paid": False}), Status.OK
|
||||
return jsonify({"paid": False}), HTTPStatus.OK
|
||||
|
||||
Reference in New Issue
Block a user