fix: unlink the entire model folder on delete
This commit is contained in:
parent
2a0d87a393
commit
5ddbf5fb34
@ -1,18 +1,11 @@
|
||||
import { fs, joinPath, Model } from "@janhq/core"
|
||||
import { fs, joinPath, Model } from '@janhq/core'
|
||||
|
||||
export const deleteModelFiles = async (model: Model) => {
|
||||
try {
|
||||
const dirPath = await joinPath(['file://models', model.id])
|
||||
|
||||
// remove all files under dirPath except model.json
|
||||
const files = await fs.readdirSync(dirPath)
|
||||
const deletePromises = files.map(async (fileName: string) => {
|
||||
if (fileName !== 'model.json') {
|
||||
return fs.unlinkSync(await joinPath([dirPath, fileName]))
|
||||
}
|
||||
})
|
||||
await Promise.allSettled(deletePromises)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
try {
|
||||
const dirPath = await joinPath(['file://models', model.id])
|
||||
// remove model folder directory
|
||||
await fs.unlinkSync(dirPath)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user