diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.py | 19 | ||||
| -rw-r--r-- | src/file_man.py | 14 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/config.py b/src/config.py index 5720221..934bafe 100644 --- a/src/config.py +++ b/src/config.py @@ -13,15 +13,16 @@ API_VERSIONS = { # file manager FILE_MAN_VERBOSE = True +FILE_MAN_COMPRESS = True # do compress all files FILE_MAN_PATH_MAP = { # external - "/": {"path": "www/index.html"}, - "/about": {"path": "www/about.html"}, - "/testing": {"path": "www/testing.html"}, - "/projects": {"path": "www/projects.html"}, - "/images/*": {"path": "www/images/*"}, - "/scripts/*": {"path": "www/scripts/*"}, - "/robots.txt": {"path": "www/robots.txt"}, - "/favicon.ico": {"path": "www/favicon.ico"}, - "/css/styles.css": {"path": "www/css/styles.css"}, + "/": {"path": "www/index.html", "compress": True}, + "/about": {"path": "www/about.html", "compress": True}, + "/testing": {"path": "www/testing.html", "compress": True}, + "/projects": {"path": "www/projects.html", "compress": True}, + "/images/*": {"path": "www/images/*", "compress": False}, + "/scripts/*": {"path": "www/scripts/*", "compress": True}, + "/robots.txt": {"path": "www/robots.txt", "compress": False}, + "/favicon.ico": {"path": "www/favicon.ico", "compress": True}, + "/css/styles.css": {"path": "www/css/styles.css", "compress": True}, } diff --git a/src/file_man.py b/src/file_man.py index 58b4015..3371dd2 100644 --- a/src/file_man.py +++ b/src/file_man.py @@ -28,9 +28,13 @@ def generate_path_map() -> dict[str, dict[str, Any]]: keypath = FILE_MAN_PATH_MAP[key]["path"][:-2] for path in list_path(keypath): webpath = f"{key[:-1]}{path.replace(keypath+'/', '')}" - path_map[webpath] = {"path": path} + path_map[webpath] = { + "path": path, + "compress": FILE_MAN_PATH_MAP[key]["compress"]} else: - path_map[key] = {"path": FILE_MAN_PATH_MAP[key]["path"]} + path_map[key] = { + "path": FILE_MAN_PATH_MAP[key]["path"], + "compress": FILE_MAN_PATH_MAP[key]["compress"]} # add headers for val in path_map.values(): @@ -48,13 +52,13 @@ def generate_path_map() -> dict[str, dict[str, Any]]: case ".png": headers["Content-Type"] = "image/png" case ".webp": - headers["Content-Type"] = "image/avif" + headers["Content-Type"] = "image/webp" case ".jpg" | ".jpeg": headers["Content-Type"] = "image/jpeg" case _: headers["Content-Type"] = "*/*" - val["headers"] = headers headers["Content-Length"] = os.path.getsize(val["path"]) + val["headers"] = headers # print list of paths if FILE_MAN_VERBOSE: @@ -81,7 +85,7 @@ def compress_path_map(path_map: dict[str, dict[str, Any]], path_prefix: str = "c os.mkdir(path_prefix) for val in path_map.values(): filepath = f"{path_prefix}/{val["path"]}" - if val["headers"]["Content-Type"].split("/")[0] == "image": # ignore images + if not val["compress"]: continue if not os.path.exists((dirs := os.path.dirname(filepath))): # add missing folders os.makedirs(dirs) |