cloudflare: fix purging of cached urls.

* Switch CloudflareService from HttpartyCache to Danbooru::Http.

* Purge cached urls from Cloudflare when a post is replaced and the md5
  doesn't change. This happens when a corrupted image is replaced or
  thumbnails are regenerated. Before we purged urls when a post was
  expunged, which was unneeded because those urls can expire naturally.
  It was also wrong because the subdomains were hardcoded, the urls used
  http:// instead of https://, and we didn't account for tagged urls.
This commit is contained in:
evazion
2019-12-15 14:03:15 -06:00
parent 15d737d68b
commit 518de2fdec
4 changed files with 37 additions and 39 deletions

View File

@@ -123,6 +123,8 @@ class UploadService
CurrentUser.as(User.system) do
post.comments.create!(body: comment_replacement_message(post, replacement), do_not_bump_post: true)
end
else
purge_cached_urls(post)
end
replacement.save!
@@ -131,6 +133,18 @@ class UploadService
post.update_iqdb_async
end
def purge_cached_urls(post)
urls = [
post.preview_file_url,
post.large_file_url,
post.file_url,
post.tagged_large_file_url,
post.tagged_file_url
]
CloudflareService.new.purge_cache(urls)
end
def rescale_notes(post)
x_scale = post.image_width.to_f / post.image_width_was.to_f
y_scale = post.image_height.to_f / post.image_height_was.to_f