O2Sound_ver2_final/backend/app/presentation/api/v1/uservideo.py

32 lines
1018 B
Python

import os
from fastapi import APIRouter, HTTPException, Depends
from app.shared.decorator.response_wrapper import response_wrapper
from fastapi.responses import FileResponse
from datetime import datetime, timezone
from app.dependencies import get_video_service
from app.services.video_service import VideoService
from urllib.parse import unquote
router = APIRouter(prefix="/user/video", tags=["user-video"])
# 임시 메모리 저장소 (테스트용)
_FAKE_DB = {}
UPLOAD_DIR = "./uploads"
@router.get("/{filename}")
def stream_video(filename: str):
safe_filename = os.path.basename(unquote(filename)) # decode URL encoding
full_path = os.path.join(UPLOAD_DIR, safe_filename)
if not os.path.exists(full_path):
print(f"[❌] 파일 없음: {full_path}")
raise HTTPException(status_code=404, detail="Video not found")
print(f"[✅] 스트리밍 시작: {full_path}")
return FileResponse(
full_path,
media_type="video/mp4",
filename=safe_filename
)