mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	fix up the migration for encrypted documents.
This commit is contained in:
		| @@ -6,13 +6,17 @@ import magic | ||||
| from django.conf import settings | ||||
| from django.db import migrations, models | ||||
|  | ||||
| from paperless.db import GnuPG | ||||
|  | ||||
| STORAGE_TYPE_UNENCRYPTED = "unencrypted" | ||||
| STORAGE_TYPE_GPG = "gpg" | ||||
|  | ||||
| def source_path(self): | ||||
|     if self.filename: | ||||
|         fname = str(self.filename) | ||||
|     else: | ||||
|         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" | ||||
|  | ||||
|     return os.path.join( | ||||
| @@ -26,9 +30,16 @@ def add_mime_types(apps, schema_editor): | ||||
|     documents = Document.objects.all() | ||||
|  | ||||
|     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() | ||||
|  | ||||
|         f.close() | ||||
|  | ||||
|  | ||||
| def add_file_extensions(apps, schema_editor): | ||||
|     Document = apps.get_model("documents", "Document") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler