mirror of
https://github.com/docusealco/docuseal
synced 2026-11-13 07:52: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: {
|
render json: {
|
||||||
id: @submission.id,
|
id: @submission.id,
|
||||||
documents: documents.map do |attachment|
|
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
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ module Mcp
|
|||||||
@template.save!
|
@template.save!
|
||||||
|
|
||||||
documents, = Templates::CreateAttachments.call(@template, { files: [file] }, extract_fields: true)
|
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?
|
if @template.fields.blank?
|
||||||
@template.fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
@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)
|
documents, = Templates::CreateAttachments.call(@template, params, extract_fields: true)
|
||||||
|
|
||||||
schema = documents.map do |doc|
|
schema = documents.map do |doc|
|
||||||
{ attachment_uuid: doc.uuid, name: doc.filename.base }
|
{ attachment_uuid: doc.uuid, name: FilenameUtils.basename(doc.blob[:filename]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class TemplatesDebugController < ApplicationController
|
|||||||
schema = documents.map do |doc|
|
schema = documents.map do |doc|
|
||||||
{
|
{
|
||||||
attachment_uuid: doc.uuid,
|
attachment_uuid: doc.uuid,
|
||||||
name: doc.filename.base,
|
name: FilenameUtils.basename(doc.blob[:filename]),
|
||||||
dynamic: dynamic_documents.find { |e| e.uuid == doc.uuid }.present?
|
dynamic: dynamic_documents.find { |e| e.uuid == doc.uuid }.present?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class TemplatesUploadsController < ApplicationController
|
|||||||
save_template!(@template, url_params)
|
save_template!(@template, url_params)
|
||||||
|
|
||||||
documents, = Templates::CreateAttachments.call(@template, url_params || params, extract_fields: true)
|
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?
|
if @template.fields.blank?
|
||||||
@template.fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
@template.fields = Templates::ProcessDocument.normalize_attachment_fields(@template, documents)
|
||||||
|
|||||||
@@ -134,9 +134,9 @@
|
|||||||
<% document = @submission.schema_documents.find { |a| item['attachment_uuid'] == a.uuid } %>
|
<% document = @submission.schema_documents.find { |a| item['attachment_uuid'] == a.uuid } %>
|
||||||
<% if document.preview_images.first %>
|
<% if document.preview_images.first %>
|
||||||
<scroll-to data-selector-id="page-<%= document.uuid %>-0" class="block cursor-pointer">
|
<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">
|
<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>
|
</div>
|
||||||
</scroll-to>
|
</scroll-to>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -18,4 +18,8 @@ module FilenameUtils
|
|||||||
def dangerous_extension(filename)
|
def dangerous_extension(filename)
|
||||||
ActiveStorage::Filename.wrap(filename).sanitized[DANGEROUS_EXTENSIONS_REGEXP, 1]&.downcase
|
ActiveStorage::Filename.wrap(filename).sanitized[DANGEROUS_EXTENSIONS_REGEXP, 1]&.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def basename(filename)
|
||||||
|
File.basename(filename, File.extname(filename))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
+1
-1
@@ -232,7 +232,7 @@ module Submitters
|
|||||||
def build_document_filename(submitter, blob, filename_format)
|
def build_document_filename(submitter, blob, filename_format)
|
||||||
return blob.filename.to_s if filename_format.blank?
|
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 = ReplaceEmailVariables.call(filename, submitter:)
|
||||||
|
|
||||||
filename = filename.gsub(' - {submission.status}') do
|
filename = filename.gsub(' - {submission.status}') do
|
||||||
|
|||||||
@@ -104,7 +104,10 @@ module Submitters
|
|||||||
|
|
||||||
def build_documents_array(submitter, expires_at: nil)
|
def build_documents_array(submitter, expires_at: nil)
|
||||||
submitter.documents.map do |attachment|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ module Templates
|
|||||||
def create_document!(template, attachment, data, scan)
|
def create_document!(template, attachment, data, scan)
|
||||||
blob = ActiveStorage::Blob.create_and_upload!(
|
blob = ActiveStorage::Blob.create_and_upload!(
|
||||||
io: StringIO.new(data),
|
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 },
|
metadata: { identified: true, analyzed: true },
|
||||||
content_type: scan ? 'image/png' : 'image/jpeg'
|
content_type: scan ? 'image/png' : 'image/jpeg'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ module Templates
|
|||||||
schema_item =
|
schema_item =
|
||||||
template.schema.find { |item| item['attachment_uuid'] == entry['attachment_uuid'] } ||
|
template.schema.find { |item| item['attachment_uuid'] == entry['attachment_uuid'] } ||
|
||||||
{ '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?
|
next if entry['pages'].blank?
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ module Templates
|
|||||||
|
|
||||||
blob = ActiveStorage::Blob.create_and_upload!(
|
blob = ActiveStorage::Blob.create_and_upload!(
|
||||||
io: StringIO.new(data),
|
io: StringIO.new(data),
|
||||||
filename: "#{attachment.filename.base}#{extension}",
|
filename: "#{FilenameUtils.basename(attachment.blob[:filename])}#{extension}",
|
||||||
metadata: { identified: true, analyzed: true },
|
metadata: { identified: true, analyzed: true },
|
||||||
content_type:
|
content_type:
|
||||||
)
|
)
|
||||||
@@ -439,7 +439,7 @@ module Templates
|
|||||||
|
|
||||||
blob = ActiveStorage::Blob.create_and_upload!(
|
blob = ActiveStorage::Blob.create_and_upload!(
|
||||||
io: StringIO.new(data),
|
io: StringIO.new(data),
|
||||||
filename: "#{old_attachment.filename.base}.pdf",
|
filename: "#{FilenameUtils.basename(old_attachment.blob[:filename])}.pdf",
|
||||||
metadata: { identified: true, analyzed: true,
|
metadata: { identified: true, analyzed: true,
|
||||||
pdf: { annotations: }.compact_blank, sha256: }.compact_blank,
|
pdf: { annotations: }.compact_blank, sha256: }.compact_blank,
|
||||||
content_type: Templates::ProcessDocument::PDF_CONTENT_TYPE
|
content_type: Templates::ProcessDocument::PDF_CONTENT_TYPE
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ module Templates
|
|||||||
documents.each_with_index do |document, index|
|
documents.each_with_index do |document, index|
|
||||||
replaced_document_schema = template.schema[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
|
if replaced_document_schema
|
||||||
template.fields.each do |field|
|
template.fields.each do |field|
|
||||||
|
|||||||
Reference in new issue
Block a user