diff --git a/app/assets/javascripts/discourse/lib/lightbox.js b/app/assets/javascripts/discourse/lib/lightbox.js index 1b5a870bb3d..50185f26393 100644 --- a/app/assets/javascripts/discourse/lib/lightbox.js +++ b/app/assets/javascripts/discourse/lib/lightbox.js @@ -36,10 +36,11 @@ Discourse.Lightbox = { image: { titleSrc: function(item) { + var href = item.el.data("download-href") || item.src; return [ item.el.attr("title"), $("span.informations", item.el).text().replace('x', '×'), - '' + I18n.t("lightbox.download") + '' + '' + I18n.t("lightbox.download") + '' ].join(' · '); } } diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 719d4f79519..b58bc337970 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -159,6 +159,11 @@ class CookedPostProcessor # then, the link to our larger image a = Nokogiri::XML::Node.new("a", @doc) img.add_next_sibling(a) + + if upload && Discourse.store.internal? + a["data-download-href"] = Discourse.store.download_url(upload) + end + a["href"] = img["src"] a["class"] = "lightbox" a.add_child(img) @@ -217,9 +222,11 @@ class CookedPostProcessor end def optimize_urls - @doc.css("a[href]").each do |a| - href = a["href"].to_s - a["href"] = schemaless absolute(href) if is_local(href) + %w{href data-download-href}.each do |selector| + @doc.css("a[#{selector}]").each do |a| + href = a["#{selector}"].to_s + a["#{selector}"] = schemaless absolute(href) if is_local(href) + end end @doc.css("img[src]").each do |img| @@ -243,17 +250,17 @@ class CookedPostProcessor end def disable_if_low_on_disk_space - if available_disk_space < SiteSetting.download_remote_images_threshold - SiteSetting.download_remote_images_to_local = false - # log the site setting change - reason = I18n.t("disable_remote_images_download_reason") - staff_action_logger = StaffActionLogger.new(Discourse.system_user) - staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason }) - # also send a private message to the site contact user - SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled) - return true - end - false + return false if available_disk_space >= SiteSetting.download_remote_images_threshold + + SiteSetting.download_remote_images_to_local = false + # log the site setting change + reason = I18n.t("disable_remote_images_download_reason") + staff_action_logger = StaffActionLogger.new(Discourse.system_user) + staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason }) + # also send a private message to the site contact user + SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled) + + true end def available_disk_space diff --git a/lib/file_store/base_store.rb b/lib/file_store/base_store.rb index a89e8d60483..74df43e1815 100644 --- a/lib/file_store/base_store.rb +++ b/lib/file_store/base_store.rb @@ -23,6 +23,9 @@ module FileStore def relative_base_url end + def download_url(upload) + end + def external? end diff --git a/lib/file_store/local_store.rb b/lib/file_store/local_store.rb index 2986d82122f..9fbffa80015 100644 --- a/lib/file_store/local_store.rb +++ b/lib/file_store/local_store.rb @@ -34,6 +34,11 @@ module FileStore "/uploads/#{RailsMultisite::ConnectionManagement.current_db}" end + def download_url(upload) + return unless upload + "#{relative_base_url}/#{upload.sha1}" + end + def external? !internal? end diff --git a/plugins/emoji/public/public b/plugins/emoji/public/public new file mode 120000 index 00000000000..9c898b22a7b --- /dev/null +++ b/plugins/emoji/public/public @@ -0,0 +1 @@ +/home/regis/Poetry/discourse/plugins/emoji/public \ No newline at end of file diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 53f1501b307..fd8ba3a7334 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -90,7 +90,7 @@ describe CookedPostProcessor do it "generates overlay information" do cpp.post_process_images - cpp.html.should match_html '