import io from django.http import FileResponse, JsonResponse from django.shortcuts import get_object_or_404 from django.views.decorators.http import require_GET from core.models import StoredFile def healthz(_request): """Liveness probe for deploy / NPM health checks.""" return JsonResponse({"status": "ok"}) @require_GET def stored_file(request, pk): """Public fetch (UUID acts as capability token).""" stored = get_object_or_404(StoredFile, pk=pk) response = FileResponse( io.BytesIO(bytes(stored.data)), content_type=stored.content_type or "application/octet-stream", ) if stored.filename: response["Content-Disposition"] = f'inline; filename="{stored.filename}"' response["Cache-Control"] = "public, max-age=86400" return response