|
1 | 1 | import math
|
2 | 2 | import json
|
| 3 | +import os |
3 | 4 |
|
4 | 5 | from django.conf import settings
|
5 | 6 | from django.shortcuts import get_object_or_404
|
6 |
| -from django.http import JsonResponse, FileResponse, Http404, HttpResponseBadRequest |
| 7 | +from django.http import JsonResponse, FileResponse, Http404, HttpResponseBadRequest, HttpResponseServerError |
7 | 8 | from django.core.paginator import Paginator, EmptyPage
|
8 | 9 | from .models import Model
|
9 | 10 | from .utils import get_kv, admin
|
@@ -80,8 +81,12 @@ def get_model(request, model_id, revision=None):
|
80 | 81 | if model.is_hidden and not admin(request):
|
81 | 82 | raise Http404('Model does not exist.')
|
82 | 83 |
|
| 84 | + model_path = '{}/{}/{}.glb'.format(settings.MODEL_DIR, model_id, revision) |
83 | 85 |
|
84 |
| - response = FileResponse(open('{}/{}/{}.glb'.format(settings.MODEL_DIR, model_id, revision), 'rb')) |
| 86 | + if not os.path.isfile(model_path): |
| 87 | + return HttpResponseServerError('Model file not found on the server') |
| 88 | + |
| 89 | + response = FileResponse(open(model_path, 'rb')) |
85 | 90 | response['Content-Disposition'] = 'attachment; filename={}_{}.glb'.format(model_id, revision)
|
86 | 91 | response['Content-Type'] = 'model/gltf-binary'
|
87 | 92 | response['Cache-Control'] = 'public, max-age=86400'
|
|
0 commit comments