Multimodal: deleting uploads on delete of all chatmessages

This commit is contained in:
vinodkiran
2024-01-31 19:16:58 -05:00
parent 5c8f48c2f1
commit aa5d1417a1
2 changed files with 28 additions and 1 deletions
+22
View File
@@ -1078,3 +1078,25 @@ export const getAllValuesFromJson = (obj: any): any[] => {
extractValues(obj)
return values
}
export const deleteFolderRecursive = (directory: string) => {
fs.readdir(directory, (error, files) => {
if (error) throw new Error('Could not read directory')
files.forEach((file) => {
const file_path = path.join(directory, file)
fs.stat(file_path, (error, stat) => {
if (error) throw new Error('File do not exist')
if (!stat.isDirectory()) {
fs.unlink(file_path, (error) => {
if (error) throw new Error('Could not delete file')
})
} else {
deleteFolderRecursive(file_path)
}
})
})
})
}