Use rather token than path

This commit is contained in:
Karel Pičman 2024-05-06 17:37:51 +02:00
parent 0c95a29154
commit a877f40257
5 changed files with 15 additions and 5 deletions

View File

@ -99,6 +99,13 @@ module DmsfUploadHelper
if new_revision.save
new_revision.assign_workflow committed_file[:dmsf_workflow_id]
begin
# If the path is not present we get it from the token
if committed_file[:token].present?
a = Attachment.find_by_token(committed_file[:token])
if a
committed_file[:tempfile_path] = a.diskfile
end
end
FileUtils.mv committed_file[:tempfile_path], new_revision.disk_file(search_if_not_exists: false)
FileUtils.chmod 'u=wr,g=r', new_revision.disk_file(search_if_not_exists: false)
if defined?(EasyExtensions)

View File

@ -21,7 +21,7 @@
# Upload
class DmsfUpload
attr_accessor :name, :disk_filename, :mime_type, :title, :description, :comment, :major_version, :minor_version,
:patch_version, :locked, :workflow, :custom_values, :tempfile_path, :digest
:patch_version, :locked, :workflow, :custom_values, :tempfile_path, :digest, :token
attr_reader :size
def disk_file
@ -37,6 +37,7 @@ class DmsfUpload
original_filename: a.filename,
comment: uploaded_file[:description],
tempfile_path: a.diskfile,
token: uploaded_file[:token],
digest: a.digest
}
DmsfUpload.new project, folder, uploaded
@ -63,6 +64,7 @@ class DmsfUpload
Rails.logger.error "Cannot find #{uploaded[:tempfile_path]}"
end
@tempfile_path = uploaded[:tempfile_path]
@token = uploaded[:token]
@digest = uploaded[:digest]
if file.nil? || file.last_revision.nil?

View File

@ -20,7 +20,7 @@
<div class="box tabular dmfs-box-tabular">
<%= hidden_field_tag "committed_files[#{i}][disk_filename]", upload.disk_filename %>
<%= hidden_field_tag "committed_files[#{i}][tempfile_path]", upload.tempfile_path %>
<%= hidden_field_tag "committed_files[#{i}][token]", upload.token %>
<%= hidden_field_tag "committed_files[#{i}][size]", upload.size %>
<%= hidden_field_tag "committed_files[#{i}][mime_type]", upload.mime_type %>
<%= hidden_field_tag "committed_files[#{i}][digest]", upload.digest %>

View File

@ -20,7 +20,7 @@
<div class="box tabular dmfs-box-tabular">
<%= hidden_field_tag "committed_files[#{i}][disk_filename]", upload.disk_filename %>
<%= hidden_field_tag "committed_files[#{i}][tempfile_path]", upload.tempfile_path %>
<%= hidden_field_tag "committed_files[#{i}][token]", upload.token %>
<%= hidden_field_tag "committed_files[#{i}][size]", upload.size %>
<%= hidden_field_tag "committed_files[#{i}][mime_type]", upload.mime_type %>
<%= hidden_field_tag "committed_files[#{i}][name]", upload.name %>

View File

@ -22,6 +22,7 @@
"original_filename":"<%= @tempfile.original_filename.html_safe %>",
"content_type": "<%= @tempfile.content_type.gsub('"', '').html_safe %>",
"disk_filename": "<%= @disk_filename.html_safe %>",
"tempfile_path": "<%= @tempfile_path.html_safe %>"
"digest": "<%= @digest.html_safe %>"
"tempfile_path": "<%= @tempfile_path.html_safe %>",
"digest": "<%= @digest.html_safe %>",
"token": "<%= @token.html_safe %>"
}