From 7ff58f17877cd5b5ce6e96def47aa7719e843977 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 11 Feb 2020 11:49:58 +1000 Subject: [PATCH] FIX: Disable preloading audio + video when secure media enabled (#8922) Meta topic: https://meta.discourse.org/t/secure-media-uploads-expire/140894 This fixes the issue where if secure media was enabled, audio and video files would do an initial load using the presigned URL for the media to get metadata information e.g. duration of track/video. However this started the expiry countdown for the URL, so when a user pressed play on the media after 15 seconds the media would be expired and AWS would return a 403 error. We do not preload media if secure media is enabled. Otherwise we just set the preload type to "metadata" which is the browser default anyway. --- .../engines/discourse-markdown-it.js.es6 | 22 +++++++++----- .../pretty-text/white-lister.js.es6 | 4 ++- test/javascripts/lib/pretty-text-test.js.es6 | 30 +++++++++++++++++-- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 index 4439455f12c..6e6392d7745 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6 @@ -141,21 +141,23 @@ export function extractDataAttribute(str) { // videoHTML and audioHTML follow the same HTML syntax // as oneboxer.rb when dealing with these formats -function videoHTML(token) { +function videoHTML(token, opts) { const src = token.attrGet("src"); const origSrc = token.attrGet("data-orig-src"); + const preloadType = opts.secureMedia ? "none" : "metadata"; return `
-
`; } -function audioHTML(token) { +function audioHTML(token, opts) { const src = token.attrGet("src"); const origSrc = token.attrGet("data-orig-src"); - return `