Add QR code for wifi on index page, some responsive design fixes

This commit is contained in:
Ana Custura 2026-02-17 15:05:59 +00:00
parent 3829abaa03
commit 60d060e907
8 changed files with 57 additions and 16 deletions

View file

@ -15,6 +15,8 @@ import secrets
import string
import glob
import time
import qrcode
from datetime import datetime
def gen_username() -> str:
words = top_n_list("en", 5000)
@ -38,6 +40,12 @@ def get_file_icon_url(path: str) -> str:
'ppt', 'pptx']:
return url_for("static", filename=f"images/extension-icons/ext-{suffix}.svg")
return url_for("static", filename=f"images/extension-icons/ext-unknown.svg")
def get_last_modified(path: str) -> str:
mod_time = time.ctime(os.path.getmtime(path))
#print(mod_time)
#dt = datetime.strptime(mod_time, "%a %b %d %H:%M:%S %Y")
#formatted_time = dt.strftime("%Y-%m-%d %H:%M")
return mod_time
def get_files_in_path(path: str):
file_list = []
@ -46,7 +54,7 @@ def get_files_in_path(path: str):
file_list = [
{"name": x.replace(path, "").strip("/"), "path": x, "is_file": os.path.isfile(x),
"is_dir": os.path.isdir(x),
"filetype": get_file_suffix(x), "last_modified": time.ctime(os.path.getmtime(x)),
"filetype": get_file_suffix(x), "last_modified": get_last_modified(x),
"icon_url": get_file_icon_url(x),
"relative_path": x.replace(app.config["BUTTERBOX_USB_PATH"], "")} for x
in list_of_files]
@ -71,6 +79,16 @@ def dump_settings(filename: str) -> None:
@app.route('/')
@app.route('/index')
def index():
display_wifi_password = False
wifi_password = get_setting("wifi_password")
if wifi_password:
wifi_ssid = get_setting("ssid")
wifi_encryption_type = "WPA2"
img = qrcode.make(f"WIFI:T:{wifi_encryption_type};S:{wifi_ssid};P:{wifi_password};;")
img.save("app/static/images/wifi_qr_code.png")
display_wifi_password = True
else:
os.remove("app/static/images/wifi_qr_code.png")
enable_chat = get_setting("enable_chat")
enable_app_store = get_setting("enable_app_store")
enable_map_viewer = get_setting("enable_map_viewer")
@ -98,7 +116,7 @@ def index():
"name": name,
"image": url_for("static", filename="images/explore-icon.svg"),
"url": url_for("files", path=""),})
return render_template('index.html', title='Home', get_setting=get_setting, services=service_array)
return render_template('index.html', title='Home', get_setting=get_setting, services=service_array, display_wifi_password=display_wifi_password)
@app.route('/files/', defaults={'path': ''})
@app.route('/files/<path:path>')