feat: remove unused image retrieval endpoint and add human-readable time formatting filters
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -211,31 +211,6 @@ async def get_generated_image(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/images/{image_id}")
|
|
||||||
async def get_generated_image(
|
|
||||||
image_id: str,
|
|
||||||
current_user: dict = Depends(get_current_user),
|
|
||||||
) -> dict:
|
|
||||||
"""Return details for a single generated image."""
|
|
||||||
user_id = current_user.get("id") or current_user.get("sub")
|
|
||||||
conn = get_conn()
|
|
||||||
row = conn.execute(
|
|
||||||
"""SELECT id, model_id, prompt, image_data, created_at
|
|
||||||
FROM generated_images
|
|
||||||
WHERE id = ? AND user_id = ?""",
|
|
||||||
[image_id, user_id],
|
|
||||||
).fetchone()
|
|
||||||
if not row:
|
|
||||||
raise HTTPException(status_code=404, detail="Image not found")
|
|
||||||
return {
|
|
||||||
"id": str(row[0]),
|
|
||||||
"model_id": row[1],
|
|
||||||
"prompt": row[2],
|
|
||||||
"image_data": row[3],
|
|
||||||
"created_at": row[4].isoformat() if row[4] else None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/video", response_model=VideoResponse)
|
@router.post("/video", response_model=VideoResponse)
|
||||||
async def generate_video(
|
async def generate_video(
|
||||||
body: VideoRequest,
|
body: VideoRequest,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Flask frontend application."""
|
"""Flask frontend application."""
|
||||||
import functools
|
import functools
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from flask import (
|
from flask import (
|
||||||
@@ -24,6 +25,42 @@ app.config.from_object(Config)
|
|||||||
# Helpers
|
# Helpers
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@app.template_filter("fromisoformat")
|
||||||
|
def from_iso_format(s: str) -> datetime:
|
||||||
|
"""Convert ISO 8601 string to datetime object."""
|
||||||
|
return datetime.fromisoformat(s)
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter("humantime")
|
||||||
|
def human_time(dt: datetime) -> str:
|
||||||
|
"""Format a datetime object into a human-readable relative time."""
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
# Ensure dt is aware for comparison
|
||||||
|
if dt.tzinfo is None:
|
||||||
|
dt = dt.replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
diff = now - dt
|
||||||
|
seconds = diff.total_seconds()
|
||||||
|
|
||||||
|
if seconds < 60:
|
||||||
|
return "just now"
|
||||||
|
elif seconds < 3600:
|
||||||
|
minutes = int(seconds / 60)
|
||||||
|
return f"{minutes} minute{'s' if minutes > 1 else ''} ago"
|
||||||
|
elif seconds < 86400:
|
||||||
|
hours = int(seconds / 3600)
|
||||||
|
return f"{hours} hour{'s' if hours > 1 else ''} ago"
|
||||||
|
elif seconds < 2592000:
|
||||||
|
days = int(seconds / 86400)
|
||||||
|
return f"{days} day{'s' if days > 1 else ''} ago"
|
||||||
|
elif seconds < 31536000:
|
||||||
|
months = int(seconds / 2592000)
|
||||||
|
return f"{months} month{'s' if months > 1 else ''} ago"
|
||||||
|
else:
|
||||||
|
years = int(seconds / 31536000)
|
||||||
|
return f"{years} year{'s' if years > 1 else ''} ago"
|
||||||
|
|
||||||
|
|
||||||
def _backend(path: str) -> str:
|
def _backend(path: str) -> str:
|
||||||
return f"{app.config['BACKEND_URL']}{path}"
|
return f"{app.config['BACKEND_URL']}{path}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user