allow to edit files
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def iso_stamp_filename(prefix: str, ext: str) -> str:
|
||||
"""Generate timestamped filename, e.g. pasted-2025-10-23T121212Z.png"""
|
||||
ts = datetime.now(timezone.utc).isoformat()
|
||||
ts = ts.replace(":", "").split(".")[0]
|
||||
if ts.endswith("+00:00"):
|
||||
ts = ts.replace("+00:00", "Z")
|
||||
return f"{prefix}-{ts}.{ext}"
|
||||
|
||||
def format_size(num_bytes: int) -> str:
|
||||
"""Return a human-readable file size (e.g., '2.3 MB', '10 Bytes')."""
|
||||
if num_bytes < 1024:
|
||||
return f"{num_bytes} Byte{'s' if num_bytes != 1 else ''}"
|
||||
|
||||
units = ["KB", "MB", "GB", "TB", "PB", "EB"]
|
||||
size = float(num_bytes)
|
||||
for unit in units:
|
||||
size /= 1024.0
|
||||
if size < 1024.0 or unit == units[-1]:
|
||||
# 1 decimal place; drop trailing .0 (optional)
|
||||
val = f"{size:.1f}"
|
||||
if val.endswith(".0"):
|
||||
val = val[:-2]
|
||||
return f"{val} {unit}"
|
||||
return f"{num_bytes} Bytes" # fallback
|
||||
|
||||
Reference in New Issue
Block a user