From d89d533e0d87c04f1a23889cbe20b9c47b90a676 Mon Sep 17 00:00:00 2001 From: Pavel Konev Date: Thu, 22 Sep 2022 23:06:43 +0300 Subject: [PATCH 1/2] First time contributor - rubocop suggestion changes in images_controller.rb https://github.com/publiclab/plots2/issues/11432 first timer issue Fixes rubocop suggestions, according to issue a issue linked above --- app/controllers/images_controller.rb | 31 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 934952875b..c4f1e905b6 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -5,19 +5,18 @@ class ImagesController < ApplicationController before_action :require_user, only: %i(create new update delete) 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 +29,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 +37,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 }] } From c7e44f7b6e21f59bd6665dbfc7aa023cf35d37bc Mon Sep 17 00:00:00 2001 From: Tilda Udufo Date: Mon, 10 Oct 2022 11:19:15 +0100 Subject: [PATCH 2/2] Update images_controller.rb --- app/controllers/images_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index c4f1e905b6..9b94117ea8 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -5,6 +5,7 @@ class ImagesController < ApplicationController before_action :require_user, only: %i(create new update delete) def shortlink + size = params[:size] || params[:s] size ||= :large size = :thumb if size.to_s == 't' size = :thumb if size.to_s == 'thumbnail'