Fix download filenames - pass filename to download attribute
Some checks failed
Push & Release 🌍 / Automation 🎛️ (push) Has been cancelled
Push & Release 🌍 / Unstable release 🚀⚠️ (push) Has been cancelled
Push & Release 🌍 / Quality checks 👌🧪 (push) Has been cancelled
Push & Release 🌍 / GitHub CodeQL 🔬 (push) Has been cancelled
Push & Release 🌍 / Deploy 🚀 (push) Has been cancelled
Some checks failed
Push & Release 🌍 / Automation 🎛️ (push) Has been cancelled
Push & Release 🌍 / Unstable release 🚀⚠️ (push) Has been cancelled
Push & Release 🌍 / Quality checks 👌🧪 (push) Has been cancelled
Push & Release 🌍 / GitHub CodeQL 🔬 (push) Has been cancelled
Push & Release 🌍 / Deploy 🚀 (push) Has been cancelled
- multiDownload now accepts objects with url+filename instead of just URLs - Maintains backward compatibility with old URL-only format - fileDownloader passes full item objects to multiDownload - Fixes issue where dotted filenames weren't used - Also fixes dialog close error and missing translation
This commit is contained in:
@@ -483,8 +483,8 @@ function onSubmit(e) {
|
||||
filename: filename
|
||||
}]);
|
||||
|
||||
toast(globalize.translate('DownloadStarted'));
|
||||
dialogHelper.close(dlg);
|
||||
toast('Download started');
|
||||
dialogHelper.close(e.target.closest('.dialog'));
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
@@ -3,8 +3,7 @@ import shell from './shell';
|
||||
|
||||
export function download(items) {
|
||||
if (!shell.downloadFiles(items)) {
|
||||
multiDownload(items.map(function (item) {
|
||||
return item.url;
|
||||
}));
|
||||
// Pass full item objects (with url and filename) to multiDownload
|
||||
multiDownload(items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,25 +27,31 @@ function fallback(urls) {
|
||||
})();
|
||||
}
|
||||
|
||||
function download(url) {
|
||||
function download(url, filename) {
|
||||
const a = document.createElement('a');
|
||||
a.download = '';
|
||||
a.download = filename || '';
|
||||
a.href = url;
|
||||
a.click();
|
||||
}
|
||||
|
||||
export default function (urls) {
|
||||
if (!urls) {
|
||||
throw new Error('`urls` required');
|
||||
export default function (items) {
|
||||
if (!items) {
|
||||
throw new Error('`items` required');
|
||||
}
|
||||
|
||||
// Support both old format (array of URLs) and new format (array of objects with url+filename)
|
||||
const isOldFormat = typeof items[0] === 'string';
|
||||
|
||||
if (typeof document.createElement('a').download === 'undefined' || browser.iOS) {
|
||||
const urls = isOldFormat ? items : items.map(item => item.url || item);
|
||||
return fallback(urls);
|
||||
}
|
||||
|
||||
let delay = 0;
|
||||
|
||||
urls.forEach(function (url) {
|
||||
setTimeout(download.bind(null, url), 100 * ++delay);
|
||||
items.forEach(function (item) {
|
||||
const url = isOldFormat ? item : (item.url || item);
|
||||
const filename = isOldFormat ? '' : (item.filename || '');
|
||||
setTimeout(download.bind(null, url, filename), 100 * ++delay);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user