From 017f99c88b17553133304b813fa7c3f1d32b79e6 Mon Sep 17 00:00:00 2001 From: saint Date: Tue, 2 Jul 2024 20:01:46 +1000 Subject: [PATCH] v0.26.2 Modify upload attachment code to try and make Discourse happy --- gossamer_forums.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 4b2d096..bc58951 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -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