Skip to content

Commit

Permalink
fix: cannot cancel model which is progress at 0 percent (#2727)
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Apr 15, 2024
1 parent f464131 commit 20657bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/node/api/processors/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Downloader implements Processor {
localPath: normalizedPath,
}
DownloadManager.instance.downloadProgressMap[modelId] = initialDownloadState
DownloadManager.instance.downloadInfo[normalizedPath] = initialDownloadState

if (downloadRequest.downloadType === 'extension') {
observer?.(DownloadEvent.onFileDownloadUpdate, initialDownloadState)
Expand Down Expand Up @@ -118,12 +119,14 @@ export class Downloader implements Processor {
if (rq) {
DownloadManager.instance.networkRequests[fileName] = undefined
rq?.abort()
} else {
observer?.(DownloadEvent.onFileDownloadError, {
fileName,
error: 'aborted',
})
}

const downloadInfo = DownloadManager.instance.downloadInfo[fileName]
observer?.(DownloadEvent.onFileDownloadError, {
...downloadInfo,
fileName,
error: 'aborted',
})
}

resumeDownload(observer: any, fileName: any) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/node/helper/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export class DownloadManager {

public static instance: DownloadManager = new DownloadManager()

// store the download information with key is model id
public downloadProgressMap: Record<string, DownloadState> = {}

// store the download infomation with key is normalized file path
public downloadInfo: Record<string, DownloadState> = {}

constructor() {
if (DownloadManager.instance) {
return DownloadManager.instance
Expand Down

0 comments on commit 20657bb

Please sign in to comment.