diff --git a/app/assets/javascripts/pretty-text/addon/upload-short-url.js b/app/assets/javascripts/pretty-text/addon/upload-short-url.js index 070881fdc4a..c8f8c723d8a 100644 --- a/app/assets/javascripts/pretty-text/addon/upload-short-url.js +++ b/app/assets/javascripts/pretty-text/addon/upload-short-url.js @@ -144,8 +144,8 @@ function _loadCachedShortUrls(uploadElements, siteSettings, opts) { let hostRegex = new RegExp("//" + window.location.host, "g"); url = url.replace(hostRegex, ""); } - let fullUrl = window.location.origin + url; - upload.src = fullUrl; + + upload.src = url; // this is necessary, otherwise because of the src change the // video/audio just doesn't bother loading! @@ -154,8 +154,8 @@ function _loadCachedShortUrls(uploadElements, siteSettings, opts) { // set the url and text for the tag within the big enterprise contract.pdf` ) .join("") + - `
` + `
` + + otherMediaSrcs + .map(src => { + if (src.short_url.indexOf("mp3") > -1) { + return ``; + } else { + return ``; + } + }) + .join("") ); } QUnit.module("lib:pretty-text/upload-short-url", { @@ -120,6 +134,12 @@ QUnit.test("resolveAllShortUrls", async assert => { url: "/uploads/default/original/3X/c/b/5.mp3", short_path: "/uploads/short-url/e.mp3" }); + + lookup = lookupCachedUploadUrl("upload://f.mp4"); + assert.deepEqual(lookup, { + url: "http://localhost:3000/uploads/default/original/3X/c/b/6.mp4", + short_path: "/uploads/short-url/f.mp4" + }); }); QUnit.test( @@ -135,10 +155,40 @@ QUnit.test( .find("img") .eq(1); let link = fixture().find("a"); + let audio = fixture() + .find("audio") + .eq(0); + let video = fixture() + .find("video") + .eq(0); assert.equal(image1.attr("src"), "/images/avatar.png?a"); assert.equal(image2.attr("src"), "/images/avatar.png?b"); assert.equal(link.attr("href"), "/uploads/short-url/c.pdf"); + assert.equal( + video.find("source").attr("src"), + "/uploads/default/original/3X/c/b/4.mp4" + ); + assert.equal( + audio.find("source").attr("src"), + "/uploads/default/original/3X/c/b/5.mp3" + ); + } +); + +QUnit.test( + "resolveAllShortUrls - url with full origin replaced correctly", + async assert => { + stubUrls(); + await resolveAllShortUrls(ajax, { secure_media: false }, fixture()[0]); + let video = fixture() + .find("video") + .eq(1); + + assert.equal( + video.find("source").attr("src"), + "http://localhost:3000/uploads/default/original/3X/c/b/6.mp4" + ); } );