Add controller for rendering avatars on simple URL
This commit is contained in:
parent
17ffbde03a
commit
512f0ccca1
20
app/controllers/avatars_controller.rb
Normal file
20
app/controllers/avatars_controller.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
class AvatarsController < ApplicationController
|
||||||
|
def show
|
||||||
|
if user = User.find_by(cn: params[:username])
|
||||||
|
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
|
||||||
|
|
||||||
|
unless user.avatar_filename == "#{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}"
|
||||||
|
else
|
||||||
|
http_status :not_found and return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -15,6 +15,9 @@ Rails.application.routes.draw do
|
|||||||
match 'signup/:step', to: 'signup#steps', as: :signup_steps, via: [:get, :post]
|
match 'signup/:step', to: 'signup#steps', as: :signup_steps, via: [:get, :post]
|
||||||
post 'signup_validate', to: 'signup#validate'
|
post 'signup_validate', to: 'signup#validate'
|
||||||
|
|
||||||
|
|
||||||
|
get "users/:username/avatars/:hash", to: "avatars#show", as: :user_avatar
|
||||||
|
|
||||||
namespace :contributions do
|
namespace :contributions do
|
||||||
root to: 'donations#index'
|
root to: 'donations#index'
|
||||||
resources :donations, only: ['index', 'create'] do
|
resources :donations, only: ['index', 'create'] do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user