http.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { NodeConnectionTypes, type INodeType, type INodeDataBaseSchema } from '../Interface'
  2. export type HttpRequestData = INodeDataBaseSchema & {
  3. method: 'get' | 'post' | 'put' | 'delete' | 'patch'
  4. ssl_verify: boolean
  5. body: {
  6. type: string
  7. data: Array<{
  8. key: string
  9. type: 'text' | 'file' | string
  10. value: string
  11. }>
  12. }
  13. params: Array<{
  14. key: string
  15. value: string
  16. }>
  17. title: string
  18. url: string
  19. authorization: {
  20. type: 'none' | 'api-key' | string
  21. config: {
  22. api_key?: string
  23. header?: string
  24. type?: 'basic' | 'bearer' | 'custom' | string
  25. [key: string]: any
  26. }
  27. }
  28. timeout_config: {
  29. max_write_timeout: number
  30. max_read_timeout: number
  31. max_connect_timeout: number
  32. }
  33. heads: Array<{
  34. name: string
  35. value: string
  36. }>
  37. }
  38. export const httpNode: INodeType = {
  39. version: ['1'],
  40. displayName: 'HTTP 请求',
  41. name: 'http-request',
  42. description: '通过HTTP请求获取数据',
  43. group: '数据处理',
  44. icon: 'lucide:link',
  45. iconColor: '#9373ee',
  46. inputs: [NodeConnectionTypes.main],
  47. outputs: (data: HttpRequestData) => {
  48. // todo: 判断异常处理,如果是分支,添加异常出口
  49. return data?.error_strategy === 'fail-branch'
  50. ? [NodeConnectionTypes.main, NodeConnectionTypes.main]
  51. : [NodeConnectionTypes.main]
  52. },
  53. validate: (data: HttpRequestData) => {
  54. return !!data?.url.trim() ? false : '请填写URL'
  55. },
  56. // 业务数据
  57. schema: {
  58. appAgentId: '',
  59. parentId: '',
  60. position: {
  61. x: 20,
  62. y: 30
  63. },
  64. width: 96,
  65. height: 96,
  66. selected: false,
  67. nodeType: 'http-request',
  68. zIndex: 1,
  69. data: {
  70. outputs: [
  71. {
  72. name: 'body',
  73. describe: '响应内容',
  74. type: 'string'
  75. },
  76. {
  77. name: 'status_code',
  78. describe: '响应状态码',
  79. type: 'number'
  80. },
  81. {
  82. name: 'headers',
  83. describe: '响应头列表 JSON',
  84. type: 'object'
  85. }
  86. ],
  87. output_can_alter: false,
  88. variables: [],
  89. method: 'post',
  90. ssl_verify: false,
  91. isInIteration: false,
  92. default_value: [],
  93. body: {
  94. type: 'json',
  95. data: [
  96. {
  97. key: '',
  98. type: 'text',
  99. value: '{"id":"b3a4aabb-a6b8-47f3-8a32-f45930f7d7b8"}'
  100. }
  101. ]
  102. },
  103. params: [],
  104. title: 'HTTP 请求',
  105. type: 'http-request',
  106. error_strategy: 'none',
  107. retry_config: {
  108. max_retries: 3,
  109. retry_enabled: false,
  110. retry_interval: 100
  111. },
  112. url: '#{env.api_address}/api/agent/getAgentInfo',
  113. authorization: {
  114. type: 'none',
  115. config: {
  116. api_key: '',
  117. header: '',
  118. type: ''
  119. }
  120. },
  121. timeout_config: {
  122. max_write_timeout: 0,
  123. max_read_timeout: 0,
  124. max_connect_timeout: 0
  125. },
  126. heads: [
  127. {
  128. name: 'Authorization',
  129. value: ''
  130. }
  131. ],
  132. selected: true,
  133. desc: '',
  134. isInLoop: false
  135. }
  136. }
  137. }