UX: Change default filename for images that have been pasted.

This commit is contained in:
Guo Xiang Tan 2017-02-01 14:44:41 +08:00
parent d449f782a3
commit 6c8c91dca4
2 changed files with 5 additions and 4 deletions

View File

@ -170,7 +170,7 @@ export function validateUploadedFiles(files, opts) {
// CHROME ONLY: if the image was pasted, sets its name to a default one // CHROME ONLY: if the image was pasted, sets its name to a default one
if (typeof Blob !== "undefined" && typeof File !== "undefined") { if (typeof Blob !== "undefined" && typeof File !== "undefined") {
if (upload instanceof Blob && !(upload instanceof File) && upload.type === "image/png") { upload.name = "blob.png"; } if (upload instanceof Blob && !(upload instanceof File) && upload.type === "image/png") { upload.name = "__blob__.png"; }
} }
opts = opts || {}; opts = opts || {};

View File

@ -74,13 +74,14 @@ class UploadsController < ApplicationController
return { errors: I18n.t("upload.file_missing") } if tempfile.nil? return { errors: I18n.t("upload.file_missing") } if tempfile.nil?
# convert pasted images to HQ jpegs # convert pasted images to HQ jpegs
if filename == "blob.png" && SiteSetting.convert_pasted_images_to_hq_jpg byebug
jpeg_path = "#{File.dirname(tempfile.path)}/blob.jpg" if filename == "__blob__.png" && SiteSetting.convert_pasted_images_to_hq_jpg
jpeg_path = "#{File.dirname(tempfile.path)}/image.jpg"
OptimizedImage.ensure_safe_paths!(tempfile.path, jpeg_path) OptimizedImage.ensure_safe_paths!(tempfile.path, jpeg_path)
`convert #{tempfile.path} -quality #{SiteSetting.convert_pasted_images_quality} #{jpeg_path}` `convert #{tempfile.path} -quality #{SiteSetting.convert_pasted_images_quality} #{jpeg_path}`
# only change the format of the image when JPG is at least 5% smaller # only change the format of the image when JPG is at least 5% smaller
if File.size(jpeg_path) < File.size(tempfile.path) * 0.95 if File.size(jpeg_path) < File.size(tempfile.path) * 0.95
filename = "blob.jpg" filename = "image.jpg"
content_type = "image/jpeg" content_type = "image/jpeg"
tempfile = File.open(jpeg_path) tempfile = File.open(jpeg_path)
else else