Some checks failed
news-summary-bot-cicd / build_push_deploy (push) Has been cancelled
- FastAPI에서 Discord 직접 전송 제거, 요약 결과를 JSON으로 반환 - app/discord.py 삭제, DISCORD_WEBHOOK_URL 환경변수 제거 - 에러 시 500 대신 200 + status: error로 응답 (n8n에서 분기 처리) - CLAUDE.md에 n8n 워크플로우 노드별 상세 설정 문서화 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from fastapi import FastAPI, Header, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from app.config import settings
|
|
from app.summarizer import summarize
|
|
from app.transcript import SkipVideo, extract_video_id, fetch_transcript
|
|
|
|
app = FastAPI(title="News Summary Bot")
|
|
|
|
|
|
class SummarizeRequest(BaseModel):
|
|
video_url: str
|
|
title: str = ""
|
|
|
|
|
|
@app.post("/summarize")
|
|
async def summarize_video(
|
|
req: SummarizeRequest,
|
|
x_api_secret: str = Header(default=""),
|
|
):
|
|
if settings.api_secret and x_api_secret != settings.api_secret:
|
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
|
|
title = req.title or "제목 없음"
|
|
|
|
try:
|
|
video_id = extract_video_id(req.video_url)
|
|
transcript = fetch_transcript(video_id)
|
|
summary = summarize(transcript, title)
|
|
except SkipVideo as e:
|
|
return {"status": "skipped", "title": title, "reason": str(e)}
|
|
except Exception as e:
|
|
return {
|
|
"status": "error",
|
|
"title": title,
|
|
"error_type": type(e).__name__,
|
|
"error_message": str(e),
|
|
}
|
|
|
|
return {"status": "ok", "title": title, "summary": summary}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|