mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-09 20:12:34 +02:00
feat: automatically import extension blueprints
This commit is contained in:
@@ -6,6 +6,10 @@ end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{html,js,json}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import importlib
|
||||
import json
|
||||
import requests
|
||||
import uuid
|
||||
@@ -9,12 +10,17 @@ from lnurl import Lnurl, LnurlWithdrawResponse
|
||||
from . import bolt11
|
||||
from .core import core_app
|
||||
from .db import init_databases, open_db
|
||||
from .extensions.withdraw import withdraw_ext
|
||||
from .helpers import ExtensionManager, megajson
|
||||
from .settings import WALLET, DEFAULT_USER_WALLET_NAME, FEE_RESERVE
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
valid_extensions = [ext for ext in ExtensionManager().extensions if ext.is_valid]
|
||||
|
||||
|
||||
# optimization & security
|
||||
# -----------------------
|
||||
|
||||
Talisman(
|
||||
app,
|
||||
content_security_policy={
|
||||
@@ -32,20 +38,41 @@ Talisman(
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# blueprints / extensions
|
||||
# -----------------------
|
||||
|
||||
app.register_blueprint(core_app)
|
||||
|
||||
for ext in valid_extensions:
|
||||
try:
|
||||
ext_module = importlib.import_module(f"lnbits.extensions.{ext.code}")
|
||||
app.register_blueprint(getattr(ext_module, f"{ext.code}_ext"), url_prefix=f"/{ext.code}")
|
||||
except Exception:
|
||||
raise ImportError(f"Please make sure that the extension `{ext.code}` follows conventions.")
|
||||
|
||||
|
||||
# filters
|
||||
app.jinja_env.globals["EXTENSIONS"] = [ext for ext in ExtensionManager().extensions if ext.is_valid]
|
||||
# -------
|
||||
|
||||
app.jinja_env.globals["EXTENSIONS"] = valid_extensions
|
||||
app.jinja_env.filters["megajson"] = megajson
|
||||
|
||||
# blueprints
|
||||
app.register_blueprint(core_app)
|
||||
app.register_blueprint(withdraw_ext, url_prefix="/withdraw")
|
||||
|
||||
# init
|
||||
# ----
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
init_databases()
|
||||
|
||||
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
# move the rest to `core_app`
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
|
||||
|
||||
@app.route("/deletewallet")
|
||||
def deletewallet():
|
||||
user_id = request.args.get("usr")
|
||||
|
@@ -23,9 +23,7 @@
|
||||
<ul class="treeview-menu">
|
||||
{% for w in user_wallets %}
|
||||
<li>
|
||||
<a href="{{ url_for('wallet') }}?wal={{ w.id }}&usr={{ w.user }}"
|
||||
><i class="fa fa-bolt"></i> {{ w.name }}</a
|
||||
>
|
||||
<a href="{{ url_for('wallet') }}?wal={{ w.id }}&usr={{ w.user }}"><i class="fa fa-bolt"></i> {{ w.name }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
<li><a onclick="sidebarmake()">Add a wallet +</a></li>
|
||||
@@ -46,23 +44,21 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<li>
|
||||
<a href="{{ url_for('extensions') }}?usr={{ user }}">Manager </a></li>
|
||||
<a href="{{ url_for('extensions') }}?usr={{ user }}">Manager</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<!-- Right side column. Contains the navbar and content of the page -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Right side column. Contains the navbar and content of the page -->
|
||||
<div class="content-wrapper">
|
||||
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<div id="wonga"></div>
|
||||
<h1>Wallet <small>Control panel</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<a href="#"><i class="fa fa-dashboard"></i> Home</a>
|
||||
</li>
|
||||
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
|
||||
<li class="active">Extensions</li>
|
||||
</ol>
|
||||
|
||||
@@ -108,11 +104,11 @@
|
||||
</div>
|
||||
<!-- /.content -->
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
window.user = {{ user | megajson | safe }}
|
||||
window.user_wallets = {{ user_wallets | megajson | safe }}
|
||||
window.user_ext = {{ user_ext | megajson | safe }}
|
||||
</script>
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user