diff --git a/app/main.py b/app/main.py
index 7ffe312..3c44691 100644
--- a/app/main.py
+++ b/app/main.py
@@ -1,7 +1,8 @@
-from flask import Flask, send_from_directory, render_template_string, abort
+from flask import Flask, send_from_directory, render_template_string, abort, url_for
import os
from logger import log
from datetime import datetime
+from urllib.parse import quote
# read version from file if exists
version = "unknown"
@@ -15,7 +16,7 @@
GUNICORN_VERSION=f"{os.getenv('GUNICORN_VERSION', 'Unknown')}"
log.info('Service started, version: [%s]', GUNICORN_VERSION)
-# HTML template for directory listing
+# HTML template for directory listing with breadcrumb navigation
DIRECTORY_LISTING_TEMPLATE = """
@@ -24,27 +25,94 @@
+
+
+
+ {% if parent_path %}
+
+ {% endif %}
+
{% for item in items %}
{% endfor %}
@@ -59,26 +127,40 @@ def get_human_readable_size(size_in_bytes):
size_in_bytes /= 1024
return f"{size_in_bytes:.1f} TB"
+def get_breadcrumbs(path):
+ """Generate breadcrumb navigation items"""
+ if not path:
+ return []
+
+ crumbs = []
+ current = ""
+ parts = path.split('/')
+
+ for part in parts:
+ if part:
+ current = os.path.join(current, part)
+ crumbs.append({
+ 'name': part,
+ 'path': f'/deb/{current}'
+ })
+
+ return crumbs
+
def get_directory_listing(base_path, current_path):
"""Generate directory listing information"""
full_path = os.path.join(base_path, current_path)
items = []
try:
- for item in os.listdir(full_path):
- item_path = os.path.join(full_path, item)
- stats = os.stat(item_path)
- is_dir = os.path.isdir(item_path)
+ for item in os.scandir(full_path):
+ stats = item.stat()
+ relative_path = os.path.relpath(item.path, base_path)
- relative_path = os.path.join(current_path, item)
- if not relative_path.startswith('/'):
- relative_path = '/' + relative_path
-
items.append({
- 'name': item,
- 'path': f"/deb{relative_path}",
- 'is_dir': is_dir,
- 'size': get_human_readable_size(stats.st_size) if not is_dir else '-',
+ 'name': item.name,
+ 'path': f"/deb/{quote(relative_path)}",
+ 'is_dir': item.is_dir(),
+ 'size': get_human_readable_size(stats.st_size) if not item.is_dir() else '-',
'modified': datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S')
})
@@ -115,10 +197,13 @@ def serve_deb_repo(path):
log.info(f"Serving directory listing for {full_path}")
items = get_directory_listing(base_path, path)
parent_path = '/deb/' + os.path.dirname(path) if path else None
+ breadcrumbs = get_breadcrumbs(path)
+
return render_template_string(
DIRECTORY_LISTING_TEMPLATE,
current_path=f"/deb/{path}",
parent_path=parent_path,
+ breadcrumbs=breadcrumbs,
items=items
)
else: