mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 01:01:11 +03:00
Multimodal: deleting uploads on delete of all chatmessages
This commit is contained in:
@@ -46,7 +46,8 @@ import {
|
|||||||
getSessionChatHistory,
|
getSessionChatHistory,
|
||||||
getAllConnectedNodes,
|
getAllConnectedNodes,
|
||||||
clearSessionMemory,
|
clearSessionMemory,
|
||||||
findMemoryNode
|
findMemoryNode,
|
||||||
|
deleteFolderRecursive
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { cloneDeep, omit, uniqWith, isEqual } from 'lodash'
|
import { cloneDeep, omit, uniqWith, isEqual } from 'lodash'
|
||||||
import { getDataSource } from './DataSource'
|
import { getDataSource } from './DataSource'
|
||||||
@@ -618,6 +619,10 @@ export class App {
|
|||||||
if (sessionId) deleteOptions.sessionId = sessionId
|
if (sessionId) deleteOptions.sessionId = sessionId
|
||||||
if (chatType) deleteOptions.chatType = chatType
|
if (chatType) deleteOptions.chatType = chatType
|
||||||
|
|
||||||
|
/* Delete all multimodal uploads corresponding to this chatflow */
|
||||||
|
const directory = path.join(getUserHome(), '.flowise', 'gptvision', chatflowid)
|
||||||
|
deleteFolderRecursive(directory)
|
||||||
|
|
||||||
const results = await this.AppDataSource.getRepository(ChatMessage).delete(deleteOptions)
|
const results = await this.AppDataSource.getRepository(ChatMessage).delete(deleteOptions)
|
||||||
return res.json(results)
|
return res.json(results)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1078,3 +1078,25 @@ export const getAllValuesFromJson = (obj: any): any[] => {
|
|||||||
extractValues(obj)
|
extractValues(obj)
|
||||||
return values
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user