Odysseus v1.0

This commit is contained in:
pewdiepie-archdaemon
2026-05-31 23:58:26 +09:00
commit e5c99a5eee
421 changed files with 271349 additions and 0 deletions

30
src/app_helpers.py Normal file
View File

@@ -0,0 +1,30 @@
# src/app_helpers.py
import os
import base64
def read_if_exists(path: str) -> str:
"""Read file if it exists, return empty string otherwise."""
try:
with open(path, "r", encoding="utf-8") as f:
return f.read().strip()
except Exception:
return ""
def file_to_data_url(path: str, mime: str) -> str:
"""Convert file to data URL."""
with open(path, "rb") as f:
b64 = base64.b64encode(f.read()).decode("ascii")
return f"data:{mime};base64,{b64}"
def abs_join(base_dir: str, rel: str) -> str:
"""Join paths and return absolute path."""
return os.path.abspath(os.path.join(base_dir, rel))
def inside_base_dir(base_dir: str, path: str) -> bool:
"""Check if path is inside base directory."""
base = os.path.realpath(base_dir)
p = os.path.realpath(path)
try:
return os.path.commonpath([base, p]) == base
except Exception:
return False