+
+
+
+
-
-
-
-
-
-
-
+
-
+
+
+
+
"""
return layout("Upload", body)
@@ -530,24 +600,38 @@ def delete_project(project_id: int):
return HTMLResponse("
")
-@app.post("/upload", response_class=HTMLResponse)
-async def upload(project_id: int = Form(...), title: str = Form(""), file: UploadFile = File(...)):
+@app.post("/projects/create-api")
+def create_project_api(name: str = Form(...)):
+ name = name.strip()
+ if not name:
+ raise HTTPException(400, "Name darf nicht leer sein")
+ with db() as c:
+ existing = c.execute("SELECT id FROM projects WHERE name=?", (name,)).fetchone()
+ if existing:
+ return {"id": existing["id"]}
+ cur = c.execute("INSERT INTO projects(name, created_at) VALUES (?,?)", (name, now_iso()))
+ return {"id": cur.lastrowid}
+
+
+@app.post("/upload")
+async def upload(project_id: int = Form(...), file: UploadFile = File(...)):
data = await file.read()
if not data:
raise HTTPException(400, "Leere Datei")
JOB_DIR.mkdir(parents=True, exist_ok=True)
filename = (file.filename or "audio.bin").replace("/", "_")
+ stem = filename.rsplit(".", 1)[0] or filename
temp_path = JOB_DIR / f"{now_iso().replace(':','-')}_{filename}"
temp_path.write_bytes(data)
job_id = enqueue_job(
"upload",
project_id=project_id,
- title=(title or "").strip() or filename,
+ title=stem,
file_path=str(temp_path),
)
- return HTMLResponse(f"
")
+ return {"job_id": job_id}
@app.get("/library", response_class=HTMLResponse)