Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubocop suggestion changes in images_controller #11436

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ class ImagesController < ApplicationController
before_action :require_user, only: %i(create new update delete)

def shortlink
size = params[:size] || params[:s]
TildaDares marked this conversation as resolved.
Show resolved Hide resolved
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

Expand All @@ -30,25 +29,25 @@ 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,
photo: params[:image][:photo],
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
}]
}
Expand Down