Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
lightbox: Make the "download" link use the new download endpoint.
Alex Vandiverb9e428dd5d26
diff --git a/static/js/lightbox.js b/static/js/lightbox.jsindex c083587898d..ceb5ac547f3 100644--- a/static/js/lightbox.js+++ b/static/js/lightbox.js@@ -217,7 +217,22 @@ function display_image(payload) {.prop("data-filename", filename || "N/A");$(".image-description .user").text(payload.user).prop("title", payload.user);- $(".image-actions .open, .image-actions .download").attr("href", payload.source);+ $(".image-actions .open").attr("href", payload.source);++ const url = new URL(payload.source, window.location.href);+ const same_origin = url.origin === window.location.origin;+ if (same_origin && url.pathname.startsWith("/user_uploads/")) {+ // Switch to the "download" handler, so S3 URLs set their Content-Disposition+ url.pathname = "/user_uploads/download/" + url.pathname.slice("/user_uploads/".length);+ $(".image-actions .download").attr("href", url.href);+ } else if (same_origin) {+ $(".image-actions .download").attr("href", payload.source);+ } else {+ // If it's not same-origin, and we don't know how to tell the remote service to put a+ // content-disposition on it, the download can't possibly download, just show -- so hide the+ // element.+ $(".image-actions .download").hide();+ }}function display_video(payload) {