feat(music-lab): verify_internal_key + /api/internal/music/update (SP-6)
X-Internal-Key 헤더 검증 dependency (insta-lab 동일 패턴). Windows music-render webhook 수신 endpoint — update_task + 옵션 add_track. Plan-B-Music Phase 1 (수신부). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
61
music-lab/app/internal_router.py
Normal file
61
music-lab/app/internal_router.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""SP-6 — Windows music-render → NAS internal webhook.
|
||||
|
||||
POST /api/internal/music/update
|
||||
- X-Internal-Key 인증 필수
|
||||
- music_tasks 테이블 row update (status, progress, message, audio_url, error)
|
||||
- 옵션 `track` 페이로드가 있으면 music_library에 add_track 호출
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from . import db
|
||||
from .auth import verify_internal_key
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class UpdatePayload(BaseModel):
|
||||
task_id: str
|
||||
status: str = Field(..., description="processing|succeeded|failed")
|
||||
progress: int = Field(..., ge=0, le=100)
|
||||
message: str = ""
|
||||
audio_url: Optional[str] = None
|
||||
error: Optional[str] = None
|
||||
track: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
@router.post(
|
||||
"/api/internal/music/update",
|
||||
dependencies=[Depends(verify_internal_key)],
|
||||
)
|
||||
def music_update(payload: UpdatePayload):
|
||||
task = db.get_task(payload.task_id)
|
||||
if task is None:
|
||||
raise HTTPException(404, f"task not found: {payload.task_id}")
|
||||
|
||||
db.update_task(
|
||||
payload.task_id,
|
||||
payload.status,
|
||||
payload.progress,
|
||||
message=payload.message,
|
||||
audio_url=payload.audio_url,
|
||||
error=payload.error,
|
||||
)
|
||||
|
||||
if payload.track:
|
||||
try:
|
||||
db.add_track(payload.track)
|
||||
except Exception:
|
||||
logger.exception("add_track 실패 task=%s (무시)", payload.task_id)
|
||||
|
||||
logger.info(
|
||||
"internal/music/update task=%s status=%s progress=%d",
|
||||
payload.task_id, payload.status, payload.progress,
|
||||
)
|
||||
return {"ok": True}
|
||||
Reference in New Issue
Block a user