From 3eb858bb6f1ae96fd82e6b9df3680efb4b2e58eb Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 17 Jan 2023 19:07:03 -0600 Subject: [PATCH] fixes for new html redirects --- workers/screenshot_worker.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/workers/screenshot_worker.rb b/workers/screenshot_worker.rb index 9d9ad2ea..d2433c27 100644 --- a/workers/screenshot_worker.rb +++ b/workers/screenshot_worker.rb @@ -36,6 +36,16 @@ class ScreenshotWorker path = "/#{path}" unless path[0] == '/' + path_for_screenshot = path + + if path.match(Site::HTML_REGEX) + path = path.match(/(.+)#{Site::HTML_REGEX}/).captures.first + end + + if path.match(/(.+)index?/) + path = path.match(/(.+)index?/).captures.first + end + uri = Addressable::URI.parse $config['screenshot_urls'].sample api_user, api_password = uri.user, uri.password uri = "#{uri.scheme}://#{uri.host}:#{uri.port}" + '?' + Rack::Utils.build_query( @@ -49,7 +59,7 @@ class ScreenshotWorker image = Rszr::Image.load base_image_tmpfile_path user_screenshots_path = File.join SCREENSHOTS_PATH, Site.sharding_dir(username), username - screenshot_path = File.join user_screenshots_path, File.dirname(path) + screenshot_path = File.join user_screenshots_path, File.dirname(path_for_screenshot) FileUtils.mkdir_p screenshot_path unless Dir.exist?(screenshot_path) @@ -62,7 +72,7 @@ class ScreenshotWorker new_img = image.resize width, height end - full_screenshot_path = File.join(user_screenshots_path, "#{path}.#{res}.jpg") + full_screenshot_path = File.join(user_screenshots_path, "#{path_for_screenshot}.#{res}.jpg") tmpfile_path = "/tmp/#{SecureRandom.uuid}.jpg" begin