Files
KiraTV/backend/api/admin/settings.py
T
joaquin f5d6745ed0 Initial commit: KiraTV IPTV proxy server
Full-stack IPTV management system with Xtream Codes API compatibility,
multi-account provider fan-out, Jellyfin local library integration,
real-time dashboard, EPG support, and A/V-sync-safe stream recovery.
2026-05-17 23:22:05 +02:00

39 lines
1.4 KiB
Python

"""Admin settings — blocked image upload/management."""
import os
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
from fastapi.responses import FileResponse
from ..auth import get_current_admin
router = APIRouter(prefix="/settings", tags=["settings"])
BLOCKED_IMAGE_PATH = "/opt/kirastream/backend/static/blocked_image.jpg"
MAX_SIZE = 10 * 1024 * 1024 # 10 MB
@router.get("/blocked-image")
async def get_blocked_image(_=Depends(get_current_admin)):
if not os.path.exists(BLOCKED_IMAGE_PATH):
raise HTTPException(404, "No blocked image configured")
return FileResponse(BLOCKED_IMAGE_PATH, media_type="image/jpeg")
@router.post("/blocked-image", status_code=201)
async def upload_blocked_image(file: UploadFile = File(...), _=Depends(get_current_admin)):
if file.content_type not in ("image/jpeg", "image/png", "image/webp", "image/gif"):
raise HTTPException(400, "Only JPEG, PNG, WebP or GIF images allowed")
data = await file.read()
if len(data) > MAX_SIZE:
raise HTTPException(413, "Image too large (max 10 MB)")
os.makedirs(os.path.dirname(BLOCKED_IMAGE_PATH), exist_ok=True)
with open(BLOCKED_IMAGE_PATH, "wb") as f:
f.write(data)
return {"ok": True, "size": len(data)}
@router.delete("/blocked-image", status_code=204)
async def delete_blocked_image(_=Depends(get_current_admin)):
if os.path.exists(BLOCKED_IMAGE_PATH):
os.remove(BLOCKED_IMAGE_PATH)