Do not use ActiveStorage variants, process original avatar
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Variants are currently broken. So we process the original file with the
most common avatar dimensions and stripping metadata, then hash and
upload only that version.
This commit is contained in:
2025-05-14 14:42:03 +04:00
parent 1884f082ee
commit 417e346074
5 changed files with 53 additions and 35 deletions
+8 -10
View File
@@ -5,22 +5,20 @@ class AvatarsController < ApplicationController
sha256_hash = params[:hash]
format = params[:format]&.to_sym || :png
size = params[:size]&.to_sym || :original
# size = params[:size]&.to_sym || :original
unless user.avatar.filename.to_s == "#{sha256_hash}.#{format}"
http_status :not_found and return
end
blob = if size == :original
user.avatar.blob
else
# TODO Variants use the same custom storage key/path, which
# makes blob downloads always fetch the original version instead
# of the variant. Needs to be fixed/added in Rails.
user.avatar_variant(size: size)&.blob
end
# TODO See note for avatar_variant in user model
# blob = if size == :original
# user.avatar.blob
# else
# user.avatar_variant(size: size)&.blob
# end
data = blob.download
data = user.avatar.blob.download
send_data data, type: "image/#{format}", disposition: "inline"
else
http_status :not_found