From b1132569868568fc287146ce68e5a003033163e5 Mon Sep 17 00:00:00 2001 From: saint Date: Thu, 15 Aug 2024 01:26:38 +1000 Subject: [PATCH] v0.36.6 Disable TIFF support. Add other image formats. Reenable exception handling. --- gossamer_forums.rb | 47 ++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index e51d14d..4a5eda5 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- Migration-Import Script -# v0.36.5 Rewrite broken upload_attachment due to 3.2.5 handling things differently +# v0.36.6 Disable TIFF support for now. It was a minor corner case to support. Added other image types. Added exception handling back to user image handling. require 'mysql2' require 'open-uri' @@ -359,7 +359,7 @@ class GossamerForumsImporter < ImportScripts::Base # Helper method to upload an attachment / image to Discourse def upload_attachment(user_id, file, filename, gossamer_url) -# begin + begin # BAD # upload = Upload.create!( @@ -432,10 +432,10 @@ class GossamerForumsImporter < ImportScripts::Base # Return the upload object upload -# rescue => e -# puts "Failed to upload attachment #{filename} for user_id #{user_id}: #{e.message}" -# nil -# end + rescue => e + puts "FAILURE: Failed to upload attachment #{filename} for user_id #{user_id}: #{e.message}" + nil + end end # Helper method to upload an attachment / image to Discourse @@ -610,7 +610,9 @@ class GossamerForumsImporter < ImportScripts::Base discourse_user.user_profile.save! # Import user files - import_user_files(discourse_user) +# TEMPORARY!! + if user[:id] > 353 + import_user_files(discourse_user) end end @@ -715,7 +717,7 @@ class GossamerForumsImporter < ImportScripts::Base # Ensure the file is a user image and has a supported MIME type next unless file['ForeignColName'] =~ /^user_image\d+$/ puts "#A" - next unless ['image/jpeg', 'image/png', 'image/gif', 'image/tiff'].include?(file['File_MimeType']) + next unless ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/heif', 'image/heic'].include?(file['File_MimeType']) puts "#B" # Download the attachment @@ -730,20 +732,21 @@ class GossamerForumsImporter < ImportScripts::Base temp_file.rewind # Convert TIFF to PNG if necessary - if file['File_MimeType'] == 'image/tiff' - begin - converted_tiff_to_png_path = convert_tiff_to_png(temp_file.path) - raise "Conversion of TIFF failed" if converted_tiff_to_png_path.nil? - temp_file.close - temp_file.unlink - temp_file = File.open(converted_tiff_to_png_path) - rescue => e - puts "Skipping image due to convert failure: #{temp_file.path}" - temp_file.close - temp_file.unlink - next - end - end + +# if file['File_MimeType'] == 'image/tiff' +# begin +# converted_tiff_to_png_path = convert_tiff_to_png(temp_file.path) +# raise "Conversion of TIFF failed" if converted_tiff_to_png_path.nil? +# temp_file.close +# temp_file.unlink +# temp_file = File.open(converted_tiff_to_png_path) +# rescue => e +# puts "Skipping image due to convert failure: #{temp_file.path}" +# temp_file.close +# temp_file.unlink +# next +# end +# end # Resize the image for the avatar / profile picture (200x200) begin