v0.25 Post image handling tweaks
This commit is contained in:
parent
779575c1b4
commit
1600e91ba4
@ -1,5 +1,5 @@
|
||||
# gossamer threads migration-import code
|
||||
# v0.24
|
||||
# v0.25
|
||||
|
||||
require 'mysql2'
|
||||
require 'open-uri'
|
||||
@ -351,21 +351,25 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
# # Error -- non-existent method upload.ensure_consistency!
|
||||
|
||||
# Use the correct content type and SHA1 hash for the upload
|
||||
content_type = `file --brief --mime-type #{file.path}`.strip
|
||||
sha1 = Digest::SHA1.file(file.path).hexdigest
|
||||
# content_type = `file --brief --mime-type #{file.path}`.strip
|
||||
# sha1 = Digest::SHA1.file(file.path).hexdigest
|
||||
|
||||
upload = Upload.create!(
|
||||
# upload = Upload.create!(
|
||||
upload = Upload.new(
|
||||
user_id: user_id,
|
||||
original_filename: filename,
|
||||
filesize: file.size,
|
||||
content_type: content_type,
|
||||
sha1: sha1,
|
||||
origin: 'composer',
|
||||
retain_hours: nil
|
||||
sha1: Digest::SHA1.file(file.path).hexdigest
|
||||
# content_type: content_type,
|
||||
# origin: 'composer',
|
||||
# retain_hours: nil
|
||||
)
|
||||
|
||||
# Move the file to the correct location
|
||||
FileUtils.mv(file.path, upload.path)
|
||||
upload_path = Upload.get_path_for_file(upload.sha1)
|
||||
FileUtils.mkdir_p(File.dirname(upload_path))
|
||||
FileUtils.mv(file.path, upload_path)
|
||||
# FileUtils.mv(file.path, upload.path)
|
||||
|
||||
upload.save!
|
||||
upload
|
||||
@ -384,6 +388,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
next unless attachment_data
|
||||
|
||||
mime_type = att_row['postatt_content']
|
||||
|
||||
temp_file = Tempfile.new(['attachment', File.extname(att_row['postatt_filename'])])
|
||||
temp_file.binmode
|
||||
temp_file.write(attachment_data)
|
||||
@ -393,11 +398,9 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
upload = upload_attachment(user_id, temp_file, att_row['postatt_filename'], attachment_url)
|
||||
next unless upload
|
||||
|
||||
# BAD
|
||||
# upload_url = upload.url
|
||||
|
||||
# Get the URL of the uploaded file from Discourse
|
||||
upload_url = Upload.get_from_url(upload.url).url
|
||||
# upload_url = Upload.get_from_url(upload.url).url
|
||||
upload_url = upload.url
|
||||
|
||||
puts "Appending to post.raw... #{upload_url} MIME type: #{mime_type}"
|
||||
if mime_type.start_with?('image/')
|
||||
|
Loading…
Reference in New Issue
Block a user