Skip to content

Commit 16267e4

Browse files
committed
add download_remote_images_to_local site setting
1 parent 6a3000f commit 16267e4

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

app/jobs/regular/pull_hotlinked_images.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ def initialize
88
end
99

1010
def execute(args)
11-
# we don't want to run the job if we're not allowed to crawl images
12-
return unless SiteSetting.crawl_images?
11+
return unless SiteSetting.download_remote_images_to_local?
1312

1413
post_id = args[:post_id]
1514
raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ en:
500500
company_domain: "The domain name owned by the company that runs this site, used in legal documents like the /tos"
501501
queue_jobs: "DEVELOPER ONLY! WARNING! By default, queue jobs in sidekiq. If disabled, your site will be broken."
502502
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
503+
download_remote_images_to_local: "Download a copy of all remote images"
503504
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
504505
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view edit history."
505506
delete_removed_posts_after: "Number of hours after which posts removed by the author will be deleted."

config/site_settings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ files:
249249
default: false
250250
detect_custom_avatars: true
251251
max_daily_gravatar_crawls: 500
252+
download_remote_images_to_local:
253+
default:
254+
test: false
255+
default: true
252256

253257
trust:
254258
default_trust_level: 0

lib/cooked_post_processor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def schemaless(url)
219219
end
220220

221221
def pull_hotlinked_images
222-
# we don't want to run the job if we're not allowed to crawl images
223-
return unless SiteSetting.crawl_images?
222+
# is the job enabled?
223+
return unless SiteSetting.download_remote_images_to_local?
224224
# we only want to run the job whenever it's changed by a user
225225
return if @post.updated_by == Discourse.system_user
226226
# make sure no other job is scheduled

spec/components/cooked_post_processor_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@
275275
let(:post) { build(:post) }
276276
let(:cpp) { CookedPostProcessor.new(post) }
277277

278-
it "does not run when crawl images is disabled" do
279-
SiteSetting.stubs(:crawl_images).returns(false)
278+
it "does not run when download_remote_images_to_local is disabled" do
279+
SiteSetting.stubs(:download_remote_images_to_local).returns(false)
280280
Jobs.expects(:cancel_scheduled_job).never
281281
cpp.pull_hotlinked_images
282282
end
283283

284-
context "when crawl_images? is enabled" do
284+
context "when download_remote_images_to_local? is enabled" do
285285

286-
before { SiteSetting.stubs(:crawl_images).returns(true) }
286+
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) }
287287

288288
it "runs only when a user updated the post" do
289289
post.updated_by = Discourse.system_user

0 commit comments

Comments
 (0)