diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index e0ad73a23..c86aa8c83 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -93,14 +93,11 @@ class DocumentSerializer(serializers.ModelSerializer): "document_type_id", "title", "content", - "mime_type", "tags", "tags_id", - "checksum", "created", "modified", "added", - "file_name", "archive_serial_number" ) diff --git a/src/documents/views.py b/src/documents/views.py index 5c8a0d9b9..4d62ae5c4 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -161,14 +161,26 @@ class DocumentViewSet(RetrieveModelMixin, else: 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) def preview(self, request, pk=None): try: response = self.file_response( pk, request, "inline") return response - except FileNotFoundError: - raise Http404("Document source file does not exist") + except (FileNotFoundError, Document.DoesNotExist): + raise Http404() @action(methods=['get'], detail=True) @cache_control(public=False, max_age=315360000) @@ -176,16 +188,16 @@ class DocumentViewSet(RetrieveModelMixin, try: return HttpResponse(Document.objects.get(id=pk).thumbnail_file, content_type='image/png') - except FileNotFoundError: - raise Http404("Document thumbnail does not exist") + except (FileNotFoundError, Document.DoesNotExist): + raise Http404() @action(methods=['get'], detail=True) def download(self, request, pk=None): try: return self.file_response( pk, request, "attachment") - except FileNotFoundError: - raise Http404("Document source file does not exist") + except (FileNotFoundError, Document.DoesNotExist): + raise Http404() class LogViewSet(ReadOnlyModelViewSet):