@@ -179,27 +179,62 @@ 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 blobUrl = URL .createObjectURL (await resp .blob ())
196+ const link = document .createElement (' a' )
197+
198+ link .href = blobUrl
199+ link .setAttribute (' download' , decodeURI (url .split (' /' ).pop ()))
200+
201+ link .click ()
202+
203+ URL .revokeObjectURL (blobUrl)
204+ })
205+ }
206+ })
190207
191- link .click ()
208+ fileRequests .reduce (
209+ (prevPromise , request ) => prevPromise .then (() => request ()),
210+ Promise .resolve ()
211+ )
192212
193- URL .revokeObjectURL (url)
194- })
195- }
213+ this .isDownloading = false
214+ },
215+ downloadSafariIos (urls ) {
216+ const fileRequests = urls .map ((url ) => {
217+ return fetch (url).then (async (resp ) => {
218+ const blob = await resp .blob ()
219+ const blobUrl = URL .createObjectURL (blob .slice (0 , blob .size , ' application/octet-stream' ))
220+ const link = document .createElement (' a' )
221+
222+ link .href = blobUrl
223+ link .setAttribute (' download' , decodeURI (url .split (' /' ).pop ()))
224+
225+ return link
196226 })
227+ })
197228
198- fileRequests . reduce (
199- ( prevPromise , request ) => prevPromise . then (() => request ()),
200- Promise . resolve ()
201- )
229+ Promise . all ( fileRequests). then (( links ) => {
230+ links . forEach (( link , index ) => {
231+ setTimeout (() => {
232+ link . click ( )
202233
234+ URL .revokeObjectURL (link .href )
235+ }, index * 50 )
236+ })
237+ }).finally (() => {
203238 this .isDownloading = false
204239 })
205240 }
0 commit comments