@@ -179,27 +179,63 @@ export default {
179179 this .isDownloading = true
180180
181181 fetch (this .baseUrl + ` /submitters/${ this .submitterSlug } /download` ).then ((response ) => response .json ()).then ((urls ) => {
182- const fileRequests = urls .map ((url ) => {
183- return () => {
184- return fetch (url).then (async (resp ) => {
185- const blobUrl = URL .createObjectURL (await resp .blob ())
186- const link = document .createElement (' a' )
182+ const isSafariIos = / iPhone| iPad| iPod/ i .test (navigator .userAgent )
187183
188- link .href = blobUrl
189- link .setAttribute (' download' , decodeURI (url .split (' /' ).pop ()))
184+ if (isSafariIos && urls .length > 1 ) {
185+ this .downloadSafariIos (urls)
186+ } else {
187+ this .downloadUrls (urls)
188+ }
189+ })
190+ },
191+ downloadUrls (urls ) {
192+ const fileRequests = urls .map ((url ) => {
193+ return () => {
194+ return fetch (url).then (async (resp ) => {
195+ const blob = await resp .blob ()
196+ const blobUrl = URL .createObjectURL (blob .slice (0 , blob .size , ' application/octet-stream' ))
197+ const link = document .createElement (' a' )
198+
199+ link .href = blobUrl
200+ link .setAttribute (' download' , decodeURI (url .split (' /' ).pop ()))
201+
202+ link .click ()
203+
204+ URL .revokeObjectURL (blobUrl)
205+ })
206+ }
207+ })
190208
191- link .click ()
209+ fileRequests .reduce (
210+ (prevPromise , request ) => prevPromise .then (() => request ()),
211+ Promise .resolve ()
212+ )
192213
193- URL .revokeObjectURL (url)
194- })
195- }
214+ this .isDownloading = false
215+ },
216+ downloadSafariIos (urls ) {
217+ const fileRequests = urls .map ((url ) => {
218+ return fetch (url).then (async (resp ) => {
219+ const blob = await resp .blob ()
220+ const blobUrl = URL .createObjectURL (blob .slice (0 , blob .size , ' application/octet-stream' ))
221+ const link = document .createElement (' a' )
222+
223+ link .href = blobUrl
224+ link .setAttribute (' download' , decodeURI (url .split (' /' ).pop ()))
225+
226+ return link
196227 })
228+ })
197229
198- fileRequests . reduce (
199- ( prevPromise , request ) => prevPromise . then (() => request ()),
200- Promise . resolve ()
201- )
230+ Promise . all ( fileRequests). then (( links ) => {
231+ links . forEach (( link , index ) => {
232+ setTimeout (() => {
233+ link . click ( )
202234
235+ URL .revokeObjectURL (link .href )
236+ }, index * 50 )
237+ })
238+ }).finally (() => {
203239 this .isDownloading = false
204240 })
205241 }
0 commit comments