From b37ec0db60d2a2420a19a08e4ea22ba21c6cd977 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer <felix@eckhofer.com> Date: Thu, 26 Dec 2024 14:10:29 +0100 Subject: [PATCH] Switch to new single-request API for filedrop --- app/jobs/pretalx/import_job.rb | 37 +++++++--------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/app/jobs/pretalx/import_job.rb b/app/jobs/pretalx/import_job.rb index ff75c19..8be478d 100644 --- a/app/jobs/pretalx/import_job.rb +++ b/app/jobs/pretalx/import_job.rb @@ -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']) -- GitLab