From 7a494abb966137483e0629714fefb7f369297273 Mon Sep 17 00:00:00 2001 From: kqjy Date: Wed, 14 Jan 2026 22:47:29 +0800 Subject: [PATCH] Reflect timezone in Object Details; Fix latest IAM bucket policy bugs --- app/ui.py | 17 ++++++++++++----- static/js/bucket-detail-main.js | 3 ++- templates/bucket_detail.html | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/ui.py b/app/ui.py index 8367f2e..6caa9b1 100644 --- a/app/ui.py +++ b/app/ui.py @@ -41,9 +41,15 @@ from .storage import ObjectStorage, StorageError ui_bp = Blueprint("ui", __name__, template_folder="../templates", url_prefix="/ui") -def _format_datetime_display(dt: datetime) -> str: - """Format a datetime for display using the configured timezone.""" - display_tz = current_app.config.get("DISPLAY_TIMEZONE", "UTC") +def _format_datetime_display(dt: datetime, display_tz: str | None = None) -> str: + """Format a datetime for display using the configured timezone. + + Args: + dt: The datetime to format + display_tz: Optional timezone string. If not provided, reads from current_app.config. + """ + if display_tz is None: + display_tz = current_app.config.get("DISPLAY_TIMEZONE", "UTC") if display_tz and display_tz != "UTC": try: tz = ZoneInfo(display_tz) @@ -52,7 +58,7 @@ def _format_datetime_display(dt: datetime) -> str: dt = dt.astimezone(tz) except (KeyError, ValueError): pass - return dt.strftime("%b %d, %Y %H:%M") + return dt.isoformat() @@ -587,6 +593,7 @@ def stream_bucket_objects(bucket_name: str): tags_template = url_for("ui.object_tags", bucket_name=bucket_name, object_key="KEY_PLACEHOLDER") copy_template = url_for("ui.copy_object", bucket_name=bucket_name, object_key="KEY_PLACEHOLDER") move_template = url_for("ui.move_object", bucket_name=bucket_name, object_key="KEY_PLACEHOLDER") + display_tz = current_app.config.get("DISPLAY_TIMEZONE", "UTC") def generate(): meta_line = json.dumps({ @@ -632,7 +639,7 @@ def stream_bucket_objects(bucket_name: str): "key": obj.key, "size": obj.size, "last_modified": obj.last_modified.isoformat(), - "last_modified_display": _format_datetime_display(obj.last_modified), + "last_modified_display": _format_datetime_display(obj.last_modified, display_tz), "etag": obj.etag, }) + "\n" diff --git a/static/js/bucket-detail-main.js b/static/js/bucket-detail-main.js index 73420a6..6f01f1d 100644 --- a/static/js/bucket-detail-main.js +++ b/static/js/bucket-detail-main.js @@ -136,6 +136,7 @@ tr.dataset.key = obj.key; tr.dataset.size = obj.size; tr.dataset.lastModified = obj.lastModified || obj.last_modified; + tr.dataset.lastModifiedDisplay = obj.lastModifiedDisplay || obj.last_modified_display || new Date(obj.lastModified || obj.last_modified).toLocaleString(); tr.dataset.etag = obj.etag; tr.dataset.previewUrl = obj.previewUrl || obj.preview_url; tr.dataset.downloadUrl = obj.downloadUrl || obj.download_url; @@ -1792,7 +1793,7 @@ previewKey.textContent = row.dataset.key; previewSize.textContent = formatBytes(Number(row.dataset.size)); - previewModified.textContent = row.dataset.lastModified; + previewModified.textContent = row.dataset.lastModifiedDisplay || row.dataset.lastModified; previewEtag.textContent = row.dataset.etag; downloadButton.href = row.dataset.downloadUrl; downloadButton.classList.remove('disabled'); diff --git a/templates/bucket_detail.html b/templates/bucket_detail.html index 905cc3a..5c64d23 100644 --- a/templates/bucket_detail.html +++ b/templates/bucket_detail.html @@ -1520,7 +1520,7 @@ {% endif %} - {% if can_edit_policy %} + {% if can_manage_lifecycle %}
{% if not lifecycle_enabled %}
+ {% endif %} + {% if can_manage_cors %}