WIP JPEG avatars
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-01-24 15:56:34 +03:00
parent 6d7d722c5d
commit 7b91618ffa
5 changed files with 75 additions and 19 deletions

View File

@@ -10,7 +10,33 @@ module LdapManager
filter = Net::LDAP::Filter.eq("cn", @cn)
entry = client.search(base: treebase, filter: filter, attributes: attributes).first
entry.try(:jpegPhoto) ? entry.jpegPhoto.first : nil
if entry&.jpegPhoto
binary_data = entry.jpegPhoto.first # Use first value (binary)
Rails.logger.debug { "Fetched jpegPhoto size: #{binary_data.bytesize}" }
create_tempfile(binary_data)
else
Rails.logger.debug { "No jpegPhoto found for cn=#{@cn}, ou=#{@ou}" }
nil
end
end
def create_tempfile(binary_data)
tempfile = Tempfile.new(['image', '.jpg'])
tempfile.binmode
tempfile.write(binary_data)
tempfile.rewind
Rails.logger.debug { "Storing debug file for cn=#{@cn}, size=#{tempfile.size}" }
data = tempfile.read
debug_file_path = "#{Rails.root}/tmp/avatar-fetched.jpg"
debug_file = File.open(debug_file_path, 'wb')
debug_file.write(data)
debug_file.close
data
end
end
end

View File

@@ -8,20 +8,30 @@ module LdapManager
end
def call
replace_attribute @dn, :jpegPhoto, @img_data
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(512, 512)
.resize_to_fill(256, 256)
.source(file)
.convert("jpeg")
.saver(strip: true)
.call
Base64.strict_encode64 processed.read
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