13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/upload_recovery.rb', line 13
def recover_post(post)
begin
analyzer = PostAnalyzer.new(post.raw, post.topic_id)
analyzer
.cooked_stripped
.css("img", "a")
.each do |media|
if media.name == "img" && orig_src = media["data-orig-src"]
if dom_class = media["class"]
next if (Post.allowed_image_classes & dom_class.split).count > 0
end
if @dry_run
puts "#{post.full_url} #{orig_src}"
else
recover_post_upload(post, Upload.sha1_from_short_url(orig_src))
end
elsif url = (media["href"] || media["src"])
data = Upload.(url)
next unless data
upload = Upload.get_from_url(url)
if !upload || upload.verification_status == Upload.verification_statuses[:invalid_etag]
if @dry_run
puts "#{post.full_url} #{url}"
else
sha1 = data[2]
recover_post_upload(post, sha1)
end
end
end
end
rescue => e
raise e if @stop_on_error
puts "#{post.full_url} #{e.class}: #{e.message}"
end
end
|