Files
2026-08-03 16:17:14 +02:00

66 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from pathlib import Path
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import HTMLResponse
# Umgebungsvariablen mit Fallback
GITEE_URL = os.getenv("GITEE_URL", "https://git.carabella.ch/")
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN", "") # Leerlassen falls nicht gesetzt
COMMIT_NAME = os.getenv("COMMIT_NAME", "KI-Sparringpartner")
# Projekt-Ordner (gemountet im Docker)
PROJECTS_DIR = Path("/projects")
def get_token():
"""Gibt Token zurück aus .env oder leer."""
return ACCESS_TOKEN or ""
app = FastAPI(title="Gitea Sync AI", version="1.0")
# 🎯 WICHTIG: Routen einbinden!
from . import routes
app.include_router(routes.router, prefix="/api")
# Frontend ausliefern - verwende relativen Pfad
TEMPLATES_DIR = Path(__file__).parent / "templates"
@app.get("/", response_class=HTMLResponse)
async def dashboard(request: Request):
with open(TEMPLATES_DIR / "index.html") as f:
return f.read()
@app.get("/projects/{project_name}") # ✅ Fuer direkten Zugriff auf Projekte!
def project_view(project_name: str, request: Request):
"""Gibt ein einfaches Verzeichnis-Display zurueck."""
from fastapi.responses import HTMLResponse
target_dir = PROJECTS_DIR / project_name
if not target_dir.exists():
return {"error": "Projekt nicht gefunden", "available_projects": [p.name for p in PROJECTS_DIR.iterdir() if p.is_dir()]}
# Einfache HTML-Ansicht:
html = f"""<!DOCTYPE html>
<html><head><title>{project_name}</title>
<style>body{{font-family:sans-serif;padding:20px;background:#f5f5f5}}
.file {{background:white;margin:10px 0;padding:15px;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,.1);cursor:pointer}}
.dir {{font-weight:bold}} a{{color:#007bff;text-decoration:none}}</style>
</head><body>
<h1>📁 {project_name}</h1>
<h3>Dateien:</h3>
<a href="/"><button style="margin:10px 0">🏠 Zurueck zum Dashboard</button></a>
"""
if (target_dir / '.git').exists():
html += '<p style="color:#28a745">✅ Git Repository</p>'
for item in sorted(target_dir.iterdir()):
icon = "📁" if item.is_dir() else "📄"
link = f"/projects/{item.name}" if item.is_dir() else "#"
html += f'<div class="file {"" if item.is_file() else "dir"}"><a href="{link}">{icon} {item.name}</a></div>'
return HTMLResponse(html)