From 23e2eebde62ff767b18e2ea9c983fa727139a886 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 28 Nov 2023 15:02:47 +0700 Subject: [PATCH] fix: clean downloading model file --- electron/handlers/download.ts | 15 --------------- plugins/model-plugin/src/index.ts | 6 +++++- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/electron/handlers/download.ts b/electron/handlers/download.ts index 3a1fc36d1e..316576e896 100644 --- a/electron/handlers/download.ts +++ b/electron/handlers/download.ts @@ -34,22 +34,7 @@ export function handleDownloaderIPCs() { ipcMain.handle('abortDownload', async (_event, fileName) => { const rq = DownloadManager.instance.networkRequests[fileName] DownloadManager.instance.networkRequests[fileName] = undefined - const userDataPath = app.getPath('userData') - const fullPath = join(userDataPath, fileName) rq?.abort() - let result = 'NULL' - unlink(fullPath, function (err) { - if (err && err.code == 'ENOENT') { - result = `File not exist: ${err}` - } else if (err) { - result = `File delete error: ${err}` - } else { - result = 'File deleted successfully' - } - console.debug( - `Delete file ${fileName} from ${fullPath} result: ${result}` - ) - }) }) /** diff --git a/plugins/model-plugin/src/index.ts b/plugins/model-plugin/src/index.ts index fd3e7331e1..f3da471a7a 100644 --- a/plugins/model-plugin/src/index.ts +++ b/plugins/model-plugin/src/index.ts @@ -56,7 +56,11 @@ export default class JanModelPlugin implements ModelPlugin { * @returns {Promise} A promise that resolves when the download has been cancelled. */ async cancelModelDownload(name: string, modelId: string): Promise { - return abortDownload(join(JanModelPlugin._homeDir, name, modelId)) + return abortDownload(join(JanModelPlugin._homeDir, name, modelId)).then( + () => { + fs.deleteFile(join(JanModelPlugin._homeDir, name, modelId)) + } + ) } /**