MyFSIO v0.2.2 Release #14
30
app/ui.py
30
app/ui.py
@@ -41,11 +41,11 @@ from .storage import ObjectStorage, StorageError
|
||||
ui_bp = Blueprint("ui", __name__, template_folder="../templates", url_prefix="/ui")
|
||||
|
||||
|
||||
def _format_datetime_display(dt: datetime, display_tz: str | None = None) -> str:
|
||||
"""Format a datetime for display using the configured timezone.
|
||||
def _convert_to_display_tz(dt: datetime, display_tz: str | None = None) -> datetime:
|
||||
"""Convert a datetime to the configured display timezone.
|
||||
|
||||
Args:
|
||||
dt: The datetime to format
|
||||
dt: The datetime to convert
|
||||
display_tz: Optional timezone string. If not provided, reads from current_app.config.
|
||||
"""
|
||||
if display_tz is None:
|
||||
@@ -58,9 +58,31 @@ def _format_datetime_display(dt: datetime, display_tz: str | None = None) -> str
|
||||
dt = dt.astimezone(tz)
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
return dt
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
dt = _convert_to_display_tz(dt, display_tz)
|
||||
return dt.strftime("%b %d, %Y %H:%M")
|
||||
|
||||
|
||||
def _format_datetime_iso(dt: datetime, display_tz: str | None = None) -> str:
|
||||
"""Format a datetime as ISO format using the configured timezone.
|
||||
|
||||
Args:
|
||||
dt: The datetime to format
|
||||
display_tz: Optional timezone string. If not provided, reads from current_app.config.
|
||||
"""
|
||||
dt = _convert_to_display_tz(dt, display_tz)
|
||||
return dt.isoformat()
|
||||
|
||||
|
||||
|
||||
def _storage() -> ObjectStorage:
|
||||
return current_app.extensions["object_storage"]
|
||||
@@ -541,6 +563,7 @@ def list_bucket_objects(bucket_name: str):
|
||||
"size": obj.size,
|
||||
"last_modified": obj.last_modified.isoformat(),
|
||||
"last_modified_display": _format_datetime_display(obj.last_modified),
|
||||
"last_modified_iso": _format_datetime_iso(obj.last_modified),
|
||||
"etag": obj.etag,
|
||||
})
|
||||
|
||||
@@ -640,6 +663,7 @@ def stream_bucket_objects(bucket_name: str):
|
||||
"size": obj.size,
|
||||
"last_modified": obj.last_modified.isoformat(),
|
||||
"last_modified_display": _format_datetime_display(obj.last_modified, display_tz),
|
||||
"last_modified_iso": _format_datetime_iso(obj.last_modified, display_tz),
|
||||
"etag": obj.etag,
|
||||
}) + "\n"
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
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.lastModifiedIso = obj.lastModifiedIso || obj.last_modified_iso || obj.lastModified || obj.last_modified;
|
||||
tr.dataset.etag = obj.etag;
|
||||
tr.dataset.previewUrl = obj.previewUrl || obj.preview_url;
|
||||
tr.dataset.downloadUrl = obj.downloadUrl || obj.download_url;
|
||||
@@ -426,6 +427,7 @@
|
||||
size: obj.size,
|
||||
lastModified: obj.last_modified,
|
||||
lastModifiedDisplay: obj.last_modified_display,
|
||||
lastModifiedIso: obj.last_modified_iso,
|
||||
etag: obj.etag,
|
||||
previewUrl: urlTemplates ? buildUrlFromTemplate(urlTemplates.preview, key) : '',
|
||||
downloadUrl: urlTemplates ? buildUrlFromTemplate(urlTemplates.download, key) : '',
|
||||
@@ -1793,7 +1795,7 @@
|
||||
|
||||
previewKey.textContent = row.dataset.key;
|
||||
previewSize.textContent = formatBytes(Number(row.dataset.size));
|
||||
previewModified.textContent = row.dataset.lastModified;
|
||||
previewModified.textContent = row.dataset.lastModifiedIso || row.dataset.lastModified;
|
||||
previewEtag.textContent = row.dataset.etag;
|
||||
downloadButton.href = row.dataset.downloadUrl;
|
||||
downloadButton.classList.remove('disabled');
|
||||
|
||||
Reference in New Issue
Block a user