shell-wget.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. headers,
  18. }) => {
  19. const requestString = []
  20. const requestBody = rawInput ? rawParams : rawRequestBody
  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) && requestBody) {
  39. requestString.push(` --body-data='${requestBody}'`)
  40. }
  41. return requestString.join(" \\\n")
  42. },
  43. }