From 26194d584b218d43c5f004b3ea875750f61378f9 Mon Sep 17 00:00:00 2001 From: ddelange <14880945+ddelange@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:58:50 +0200 Subject: [PATCH] Fix syntax --- client/src/utils/download.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/client/src/utils/download.js b/client/src/utils/download.js index 75edbd1..1fd6739 100644 --- a/client/src/utils/download.js +++ b/client/src/utils/download.js @@ -4,37 +4,36 @@ /** * Creates a promise that resolves after the specified number of milliseconds */ -const delay = (milliseconds: number): Promise => { - return new Promise((resolve) => setTimeout(resolve, milliseconds)); -}; +const delay = milliseconds => new Promise(resolve => { + setTimeout(resolve, milliseconds); +}); /** * Downloads a single file * @param file - An instance of the File type representing the file to download */ -const download = async (file: File): Promise => { +const download = async (file) => { const a = document.createElement('a'); const url = URL.createObjectURL(file); a.download = file.name; a.href = url; a.style.display = 'none'; - document.body.appendChild(a); + document.body.append(a); a.click(); - await delay(100); // Needed for Chrome + await delay(100); // for Chrome a.remove(); URL.revokeObjectURL(url); }; /** - * Initiates multiple file downloads with a delay between each one + * Initiates multiple file downloads with a constant delay between each one * @param files - An array of instances of the File type representing the files to download */ -const multiDownload = async (files: readonly File[]): Promise => { +const multiDownload = async (files) => { if (!files) { throw new Error('`files` required'); - } - - // Trigger a download every second + }; + for (const file of files) { await delay(1000); download(file);