mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
fix up the migration for encrypted documents and a couple other associated issues.
This commit is contained in:
parent
5c310c51d4
commit
aa8789ae31
@ -30,12 +30,14 @@ def add_mime_types(apps, schema_editor):
|
|||||||
documents = Document.objects.all()
|
documents = Document.objects.all()
|
||||||
|
|
||||||
for d in documents:
|
for d in documents:
|
||||||
if d.storage_type == STORAGE_TYPE_GPG:
|
|
||||||
f = GnuPG.decrypted(open(source_path(d), "rb"))
|
|
||||||
else:
|
|
||||||
f = open(source_path(d), "rb")
|
f = open(source_path(d), "rb")
|
||||||
|
if d.storage_type == STORAGE_TYPE_GPG:
|
||||||
|
|
||||||
d.mime_type = magic.from_buffer(f.read(1024), mime=True)
|
data = GnuPG.decrypted(f)
|
||||||
|
else:
|
||||||
|
data = f.read(1024)
|
||||||
|
|
||||||
|
d.mime_type = magic.from_buffer(data, mime=True)
|
||||||
d.save()
|
d.save()
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -169,7 +169,12 @@ class DocumentViewSet(RetrieveModelMixin,
|
|||||||
parser_class = get_parser_class_for_mime_type(mime_type)
|
parser_class = get_parser_class_for_mime_type(mime_type)
|
||||||
if parser_class:
|
if parser_class:
|
||||||
parser = parser_class(logging_group=None)
|
parser = parser_class(logging_group=None)
|
||||||
|
|
||||||
|
try:
|
||||||
return parser.extract_metadata(file, mime_type)
|
return parser.extract_metadata(file, mime_type)
|
||||||
|
except Exception as e:
|
||||||
|
# TODO: cover GPG errors, remove later.
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -215,7 +220,12 @@ class DocumentViewSet(RetrieveModelMixin,
|
|||||||
@cache_control(public=False, max_age=315360000)
|
@cache_control(public=False, max_age=315360000)
|
||||||
def thumb(self, request, pk=None):
|
def thumb(self, request, pk=None):
|
||||||
try:
|
try:
|
||||||
return HttpResponse(Document.objects.get(id=pk).thumbnail_file,
|
doc = Document.objects.get(id=pk)
|
||||||
|
if doc.storage_type == Document.STORAGE_TYPE_GPG:
|
||||||
|
handle = GnuPG.decrypted(doc.thumbnail_file)
|
||||||
|
else:
|
||||||
|
handle = doc.thumbnail_file
|
||||||
|
return HttpResponse(handle,
|
||||||
content_type='image/png')
|
content_type='image/png')
|
||||||
except (FileNotFoundError, Document.DoesNotExist):
|
except (FileNotFoundError, Document.DoesNotExist):
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user