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.
This commit is contained in:
parent
cf3fa50b55
commit
5c310c51d4
@ -6,13 +6,17 @@ import magic
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from paperless.db import GnuPG
|
||||||
|
|
||||||
|
STORAGE_TYPE_UNENCRYPTED = "unencrypted"
|
||||||
|
STORAGE_TYPE_GPG = "gpg"
|
||||||
|
|
||||||
def source_path(self):
|
def source_path(self):
|
||||||
if self.filename:
|
if self.filename:
|
||||||
fname = str(self.filename)
|
fname = str(self.filename)
|
||||||
else:
|
else:
|
||||||
fname = "{:07}.{}".format(self.pk, self.file_type)
|
fname = "{:07}.{}".format(self.pk, self.file_type)
|
||||||
if self.storage_type == self.STORAGE_TYPE_GPG:
|
if self.storage_type == STORAGE_TYPE_GPG:
|
||||||
fname += ".gpg"
|
fname += ".gpg"
|
||||||
|
|
||||||
return os.path.join(
|
return os.path.join(
|
||||||
@ -26,9 +30,16 @@ def add_mime_types(apps, schema_editor):
|
|||||||
documents = Document.objects.all()
|
documents = Document.objects.all()
|
||||||
|
|
||||||
for d in documents:
|
for d in documents:
|
||||||
d.mime_type = magic.from_file(source_path(d), mime=True)
|
if d.storage_type == STORAGE_TYPE_GPG:
|
||||||
|
f = GnuPG.decrypted(open(source_path(d), "rb"))
|
||||||
|
else:
|
||||||
|
f = open(source_path(d), "rb")
|
||||||
|
|
||||||
|
d.mime_type = magic.from_buffer(f.read(1024), mime=True)
|
||||||
d.save()
|
d.save()
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def add_file_extensions(apps, schema_editor):
|
def add_file_extensions(apps, schema_editor):
|
||||||
Document = apps.get_model("documents", "Document")
|
Document = apps.get_model("documents", "Document")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user