@@ -17,6 +17,7 @@ export class DownloadManagerService {
1717 private allDownloadStates : DownloadState [ ] = [ ] ;
1818 private abortControllers : Record < string , Record < string , AbortController > > =
1919 { } ;
20+ private timeouts : Record < string , NodeJS . Timeout > = { } ;
2021
2122 constructor (
2223 private readonly httpService : HttpService ,
@@ -27,20 +28,21 @@ export class DownloadManagerService {
2728 if ( ! this . abortControllers [ downloadId ] ) {
2829 return ;
2930 }
31+ clearTimeout ( this . timeouts [ downloadId ] ) ;
3032 Object . keys ( this . abortControllers [ downloadId ] ) . forEach ( ( destination ) => {
3133 this . abortControllers [ downloadId ] [ destination ] . abort ( ) ;
3234 } ) ;
3335 delete this . abortControllers [ downloadId ] ;
34-
36+
3537 const currentDownloadState = this . allDownloadStates . find (
3638 ( downloadState ) => downloadState . id === downloadId ,
3739 ) ;
3840 this . allDownloadStates = this . allDownloadStates . filter (
3941 ( downloadState ) => downloadState . id !== downloadId ,
4042 ) ;
4143
42- if ( currentDownloadState ) {
43- this . deleteDownloadStateFiles ( currentDownloadState ) ;
44+ if ( currentDownloadState ) {
45+ this . deleteDownloadStateFiles ( currentDownloadState ) ;
4446 }
4547 this . eventEmitter . emit ( 'download.event' , this . allDownloadStates ) ;
4648 }
@@ -175,7 +177,10 @@ export class DownloadManagerService {
175177 const timeout = 20000 ; // Timeout period for receiving new data
176178 let timeoutId : NodeJS . Timeout ;
177179 const resetTimeout = ( ) => {
178- if ( timeoutId ) clearTimeout ( timeoutId ) ;
180+ if ( timeoutId ) {
181+ clearTimeout ( timeoutId ) ;
182+ delete this . timeouts [ downloadId ] ;
183+ }
179184 timeoutId = setTimeout ( ( ) => {
180185 try {
181186 this . handleError (
@@ -188,6 +193,7 @@ export class DownloadManagerService {
188193 resolve ( ) ;
189194 }
190195 } , timeout ) ;
196+ this . timeouts [ downloadId ] = timeoutId ;
191197 } ;
192198
193199 let transferredBytes = 0 ;
@@ -302,7 +308,7 @@ export class DownloadManagerService {
302308 }
303309
304310 private deleteDownloadStateFiles ( downloadState : DownloadState ) {
305- if ( ! downloadState . children ?. length ) return ;
311+ if ( ! downloadState . children ?. length ) return ;
306312 downloadState . children . forEach ( ( child ) => {
307313 unlinkSync ( child . id ) ;
308314 } ) ;
0 commit comments