60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""
|
|
发布管理 API
|
|
"""
|
|
from fastapi import APIRouter, HTTPException, BackgroundTasks
|
|
from pydantic import BaseModel
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
from loguru import logger
|
|
from app.services.publish_service import PublishService
|
|
|
|
router = APIRouter()
|
|
publish_service = PublishService()
|
|
|
|
class PublishRequest(BaseModel):
|
|
video_path: str
|
|
platform: str
|
|
title: str
|
|
tags: List[str] = []
|
|
description: str = ""
|
|
publish_time: Optional[datetime] = None
|
|
|
|
class PublishResponse(BaseModel):
|
|
success: bool
|
|
message: str
|
|
platform: str
|
|
url: Optional[str] = None
|
|
|
|
@router.post("/", response_model=PublishResponse)
|
|
async def publish_video(request: PublishRequest, background_tasks: BackgroundTasks):
|
|
try:
|
|
result = await publish_service.publish(
|
|
video_path=request.video_path,
|
|
platform=request.platform,
|
|
title=request.title,
|
|
tags=request.tags,
|
|
description=request.description,
|
|
publish_time=request.publish_time
|
|
)
|
|
return PublishResponse(
|
|
success=result.get("success", False),
|
|
message=result.get("message", ""),
|
|
platform=request.platform,
|
|
url=result.get("url")
|
|
)
|
|
except Exception as e:
|
|
logger.error(f"发布失败: {e}")
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
@router.get("/platforms")
|
|
async def list_platforms():
|
|
return {"platforms": [{"id": pid, **pinfo} for pid, pinfo in publish_service.PLATFORMS.items()]}
|
|
|
|
@router.get("/accounts")
|
|
async def list_accounts():
|
|
return {"accounts": publish_service.get_accounts()}
|
|
|
|
@router.post("/login/{platform}")
|
|
async def login_platform(platform: str):
|
|
return await publish_service.login(platform)
|