Decode the filename form the URL
This commit is contained in:
@@ -11,13 +11,22 @@ ActionText::RichText.all.where("body LIKE '%/rails/active_storage/%'").find_each
|
|||||||
blobs = rich_text.embeds.map(&:blob)
|
blobs = rich_text.embeds.map(&:blob)
|
||||||
|
|
||||||
rich_text.body.send(:attachment_nodes).each do |node|
|
rich_text.body.send(:attachment_nodes).each do |node|
|
||||||
filename = node["filename"]
|
url = node["url"]
|
||||||
|
next unless url
|
||||||
|
|
||||||
|
url_encoded_filename = url.split("/").last
|
||||||
|
filename = URI.decode_www_form_component(url_encoded_filename)
|
||||||
|
|
||||||
|
counter += 1
|
||||||
blob = blobs.select { |b| b.filename == filename }
|
blob = blobs.select { |b| b.filename == filename }
|
||||||
raise "Multiple blobs with filename #{filename}" if blob.size > 1
|
raise "Multiple blobs with filename #{filename}" if blob.size > 1
|
||||||
blob = blob.first
|
blob = blob.first
|
||||||
|
|
||||||
node["sgid"] = blob.attachable_sgid
|
if blob
|
||||||
|
node["sgid"] = blob.attachable_sgid
|
||||||
|
else
|
||||||
|
skipped += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rich_text.save!
|
rich_text.save!
|
||||||
|
|||||||
Reference in New Issue
Block a user