39 lines
980 B
Python
39 lines
980 B
Python
"""µFrame compile endpoint — POST /api/compile."""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
import uframe
|
|
from uframe.errors import UFrameError
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CompileRequest(BaseModel):
|
|
source: str
|
|
width: int = 64
|
|
|
|
|
|
class CompileResponse(BaseModel):
|
|
ascii: str
|
|
micron: str
|
|
script: str
|
|
is_dynamic: bool
|
|
warnings: list[str]
|
|
|
|
|
|
@router.post("/compile", response_model=CompileResponse)
|
|
async def compile_source(req: CompileRequest):
|
|
"""Compile µFrame .uf source into ASCII and Micron output."""
|
|
try:
|
|
result = uframe.compile(req.source, width=req.width)
|
|
return CompileResponse(
|
|
ascii=result.ascii,
|
|
micron=result.micron,
|
|
script=result.script,
|
|
is_dynamic=result.is_dynamic,
|
|
warnings=[w.message for w in result.warnings],
|
|
)
|
|
except UFrameError as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|