44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
from typing import Optional, List
|
|
from ..downloader_manager import manager
|
|
|
|
router = APIRouter()
|
|
|
|
class DownloadRequest(BaseModel):
|
|
urls: List[str]
|
|
download_images: bool = True
|
|
download_videos: bool = True
|
|
max_workers: int = 3
|
|
force_overwrite: bool = False
|
|
|
|
class StatusResponse(BaseModel):
|
|
active: bool
|
|
status: str
|
|
downloaded: int
|
|
total: int
|
|
speed: float
|
|
eta: float
|
|
current_file: str
|
|
|
|
@router.post("/start")
|
|
def start_download(request: DownloadRequest):
|
|
try:
|
|
manager.start_download(request.urls, request.model_dump())
|
|
return {"message": "Download started"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
@router.post("/cancel")
|
|
def cancel_download():
|
|
manager.cancel_download()
|
|
return {"message": "Cancellation requested"}
|
|
|
|
@router.get("/status", response_model=StatusResponse)
|
|
def get_status():
|
|
return manager.progress
|
|
|
|
@router.get("/logs", response_model=List[str])
|
|
def get_logs():
|
|
return manager.logs
|