mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	fixed the decryption code, but its still untested.
This commit is contained in:
		
							parent
							
								
									ef15de18a9
								
							
						
					
					
						commit
						2a4fe4dceb
					
				@ -61,18 +61,28 @@ class Command(BaseCommand):
 | 
				
			|||||||
                document).encode('utf-8'), "green"))
 | 
					                document).encode('utf-8'), "green"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            old_paths = [document.source_path, document.thumbnail_path]
 | 
					            old_paths = [document.source_path, document.thumbnail_path]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            raw_document = GnuPG.decrypted(document.source_file, passphrase)
 | 
					            raw_document = GnuPG.decrypted(document.source_file, passphrase)
 | 
				
			||||||
            raw_thumb = GnuPG.decrypted(document.thumbnail_file, passphrase)
 | 
					            raw_thumb = GnuPG.decrypted(document.thumbnail_file, passphrase)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
 | 
					            document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ext = os.path.splitext(document.filename)[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if not ext == '.gpg':
 | 
				
			||||||
 | 
					                raise CommandError(
 | 
				
			||||||
 | 
					                    f"Abort: encrypted file {document.source_path} does not "
 | 
				
			||||||
 | 
					                    f"end with .gpg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            document.filename = os.path.splitext(document.source_path)[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(document.source_path, "wb") as f:
 | 
					            with open(document.source_path, "wb") as f:
 | 
				
			||||||
                f.write(raw_document)
 | 
					                f.write(raw_document)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(document.thumbnail_path, "wb") as f:
 | 
					            with open(document.thumbnail_path, "wb") as f:
 | 
				
			||||||
                f.write(raw_thumb)
 | 
					                f.write(raw_thumb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            document.save(update_fields=("storage_type",))
 | 
					            document.save(update_fields=("storage_type", "filename"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for path in old_paths:
 | 
					            for path in old_paths:
 | 
				
			||||||
                os.unlink(path)
 | 
					                os.unlink(path)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user