mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
add download_remote_images_to_local site setting
This commit is contained in:
@ -8,8 +8,7 @@ module Jobs
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
# we don't want to run the job if we're not allowed to crawl images
|
return unless SiteSetting.download_remote_images_to_local?
|
||||||
return unless SiteSetting.crawl_images?
|
|
||||||
|
|
||||||
post_id = args[:post_id]
|
post_id = args[:post_id]
|
||||||
raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
|
raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
|
||||||
|
@ -500,6 +500,7 @@ en:
|
|||||||
company_domain: "The domain name owned by the company that runs this site, used in legal documents like the /tos"
|
company_domain: "The domain name owned by the company that runs this site, used in legal documents like the /tos"
|
||||||
queue_jobs: "DEVELOPER ONLY! WARNING! By default, queue jobs in sidekiq. If disabled, your site will be broken."
|
queue_jobs: "DEVELOPER ONLY! WARNING! By default, queue jobs in sidekiq. If disabled, your site will be broken."
|
||||||
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
|
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
|
||||||
|
download_remote_images_to_local: "Download a copy of all remote images"
|
||||||
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
|
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
|
||||||
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view edit history."
|
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view edit history."
|
||||||
delete_removed_posts_after: "Number of hours after which posts removed by the author will be deleted."
|
delete_removed_posts_after: "Number of hours after which posts removed by the author will be deleted."
|
||||||
|
@ -249,6 +249,10 @@ files:
|
|||||||
default: false
|
default: false
|
||||||
detect_custom_avatars: true
|
detect_custom_avatars: true
|
||||||
max_daily_gravatar_crawls: 500
|
max_daily_gravatar_crawls: 500
|
||||||
|
download_remote_images_to_local:
|
||||||
|
default:
|
||||||
|
test: false
|
||||||
|
default: true
|
||||||
|
|
||||||
trust:
|
trust:
|
||||||
default_trust_level: 0
|
default_trust_level: 0
|
||||||
|
@ -219,8 +219,8 @@ class CookedPostProcessor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pull_hotlinked_images
|
def pull_hotlinked_images
|
||||||
# we don't want to run the job if we're not allowed to crawl images
|
# is the job enabled?
|
||||||
return unless SiteSetting.crawl_images?
|
return unless SiteSetting.download_remote_images_to_local?
|
||||||
# we only want to run the job whenever it's changed by a user
|
# we only want to run the job whenever it's changed by a user
|
||||||
return if @post.updated_by == Discourse.system_user
|
return if @post.updated_by == Discourse.system_user
|
||||||
# make sure no other job is scheduled
|
# make sure no other job is scheduled
|
||||||
|
@ -275,15 +275,15 @@ describe CookedPostProcessor do
|
|||||||
let(:post) { build(:post) }
|
let(:post) { build(:post) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
it "does not run when crawl images is disabled" do
|
it "does not run when download_remote_images_to_local is disabled" do
|
||||||
SiteSetting.stubs(:crawl_images).returns(false)
|
SiteSetting.stubs(:download_remote_images_to_local).returns(false)
|
||||||
Jobs.expects(:cancel_scheduled_job).never
|
Jobs.expects(:cancel_scheduled_job).never
|
||||||
cpp.pull_hotlinked_images
|
cpp.pull_hotlinked_images
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when crawl_images? is enabled" do
|
context "when download_remote_images_to_local? is enabled" do
|
||||||
|
|
||||||
before { SiteSetting.stubs(:crawl_images).returns(true) }
|
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) }
|
||||||
|
|
||||||
it "runs only when a user updated the post" do
|
it "runs only when a user updated the post" do
|
||||||
post.updated_by = Discourse.system_user
|
post.updated_by = Discourse.system_user
|
||||||
|
Reference in New Issue
Block a user