Make Download actually download
The `download` attribute is ignored by every browser when the href is cross-origin, and the file we redirect to is signed with an inline disposition - so clicking Download opened the mp4 in a tab instead of saving it. ?dl=1 asks the worker to serve it as an attachment.
This commit is contained in:
parent
f115eca329
commit
f468604438
1 changed files with 9 additions and 1 deletions
10
videos.html
10
videos.html
|
|
@ -71,7 +71,15 @@ function card(p) {
|
|||
cta += '<a class="btn ghost" style="display:inline-block;text-decoration:none;margin-top:10px;margin-left:8px" href="/script.html?id='
|
||||
+ encodeURIComponent(p.id) + '">Edit</a>';
|
||||
cta += '<a class="btn ghost" style="display:inline-block;text-decoration:none;margin-top:10px;margin-left:8px" href="'
|
||||
+ esc(p.video_url) + '" download>Download</a>';
|
||||
+ esc(dlUrl(p.video_url)) + '" download>Download</a>';
|
||||
}
|
||||
|
||||
// `download` on a cross-origin link is ignored by the browser, and the
|
||||
// storage URL is signed with an inline disposition, so a click just opened
|
||||
// the video. Asking the worker for ?dl=1 makes it serve an attachment.
|
||||
function dlUrl(u) {
|
||||
u = String(u || "");
|
||||
return /\/media\/[0-9a-fA-F-]{16,}$/.test(u) ? u + "?dl=1" : u;
|
||||
}
|
||||
|
||||
// Through our own domain, so an open is a page load we can count. A link
|
||||
|
|
|
|||
Loading…
Reference in a new issue