fix: clean downloading model file

This commit is contained in:
Louis 2023-11-28 15:02:47 +07:00
parent 1407c22f29
commit d6807f50c4
2 changed files with 5 additions and 16 deletions

View File

@ -34,22 +34,7 @@ export function handleDownloaderIPCs() {
ipcMain.handle('abortDownload', async (_event, fileName) => { ipcMain.handle('abortDownload', async (_event, fileName) => {
const rq = DownloadManager.instance.networkRequests[fileName] const rq = DownloadManager.instance.networkRequests[fileName]
DownloadManager.instance.networkRequests[fileName] = undefined DownloadManager.instance.networkRequests[fileName] = undefined
const userDataPath = app.getPath('userData')
const fullPath = join(userDataPath, fileName)
rq?.abort() 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}`
)
})
}) })
/** /**

View File

@ -56,7 +56,11 @@ export default class JanModelPlugin implements ModelPlugin {
* @returns {Promise<void>} A promise that resolves when the download has been cancelled. * @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/ */
async cancelModelDownload(name: string, modelId: string): Promise<void> { 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))
}
)
} }
/** /**