update
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import asyncio
|
||||
import shutil
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from config import FORMAT_META
|
||||
from config import FORMAT_META, PROJECTS_DIR
|
||||
from database import (
|
||||
create_guide, delete_guide, get_guide, list_guides,
|
||||
create_baustein as db_create_baustein, list_bausteine, get_baustein, delete_baustein as db_delete_baustein,
|
||||
@@ -18,9 +19,9 @@ from models import (
|
||||
BausteinCreateRequest, BausteinReworkRequest, BausteinSortRequest, BausteinResponse, SuggestionResponse,
|
||||
TopicSuggestRequest, TopicSuggestion,
|
||||
GuideChatRequest, GuideChatResponse,
|
||||
ProgressUpdate, ProgressResponse,
|
||||
ProgressUpdate, ProgressResponse, ProjectResponse,
|
||||
)
|
||||
from paths import final_paths
|
||||
from paths import final_paths, project_dir, project_cache_path
|
||||
|
||||
router = APIRouter(prefix="/api")
|
||||
|
||||
@@ -30,6 +31,34 @@ async def get_formats():
|
||||
return FORMAT_META
|
||||
|
||||
|
||||
def _safe_project_name(name: str) -> str:
|
||||
if not name or "/" in name or "\\" in name or ".." in name or "\x00" in name:
|
||||
raise HTTPException(400, "Ungültiger Projektname")
|
||||
return name
|
||||
|
||||
|
||||
@router.get("/projects", response_model=list[ProjectResponse])
|
||||
async def list_projects():
|
||||
if not PROJECTS_DIR.is_dir():
|
||||
return []
|
||||
result = []
|
||||
for entry in sorted(PROJECTS_DIR.iterdir()):
|
||||
if entry.is_dir():
|
||||
result.append({"name": entry.name, "cached": project_cache_path(entry.name).exists()})
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/projects/{name}")
|
||||
async def remove_project(name: str):
|
||||
_safe_project_name(name)
|
||||
pdir = project_dir(name)
|
||||
if not pdir.is_dir():
|
||||
raise HTTPException(404, "Projekt nicht gefunden")
|
||||
shutil.rmtree(pdir)
|
||||
project_cache_path(name).unlink(missing_ok=True)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.post("/topic-suggestions", response_model=list[TopicSuggestion])
|
||||
async def topic_suggestions(req: TopicSuggestRequest):
|
||||
guides = await list_guides()
|
||||
@@ -51,7 +80,7 @@ async def create(req: GuideCreateRequest):
|
||||
"updated_at": now,
|
||||
}
|
||||
await create_guide(guide)
|
||||
asyncio.create_task(generate_guide(guide["id"], guide["topic"], guide["format"], guide["instructions"]))
|
||||
asyncio.create_task(generate_guide(guide["id"], guide["topic"], guide["format"], guide["instructions"], req.reindex))
|
||||
return guide
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user