1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Backport pull request #5910 from jellyfin-web/release-10.9.z

Fix "Download All" for Safari

Original-merge: 4071c44437

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: thornbill <thornbill@users.noreply.github.com>
This commit is contained in:
jchuong 2024-08-13 11:53:24 -04:00 committed by thornbill
parent 37fbfb3772
commit 6d350b8aa4

View file

@ -27,19 +27,11 @@ function fallback(urls) {
})();
}
function sameDomain(url) {
const a = document.createElement('a');
a.href = url;
return window.location.hostname === a.hostname && window.location.protocol === a.protocol;
}
function download(url) {
const a = document.createElement('a');
a.download = '';
a.href = url;
// firefox doesn't support `a.click()`...
a.dispatchEvent(new MouseEvent('click'));
a.click();
}
export default function (urls) {
@ -47,19 +39,13 @@ export default function (urls) {
throw new Error('`urls` required');
}
if (typeof document.createElement('a').download === 'undefined') {
if (typeof document.createElement('a').download === 'undefined' || browser.iOS) {
return fallback(urls);
}
let delay = 0;
urls.forEach(function (url) {
// the download init has to be sequential for firefox if the urls are not on the same domain
if (browser.firefox && !sameDomain(url)) {
setTimeout(download.bind(null, url), 100 * ++delay);
return;
}
download(url);
setTimeout(download.bind(null, url), 100 * ++delay);
});
}