@@ -97,6 +97,10 @@ export default {
9797 }
9898 },
9999
100+ created () {
101+ this .createSubdirectory = this .browserItems .illustrationCreateSubdirectory ;
102+ },
103+
100104 mounted () {
101105 /**
102106 * @var {IllustTool}
@@ -229,6 +233,27 @@ export default {
229233 }
230234 },
231235
236+ /**
237+ * Download multiple files
238+ *
239+ * @param {Object[]} files
240+ * @param {{savePath: string}} options
241+ * @param {number} [index= 0 ]
242+ * @returns {Promise}
243+ */
244+ downloadMultipleFiles (files , { savePath }, index = 0 ) {
245+ let file = files[index];
246+
247+ if (! file) {
248+ return Promise .resolve ();
249+ }
250+
251+ return this .downloadFile ({
252+ src: file .data , filename: file .filename , folder: savePath
253+ })
254+ .then (() => this .downloadMultipleFiles (files, { savePath }, index + 1 ));
255+ },
256+
232257 /**
233258 * Download multiple files. The browser will popup a confirm dialog for user
234259 * for asking user if he/she agree to download multiple files from the website.
@@ -251,32 +276,29 @@ export default {
251276 }
252277
253278 if ((files .length === 1 && this .alwaysPack ) || (files .length > 1 && this .packFiles )) {
254- this .tool .getPackedFile ({files}).then (file => {
279+ this .tool .getPackedFile ({files}).then (result => {
255280 /**
256281 * Download zip file
257282 */
258- this .downloadFile (file .data , file .filename , {
259- folder: savePath,
260- statType: ' illust'
261- });
283+ this .downloadFile ({
284+ src: result .data ,
285+ filename: result .filename ,
286+ folder: savePath
287+ })
288+ .then (() => this .updateDownloadStat (' illust' ));
262289 });
263290 } else {
264- savePath = pathjoin (savePath, this .tool .relativePath , ' /' );
291+ if (this .createSubdirectory ) {
292+ savePath = pathjoin (savePath, this .tool .relativePath , ' /' );
293+ } else {
294+ savePath = pathjoin (savePath, ' /' );
295+ }
265296
266297 /**
267298 * Cache files and change button type
268299 */
269-
270- files .forEach (file => {
271- this .downloadFile (
272- new Blob ([file .data ], { type: file .mimeType }),
273- file .filename ,
274- {
275- folder: savePath,
276- statType: ' illust'
277- }
278- );
279- });
300+ this .downloadMultipleFiles (files, { savePath })
301+ .then (() => this .updateDownloadStat (' illust' ));
280302 }
281303
282304 this .saveDownloadRecord ({ illust: 1 });
0 commit comments