mirror of
https://github.com/docusealco/docuseal
synced 2026-11-09 15:42:32 -05:00
adjust filename
This commit is contained in:
1 parent
256d14eb94
commit
1b63b16691
12 files changed
+26
-14
No files matched your search
@@ -22,7 +22,7 @@ module Api
|
||||
render json: {
|
||||
id: @submission.id,
|
||||
documents: documents.map do |attachment|
|
||||
{ name: attachment.filename.base, url: ActiveStorage::Blob.proxy_url(attachment.blob, expires_at:) }
|
||||
{ name: FilenameUtils.basename(attachment.blob[:filename]), url: ActiveStorage::Blob.proxy_url(attachment.blob, expires_at:) }
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
@@ -66,7 +66,9 @@ module Mcp
|
||||
@template.save!
|
||||
|
||||
documents, = Templates::CreateAttachments.call(@template, { files: [file] }, extract_fields: true)
|
||||
schema = documents.map { |doc| { attachment_uuid: doc.uuid, name: doc.filename.base } }
|
||||
schema = documents.map do |doc|
|
||||
{ attachment_uuid: doc.uuid, name: FilenameUtils.basename(doc.blob[:filename]) }
|
||||
end
|
||||
|
||||
if @template.fields.blank?
|
||||
@template.fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
||||
|
||||
@@ -31,7 +31,7 @@ class TemplateDocumentsController < ApplicationController
|
||||
documents, = Templates::CreateAttachments.call(@template, params, extract_fields: true)
|
||||
|
||||
schema = documents.map do |doc|
|
||||
{ attachment_uuid: doc.uuid, name: doc.filename.base }
|
||||
{ attachment_uuid: doc.uuid, name: FilenameUtils.basename(doc.blob[:filename]) }
|
||||
end
|
||||
|
||||
render json: {
|
||||
|
||||
@@ -67,7 +67,7 @@ class TemplatesDebugController < ApplicationController
|
||||
schema = documents.map do |doc|
|
||||
{
|
||||
attachment_uuid: doc.uuid,
|
||||
name: doc.filename.base,
|
||||
name: FilenameUtils.basename(doc.blob[:filename]),
|
||||
dynamic: dynamic_documents.find { |e| e.uuid == doc.uuid }.present?
|
||||
}
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ class TemplatesUploadsController < ApplicationController
|
||||
save_template!(@template, url_params)
|
||||
|
||||
documents, = Templates::CreateAttachments.call(@template, url_params || params, extract_fields: true)
|
||||
schema = documents.map { |doc| { attachment_uuid: doc.uuid, name: doc.filename.base } }
|
||||
schema = documents.map { |doc| { attachment_uuid: doc.uuid, name: FilenameUtils.basename(doc.blob[:filename]) } }
|
||||
|
||||
if @template.fields.blank?
|
||||
@template.fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
||||
|
||||
@@ -134,9 +134,9 @@
|
||||
<% document = @submission.schema_documents.find { |a| item['attachment_uuid'] == a.uuid } %>
|
||||
<% if document.preview_images.first %>
|
||||
<scroll-to data-selector-id="page-<%= document.uuid %>-0" class="block cursor-pointer">
|
||||
<img src="<%= (document.preview_images.find { |e| e.filename.base.to_i.zero? } || document.preview_images.first).url(time: service_url_time) %>" width="<%= document.preview_images.first.metadata['width'] %>" height="<%= document.preview_images.first.metadata['height'] %>" class="rounded border" loading="lazy" alt="<%= item['name'].presence || document.filename.base %>">
|
||||
<img src="<%= (document.preview_images.find { |e| e.filename.base.to_i.zero? } || document.preview_images.first).url(time: service_url_time) %>" width="<%= document.preview_images.first.metadata['width'] %>" height="<%= document.preview_images.first.metadata['height'] %>" class="rounded border" loading="lazy" alt="<%= item['name'].presence || FilenameUtils.basename(document.blob[:filename]) %>">
|
||||
<div class="pb-2 pt-1.5 text-center" dir="auto">
|
||||
<%= item['name'].presence || document.filename.base %>
|
||||
<%= item['name'].presence || FilenameUtils.basename(document.blob[:filename]) %>
|
||||
</div>
|
||||
</scroll-to>
|
||||
<% end %>
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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|
|
||||
|
||||
Reference in new issue
Block a user