From 245c3285704cbc3999c379c906e504baae50c2ac Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Tue, 18 Nov 2025 19:39:32 +0100 Subject: [PATCH] Decode the filename form the URL --- script/fix-active-storage-links.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/script/fix-active-storage-links.rb b/script/fix-active-storage-links.rb index 2fa66bbfd..d2cb856bf 100644 --- a/script/fix-active-storage-links.rb +++ b/script/fix-active-storage-links.rb @@ -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 - node["sgid"] = blob.attachable_sgid + if blob + node["sgid"] = blob.attachable_sgid + else + skipped += 1 + end end rich_text.save!