diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 934952875b..9b94117ea8 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -6,18 +6,18 @@ class ImagesController < ApplicationController def shortlink size = params[:size] || params[:s] - size = size || :large - size = :thumb if (size.to_s == "t") - size = :thumb if (size.to_s == "thumbnail") - size = :medium if (size.to_s == "m") - size = :large if (size.to_s == "l") - size = :original if (size.to_s == "o") + size ||= :large + size = :thumb if size.to_s == 't' + size = :thumb if size.to_s == 'thumbnail' + size = :medium if size.to_s == 'm' + size = :large if size.to_s == 'l' + size = :original if size.to_s == 'o' image = Image.find(params[:id]) - if image.is_image? - path = URI.parse(image.path(size)).path - else - path = URI.parse(image.path(:original)).path # PDFs etc don't get resized - end + path = if image.is_image? + URI.parse(image.path(size)).path + else + URI.parse(image.path(:original)).path # PDFs etc don't get resized + end redirect_to path end @@ -30,7 +30,7 @@ def create filetype = params[:data].split(';').first.split('/').last @image = Image.new(uid: current_user.uid, photo: params[:data], - photo_file_name: 'dataurl.' + filetype) + photo_file_name: "dataurl.#{filetype}") @image.save! else @image = Image.new(uid: current_user.uid, @@ -38,17 +38,17 @@ def create title: params[:image][:title], notes: params[:image][:notes]) end - @image.nid = Node.find(params[:nid].to_i).nid unless params[:nid].nil? || params[:nid] == 'undefined' || params[:nid].to_i == 0 + @image.nid = Node.find(params[:nid].to_i).nid unless params[:nid].nil? || params[:nid] == 'undefined' || params[:nid].to_i.zero? if @image.save! render json: { id: @image.id, url: @image.shortlink, - full: 'https://' + request.host.to_s + '/' + @image.path(:large), + full: "https://#{request.host}/#{@image.path(:large)}", filename: @image.photo_file_name, href: @image.shortlink, # Woofmark/PublicLab.Editor title: @image.photo_file_name, results: [{ # Woofmark/PublicLab.Editor - href: @image.shortlink + "." + @image.filetype, + href: "#{@image.shortlink}.#{@image.filetype}", title: @image.photo_file_name }] }