Try to fix saved diagrams

This commit is contained in:
dvirlabs 2025-07-12 23:28:45 +03:00
parent 1b5d7735ce
commit 32b6740669
3 changed files with 3 additions and 30 deletions

View File

@ -1,19 +0,0 @@
{
"nodes": [
{
"id": "1",
"type": "custom",
"data": {
"label": "Node 1",
"icon": "https://s3.dvirlabs.com/lab-icons/infra/cloudflare.svg"
},
"position": {
"x": 19.293138020977764,
"y": 245.65982158849926
},
"width": 103,
"height": 103
}
],
"edges": []
}

View File

@ -12,16 +12,14 @@ app = FastAPI()
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=["*"], # בהמשך תוכל לצמצם לכתובת הפרונטאנד allow_origins=["*"],
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"],
) )
# Static icon info
BASE_URL = "https://s3.dvirlabs.com/lab-icons" BASE_URL = "https://s3.dvirlabs.com/lab-icons"
S3_INDEX_URL = "https://s3.dvirlabs.com/lab-icons/?list-type=2" S3_INDEX_URL = "https://s3.dvirlabs.com/lab-icons/?list-type=2"
# Directory for storing diagrams
BASE_DIR = Path(__file__).parent.resolve() BASE_DIR = Path(__file__).parent.resolve()
DATA_DIR = BASE_DIR / "diagrams" DATA_DIR = BASE_DIR / "diagrams"
DATA_DIR.mkdir(exist_ok=True) DATA_DIR.mkdir(exist_ok=True)
@ -40,6 +38,8 @@ def fetch_diagram(name: str):
@app.post("/diagram/save") @app.post("/diagram/save")
def save_diagram(name: str, payload: DiagramItem): def save_diagram(name: str, payload: DiagramItem):
if not name:
raise HTTPException(status_code=400, detail="Missing diagram name")
try: try:
path = DATA_DIR / f"diagram_{name}.json" path = DATA_DIR / f"diagram_{name}.json"
with open(path, "w") as f: with open(path, "w") as f:
@ -68,14 +68,6 @@ def delete_diagram(name: str):
@app.get("/icons", response_model=Dict[str, List[str]]) @app.get("/icons", response_model=Dict[str, List[str]])
def list_icons(): def list_icons():
"""
Returns a dictionary of available icons grouped by folder (category).
Example:
{
"dev-tools": [ "https://s3.dvirlabs.com/lab-icons/dev-tools/gitea.svg", ... ],
"observability": [ ... ]
}
"""
resp = requests.get(S3_INDEX_URL) resp = requests.get(S3_INDEX_URL)
if resp.status_code != 200: if resp.status_code != 200:
raise HTTPException(status_code=500, detail="Failed to fetch icon list from S3") raise HTTPException(status_code=500, detail="Failed to fetch icon list from S3")