Merge branch 'dev' into feature-ocrmypdf

This commit is contained in:
Jonas Winkler 2020-11-25 17:17:14 +01:00
commit af99cbccd9
2 changed files with 18 additions and 9 deletions

View File

@ -93,14 +93,11 @@ class DocumentSerializer(serializers.ModelSerializer):
"document_type_id", "document_type_id",
"title", "title",
"content", "content",
"mime_type",
"tags", "tags",
"tags_id", "tags_id",
"checksum",
"created", "created",
"modified", "modified",
"added", "added",
"file_name",
"archive_serial_number" "archive_serial_number"
) )

View File

@ -161,14 +161,26 @@ class DocumentViewSet(RetrieveModelMixin,
else: else:
return HttpResponseBadRequest(str(form.errors)) return HttpResponseBadRequest(str(form.errors))
@action(methods=['get'], detail=True)
def metadata(self, request, pk=None):
try:
doc = Document.objects.get(pk=pk)
return Response({
"paperless__checksum": doc.checksum,
"paperless__mime_type": doc.mime_type,
"paperless__filename": doc.filename,
})
except Document.DoesNotExist:
raise Http404()
@action(methods=['get'], detail=True) @action(methods=['get'], detail=True)
def preview(self, request, pk=None): def preview(self, request, pk=None):
try: try:
response = self.file_response( response = self.file_response(
pk, request, "inline") pk, request, "inline")
return response return response
except FileNotFoundError: except (FileNotFoundError, Document.DoesNotExist):
raise Http404("Document source file does not exist") raise Http404()
@action(methods=['get'], detail=True) @action(methods=['get'], detail=True)
@cache_control(public=False, max_age=315360000) @cache_control(public=False, max_age=315360000)
@ -176,16 +188,16 @@ class DocumentViewSet(RetrieveModelMixin,
try: try:
return HttpResponse(Document.objects.get(id=pk).thumbnail_file, return HttpResponse(Document.objects.get(id=pk).thumbnail_file,
content_type='image/png') content_type='image/png')
except FileNotFoundError: except (FileNotFoundError, Document.DoesNotExist):
raise Http404("Document thumbnail does not exist") raise Http404()
@action(methods=['get'], detail=True) @action(methods=['get'], detail=True)
def download(self, request, pk=None): def download(self, request, pk=None):
try: try:
return self.file_response( return self.file_response(
pk, request, "attachment") pk, request, "attachment")
except FileNotFoundError: except (FileNotFoundError, Document.DoesNotExist):
raise Http404("Document source file does not exist") raise Http404()
class LogViewSet(ReadOnlyModelViewSet): class LogViewSet(ReadOnlyModelViewSet):