Replace content CLI with Textual TUI
This commit is contained in:
1 parent
0d58ddd430
commit
737700a9a8
28 files changed
+2403
-167
No files matched your search
@@ -0,0 +1,30 @@
|
||||
from jsonfile import PROJECT_ROOT
|
||||
|
||||
STATIC_DIR = PROJECT_ROOT / "static"
|
||||
IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".avif", ".ico"}
|
||||
|
||||
|
||||
def site_path(file_path) -> str:
|
||||
return "/" + file_path.relative_to(STATIC_DIR).as_posix()
|
||||
|
||||
|
||||
def list_images() -> list[dict]:
|
||||
if not STATIC_DIR.exists():
|
||||
return []
|
||||
images = []
|
||||
for file_path in sorted(STATIC_DIR.rglob("*")):
|
||||
if file_path.is_file() and file_path.suffix.lower() in IMAGE_EXTENSIONS:
|
||||
images.append({"path": site_path(file_path), "size": file_path.stat().st_size})
|
||||
return images
|
||||
|
||||
|
||||
def image_exists(path: str) -> bool:
|
||||
return (STATIC_DIR / path.lstrip("/")).is_file()
|
||||
|
||||
|
||||
def format_size(size: int) -> str:
|
||||
for unit in ["B", "KB", "MB"]:
|
||||
if size < 1024:
|
||||
return f"{size:.0f} {unit}" if unit == "B" else f"{size:.1f} {unit}"
|
||||
size /= 1024
|
||||
return f"{size:.1f} GB"
|
||||
Reference in new issue
Block a user