v0.36.6 Disable TIFF support. Add other image formats. Reenable exception handling.
This commit is contained in:
parent
cd4e051367
commit
b113256986
@ -1,7 +1,7 @@
|
|||||||
# Federated Computer, Inc.
|
# Federated Computer, Inc.
|
||||||
# David Sainty <saint@federated.computer> 2024 A.D.
|
# David Sainty <saint@federated.computer> 2024 A.D.
|
||||||
# Gossamer Threads to Discourse -- Migration-Import Script
|
# 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 'mysql2'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
@ -359,7 +359,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
# Helper method to upload an attachment / image to Discourse
|
# Helper method to upload an attachment / image to Discourse
|
||||||
def upload_attachment(user_id, file, filename, gossamer_url)
|
def upload_attachment(user_id, file, filename, gossamer_url)
|
||||||
# begin
|
begin
|
||||||
|
|
||||||
# BAD
|
# BAD
|
||||||
# upload = Upload.create!(
|
# upload = Upload.create!(
|
||||||
@ -432,10 +432,10 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
# Return the upload object
|
# Return the upload object
|
||||||
upload
|
upload
|
||||||
# rescue => e
|
rescue => e
|
||||||
# puts "Failed to upload attachment #{filename} for user_id #{user_id}: #{e.message}"
|
puts "FAILURE: Failed to upload attachment #{filename} for user_id #{user_id}: #{e.message}"
|
||||||
# nil
|
nil
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper method to upload an attachment / image to Discourse
|
# Helper method to upload an attachment / image to Discourse
|
||||||
@ -610,7 +610,9 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
discourse_user.user_profile.save!
|
discourse_user.user_profile.save!
|
||||||
|
|
||||||
# Import user files
|
# Import user files
|
||||||
import_user_files(discourse_user)
|
# TEMPORARY!!
|
||||||
|
if user[:id] > 353
|
||||||
|
import_user_files(discourse_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -715,7 +717,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Ensure the file is a user image and has a supported MIME type
|
# Ensure the file is a user image and has a supported MIME type
|
||||||
next unless file['ForeignColName'] =~ /^user_image\d+$/
|
next unless file['ForeignColName'] =~ /^user_image\d+$/
|
||||||
puts "#A"
|
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"
|
puts "#B"
|
||||||
|
|
||||||
# Download the attachment
|
# Download the attachment
|
||||||
@ -730,20 +732,21 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
temp_file.rewind
|
temp_file.rewind
|
||||||
|
|
||||||
# Convert TIFF to PNG if necessary
|
# Convert TIFF to PNG if necessary
|
||||||
if file['File_MimeType'] == 'image/tiff'
|
|
||||||
begin
|
# if file['File_MimeType'] == 'image/tiff'
|
||||||
converted_tiff_to_png_path = convert_tiff_to_png(temp_file.path)
|
# begin
|
||||||
raise "Conversion of TIFF failed" if converted_tiff_to_png_path.nil?
|
# converted_tiff_to_png_path = convert_tiff_to_png(temp_file.path)
|
||||||
temp_file.close
|
# raise "Conversion of TIFF failed" if converted_tiff_to_png_path.nil?
|
||||||
temp_file.unlink
|
# temp_file.close
|
||||||
temp_file = File.open(converted_tiff_to_png_path)
|
# temp_file.unlink
|
||||||
rescue => e
|
# temp_file = File.open(converted_tiff_to_png_path)
|
||||||
puts "Skipping image due to convert failure: #{temp_file.path}"
|
# rescue => e
|
||||||
temp_file.close
|
# puts "Skipping image due to convert failure: #{temp_file.path}"
|
||||||
temp_file.unlink
|
# temp_file.close
|
||||||
next
|
# temp_file.unlink
|
||||||
end
|
# next
|
||||||
end
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
# Resize the image for the avatar / profile picture (200x200)
|
# Resize the image for the avatar / profile picture (200x200)
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user