Represent tracing media as symbols and add pool thumbnails

This commit is contained in:
Olive Vaughn 2026-10-04 00:02:12 -04:00
parent 551d572347
commit 17e1b4f403
49 changed files with 1777 additions and 864 deletions

View file

@ -43,7 +43,7 @@ from django.views.decorators.http import require_http_methods
from . import blobs, extraction
from .consumers import broadcast
from .models import Analysis, Block, Blob, Clip, Extraction, Footage, Leaf, Project, Revision, Sound, Source
from .models import Analysis, Block, Blob, Clip, Extraction, Footage, Image, Leaf, Project, Revision, Sound, Source
KEY_LENGTH = 71 # "sha256:" + 64 hex
@ -287,6 +287,50 @@ def sound_detail(request, sound_id):
return JsonResponse(_sound_json(row))
def _image_json(row):
return {"id": str(row.id), "label": row.label or row.filename,
"filename": row.filename, "width": row.width, "height": row.height,
"digest": row.blob_id, "url": f"/blob/{row.blob_id}"}
@require_http_methods(["GET", "POST"])
def images(request):
"""Stills to trace over. The document names one by its blob digest, so an
image is the same picture in every project that uses it."""
if request.method == "GET":
return JsonResponse({"images": [_image_json(row)
for row in Image.objects.order_by("-created")]})
upload = request.FILES.get("file")
if upload is None:
return JsonResponse({"error": "upload an image as the file field"}, status=400)
try:
digest, size = blobs.write_stream(upload.chunks())
width, height = extraction.probe_image(blobs.path_for(digest))
blob, _ = Blob.objects.get_or_create(
digest=digest, defaults={"size": size,
"media_type": upload.content_type or "image/png"})
row, created = Image.objects.get_or_create(
blob=blob, defaults={"filename": Path(upload.name).name[:255],
"width": width, "height": height})
return JsonResponse(_image_json(row), status=201 if created else 200)
except (ValueError, OSError) as exc:
return JsonResponse({"error": str(exc)}, status=400)
@require_http_methods(["GET", "PATCH"])
def image_detail(request, image_id):
try:
row = Image.objects.get(id=image_id)
except Image.DoesNotExist:
return JsonResponse({"error": "no such image"}, status=404)
try:
if request.method == "PATCH":
row = _relabel(request, row)
except Bad as exc:
return _error(exc)
return JsonResponse(_image_json(row))
def _extraction_json(row):
return {"key": row.key, "source": str(row.source_id), "state": row.state,
"progress": row.progress, "error": row.error,