fix: cannot cancel model which is progress at 0 percent (#2727)
Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
f4641316b1
commit
20657bb3da
@ -66,6 +66,7 @@ export class Downloader implements Processor {
|
|||||||
localPath: normalizedPath,
|
localPath: normalizedPath,
|
||||||
}
|
}
|
||||||
DownloadManager.instance.downloadProgressMap[modelId] = initialDownloadState
|
DownloadManager.instance.downloadProgressMap[modelId] = initialDownloadState
|
||||||
|
DownloadManager.instance.downloadInfo[normalizedPath] = initialDownloadState
|
||||||
|
|
||||||
if (downloadRequest.downloadType === 'extension') {
|
if (downloadRequest.downloadType === 'extension') {
|
||||||
observer?.(DownloadEvent.onFileDownloadUpdate, initialDownloadState)
|
observer?.(DownloadEvent.onFileDownloadUpdate, initialDownloadState)
|
||||||
@ -118,13 +119,15 @@ export class Downloader implements Processor {
|
|||||||
if (rq) {
|
if (rq) {
|
||||||
DownloadManager.instance.networkRequests[fileName] = undefined
|
DownloadManager.instance.networkRequests[fileName] = undefined
|
||||||
rq?.abort()
|
rq?.abort()
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
const downloadInfo = DownloadManager.instance.downloadInfo[fileName]
|
||||||
observer?.(DownloadEvent.onFileDownloadError, {
|
observer?.(DownloadEvent.onFileDownloadError, {
|
||||||
|
...downloadInfo,
|
||||||
fileName,
|
fileName,
|
||||||
error: 'aborted',
|
error: 'aborted',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
resumeDownload(observer: any, fileName: any) {
|
resumeDownload(observer: any, fileName: any) {
|
||||||
DownloadManager.instance.networkRequests[fileName]?.resume()
|
DownloadManager.instance.networkRequests[fileName]?.resume()
|
||||||
|
|||||||
@ -8,8 +8,12 @@ export class DownloadManager {
|
|||||||
|
|
||||||
public static instance: DownloadManager = new DownloadManager()
|
public static instance: DownloadManager = new DownloadManager()
|
||||||
|
|
||||||
|
// store the download information with key is model id
|
||||||
public downloadProgressMap: Record<string, DownloadState> = {}
|
public downloadProgressMap: Record<string, DownloadState> = {}
|
||||||
|
|
||||||
|
// store the download infomation with key is normalized file path
|
||||||
|
public downloadInfo: Record<string, DownloadState> = {}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
if (DownloadManager.instance) {
|
if (DownloadManager.instance) {
|
||||||
return DownloadManager.instance
|
return DownloadManager.instance
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user