feat: add FastAPI app with file listing endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-16 13:47:23 +02:00
parent 079afeee7c
commit 9569103edd
7 changed files with 71 additions and 0 deletions
View File
+3
View File
@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()
+48
View File
@@ -0,0 +1,48 @@
import os
from fastapi import APIRouter, Query
from fastapi.responses import FileResponse
from ..config import MEDIA_DIRS, VIDEO_EXTENSIONS
router = APIRouter()
def _scan_videos(root: str) -> list[dict]:
results = []
for dirpath, _, filenames in os.walk(root):
for f in sorted(filenames):
if os.path.splitext(f)[1].lower() in VIDEO_EXTENSIONS:
full = os.path.join(dirpath, f)
rel = os.path.relpath(full, root)
results.append({
"name": f,
"path": rel,
"root": root,
"size": os.path.getsize(full),
})
return results
@router.get("/files")
def list_files(root: str | None = Query(None)):
dirs = [root] if root and root in MEDIA_DIRS else MEDIA_DIRS
files = []
for d in dirs:
files.extend(_scan_videos(d))
return files
@router.get("/roots")
def list_roots():
return MEDIA_DIRS
@router.get("/video/{path:path}")
def serve_video(path: str, root: str = Query(...)):
if root not in MEDIA_DIRS:
return {"error": "invalid root"}
full = os.path.join(root, path)
if not os.path.isfile(full):
return {"error": "not found"}
return FileResponse(full, media_type="video/mp4")
+3
View File
@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()
+3
View File
@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()
+3
View File
@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()