shell-wget.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export const ShellWgetCodegen = {
  2. id: "shell-wget",
  3. name: "Shell wget",
  4. language: "sh",
  5. generator: ({
  6. url,
  7. pathName,
  8. queryString,
  9. auth,
  10. httpUser,
  11. httpPassword,
  12. bearerToken,
  13. method,
  14. rawInput,
  15. rawParams,
  16. rawRequestBody,
  17. contentType,
  18. headers,
  19. }) => {
  20. const requestString = []
  21. requestString.push(`wget -O - --method=${method}`)
  22. requestString.push(` '${url}${pathName}?${queryString}'`)
  23. if (auth === "Basic Auth") {
  24. const basic = `${httpUser}:${httpPassword}`
  25. requestString.push(
  26. ` --header='Authorization: Basic ${window.btoa(
  27. unescape(encodeURIComponent(basic))
  28. )}'`
  29. )
  30. } else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
  31. requestString.push(` --header='Authorization: Bearer ${bearerToken}'`)
  32. }
  33. if (headers) {
  34. headers.forEach(({ key, value }) => {
  35. if (key) requestString.push(` --header='${key}: ${value}'`)
  36. })
  37. }
  38. if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
  39. const requestBody = rawInput ? rawParams : rawRequestBody
  40. requestString.push(
  41. ` --header='Content-Type: ${contentType}; charset=utf-8'`
  42. )
  43. requestString.push(` --body-data='${requestBody}'`)
  44. }
  45. return requestString.join(" \\\n")
  46. },
  47. }