fix: unlink the entire model folder on delete

This commit is contained in:
Louis 2024-10-30 16:08:13 +07:00
parent 2a0d87a393
commit 5ddbf5fb34
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -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)
}
}