Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class DownloadManagerService {
private allDownloadStates: DownloadState[] = [];
private abortControllers: Record<string, Record<string, AbortController>> =
{};
private timeouts: Record<string, NodeJS.Timeout> = {};

constructor(
private readonly httpService: HttpService,
Expand All @@ -27,20 +28,21 @@ export class DownloadManagerService {
if (!this.abortControllers[downloadId]) {
return;
}
clearTimeout(this.timeouts[downloadId]);
Object.keys(this.abortControllers[downloadId]).forEach((destination) => {
this.abortControllers[downloadId][destination].abort();
});
delete this.abortControllers[downloadId];

const currentDownloadState = this.allDownloadStates.find(
(downloadState) => downloadState.id === downloadId,
);
this.allDownloadStates = this.allDownloadStates.filter(
(downloadState) => downloadState.id !== downloadId,
);

if (currentDownloadState){
this.deleteDownloadStateFiles(currentDownloadState);
if (currentDownloadState) {
this.deleteDownloadStateFiles(currentDownloadState);
}
this.eventEmitter.emit('download.event', this.allDownloadStates);
}
Expand Down Expand Up @@ -175,7 +177,10 @@ export class DownloadManagerService {
const timeout = 20000; // Timeout period for receiving new data
let timeoutId: NodeJS.Timeout;
const resetTimeout = () => {
if (timeoutId) clearTimeout(timeoutId);
if (timeoutId) {
clearTimeout(timeoutId);
delete this.timeouts[downloadId];
}
timeoutId = setTimeout(() => {
try {
this.handleError(
Expand All @@ -188,6 +193,7 @@ export class DownloadManagerService {
resolve();
}
}, timeout);
this.timeouts[downloadId] = timeoutId;
};

let transferredBytes = 0;
Expand Down Expand Up @@ -302,7 +308,7 @@ export class DownloadManagerService {
}

private deleteDownloadStateFiles(downloadState: DownloadState) {
if(!downloadState.children?.length) return;
if (!downloadState.children?.length) return;
downloadState.children.forEach((child) => {
unlinkSync(child.id);
});
Expand Down