thumbnails
This commit is contained in:
parent
5861113aeb
commit
caa2aa6b9b
10 changed files with 403 additions and 19 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
|
||||
from django.contrib.auth import authenticate, login as dj_login, logout as dj_logout
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseNotAllowed, JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
|
@ -9,6 +10,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|||
|
||||
from .attribution import annotation_layer, apply_attribution
|
||||
from .models import Project, Revision
|
||||
from .thumbnails import enqueue_thumbnail_generation
|
||||
|
||||
MAX_CLIP_BYTES = 100 * 1024 * 1024
|
||||
|
||||
|
|
@ -33,6 +35,17 @@ def _editable(request, pk):
|
|||
|
||||
|
||||
def _meta(request, project):
|
||||
thumbnails = dict(project.thumbnail_manifest or {})
|
||||
if thumbnails.get("template"):
|
||||
thumbnails["template"] = request.build_absolute_uri(thumbnails["template"])
|
||||
if thumbnails.get("clips"):
|
||||
thumbnails["clips"] = {
|
||||
clip_id: [
|
||||
dict(tile, url=request.build_absolute_uri(tile["url"]))
|
||||
for tile in tiles
|
||||
]
|
||||
for clip_id, tiles in thumbnails["clips"].items()
|
||||
}
|
||||
return {
|
||||
"id": project.pk,
|
||||
"name": project.name,
|
||||
|
|
@ -40,6 +53,9 @@ def _meta(request, project):
|
|||
"owner": project.owner.get_username(),
|
||||
"otio": request.build_absolute_uri(project.otio.url) if project.otio else None,
|
||||
"clip": request.build_absolute_uri(project.clip.url) if project.clip else None,
|
||||
"thumbnail_status": project.thumbnail_status,
|
||||
"thumbnail_error": project.thumbnail_error,
|
||||
"thumbnails": thumbnails or None,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -89,7 +105,14 @@ def projects(request):
|
|||
return JsonResponse({"detail": "name, otio and clip are required"}, status=400)
|
||||
if clip.size > MAX_CLIP_BYTES:
|
||||
return JsonResponse({"detail": "clip exceeds 100 MB"}, status=400)
|
||||
project = Project.objects.create(owner=request.user, name=name, otio=otio, clip=clip)
|
||||
project = Project.objects.create(
|
||||
owner=request.user,
|
||||
name=name,
|
||||
otio=otio,
|
||||
clip=clip,
|
||||
thumbnail_status="pending",
|
||||
)
|
||||
transaction.on_commit(lambda: enqueue_thumbnail_generation(project.pk))
|
||||
return JsonResponse(_meta(request, project), status=201)
|
||||
return HttpResponseNotAllowed(["GET", "POST"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue