You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.ts 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import type { NodeDefault } from '../../types'
  2. import { AuthorizationType, BodyType, Method } from './types'
  3. import type { BodyPayload, HttpNodeType } from './types'
  4. import { genNodeMetaData } from '@/app/components/workflow/utils'
  5. import { BlockEnum } from '@/app/components/workflow/types'
  6. import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
  7. const metaData = genNodeMetaData({
  8. classification: BlockClassificationEnum.Utilities,
  9. sort: 1,
  10. type: BlockEnum.HttpRequest,
  11. })
  12. const nodeDefault: NodeDefault<HttpNodeType> = {
  13. metaData,
  14. defaultValue: {
  15. variables: [],
  16. method: Method.get,
  17. url: '',
  18. authorization: {
  19. type: AuthorizationType.none,
  20. config: null,
  21. },
  22. headers: '',
  23. params: '',
  24. body: {
  25. type: BodyType.none,
  26. data: [],
  27. },
  28. ssl_verify: true,
  29. timeout: {
  30. max_connect_timeout: 0,
  31. max_read_timeout: 0,
  32. max_write_timeout: 0,
  33. },
  34. retry_config: {
  35. retry_enabled: true,
  36. max_retries: 3,
  37. retry_interval: 100,
  38. },
  39. },
  40. checkValid(payload: HttpNodeType, t: any) {
  41. let errorMessages = ''
  42. if (!errorMessages && !payload.url)
  43. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
  44. if (!errorMessages
  45. && payload.body.type === BodyType.binary
  46. && ((!(payload.body.data as BodyPayload)[0]?.file) || (payload.body.data as BodyPayload)[0]?.file?.length === 0)
  47. )
  48. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.binaryFileVariable') })
  49. return {
  50. isValid: !errorMessages,
  51. errorMessage: errorMessages,
  52. }
  53. },
  54. }
  55. export default nodeDefault