lib/lockbox/utils.rb in lockbox-0.4.1 vs lib/lockbox/utils.rb in lockbox-0.4.2

- old
+ new

@@ -61,18 +61,21 @@ filename: attachable.original_filename, content_type: attachable.content_type } when Hash io = attachable[:io] - attachable = { - io: box.encrypt_io(io), - filename: attachable[:filename], - content_type: attachable[:content_type] - } + attachable = attachable.dup + attachable[:io] = box.encrypt_io(io) else - raise NotImplementedError, "Not supported" + # TODO raise ArgumentError + raise NotImplementedError, "Could not find or build blob: expected attachable, got #{attachable.inspect}" end + + # don't analyze encrypted data + metadata = {"analyzed" => true} + metadata["encrypted"] = true if options[:migrating] + attachable[:metadata] = (attachable[:metadata] || {}).merge(metadata) end # set content type based on unencrypted data # keep synced with ActiveStorage::Blob#extract_content_type attachable[:io].extracted_content_type = Marcel::MimeType.for(io, name: attachable[:filename].to_s, declared_type: attachable[:content_type]) @@ -82,8 +85,16 @@ def self.decrypt_result(record, name, options, result) ActiveSupport::Notifications.instrument("decrypt_file.lockbox", {name: name}) do Utils.build_box(record, options, record.class.table_name, name).decrypt(result) end + end + + def self.rebuild_attachable(attachment) + { + io: StringIO.new(attachment.download), + filename: attachment.filename, + content_type: attachment.content_type + } end end end