This commit is contained in:
team3
2026-07-10 17:14:17 +02:00
parent 58bb600ba3
commit 917b3ac702
6 changed files with 83 additions and 13 deletions

View File

@@ -4,6 +4,8 @@ scrollt je Spalte; Deltas kommen über /ws."""
import asyncio
import logging
import subprocess
from pathlib import Path
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect
from fastapi.middleware.cors import CORSMiddleware
@@ -16,7 +18,7 @@ import db
import guide
import ledger
import pipeline
from config import FRONTEND_DIST
from config import FRONTEND_DIST, PROJECT_ROOT
from ws import hub
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
@@ -159,6 +161,30 @@ def health():
return {"ok": True}
# Themen-Transfer nur im lokalen Dev-Betrieb: der Server-Container (erkennbar an
# /.dockerenv) hat weder ssh-Schlüssel noch das make-Gegenstück.
_TRANSFER_LOKAL = not Path("/.dockerenv").exists()
@app.get("/api/transfer")
def transfer_info():
return {"verfuegbar": _TRANSFER_LOKAL}
@app.post("/api/topics/{topic}/transfer/{richtung}")
async def transfer_ausfuehren(topic: str, richtung: str):
if not _TRANSFER_LOKAL:
raise HTTPException(403, "Transfer nur lokal verfügbar")
if richtung not in ("push", "pull"):
raise HTTPException(404, "unbekannte Richtung")
res = await asyncio.to_thread(
subprocess.run, ["make", f"server-{richtung}", f"TOPIC={topic}"],
cwd=PROJECT_ROOT, capture_output=True, text=True, timeout=600)
if res.returncode:
raise HTTPException(500, (res.stderr or res.stdout)[-400:])
return {"ok": True}
@app.get("/api/topics/{topic}/guide")
def guide_holen(topic: str):
# kein markdown-Feld: das Frontend rendert aus kapitel; Roh-Markdown