utils.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import type { InputForm } from './type'
  2. import { InputVarType } from '@/app/components/workflow/types'
  3. import { getProcessedFiles } from '@/app/components/base/file-uploader/utils'
  4. export const processOpeningStatement = (openingStatement: string, inputs: Record<string, any>, inputsForm: InputForm[]) => {
  5. if (!openingStatement)
  6. return openingStatement
  7. return openingStatement.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
  8. const name = inputs[key]
  9. if (name) { // has set value
  10. return name
  11. }
  12. const valueObj = inputsForm.find(v => v.variable === key)
  13. return valueObj ? `{{${valueObj.label}}}` : match
  14. })
  15. }
  16. export const getProcessedInputs = (inputs: Record<string, any>, inputsForm: InputForm[]) => {
  17. const processedInputs = { ...inputs }
  18. inputsForm.forEach((item) => {
  19. if (item.type === InputVarType.multiFiles && inputs[item.variable])
  20. processedInputs[item.variable] = getProcessedFiles(inputs[item.variable])
  21. if (item.type === InputVarType.singleFile && inputs[item.variable])
  22. processedInputs[item.variable] = getProcessedFiles([inputs[item.variable]])[0]
  23. })
  24. return processedInputs
  25. }