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,17 +1,10 @@
import { fs, joinPath, Model } from "@janhq/core" import { fs, joinPath, Model } from '@janhq/core'
export const deleteModelFiles = async (model: Model) => { export const deleteModelFiles = async (model: Model) => {
try { try {
const dirPath = await joinPath(['file://models', model.id]) const dirPath = await joinPath(['file://models', model.id])
// remove model folder directory
// remove all files under dirPath except model.json await fs.unlinkSync(dirPath)
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) { } catch (err) {
console.error(err) console.error(err)
} }