(chatflow: ChatFlow)
| 5 | import { UsageCacheManager } from '../UsageCacheManager' |
| 6 | |
| 7 | export const containsBase64File = (chatflow: ChatFlow) => { |
| 8 | const parsedFlowData: IReactFlowObject = JSON.parse(chatflow.flowData) |
| 9 | const re = new RegExp('^data.*;base64', 'i') |
| 10 | let found = false |
| 11 | const nodes = parsedFlowData.nodes |
| 12 | for (const node of nodes) { |
| 13 | if (node.data.category !== 'Document Loaders') { |
| 14 | continue |
| 15 | } |
| 16 | const inputs = node.data.inputs |
| 17 | if (inputs) { |
| 18 | const keys = Object.getOwnPropertyNames(inputs) |
| 19 | for (let i = 0; i < keys.length; i++) { |
| 20 | const input = inputs[keys[i]] |
| 21 | if (!input) { |
| 22 | continue |
| 23 | } |
| 24 | if (typeof input !== 'string') { |
| 25 | continue |
| 26 | } |
| 27 | if (input.startsWith('[')) { |
| 28 | try { |
| 29 | const files = JSON.parse(input) |
| 30 | for (let j = 0; j < files.length; j++) { |
| 31 | const file = files[j] |
| 32 | if (re.test(file)) { |
| 33 | found = true |
| 34 | break |
| 35 | } |
| 36 | } |
| 37 | } catch (e) { |
| 38 | continue |
| 39 | } |
| 40 | } |
| 41 | if (re.test(input)) { |
| 42 | found = true |
| 43 | break |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return found |
| 49 | } |
| 50 | |
| 51 | export const updateFlowDataWithFilePaths = async ( |
| 52 | chatflowid: string, |
no test coverage detected