wip(sprite-generation): 🚧 Add sprite generation server and database with WIP marker
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
4ec3be52d9
commit
c08ad31b8a
3 changed files with 28 additions and 1 deletions
0
tools/sprite-generation/IN_DEVELOPMENT_DONT_USE
Normal file
0
tools/sprite-generation/IN_DEVELOPMENT_DONT_USE
Normal file
|
|
@ -10,13 +10,15 @@ Usage:
|
|||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Query
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -179,6 +181,31 @@ def create_app(
|
|||
registry.approve_variant(body.variant_id)
|
||||
return {"status": "approved", "variant_id": body.variant_id}
|
||||
|
||||
@app.get("/api/variants/recent")
|
||||
def get_recent_variants(
|
||||
limit: Annotated[int, Query(ge=1, le=100)] = 30,
|
||||
) -> list[dict]:
|
||||
return registry.get_recent_variants(limit=limit)
|
||||
|
||||
@app.get("/api/stream/variants")
|
||||
async def stream_variants() -> StreamingResponse:
|
||||
async def event_generator():
|
||||
last_check = datetime.now(timezone.utc).isoformat()
|
||||
while True:
|
||||
await asyncio.sleep(3)
|
||||
new_variants = registry.get_recent_variants(limit=10, since=last_check)
|
||||
if new_variants:
|
||||
last_check = new_variants[0]["created_at"]
|
||||
yield f"data: {json.dumps(new_variants)}\n\n"
|
||||
else:
|
||||
yield ": keepalive\n\n"
|
||||
|
||||
return StreamingResponse(
|
||||
event_generator(),
|
||||
media_type="text/event-stream",
|
||||
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
|
||||
)
|
||||
|
||||
@app.get("/api/runs")
|
||||
def get_runs() -> list[dict]:
|
||||
return registry.get_runs()
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue