From 389312057dbf83024769020d633001f3ce765d56 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer <felix@eckhofer.com> Date: Thu, 26 Dec 2024 14:35:03 +0100 Subject: [PATCH] Switch back to a simple config for filedrop Also account for absolute/relative paths --- app/jobs/pretalx/import_job.rb | 20 ++++++++++---------- db/seeds.rb | 10 ++-------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/app/jobs/pretalx/import_job.rb b/app/jobs/pretalx/import_job.rb index 8be478d..9418064 100644 --- a/app/jobs/pretalx/import_job.rb +++ b/app/jobs/pretalx/import_job.rb @@ -8,7 +8,7 @@ module Pretalx queue_as :default include ActionView::Helpers - def import_schedule(conference, url, filedrop_config) + def import_schedule(conference, url, filedrop_url) response = HTTParty.get(url) response.success? or return Rails.logger.error "Failed to fetch schedule from #{url}" @@ -17,7 +17,7 @@ module Pretalx schedule.dig('schedule', 'conference', 'rooms') && schedule.dig('schedule', 'conference', 'days') - filedrop_index = fetch_filedrop_index(filedrop_config) + filedrop_index = fetch_filedrop_index(filedrop_url) # We keep a local hash of the stages, because the sessions reference stages by name instead of id stages = {} @@ -62,7 +62,7 @@ module Pretalx end end session.recorded = !session_data.fetch('do_not_record', false) - update_filedrop_data(session, filedrop_index[session.ref_id], filedrop_config) if filedrop_index[session.ref_id] + update_filedrop_data(session, filedrop_index[session.ref_id], filedrop_url) if filedrop_index[session.ref_id] session.save! end end @@ -83,14 +83,12 @@ module Pretalx private - def fetch_filedrop_index(filedrop_config) - if !filedrop_config || !filedrop_config['url'] - return {} - end + def fetch_filedrop_index(filedrop_url) + return {} unless filedrop_url begin response = HTTParty.get( - filedrop_config['url'] + "/", + filedrop_url, basic_auth: { username: fetch_credential("filedrop_user"), password: fetch_credential("filedrop_password") }, @@ -112,7 +110,7 @@ module Pretalx end end - def update_filedrop_data(session, filedrop_data, filedrop_config) + def update_filedrop_data(session, filedrop_data, filedrop_url) existing_comments = session.filedrop_comments.pluck(:body) new_comments = filedrop_data["comments"]&.pluck("body") || [] @@ -142,7 +140,9 @@ module Pretalx 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']) - file.download(filedrop_config['url'] + file_data['url']) unless filedrop_config.fetch('skip_downloads', false) + uri = URI(filedrop_url.chomp("/")) + uri.path = path.start_with?("/") ? path : [uri.path, path].join("/") + file.download(uri) file.save end end diff --git a/db/seeds.rb b/db/seeds.rb index 848e809..5597543 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -56,10 +56,7 @@ Conference.find_or_create_by(slug: "38c3").tap do |c| c.ends_at = DateTime.parse("30 December 2024 19:00 CET") c.data = { "schedule_url" => "https://api.events.ccc.de/congress/2024/assembly/6840c453-af5c-413c-8127-adcbdcd98e9e/schedule.json", - "filedrop" => { - "url" => "https://speakers.c3lingo.org" - } - + "filedrop_url" => "https://speakers.c3lingo.org/" } c.import_job_class = "pretalx" c.location = "Congress Center Hamburg" @@ -73,10 +70,7 @@ Conference.find_or_create_by(slug: "38c3-more").tap do |c| c.ends_at = DateTime.parse("30 December 2024 19:00 CET") c.data = { "schedule_url" => "https://api.events.ccc.de/congress/2024/assembly/6840c453-af5c-413c-8127-adcbdcd98e9e/schedule.json", - "filedrop" => { - "url" => "https://speakers.c3lingo.org", - "skip_downloads" => true - } + "filedrop_url" => "https://speakers.c3lingo.org/" } c.import_job_class = "pretalx" c.location = "Congress Center Hamburg" -- GitLab