Fix S3 keys/paths for user avatars
Also fixes the avatars controller to work with all back-ends
This commit is contained in:
@@ -4,17 +4,23 @@ class AvatarsController < ApplicationController
|
||||
http_status :not_found and return unless user.avatar.attached?
|
||||
|
||||
sha256_hash = params[:hash]
|
||||
format = params[:format].to_sym || :png
|
||||
size = params[:size]&.to_sym || :large
|
||||
format = params[:format]&.to_sym || :png
|
||||
size = params[:size]&.to_sym || :original
|
||||
|
||||
unless user.avatar_filename == "#{sha256_hash}.#{format}"
|
||||
unless user.avatar.filename.to_s == "#{sha256_hash}.#{format}"
|
||||
http_status :not_found and return
|
||||
end
|
||||
|
||||
send_file user.avatar.service.path_for(user.avatar.key),
|
||||
disposition: "inline", type: "image/#{format}"
|
||||
blob = if size == :original
|
||||
user.avatar.blob
|
||||
else
|
||||
user.avatar_variant(size: size)&.blob
|
||||
end
|
||||
|
||||
data = blob.download
|
||||
send_data data, type: "image/#{format}", disposition: "inline"
|
||||
else
|
||||
http_status :not_found and return
|
||||
http_status :not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user