@@ -27,6 +27,7 @@ import { Book } from './item/Book';
2727import { ItemGroup } from './item/ItemGroup' ;
2828import { Item } from './item/Item' ;
2929import { TraunerShelf } from './shelf/TraunerShelf' ;
30+ import retry from 'async-retry' ;
3031
3132const cmd = command ( {
3233 name : 'd4sd' ,
@@ -68,6 +69,13 @@ const cmd = command({
6869 defaultValue : ( ) => 10 ,
6970 description : 'Specifies the maximum amount of pages downloaded at once.' ,
7071 } ) ,
72+ maxRetries : option ( {
73+ long : 'max-retries' ,
74+ short : 'r' ,
75+ type : number ,
76+ defaultValue : ( ) => 10 ,
77+ description : 'Change the maximum retries value.' ,
78+ } ) ,
7179 outDir : option ( {
7280 long : 'out-dir' ,
7381 short : 'o' ,
@@ -85,6 +93,7 @@ const cmd = command({
8593 short : 't' ,
8694 type : optional ( number ) ,
8795 description : 'Terminates the download, when exceeded.' ,
96+ defaultValue : ( ) => 300000 ,
8897 } ) ,
8998 } ,
9099 handler : async ( args ) => {
@@ -178,10 +187,12 @@ const cmd = command({
178187 } else {
179188 for ( const itemRef of itemRefs ) {
180189 console . log ( `Resolving "${ itemRef . title } "...` ) ;
181- const item = await itemRef . resolve ( ) ;
190+ const item = await retry ( ( ) => itemRef . resolve ( ) , {
191+ retries : args . maxRetries ,
192+ } ) ;
182193 if ( ! item ) {
183194 console . error (
184- `Failed to resolve item type of "${ itemRef . title } ".`
195+ `Failed to resolve item type of "${ itemRef . title } ". Retried ${ args . maxRetries } times. `
185196 ) ;
186197 continue ;
187198 }
@@ -240,7 +251,9 @@ const cmd = command({
240251
241252 let err : unknown = null ;
242253 try {
243- await item . download ( args . outDir , options ) ;
254+ await retry ( ( ) => item . download ( args . outDir , options ) , {
255+ retries : args . maxRetries ,
256+ } ) ;
244257 } catch ( e ) {
245258 err = e ;
246259 }
@@ -250,7 +263,9 @@ const cmd = command({
250263
251264 if ( err ) {
252265 console . error ( err ) ;
253- console . error ( `Failed to download "${ itemRef . title } !"` ) ;
266+ console . error (
267+ `Failed to download "${ itemRef . title } ! Retried ${ args . maxRetries } times."`
268+ ) ;
254269 continue ;
255270 }
256271
0 commit comments