FEATURE: use original filename when clicking the download link in the lightbox
This commit is contained in:
parent
4762b4ac24
commit
31e9cafe0e
|
@ -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', '×'),
|
||||
'<a class="image-source-link" href="' + item.src + '" target="_blank">' + I18n.t("lightbox.download") + '</a>'
|
||||
'<a class="image-source-link" href="' + href + '">' + I18n.t("lightbox.download") + '</a>'
|
||||
].join(' · ');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,9 @@ module FileStore
|
|||
def relative_base_url
|
||||
end
|
||||
|
||||
def download_url(upload)
|
||||
end
|
||||
|
||||
def external?
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/home/regis/Poetry/discourse/plugins/emoji/public
|
|
@ -90,7 +90,7 @@ describe CookedPostProcessor do
|
|||
|
||||
it "generates overlay information" do
|
||||
cpp.post_process_images
|
||||
cpp.html.should match_html '<div class="lightbox-wrapper"><a href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/_optimized/da3/9a3/ee5e6b4b0d_690x1380.png" width="690" height="1380"><div class="meta">
|
||||
cpp.html.should match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/_optimized/da3/9a3/ee5e6b4b0d_690x1380.png" width="690" height="1380"><div class="meta">
|
||||
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
||||
</div></a></div>'
|
||||
cpp.should be_dirty
|
||||
|
|
Loading…
Reference in New Issue