From 6077ac013bd3d5024494233dae9241474f846f04 Mon Sep 17 00:00:00 2001 From: Simon Cossar Date: Sun, 15 May 2016 23:12:05 -0700 Subject: [PATCH] FIX[WIP]: return correct path for uploads stored on s3 (#4222) * return correct path for uploads stored on s3 * rename method --- .../javascripts/discourse/lib/utilities.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/utilities.js b/app/assets/javascripts/discourse/lib/utilities.js index 374cfbaf4..16fb66b63 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js +++ b/app/assets/javascripts/discourse/lib/utilities.js @@ -249,16 +249,25 @@ Discourse.Utilities = { .join(", "); }, + uploadLocation: function(url) { + if (Discourse.CDN) { + return Discourse.CDN.startsWith('//') ? "http:" + Discourse.getURLWithCDN(url) : Discourse.getURLWithCDN(url); + } else if (Discourse.SiteSettings.enable_s3_uploads) { + return 'https:' + url; + } else { + var protocol = window.location.protocol + '//', + hostname = window.location.hostname, + port = ':' + window.location.port; + return protocol + hostname + port + url; + } + }, + getUploadMarkdown: function(upload) { if (Discourse.Utilities.isAnImage(upload.original_filename)) { return ''; } else if (!Discourse.SiteSettings.prevent_anons_from_downloading_files && (/\.(mov|mp4|webm|ogv|mp3|ogg|wav)$/i).test(upload.original_filename)) { // is Audio/Video - if (Discourse.CDN) { - return Discourse.CDN.startsWith('//') ? "http:" + Discourse.getURLWithCDN(upload.url) : Discourse.getURLWithCDN(upload.url); - } else { - return "http://" + Discourse.BaseUrl + upload.url; - } + return Discourse.Utilities.uploadLocation(upload.url); } else { return '' + upload.original_filename + ' (' + I18n.toHumanSize(upload.filesize) + ')'; }