From 040fd333e289a92b3516a0bfff7eb114ebd8be6a Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 29 Aug 2022 11:50:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20cache=20bootstrap=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.py | 30 +++++++++++++++++++++++++----- src/main.py | 3 +++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/index.py b/src/index.py index 6fdb30e..d1f8bc7 100644 --- a/src/index.py +++ b/src/index.py @@ -9,19 +9,39 @@ import gnupg main_pages = Blueprint("main", __name__) + +def download_file(url, file): + os.makedirs("/app/static/", exist_ok=True) + r = requests.get(url, allow_redirects=True) + open(file, "wb").write(r.content) + + +def cache_bootstrap(): + download_file( + "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css", + "/app/static/bootstrap.min.css", + ) + download_file( + "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css", + "/app/static/bootstrap-icons.css", + ) + download_file( + "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js", + "/app/static/bootstrap.bundle.min.js", + ) + + # Bootstrap CSS BOOTSTRAP = [ Reference( - "https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css", + "/static/bootstrap.min.css", "stylesheet", ), Reference( - "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css", + "/static/bootstrap-icons.css", "stylesheet", ), - Script( - src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" - ), + Script(src="/static/bootstrap.bundle.min.js"), ] # Encrypt msg with GPG diff --git a/src/main.py b/src/main.py index e929542..77954a5 100644 --- a/src/main.py +++ b/src/main.py @@ -12,4 +12,7 @@ app.register_blueprint(asset_pages, url_prefix="/assets") if __name__ == "__main__": + from index import cache_bootstrap + + cache_bootstrap() app.run(host="0.0.0.0", port=1030, debug=True, threaded=True)