A platform for community discussion. Free, open, simple.
FIX: Do not try to recover invalid `Upload#short_url` in `UploadRecovery`.
Guo Xiang Tan5eb65ad612ae
diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rbindex 70021d29ac4..8eb1e7725a8 100644--- a/lib/upload_recovery.rb+++ b/lib/upload_recovery.rb@@ -34,9 +34,12 @@ class UploadRecoveryprivatedef recover_post_upload(post, short_url)+ sha1 = Upload.sha1_from_short_url(short_url)+ return unless sha1.present?+attributes = {post: post,- sha1: Upload.sha1_from_short_url(short_url)+ sha1: sha1}if Discourse.store.external?@@ -47,8 +50,6 @@ class UploadRecoveryenddef recover_from_local(post:, sha1:)- return unless sha1.present?-public_path = Rails.root.join("public")@paths ||= begindiff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rbindex 1d3f74a9d55..01334c5e7e5 100644--- a/spec/lib/upload_recovery_spec.rb+++ b/spec/lib/upload_recovery_spec.rb@@ -18,31 +18,45 @@ RSpec.describe UploadRecovery do).tap(&:link_post_uploads)end+ let(:upload_recovery) { UploadRecovery.new }+before doSiteSetting.queue_jobs = falseenddescribe '#recover' do- it 'should recover the upload' do- begin- stub_request(:get, "http://test.localhost#{upload.url}")- .to_return(status: 200)-- expect do- upload.destroy!- end.to change { post.reload.uploads.count }.from(1).to(0)-- expect do- UploadRecovery.new.recover- end.to change { post.reload.uploads.count }.from(0).to(1)- ensure- public_path = "#{Discourse.store.public_dir}#{upload.url}"-- [- public_path,- public_path.sub("uploads", "uploads/tombstone")- ].each { |path| File.delete(path) if File.exists?(path) }+ after do+ public_path = "#{Discourse.store.public_dir}#{upload.url}"++ [+ public_path,+ public_path.sub("uploads", "uploads/tombstone")+ ].each { |path| File.delete(path) if File.exists?(path) }+ end++ describe 'when given an invalid sha1' do+ it 'should not do anything' do+ upload_recovery.expects(:recover_from_local).never++ post.update!(+ raw: ""+ )++ upload_recovery.recoverendend++ it 'should recover the upload' do+ stub_request(:get, "http://test.localhost#{upload.url}")+ .to_return(status: 200)++ expect do+ upload.destroy!+ end.to change { post.reload.uploads.count }.from(1).to(0)++ expect do+ upload_recovery.recover+ end.to change { post.reload.uploads.count }.from(0).to(1)+ endendend