download js lib for crypto stuff

This commit is contained in:
Mylloon 2022-10-26 15:36:53 +02:00
parent 84d6d87d98
commit 1cc02f89e3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 32 additions and 0 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ __pycache__/
.vscode/ .vscode/
src/public/fonts/ src/public/fonts/
src/public/js/libs/

View file

@ -3,12 +3,14 @@ from flask import Flask, redirect
from routes.index import router as index from routes.index import router as index
from routes.upload import router as upload from routes.upload import router as upload
from utils.font import init as init_font from utils.font import init as init_font
from utils.libjs import init as init_libjs
app = Flask(__name__, static_url_path="/", static_folder="public") app = Flask(__name__, static_url_path="/", static_folder="public")
app.register_blueprint(index, url_prefix="/index") app.register_blueprint(index, url_prefix="/index")
app.register_blueprint(upload, url_prefix="/upload") app.register_blueprint(upload, url_prefix="/upload")
init_font("1.3.0") init_font("1.3.0")
init_libjs("fc5e3c53e41490e24ca7f67cb24e7ab389b770f9")
@app.route("/") @app.route("/")

29
src/utils/libjs.py Normal file
View file

@ -0,0 +1,29 @@
from os import mkdir
from requests import get
from utils.misc import exist
def init(commit_hash):
""" Download JS libraries"""
path = "./src/public/js/libs"
filename = "bigint-mod.js"
# If there is filename changes, you should change
# the name in the js imports too (./src/public/js/rsa.js)
# Check if js/lib directory exists
if not exist(path):
mkdir(path)
# TODO: Store the version used and redownload on version changes
# Download the js file if needed
if not exist(f"{path}/{filename}"):
# Download the font file
file_url = f"https://github.com/juanelas/bigint-mod-arith/blob/{commit_hash}/dist/esm/index.browser.js"
data = get(file_url).content
# Save the file
with open(f"{path}/{filename}", "wb") as file:
file.write(data)