Skip to content
Snippets Groups Projects
Verified Commit b37ec0db authored by tribut's avatar tribut :man_dancing:
Browse files

Switch to new single-request API for filedrop

parent 609907e9
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ module Pretalx
end
end
session.recorded = !session_data.fetch('do_not_record', false)
update_filedrop_data(session, filedrop_config) if filedrop_index[session.ref_id]
update_filedrop_data(session, filedrop_index[session.ref_id], filedrop_config) if filedrop_index[session.ref_id]
session.save!
end
end
......@@ -95,7 +95,7 @@ module Pretalx
username: fetch_credential("filedrop_user"),
password: fetch_credential("filedrop_password") },
headers: { 'Accept' => 'application/json' },
timeout: 5
timeout: 30
)
data = JSON.parse(response.body)
rescue => e
......@@ -112,32 +112,9 @@ module Pretalx
end
end
def update_filedrop_data(session, filedrop_config)
if !filedrop_config || !filedrop_config['url']
return {}
end
response = HTTParty.get(
filedrop_config['url'] + "/talks/" + session.ref_id,
basic_auth: {
username: fetch_credential("filedrop_user"),
password: fetch_credential("filedrop_password") },
headers: { 'Accept' => 'application/json' }
)
begin
data = JSON.parse(response.body)
rescue => e
Rails.logger.warn("Filedrop response could not be parsed: #{e.message}")
return {}
end
if !data["files"].is_a?(Array) || !data["comments"].is_a?(Array)
Rails.logger.warn("Filedrop info for #{session.ref_id} was incomplete")
return {}
end
def update_filedrop_data(session, filedrop_data, filedrop_config)
existing_comments = session.filedrop_comments.pluck(:body)
new_comments = data["comments"]&.pluck("body") || []
new_comments = filedrop_data["comments"]&.pluck("body") || []
# Remove comments not in the JSON file
(existing_comments - new_comments).each do |body|
......@@ -145,7 +122,7 @@ module Pretalx
end
# Add or update comments
data["comments"]&.each do |comment_data|
filedrop_data["comments"]&.each do |comment_data|
session.filedrop_comments.find_or_initialize_by(body: comment_data['body']).tap do |comment|
comment.orig_created = parse_datetime_or_nil(comment_data['meta']['created'])
comment.save!
......@@ -153,7 +130,7 @@ module Pretalx
end
existing_files = session.filedrop_files.pluck(:name, :checksum)
new_files = data['files']&.map { |d| [d['name'], d.dig('meta', 'hash')] } || []
new_files = filedrop_data['files']&.map { |d| [d['name'], d.dig('meta', 'hash')] } || []
# Remove files not in the JSON file
(existing_files - new_files).each do |name, checksum|
......@@ -161,7 +138,7 @@ module Pretalx
end
# Add or update files
data['files']&.each do |file_data|
filedrop_data['files']&.each do |file_data|
session.filedrop_files.find_or_initialize_by(name: file_data['name'], checksum: file_data['meta']['hash']).tap do |file|
file.size = file_data['meta']['size']
file.orig_created = parse_datetime_or_nil(file_data['meta']['created'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment