From 1b9db2f61e360671442d84e5fa70d35d4955851d Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Wed, 24 Jul 2019 07:06:05 +0200 Subject: [PATCH] Fix for file annotating on Safari --- app/assets/javascripts/sitewide/file_preview.js | 17 ++++++++++++++--- app/controllers/assets_controller.rb | 13 ++++++++++++- config/routes.rb | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/sitewide/file_preview.js b/app/assets/javascripts/sitewide/file_preview.js index 694538bab..d692ed11b 100644 --- a/app/assets/javascripts/sitewide/file_preview.js +++ b/app/assets/javascripts/sitewide/file_preview.js @@ -172,7 +172,18 @@ var FilePreviewModal = (function() { }; } - function initImageEditor(data) { + function preInitImageEditor(data) { + $.ajax({ + url: data['download-url'], + type: 'get', + success: function(responseData) { + var fileUrl = responseData; + initImageEditor(data, fileUrl); + } + }); + } + + function initImageEditor(data, fileUrl) { var imageEditor; var ps; var blackTheme = { @@ -261,7 +272,7 @@ var FilePreviewModal = (function() { imageEditor = new tui.ImageEditor('#tui-image-editor', { includeUI: { loadImage: { - path: data['download-url'], + path: fileUrl, name: data.filename }, theme: blackTheme, @@ -453,7 +464,7 @@ var FilePreviewModal = (function() { ev.preventDefault(); ev.stopPropagation(); modal.modal('hide'); - initImageEditor(data); + preInitImageEditor(data); }); } else { modal.find('.file-edit-link').css('display', 'none'); diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index 26ee0ba8a..f18cd027f 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -52,7 +52,7 @@ class AssetsController < ApplicationController 'filename' => truncate(escape_input(@asset.file_file_name), length: Constants::FILENAME_TRUNCATION_LENGTH), - 'download-url' => download_asset_path(@asset, timestamp: Time.now.to_i) + 'download-url' => asset_file_url_path(@asset) } can_edit = if @assoc.class == Step @@ -132,6 +132,17 @@ class AssetsController < ApplicationController end end + def file_url + render_404 and return unless @asset.file_present + + url = if @asset.file.is_stored_on_s3? + @asset.presigned_url(download: true) + else + @asset.file.url + end + render plain: url + end + def edit action = @asset.file_file_size.zero? && !@asset.locked? ? 'editnew' : 'edit' @action_url = append_wd_params(@asset diff --git a/config/routes.rb b/config/routes.rb index 09db94a91..143284620 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -593,6 +593,7 @@ Rails.application.routes.draw do to: 'assets#file_preview', as: 'asset_file_preview' get 'files/:id/download', to: 'assets#download', as: 'download_asset' + get 'files/:id/file_url', to: 'assets#file_url', as: 'asset_file_url' get 'files/:id/preview', to: 'assets#preview', as: 'preview_asset' get 'files/:id/view', to: 'assets#view', as: 'view_asset' get 'files/:id/edit', to: 'assets#edit', as: 'edit_asset'