Replace the FastAPI/SQLAlchemy/Alembic web service with a Django project
laid out like cumorah-build: manage.py at the root, settings in the
privatestudio.settings package (base/dev/production), and a
privatestudio.studio app.
- Studio model owns a unique bucket_name; access is granted through
membership in the studio's auth Group. Assets, profiles and jobs are
scoped to a studio; API keys and S3 credentials stay per user.
- JSON API via Django Ninja under /api/ (profiles and transcode jobs now
live under /api/studios/{bucket}/).
- S3-compatible interface as plain class-based views under /s3/,
supporting bearer tokens and AWS v4 signatures.
- create_studio and create_key management commands replace ps-serve.
- Fresh Django initial migration; tests ported to Django TestCase.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""Transcode profile management endpoints (scoped to a studio)."""
|
|
from django.shortcuts import get_object_or_404
|
|
from ninja import Router, Schema
|
|
from ninja.errors import HttpError
|
|
|
|
from privatestudio.studio.models import TranscodeProfile
|
|
from privatestudio.studio.routers.common import get_studio_for_user, parse_yaml_body
|
|
|
|
router = Router()
|
|
|
|
|
|
class ProfileResponse(Schema):
|
|
id: int
|
|
name: str
|
|
profile_definition: str
|
|
created_at: str
|
|
|
|
|
|
def _profile_response(profile: TranscodeProfile) -> dict:
|
|
return {
|
|
"id": profile.id,
|
|
"name": profile.name,
|
|
"profile_definition": profile.profile_definition,
|
|
"created_at": profile.created_at.isoformat(),
|
|
}
|
|
|
|
|
|
@router.post("/studios/{bucket}/profiles", response=ProfileResponse)
|
|
def create_profile(request, bucket: str, name: str):
|
|
"""
|
|
Create a new transcode profile.
|
|
|
|
The request body must contain the YAML profile definition.
|
|
"""
|
|
studio = get_studio_for_user(request.auth, bucket)
|
|
profile_data = parse_yaml_body(request)
|
|
if "profiles" not in profile_data:
|
|
raise HttpError(400, "Profile definition must contain a 'profiles' section")
|
|
|
|
if TranscodeProfile.objects.filter(studio=studio, name=name).exists():
|
|
raise HttpError(409, f"Profile '{name}' already exists")
|
|
|
|
profile = TranscodeProfile.objects.create(
|
|
studio=studio,
|
|
created_by=request.auth,
|
|
name=name,
|
|
profile_definition=request.body.decode("utf-8"),
|
|
)
|
|
return _profile_response(profile)
|
|
|
|
|
|
@router.get("/studios/{bucket}/profiles", response=list[ProfileResponse])
|
|
def list_profiles(request, bucket: str):
|
|
"""List all transcode profiles for the studio."""
|
|
studio = get_studio_for_user(request.auth, bucket)
|
|
return [_profile_response(p) for p in studio.transcode_profiles.order_by("id")]
|
|
|
|
|
|
@router.get("/studios/{bucket}/profiles/{profile_id}", response=ProfileResponse)
|
|
def get_profile(request, bucket: str, profile_id: int):
|
|
"""Get a specific transcode profile."""
|
|
studio = get_studio_for_user(request.auth, bucket)
|
|
return _profile_response(get_object_or_404(TranscodeProfile, pk=profile_id, studio=studio))
|