I think either of those should work. However you can get those images to the new site, they should generate the same sha so that will magically make the existing links in the topics work.
Maybe you could do something like
cat_id=123
Topic.where(category_id: cat_id).each do| t|
Post.where(topic_id: t.id) do |p|
p.cooked.match(image url)....
puts(the match)
And I think if you do that and paste those links into a post anywhere on your site it should download all of those images to local and make the same sha, so then those links. You can try a couple by hand to see.
It’s the middle of the night. Your mileage may vary.