use attachment key for BrayniacAI API payload
This commit is contained in:
@@ -8,28 +8,27 @@ class MatchAppearanceReleasesJob < ApplicationJob
|
||||
|
||||
return if filtered_attachments_object[:keys].blank?
|
||||
|
||||
matching_request = MatchingRequest.create project: project, attachments: filtered_attachments_object[:signed_keys]
|
||||
|
||||
matching_request = MatchingRequest.create project: project, attachments: filtered_attachments_object[:signed_ids]
|
||||
payload = { request_id: matching_request.id, bucket: aws_bucket_name, files: filtered_attachments_object[:keys]}
|
||||
|
||||
# response = BrayniacAI::AppearanceReleaseMatching.match_attachments payload
|
||||
BrayniacAI::QrMatching.enable_logging
|
||||
response = BrayniacAI::QrMatching.create! payload
|
||||
|
||||
matches = response[:matches] || []
|
||||
|
||||
handle_matches matches, project
|
||||
matches = response.attributes[:matches] || []
|
||||
key_signed_id_hash = Hash[filtered_attachments_object[:keys].zip(filtered_attachments_object[:signed_ids])]
|
||||
handle_matches matches, project, key_signed_id_hash
|
||||
matching_request.destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_matches(matches, project)
|
||||
matches.each do |match|
|
||||
contract = match[:contracts].blank? ? nil : match[:contracts].first
|
||||
headshot = match[:headshots].blank? ? nil : match[:headshots].first
|
||||
def handle_matches(matches, project, key_signed_id_hash)
|
||||
matches.each do |qr_matching_match|
|
||||
match = qr_matching_match.attributes
|
||||
contract_key = match[:contracts].blank? ? nil : match[:contracts].first
|
||||
headshot_key = match[:headshots].blank? ? nil : match[:headshots].first
|
||||
identifier = match[:identifier]
|
||||
|
||||
contract = key_signed_id_hash[contract_key]
|
||||
headshot = key_signed_id_hash[headshot_key]
|
||||
|
||||
next if contract.nil? && headshot.nil?
|
||||
|
||||
identified_release = identifier.blank? ? nil : AppearanceRelease.find_by(identifier: identifier)
|
||||
@@ -80,8 +79,8 @@ class MatchAppearanceReleasesJob < ApplicationJob
|
||||
|
||||
def filter_attachments(attachments)
|
||||
filtered_attachments_keys = []
|
||||
filtered_attachments_names = []
|
||||
filtered_attachments_signed_ids = []
|
||||
|
||||
attachments.each do |attachment|
|
||||
blob = ActiveStorage::Blob.find_signed attachment
|
||||
next if blob.nil?
|
||||
@@ -90,13 +89,12 @@ class MatchAppearanceReleasesJob < ApplicationJob
|
||||
next unless blob.image? || extension == 'pdf'
|
||||
|
||||
filtered_attachments_keys << blob.key
|
||||
filtered_attachments_names << blob.filename.to_s
|
||||
filtered_attachments_signed_ids << attachment
|
||||
end
|
||||
|
||||
{
|
||||
keys: filtered_attachments_keys,
|
||||
names: filtered_attachments_names,
|
||||
signed_keys: filtered_attachments_signed_ids
|
||||
signed_ids: filtered_attachments_signed_ids
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user