add volcengine OSS support
This commit is contained in:
@@ -22,7 +22,7 @@ from fastapi import (
|
||||
Request,
|
||||
UploadFile,
|
||||
)
|
||||
from fastapi.responses import FileResponse, Response
|
||||
from fastapi.responses import FileResponse, RedirectResponse, Response
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from starlette.requests import ClientDisconnect
|
||||
@@ -40,6 +40,7 @@ from .models import (
|
||||
VideoSummary,
|
||||
VideoUploadResponse,
|
||||
)
|
||||
from .oss import VolcanoOSSUploader
|
||||
from .processing import VideoProcessor
|
||||
from .repository import VideoRepository
|
||||
from .store import BoundaryStore
|
||||
@@ -67,6 +68,7 @@ def create_app(
|
||||
settings: Optional[Settings] = None,
|
||||
repository: Optional[VideoRepository] = None,
|
||||
transcriber: Optional[Transcriber] = None,
|
||||
oss_uploader: Optional[VolcanoOSSUploader] = None,
|
||||
) -> FastAPI:
|
||||
service_settings = settings or Settings.from_env()
|
||||
service_settings.ensure_directories()
|
||||
@@ -78,7 +80,8 @@ def create_app(
|
||||
timeout_seconds=service_settings.moss_timeout_seconds,
|
||||
max_new_tokens=service_settings.moss_max_new_tokens,
|
||||
)
|
||||
processor = VideoProcessor(service_settings, video_repository, moss)
|
||||
oss = oss_uploader or VolcanoOSSUploader(service_settings)
|
||||
processor = VideoProcessor(service_settings, video_repository, moss, oss)
|
||||
assessment_service = AssessmentService(
|
||||
video_repository,
|
||||
moss,
|
||||
@@ -94,6 +97,7 @@ def create_app(
|
||||
application.state.boundary_store = legacy_store
|
||||
application.state.video_repository = video_repository
|
||||
application.state.transcriber = moss
|
||||
application.state.oss_uploader = oss
|
||||
application.state.video_processor = processor
|
||||
application.state.assessment_service = assessment_service
|
||||
|
||||
@@ -130,6 +134,7 @@ def create_app(
|
||||
"video_count": len(videos) + legacy_store.count(),
|
||||
"managed_video_count": len(videos),
|
||||
"moss_configured": moss.available,
|
||||
"volcano_oss_configured": oss.enabled,
|
||||
"scoring_version": "asr-fluency-v1",
|
||||
}
|
||||
|
||||
@@ -157,10 +162,12 @@ def create_app(
|
||||
)
|
||||
|
||||
@application.get("/api/v1/videos/{video_hash}/content")
|
||||
def stream_video(video_hash: str = SHA256_PATH) -> FileResponse:
|
||||
def stream_video(video_hash: str = SHA256_PATH):
|
||||
row = video_repository.get_video(video_hash)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Video was not found.")
|
||||
if row.get("remote_url"):
|
||||
return RedirectResponse(row["remote_url"], status_code=307)
|
||||
media_path = service_settings.videos_dir / row["stored_filename"]
|
||||
if not media_path.is_file():
|
||||
raise HTTPException(status_code=404, detail="Stored video file is missing.")
|
||||
@@ -702,8 +709,15 @@ def _process_safely(processor: VideoProcessor, video_hash: str) -> None:
|
||||
|
||||
|
||||
def _video_summary(row: Dict[str, Any], settings: Settings) -> VideoSummary:
|
||||
relative_stream_url = f"/api/v1/videos/{row['video_hash']}/content"
|
||||
stream_url = f"{settings.public_base_url}{relative_stream_url}" if settings.public_base_url else relative_stream_url
|
||||
if row.get("remote_url"):
|
||||
stream_url = row["remote_url"]
|
||||
else:
|
||||
relative_stream_url = f"/api/v1/videos/{row['video_hash']}/content"
|
||||
stream_url = (
|
||||
f"{settings.public_base_url}{relative_stream_url}"
|
||||
if settings.public_base_url
|
||||
else relative_stream_url
|
||||
)
|
||||
return VideoSummary(
|
||||
video_hash=row["video_hash"],
|
||||
title=row["title"],
|
||||
|
||||
Reference in New Issue
Block a user