DEV: improve uploads:recover job so it stores a map of old to new sha
Previous attempt created broken images
This commit is contained in:
parent
ebcb571de7
commit
e8799f0ba4
|
@ -894,6 +894,18 @@ def inline_uploads(post)
|
|||
|
||||
post.raw = post.raw.gsub(/(\((\/uploads\S+).*\))/) do
|
||||
upload = Upload.find_by(url: $2)
|
||||
if !upload
|
||||
data = Upload.extract_url($2)
|
||||
if data && sha1 = data[2]
|
||||
upload = Upload.find_by(sha1: sha1)
|
||||
if !upload
|
||||
sha_map = JSON.parse(post.custom_fields["UPLOAD_SHA1_MAP"] || "{}")
|
||||
if mapped_sha = sha_map[sha1]
|
||||
upload = Upload.find_by(sha1: mapped_sha)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result = $1
|
||||
|
||||
if upload&.id
|
||||
|
|
|
@ -67,9 +67,14 @@ class UploadRecovery
|
|||
return if !upload.persisted?
|
||||
|
||||
if upload.sha1 != sha1
|
||||
STDERR.puts "Warning #{post.url} had an incorrect sha, remapping #{sha1} to #{upload.sha1}"
|
||||
post.raw = post.raw.gsub(sha1, upload.sha1)
|
||||
post.save!
|
||||
STDERR.puts "Warning #{post.url} had an incorrect #{sha1} should be #{upload.sha1} storing in custom field 'rake uploads:fix_relative_upload_links' can fix this"
|
||||
|
||||
sha_map = post.custom_fields["UPLOAD_SHA1_MAP"] || "{}"
|
||||
sha_map = JSON.parse(sha_map)
|
||||
sha_map[sha1] = upload.sha1
|
||||
|
||||
post.custom_fields["UPLOAD_SHA1_MAP"] = sha_map.to_json
|
||||
post.save_custom_fields
|
||||
end
|
||||
|
||||
post.rebake!
|
||||
|
|
Loading…
Reference in New Issue