mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 03:46:39 +08:00
Improve large image saving after editing [SCI-3289]
This commit is contained in:
parent
05963eb245
commit
9e91e9e59d
3 changed files with 27 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
|
/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }]*/
|
||||||
/* eslint no-use-before-define: ["error", { "functions": false }]*/
|
/* eslint no-use-before-define: ["error", { "functions": false }]*/
|
||||||
/* global fabric tui animateSpinner setupAssetsLoading I18n*/
|
/* global Uint8Array fabric tui animateSpinner setupAssetsLoading I18n*/
|
||||||
//= require assets
|
//= require assets
|
||||||
|
|
||||||
var FilePreviewModal = (function() {
|
var FilePreviewModal = (function() {
|
||||||
|
@ -282,10 +282,30 @@ var FilePreviewModal = (function() {
|
||||||
$('.tui-image-editor-header').hide();
|
$('.tui-image-editor-header').hide();
|
||||||
|
|
||||||
$('.file-save-link').off().click(function(ev) {
|
$('.file-save-link').off().click(function(ev) {
|
||||||
|
var imageBlob;
|
||||||
|
var imageDataURL;
|
||||||
|
var imageFormat;
|
||||||
var dataUpload = new FormData();
|
var dataUpload = new FormData();
|
||||||
|
var blobArray;
|
||||||
|
var bytePosition;
|
||||||
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
dataUpload.append('image', imageEditor.toDataURL());
|
|
||||||
|
imageFormat = (data['mime-type'] === 'image/png') ? 'png' : 'jpeg';
|
||||||
|
|
||||||
|
imageDataURL = imageEditor.toDataURL({ format: imageFormat });
|
||||||
|
imageDataURL = atob(imageDataURL.split(',')[1]);
|
||||||
|
|
||||||
|
blobArray = new Uint8Array(imageDataURL.length);
|
||||||
|
|
||||||
|
for (bytePosition = 0; bytePosition < imageDataURL.length; bytePosition += 1) {
|
||||||
|
blobArray[bytePosition] = imageDataURL.charCodeAt(bytePosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
imageBlob = new Blob([blobArray]);
|
||||||
|
|
||||||
|
dataUpload.append('image', imageBlob);
|
||||||
animateSpinner(null, true);
|
animateSpinner(null, true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
|
|
@ -63,6 +63,7 @@ class AssetsController < ApplicationController
|
||||||
if @asset.is_image?
|
if @asset.is_image?
|
||||||
response_json.merge!(
|
response_json.merge!(
|
||||||
'editable' => @asset.editable_image? && can_edit,
|
'editable' => @asset.editable_image? && can_edit,
|
||||||
|
'mime-type' => @asset.file.content_type,
|
||||||
'processing' => @asset.file.processing?,
|
'processing' => @asset.file.processing?,
|
||||||
'large-preview-url' => @asset.url(:large),
|
'large-preview-url' => @asset.url(:large),
|
||||||
'processing-url' => image_tag('medium/processing.gif')
|
'processing-url' => image_tag('medium/processing.gif')
|
||||||
|
@ -151,11 +152,10 @@ class AssetsController < ApplicationController
|
||||||
|
|
||||||
def update_image
|
def update_image
|
||||||
@asset = Asset.find(params[:id])
|
@asset = Asset.find(params[:id])
|
||||||
|
orig_file_name = @asset.file_file_name
|
||||||
return render_403 unless can_read_team?(@asset.team)
|
return render_403 unless can_read_team?(@asset.team)
|
||||||
image_file = Paperclip.io_adapters.for(params[:image])
|
@asset.file = params[:image]
|
||||||
image_format = image_file.content_type.split('/')[1]
|
@asset.file_file_name = orig_file_name
|
||||||
image_file.original_filename = @asset.file_file_name.ext(image_format)
|
|
||||||
@asset.file = image_file
|
|
||||||
@asset.save!
|
@asset.save!
|
||||||
# Post process file here
|
# Post process file here
|
||||||
@asset.post_process_file(@asset.team)
|
@asset.post_process_file(@asset.team)
|
||||||
|
|
|
@ -220,7 +220,7 @@ class Constants
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
WHITELISTED_IMAGE_TYPES_EDITABLE = %w(
|
WHITELISTED_IMAGE_TYPES_EDITABLE = %w(
|
||||||
gif jpeg pjpeg png
|
jpeg pjpeg png
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
WHITELISTED_TAGS = %w(
|
WHITELISTED_TAGS = %w(
|
||||||
|
|
Loading…
Add table
Reference in a new issue