Etappe 5: API + Auth + WebUI — Erste Implementierung
- React-UI: Dashboard mit Stats, Geräte, Jobs - API: /jobs und /devices endpoints - CORS aktiviert für UI-Kommunikation
This commit is contained in:
+67
-2
@@ -1,6 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
app = FastAPI(
|
||||
title="Rippy API",
|
||||
@@ -8,6 +12,30 @@ app = FastAPI(
|
||||
version="1.0.0"
|
||||
)
|
||||
|
||||
# CORS hinzufügen
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
class Job(BaseModel):
|
||||
id: str
|
||||
type: str
|
||||
status: str
|
||||
device: str
|
||||
startTime: str
|
||||
endTime: Optional[str] = None
|
||||
progress: int = 0
|
||||
|
||||
class Device(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
type: str
|
||||
path: str
|
||||
status: str
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
@@ -21,3 +49,40 @@ async def root():
|
||||
"version": "1.0.0",
|
||||
"description": "Automatisches Ripping-System für CD, DVD und Blu-ray"
|
||||
}
|
||||
|
||||
|
||||
@app.get("/jobs", response_model=List[Job])
|
||||
async def get_jobs():
|
||||
"""Holt alle Jobs."""
|
||||
return []
|
||||
|
||||
|
||||
@app.get("/devices", response_model=List[Device])
|
||||
async def get_devices():
|
||||
"""Holt alle Geräte."""
|
||||
devices = []
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["ls", "-la", "/dev/disc/"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
|
||||
for line in result.stdout.strip().split('\n')[1:]:
|
||||
if line and 'total' not in line:
|
||||
parts = line.split()
|
||||
if len(parts) >= 9:
|
||||
name = parts[-1]
|
||||
devices.append(Device(
|
||||
id=name,
|
||||
name=f"Laufwerk {name}",
|
||||
type="dvd",
|
||||
path=f"/dev/disc/{name}",
|
||||
status="ready"
|
||||
))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return devices
|
||||
|
||||
Reference in New Issue
Block a user