Decode the filename form the URL

This commit is contained in:
Stanko K.R.
2025-11-18 19:39:32 +01:00
parent d574748432
commit 245c328570
+10 -1
View File
@@ -11,13 +11,22 @@ ActionText::RichText.all.where("body LIKE '%/rails/active_storage/%'").find_each
blobs = rich_text.embeds.map(&:blob)
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 }
raise "Multiple blobs with filename #{filename}" if blob.size > 1
blob = blob.first
if blob
node["sgid"] = blob.attachable_sgid
else
skipped += 1
end
end
rich_text.save!