mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
Feature/s3 storage (#2226)
* centralizing file writing.... * allowing s3 as storage option * allowing s3 as storage option * update s3 storage --------- Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { ChatFlow } from '../database/entities/ChatFlow'
|
||||
import path from 'path'
|
||||
import { getStoragePath } from 'flowise-components'
|
||||
import fs from 'fs'
|
||||
import { IReactFlowObject } from '../Interface'
|
||||
import { addBase64FilesToStorage } from 'flowise-components'
|
||||
|
||||
export const containsBase64File = (chatflow: ChatFlow) => {
|
||||
const parsedFlowData: IReactFlowObject = JSON.parse(chatflow.flowData)
|
||||
@@ -48,23 +46,7 @@ export const containsBase64File = (chatflow: ChatFlow) => {
|
||||
return found
|
||||
}
|
||||
|
||||
function addFileToStorage(file: string, chatflowid: string, fileNames: string[]) {
|
||||
const dir = path.join(getStoragePath(), chatflowid)
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
|
||||
const splitDataURI = file.split(',')
|
||||
const filename = splitDataURI.pop()?.split(':')[1] ?? ''
|
||||
const bf = Buffer.from(splitDataURI.pop() || '', 'base64')
|
||||
|
||||
const filePath = path.join(dir, filename)
|
||||
fs.writeFileSync(filePath, bf)
|
||||
fileNames.push(filename)
|
||||
return 'FILE-STORAGE::' + JSON.stringify(fileNames)
|
||||
}
|
||||
|
||||
export const updateFlowDataWithFilePaths = (chatflowid: string, flowData: string) => {
|
||||
export const updateFlowDataWithFilePaths = async (chatflowid: string, flowData: string) => {
|
||||
try {
|
||||
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
|
||||
const re = new RegExp('^data.*;base64', 'i')
|
||||
@@ -93,14 +75,14 @@ export const updateFlowDataWithFilePaths = (chatflowid: string, flowData: string
|
||||
for (let j = 0; j < files.length; j++) {
|
||||
const file = files[j]
|
||||
if (re.test(file)) {
|
||||
node.data.inputs[key] = addFileToStorage(file, chatflowid, fileNames)
|
||||
node.data.inputs[key] = await addBase64FilesToStorage(file, chatflowid, fileNames)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
continue
|
||||
}
|
||||
} else if (re.test(input)) {
|
||||
node.data.inputs[key] = addFileToStorage(input, chatflowid, fileNames)
|
||||
node.data.inputs[key] = await addBase64FilesToStorage(input, chatflowid, fileNames)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user