4d1f613a1c
- React-UI: Dashboard mit Stats, Geräte, Jobs - API: /jobs und /devices endpoints - CORS aktiviert für UI-Kommunikation
89 lines
1.9 KiB
Python
89 lines
1.9 KiB
Python
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",
|
|
description="API für das automatische Ripping-System",
|
|
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():
|
|
return {"status": "ok", "service": "api"}
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"name": "Rippy",
|
|
"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
|