From 1b14545d0db8b4b44c50c274ab9e4e284182df1f Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 6 Apr 2018 21:18:46 -0500 Subject: [PATCH] Fix #3603: Unable to view images on Hijiribe/Sonohara when Danbooru domain is blocked. --- app/controllers/application_controller.rb | 1 + app/logical/current_user.rb | 8 ++++++++ app/logical/storage_manager.rb | 2 +- config/danbooru_default_config.rb | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1dfeccf3972..5b4c3968b5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -172,6 +172,7 @@ def set_current_user def reset_current_user CurrentUser.user = nil CurrentUser.ip_addr = nil + CurrentUser.root_url = root_url end def set_started_at_session diff --git a/app/logical/current_user.rb b/app/logical/current_user.rb index 194a721b3f2..5d60eb78a5c 100644 --- a/app/logical/current_user.rb +++ b/app/logical/current_user.rb @@ -48,6 +48,14 @@ def self.ip_addr Thread.current[:current_ip_addr] end + def self.root_url + Thread.current[:current_root_url] || "http://#{Danbooru.config.hostname}/" + end + + def self.root_url=(root_url) + Thread.current[:current_root_url] = root_url + end + def self.id if user.nil? nil diff --git a/app/logical/storage_manager.rb b/app/logical/storage_manager.rb index dcc2b044ce6..3f8c54dc182 100644 --- a/app/logical/storage_manager.rb +++ b/app/logical/storage_manager.rb @@ -14,7 +14,7 @@ def initialize(base_url: default_base_url, base_dir: DEFAULT_BASE_DIR, hierarchi end def default_base_url - Rails.application.routes.url_helpers.root_url + "data" + CurrentUser.root_url + "data" end # Store the given file at the given path. If a file already exists at that diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 2468ea4e3ad..c4295da776b 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -230,7 +230,7 @@ def storage_manager # base_url - where to serve files from (default: http://#{hostname}/data) # hierarchical: false - store files in a single directory # hierarchical: true - store files in a hierarchical directory structure, based on the MD5 hash - StorageManager::Local.new(base_dir: "#{Rails.root}/public/data", hierarchical: false) + StorageManager::Local.new(base_url: CurrentUser.root_url + "data", base_dir: "#{Rails.root}/public/data", hierarchical: false) # Store files on one or more remote host(s). Configure SSH settings in # ~/.ssh_config or in the ssh_options param (ref: http://net-ssh.github.io/net-ssh/Net/SSH.html#method-c-start)