A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
api serves archive files by default.
Jonas Winkler95ec520f137c
diff --git a/src/documents/views.py b/src/documents/views.pyindex 14323e933..5c8a0d9b9 100755--- a/src/documents/views.py+++ b/src/documents/views.py@@ -1,3 +1,5 @@+import os+from django.db.models import Count, Maxfrom django.http import HttpResponse, HttpResponseBadRequest, Http404from django.views.decorators.cache import cache_control@@ -126,15 +128,25 @@ class DocumentViewSet(RetrieveModelMixin,index.remove_document_from_index(self.get_object())return super(DocumentViewSet, self).destroy(request, *args, **kwargs)- def file_response(self, pk, disposition):- doc = Document.objects.get(id=pk)+ @staticmethod+ def original_requested(request):+ return (+ 'original' in request.query_params and+ request.query_params['original'] == 'true'+ )- if doc.storage_type == Document.STORAGE_TYPE_UNENCRYPTED:+ def file_response(self, pk, request, disposition):+ doc = Document.objects.get(id=pk)+ mime_type = doc.mime_type+ if not self.original_requested(request) and os.path.isfile(doc.archive_path):+ file_handle = doc.archive_file+ mime_type = 'application/pdf'+ elif doc.storage_type == Document.STORAGE_TYPE_UNENCRYPTED:file_handle = doc.source_fileelse:file_handle = GnuPG.decrypted(doc.source_file)- response = HttpResponse(file_handle, content_type=doc.mime_type)+ response = HttpResponse(file_handle, content_type=mime_type)response["Content-Disposition"] = '{}; filename="{}"'.format(disposition, doc.file_name)return response@@ -152,7 +164,8 @@ class DocumentViewSet(RetrieveModelMixin,@action(methods=['get'], detail=True)def preview(self, request, pk=None):try:- response = self.file_response(pk, "inline")+ response = self.file_response(+ pk, request, "inline")return responseexcept FileNotFoundError:raise Http404("Document source file does not exist")@@ -169,7 +182,8 @@ class DocumentViewSet(RetrieveModelMixin,@action(methods=['get'], detail=True)def download(self, request, pk=None):try:- return self.file_response(pk, "attachment")+ return self.file_response(+ pk, request, "attachment")except FileNotFoundError:raise Http404("Document source file does not exist")