adjust filename

This commit is contained in:
Pete Matsyburka committed 2026-11-05 01:15:16 +02:00
1 parent 256d14eb94
commit 1b63b16691
12 files changed
+26 -14

No files matched your search

+4
View File
@@ -18,4 +18,8 @@ module FilenameUtils
def dangerous_extension(filename)
ActiveStorage::Filename.wrap(filename).sanitized[DANGEROUS_EXTENSIONS_REGEXP, 1]&.downcase
end
def basename(filename)
File.basename(filename, File.extname(filename))
end
end
+1 -1
View File
@@ -232,7 +232,7 @@ module Submitters
def build_document_filename(submitter, blob, filename_format)
return blob.filename.to_s if filename_format.blank?
filename = filename_format.gsub('{document.name}', blob.filename.base)
filename = filename_format.gsub('{document.name}', FilenameUtils.basename(blob[:filename]))
filename = ReplaceEmailVariables.call(filename, submitter:)
filename = filename.gsub(' - {submission.status}') do
+4 -1
View File
@@ -104,7 +104,10 @@ module Submitters
def build_documents_array(submitter, expires_at: nil)
submitter.documents.map do |attachment|
{ 'name' => attachment.filename.base, 'url' => rails_storage_proxy_url(attachment, expires_at:) }
{
'name' => FilenameUtils.basename(attachment.blob[:filename]),
'url' => rails_storage_proxy_url(attachment, expires_at:)
}
end
end
+1 -1
View File
@@ -26,7 +26,7 @@ module Templates
def create_document!(template, attachment, data, scan)
blob = ActiveStorage::Blob.create_and_upload!(
io: StringIO.new(data),
filename: "#{attachment.filename.base}.#{scan ? 'png' : 'jpg'}",
filename: "#{FilenameUtils.basename(attachment.blob[:filename])}.#{scan ? 'png' : 'jpg'}",
metadata: { identified: true, analyzed: true },
content_type: scan ? 'image/png' : 'image/jpeg'
)
+3 -3
View File
@@ -52,7 +52,7 @@ module Templates
schema_item =
template.schema.find { |item| item['attachment_uuid'] == entry['attachment_uuid'] } ||
{ 'attachment_uuid' => entry['attachment_uuid'],
'name' => attachments_index[entry['attachment_uuid']].filename.base }
'name' => FilenameUtils.basename(attachments_index[entry['attachment_uuid']].blob[:filename]) }
next if entry['pages'].blank?
@@ -270,7 +270,7 @@ module Templates
blob = ActiveStorage::Blob.create_and_upload!(
io: StringIO.new(data),
filename: "#{attachment.filename.base}#{extension}",
filename: "#{FilenameUtils.basename(attachment.blob[:filename])}#{extension}",
metadata: { identified: true, analyzed: true },
content_type:
)
@@ -439,7 +439,7 @@ module Templates
blob = ActiveStorage::Blob.create_and_upload!(
io: StringIO.new(data),
filename: "#{old_attachment.filename.base}.pdf",
filename: "#{FilenameUtils.basename(old_attachment.blob[:filename])}.pdf",
metadata: { identified: true, analyzed: true,
pdf: { annotations: }.compact_blank, sha256: }.compact_blank,
content_type: Templates::ProcessDocument::PDF_CONTENT_TYPE
+4 -1
View File
@@ -12,7 +12,10 @@ module Templates
documents.each_with_index do |document, index|
replaced_document_schema = template.schema[index]
template.schema[index] = { attachment_uuid: document.uuid, name: document.filename.base }
template.schema[index] = {
attachment_uuid: document.uuid,
name: FilenameUtils.basename(document.blob[:filename])
}
if replaced_document_schema
template.fields.each do |field|