mirror of
https://github.com/discourse/discourse.git
synced 2025-03-02 17:29:25 +00:00
FIX: UploadRecovery
should look through posts for img src and bbcode.
This commit is contained in:
parent
1f9799c979
commit
6a95d3fded
@ -15,34 +15,29 @@ class UploadRecovery
|
|||||||
analyzer = PostAnalyzer.new(post.raw, post.topic_id)
|
analyzer = PostAnalyzer.new(post.raw, post.topic_id)
|
||||||
|
|
||||||
analyzer.cooked_stripped.css("img", "a").each do |media|
|
analyzer.cooked_stripped.css("img", "a").each do |media|
|
||||||
if media.name == "img"
|
if media.name == "img" && orig_src = media["data-orig-src"]
|
||||||
if dom_class = media["class"]
|
if dom_class = media["class"]
|
||||||
if (Post.white_listed_image_classes & dom_class.split).count > 0
|
if (Post.white_listed_image_classes & dom_class.split).count > 0
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
orig_src = media["data-orig-src"]
|
if @dry_run
|
||||||
|
puts "#{post.full_url} #{orig_src}"
|
||||||
if orig_src
|
else
|
||||||
if @dry_run
|
recover_post_upload(post, Upload.sha1_from_short_url(orig_src))
|
||||||
puts "#{post.full_url} #{orig_src}"
|
|
||||||
else
|
|
||||||
recover_post_upload(post, Upload.sha1_from_short_url(orig_src))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elsif media.name == "a"
|
elsif url = (media["href"] || media["src"])
|
||||||
href = media["href"]
|
data = Upload.extract_upload_url(url)
|
||||||
|
next unless data
|
||||||
|
|
||||||
if href && data = Upload.extract_upload_url(href)
|
sha1 = data[2]
|
||||||
sha1 = data[2]
|
|
||||||
|
|
||||||
unless upload = Upload.get_from_url(href)
|
unless upload = Upload.get_from_url(url)
|
||||||
if @dry_run
|
if @dry_run
|
||||||
puts "#{post.full_url} #{href}"
|
puts "#{post.full_url} #{url}"
|
||||||
else
|
else
|
||||||
recover_post_upload(post, sha1)
|
recover_post_upload(post, sha1)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -113,6 +113,60 @@ RSpec.describe UploadRecovery do
|
|||||||
expect(File.read(Discourse.store.path_for(post.uploads.first)))
|
expect(File.read(Discourse.store.path_for(post.uploads.first)))
|
||||||
.to eq(File.read(file_from_fixtures("smallest.png")))
|
.to eq(File.read(file_from_fixtures("smallest.png")))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'image tag' do
|
||||||
|
let(:post) do
|
||||||
|
Fabricate(:post,
|
||||||
|
raw: <<~SQL,
|
||||||
|
<img src='#{upload.url}'>
|
||||||
|
SQL
|
||||||
|
user: user
|
||||||
|
).tap(&:link_post_uploads)
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
expect(File.read(Discourse.store.path_for(post.uploads.first)))
|
||||||
|
.to eq(File.read(file_from_fixtures("smallest.png")))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'bbcode' do
|
||||||
|
let(:post) do
|
||||||
|
Fabricate(:post,
|
||||||
|
raw: <<~SQL,
|
||||||
|
[img]#{upload.url}[/img]
|
||||||
|
SQL
|
||||||
|
user: user
|
||||||
|
).tap(&:link_post_uploads)
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
expect(File.read(Discourse.store.path_for(post.uploads.first)))
|
||||||
|
.to eq(File.read(file_from_fixtures("smallest.png")))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#recover_user_profile_backgrounds" do
|
describe "#recover_user_profile_backgrounds" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user