akkounts/app/services/ldap_manager/update_avatar.rb
Râu Cao 7b91618ffa
Some checks failed
continuous-integration/drone/push Build is failing
WIP JPEG avatars
2025-05-08 21:16:33 +04:00

38 lines
866 B
Ruby

require "image_processing/vips"
module LdapManager
class UpdateAvatar < LdapManagerService
def initialize(dn:, file:)
@dn = dn
@img_data = process(file)
end
def call
Rails.logger.debug { "Storing jpegPhoto for dn=#{@dn}, size=#{@img_data.bytesize}" }
result = replace_attribute @dn, :jpegPhoto, @img_data
Rails.logger.debug { "LDAP replace_attribute result: #{result}" }
result
end
private
def process(file)
processed = ImageProcessing::Vips
.resize_to_fill(256, 256)
.source(file)
.convert("jpeg")
.saver(strip: true)
.call
data = processed.read
debug_file_path = "#{Rails.root}/tmp/avatar-processed.jpg"
debug_file = File.open(debug_file_path, 'wb')
debug_file.write(data)
debug_file.close
data
end
end
end