feat: sync registry with suggestions
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
"""µFrame compile + DSL metadata endpoints."""
|
||||
"""µFrame compile, DSL metadata, and image upload endpoints."""
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException, UploadFile, File
|
||||
from pydantic import BaseModel
|
||||
|
||||
import uframe
|
||||
@@ -10,6 +13,8 @@ from uframe.registry import get_dsl_meta
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
UPLOAD_DIR = Path(os.environ.get("SOURCES_DIR", "/data/sources")) / "images"
|
||||
|
||||
|
||||
class CompileRequest(BaseModel):
|
||||
source: str
|
||||
@@ -44,3 +49,36 @@ async def compile_source(req: CompileRequest):
|
||||
async def dsl_meta():
|
||||
"""Return DSL metadata for frontend syntax highlighting and autocomplete."""
|
||||
return get_dsl_meta()
|
||||
|
||||
|
||||
@router.post("/upload-image")
|
||||
async def upload_image(file: UploadFile = File(...)):
|
||||
"""Upload an image for use in .uf pages."""
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
# Sanitize filename
|
||||
name = file.filename or "upload.png"
|
||||
safe_name = "".join(c for c in name if c.isalnum() or c in "._-").rstrip(".")
|
||||
if not safe_name:
|
||||
safe_name = "upload.png"
|
||||
dest = UPLOAD_DIR / safe_name
|
||||
content = await file.read()
|
||||
dest.write_bytes(content)
|
||||
# Return the path relative to backend working directory
|
||||
rel_path = str(dest)
|
||||
return {"path": rel_path, "filename": safe_name, "size": len(content)}
|
||||
|
||||
|
||||
@router.get("/images")
|
||||
async def list_images():
|
||||
"""List uploaded images available for embedding."""
|
||||
if not UPLOAD_DIR.is_dir():
|
||||
return []
|
||||
images = []
|
||||
for f in sorted(UPLOAD_DIR.iterdir()):
|
||||
if f.suffix.lower() in (".png", ".jpg", ".jpeg", ".bmp", ".webp", ".gif"):
|
||||
images.append({
|
||||
"filename": f.name,
|
||||
"path": str(f),
|
||||
"size": f.stat().st_size,
|
||||
})
|
||||
return images
|
||||
|
||||
@@ -2,4 +2,5 @@ fastapi>=0.115
|
||||
uvicorn[standard]>=0.34
|
||||
docker>=7.0
|
||||
Pillow>=10.0
|
||||
python-multipart>=0.0.6
|
||||
md2txt @ git+https://codeberg.org/randogoth/md2txt
|
||||
|
||||
Reference in New Issue
Block a user