Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cannot cancel model which is progress at 0 percent #2727

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
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
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
Loading