Skip to content

Commit

Permalink
fix: clean downloading model file
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Nov 28, 2023
1 parent 2d78b2d commit 23e2eeb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
15 changes: 0 additions & 15 deletions electron/handlers/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)
})
})

/**
Expand Down
6 changes: 5 additions & 1 deletion plugins/model-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export default class JanModelPlugin implements ModelPlugin {
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
async cancelModelDownload(name: string, modelId: string): Promise<void> {
return abortDownload(join(JanModelPlugin._homeDir, name, modelId))
return abortDownload(join(JanModelPlugin._homeDir, name, modelId)).then(
() => {
fs.deleteFile(join(JanModelPlugin._homeDir, name, modelId))
}
)
}

/**
Expand Down

0 comments on commit 23e2eeb

Please sign in to comment.