v0.26.2 Modify upload attachment code to try and make Discourse happy
This commit is contained in:
parent
382fd239a2
commit
017f99c88b
@ -1,5 +1,5 @@
|
||||
# gossamer threads migration-import code
|
||||
# v0.26
|
||||
# v0.26.2
|
||||
|
||||
require 'mysql2'
|
||||
require 'open-uri'
|
||||
@ -359,28 +359,36 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
|
||||
# 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
|
||||
|
||||
# Generate SHA1 hash for the file
|
||||
sha1 = Digest::SHA1.file(file.path).hexdigest
|
||||
|
||||
# upload = Upload.create!(
|
||||
upload = Upload.new(
|
||||
user_id: user_id,
|
||||
original_filename: filename,
|
||||
filesize: file.size,
|
||||
sha1: Digest::SHA1.file(file.path).hexdigest
|
||||
sha1: sha1,
|
||||
url: gossamer_url
|
||||
# content_type: content_type,
|
||||
# origin: 'composer',
|
||||
# retain_hours: nil
|
||||
)
|
||||
|
||||
# Use Discourse's internal method to upload the file
|
||||
file.rewind
|
||||
Discourse.store.upload(file, upload.sha1)
|
||||
# Use FileStore::LocalStore to store the file
|
||||
store = FileStore::LocalStore.new
|
||||
upload.url = store.store_file(file, store.get_path_for('original', upload.id, upload.sha1, File.extname(file.path)))
|
||||
|
||||
# # Use Discourse's internal method to upload the file
|
||||
# file.rewind
|
||||
# Discourse.store.upload(file, upload.sha1)
|
||||
|
||||
# # Move the file to the correct location
|
||||
# upload_path = Upload.get_path_for_file(upload.sha1)
|
||||
# FileUtils.mkdir_p(File.dirname(upload_path))
|
||||
# FileUtils.mv(file.path, upload.path)
|
||||
|
||||
# Save the upload object
|
||||
upload.save!
|
||||
upload
|
||||
rescue => e
|
||||
|
Loading…
Reference in New Issue
Block a user