Files
QR-master/.output/server/node_modules/just-bash/dist/bundle/chunks/curl-PAWGO3EH.js
2026-07-15 18:08:51 +02:00

27 lines
11 KiB
JavaScript

import{createRequire} from"node:module";const require=createRequire(import.meta.url);
import{b as F}from"./chunk-WNH3HOQA.js";import{d as u}from"./chunk-HBVMHTO5.js";import{a as T}from"./chunk-W5DWRFSU.js";import{a as w,b,c}from"./chunk-QAYAQNCG.js";import"./chunk-BZUGFHVS.js";function O(s){let e=s.indexOf("=");if(e>=0){let i=s.slice(0,e),r=s.slice(e+1);return i?`${encodeURIComponent(i)}=${encodeURIComponent(r)}`:encodeURIComponent(r)}return encodeURIComponent(s)}function m(s){let e=s.indexOf("=");if(e<0)return null;let i=s.slice(0,e),r=s.slice(e+1),t,a,o=r.match(/;type=([^;]+)$/);o&&(a=o[1],r=r.slice(0,-o[0].length));let n=r.match(/;filename=([^;]+)/);return n&&(t=n[1],r=r.replace(n[0],"")),(r.startsWith("@")||r.startsWith("<"))&&(t=t??r.slice(1).split("/").pop()),{name:i,value:r,filename:t,contentType:a}}function W(s,e){let i=`----CurlFormBoundary${Date.now().toString(36)}`,r=[];for(let t of s){let a=t.value;if(a.startsWith("@")||a.startsWith("<")){let n=a.slice(1);a=e.get(n)??""}let o=`--${i}\r
`;t.filename?(o+=`Content-Disposition: form-data; name="${t.name}"; filename="${t.filename}"\r
`,t.contentType&&(o+=`Content-Type: ${t.contentType}\r
`)):o+=`Content-Disposition: form-data; name="${t.name}"\r
`,o+=`\r
${a}\r
`,r.push(o)}return r.push(`--${i}--\r
`),{body:r.join(""),boundary:i}}var $={name:"curl",summary:"transfer a URL",usage:"curl [OPTIONS] URL",options:["-X, --request METHOD HTTP method (GET, POST, PUT, DELETE, etc.)","-H, --header HEADER Add header (can be used multiple times)","-d, --data DATA HTTP POST data (DATA=@file reads from file, strips newlines)"," --data-raw DATA HTTP POST data (no @ interpretation)"," --data-binary DATA HTTP POST binary data (DATA=@file reads file verbatim)"," --data-urlencode DATA URL-encode and POST data (supports @file and name@file)","-F, --form NAME=VALUE Multipart form data","-u, --user USER:PASS HTTP authentication","-A, --user-agent STR Set User-Agent header","-e, --referer URL Set Referer header","-b, --cookie DATA Send cookies (name=value or @file)","-c, --cookie-jar FILE Save cookies to file","-T, --upload-file FILE Upload file (PUT)","-o, --output FILE Write output to file","-O, --remote-name Write to file named from URL","-I, --head Show headers only (HEAD request)","-i, --include Include response headers in output","-s, --silent Silent mode (no progress)","-S, --show-error Show errors even when silent","-f, --fail Fail silently on HTTP errors (no output)","-L, --location Follow redirects (default)"," --max-redirs NUM Maximum redirects (default: 20)","-m, --max-time SECS Maximum time for request"," --connect-timeout SECS Connection timeout","-w, --write-out FMT Output format after completion","-v, --verbose Verbose output"," --help Display this help and exit","","Note: Network access must be configured via BashEnv network option."," curl is not available by default for security reasons."]};function f(s,e,i){i.allowFile&&e.startsWith("@")?(s.dataFile={mode:i.binary?"binary":"ascii",path:e.slice(1)},s.data=void 0):(s.data=e,s.dataFile=void 0),i.binary&&(s.dataBinary=!0)}function P(s,e){if(e.startsWith("@")){s.urlencodeFiles.push({path:e.slice(1)});return}let i=e.indexOf("@"),r=e.indexOf("=");if(i>0&&(r<0||i<r)){s.urlencodeFiles.push({name:e.slice(0,i),path:e.slice(i+1)});return}s.data=(s.data?`${s.data}&`:"")+O(e)}function v(s){let e={method:"GET",headers:new u,dataBinary:!1,urlencodeFiles:[],formFields:[],useRemoteName:!1,headOnly:!1,includeHeaders:!1,silent:!1,showError:!1,failSilently:!1,followRedirects:!0,verbose:!1},i=!1;for(let r=0;r<s.length;r++){let t=s[r];if(t==="-X"||t==="--request")e.method=s[++r]??"GET";else if(t.startsWith("-X"))e.method=t.slice(2);else if(t.startsWith("--request="))e.method=t.slice(10);else if(t==="-H"||t==="--header"){let a=s[++r];if(a){let o=a.indexOf(":");if(o>0){let n=a.slice(0,o).trim(),l=a.slice(o+1).trim();e.headers.append(n,l)}}}else if(t.startsWith("--header=")){let a=t.slice(9),o=a.indexOf(":");if(o>0){let n=a.slice(0,o).trim(),l=a.slice(o+1).trim();e.headers.append(n,l)}}else if(t==="-d"||t==="--data")f(e,s[++r]??"",{binary:!1,allowFile:!0}),i=!0;else if(t==="--data-raw")f(e,s[++r]??"",{binary:!1,allowFile:!1}),i=!0;else if(t.startsWith("-d"))f(e,t.slice(2),{binary:!1,allowFile:!0}),i=!0;else if(t.startsWith("--data="))f(e,t.slice(7),{binary:!1,allowFile:!0}),i=!0;else if(t.startsWith("--data-raw="))f(e,t.slice(11),{binary:!1,allowFile:!1}),i=!0;else if(t==="--data-binary")f(e,s[++r]??"",{binary:!0,allowFile:!0}),i=!0;else if(t.startsWith("--data-binary="))f(e,t.slice(14),{binary:!0,allowFile:!0}),i=!0;else if(t==="--data-urlencode")P(e,s[++r]??""),i=!0;else if(t.startsWith("--data-urlencode="))P(e,t.slice(17)),i=!0;else if(t==="-F"||t==="--form"){let a=s[++r]??"",o=m(a);o&&e.formFields.push(o),i=!0}else if(t.startsWith("--form=")){let a=t.slice(7),o=m(a);o&&e.formFields.push(o),i=!0}else if(t==="-u"||t==="--user")e.user=s[++r];else if(t.startsWith("-u"))e.user=t.slice(2);else if(t.startsWith("--user="))e.user=t.slice(7);else if(t==="-A"||t==="--user-agent")e.headers.set("User-Agent",s[++r]??"");else if(t.startsWith("-A"))e.headers.set("User-Agent",t.slice(2));else if(t.startsWith("--user-agent="))e.headers.set("User-Agent",t.slice(13));else if(t==="-e"||t==="--referer")e.headers.set("Referer",s[++r]??"");else if(t.startsWith("-e"))e.headers.set("Referer",t.slice(2));else if(t.startsWith("--referer="))e.headers.set("Referer",t.slice(10));else if(t==="-b"||t==="--cookie")e.headers.set("Cookie",s[++r]??"");else if(t.startsWith("-b"))e.headers.set("Cookie",t.slice(2));else if(t.startsWith("--cookie="))e.headers.set("Cookie",t.slice(9));else if(t==="-c"||t==="--cookie-jar")e.cookieJar=s[++r];else if(t.startsWith("--cookie-jar="))e.cookieJar=t.slice(13);else if(t==="-T"||t==="--upload-file")e.uploadFile=s[++r],e.method==="GET"&&(e.method="PUT");else if(t.startsWith("--upload-file="))e.uploadFile=t.slice(14),e.method==="GET"&&(e.method="PUT");else if(t==="-m"||t==="--max-time"){let a=parseFloat(s[++r]??"0");!Number.isNaN(a)&&a>0&&(e.timeoutMs=a*1e3)}else if(t.startsWith("--max-time=")){let a=parseFloat(t.slice(11));!Number.isNaN(a)&&a>0&&(e.timeoutMs=a*1e3)}else if(t==="--connect-timeout"){let a=parseFloat(s[++r]??"0");!Number.isNaN(a)&&a>0&&e.timeoutMs===void 0&&(e.timeoutMs=a*1e3)}else if(t.startsWith("--connect-timeout=")){let a=parseFloat(t.slice(18));!Number.isNaN(a)&&a>0&&e.timeoutMs===void 0&&(e.timeoutMs=a*1e3)}else if(t==="-o"||t==="--output")e.outputFile=s[++r];else if(t.startsWith("--output="))e.outputFile=t.slice(9);else if(t==="-O"||t==="--remote-name")e.useRemoteName=!0;else if(t==="-I"||t==="--head")e.headOnly=!0,e.method="HEAD";else if(t==="-i"||t==="--include")e.includeHeaders=!0;else if(t==="-s"||t==="--silent")e.silent=!0;else if(t==="-S"||t==="--show-error")e.showError=!0;else if(t==="-f"||t==="--fail")e.failSilently=!0;else if(t==="-L"||t==="--location")e.followRedirects=!0;else if(t==="--max-redirs")r++;else if(!t.startsWith("--max-redirs="))if(t==="-w"||t==="--write-out")e.writeOut=s[++r];else if(t.startsWith("--write-out="))e.writeOut=t.slice(12);else if(t==="-v"||t==="--verbose")e.verbose=!0;else{if(t.startsWith("--")&&t!=="--")return c("curl",t);if(t.startsWith("-")&&t!=="-")for(let a of t.slice(1))switch(a){case"s":e.silent=!0;break;case"S":e.showError=!0;break;case"f":e.failSilently=!0;break;case"L":e.followRedirects=!0;break;case"I":e.headOnly=!0,e.method="HEAD";break;case"i":e.includeHeaders=!0;break;case"O":e.useRemoteName=!0;break;case"v":e.verbose=!0;break;default:return c("curl",`-${a}`)}else t.startsWith("-")||(e.url=t)}}return i&&e.method==="GET"&&(e.method="POST"),e}function h(s){return Object.entries(s).map(([e,i])=>`${e}: ${i}`).join(`\r
`)}function S(s){try{return new URL(s).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function p(s,e){let i=s;return i=i.replace(/%\{http_code\}/g,String(e.status)),i=i.replace(/%\{content_type\}/g,e.headers["content-type"]||""),i=i.replace(/%\{url_effective\}/g,e.url),i=i.replace(/%\{size_download\}/g,String(e.bodyLength)),i=i.replace(/\\n/g,`
`),i}async function A(s,e){if(s.dataFile){let i=e.fs.resolvePath(e.cwd,s.dataFile.path),r=await e.fs.readFile(i);return s.dataFile.mode==="ascii"&&(r=r.replace(/[\r\n]/g,"")),s.data?`${r}&${s.data}`:r}return s.data}async function E(s,e,i){if(s.urlencodeFiles.length===0)return i;let r=i?[i]:[];for(let t of s.urlencodeFiles){let a=e.fs.resolvePath(e.cwd,t.path),o=await e.fs.readFile(a),n=encodeURIComponent(o);r.push(t.name?`${encodeURIComponent(t.name)}=${n}`:n)}return r.join("&")}async function H(s,e){if(s.uploadFile){let r=e.fs.resolvePath(e.cwd,s.uploadFile);return{body:await e.fs.readFile(r)}}if(s.formFields.length>0){let r=new Map;for(let o of s.formFields)if(o.value.startsWith("@")||o.value.startsWith("<")){let n=e.fs.resolvePath(e.cwd,o.value.slice(1));try{let l=await e.fs.readFile(n);r.set(o.value.slice(1),l)}catch{r.set(o.value.slice(1),"")}}let{body:t,boundary:a}=W(s.formFields,r);return{body:t,contentType:`multipart/form-data; boundary=${a}`}}let i=await A(s,e);return i=await E(s,e,i),i!==void 0?{body:i}:{}}function k(s,e){let i=new u(s.headers);if(s.user){let r=Buffer.from(s.user).toString("base64");i.set("Authorization",`Basic ${r}`)}return e&&!i.has("Content-Type")&&i.set("Content-Type",e),i}async function C(s,e,i){if(!s.cookieJar)return;let r=e["set-cookie"];if(!r)return;let t=i.fs.resolvePath(i.cwd,s.cookieJar);await i.fs.writeFile(t,r)}function U(s){return F(s,"binary")}function x(s,e,i){let r="";if(s.verbose){r+=`> ${s.method} ${i}
`;for(let[t,a]of s.headers)r+=`> ${t}: ${a}
`;r+=`>
`,r+=`< HTTP/1.1 ${e.status} ${e.statusText}
`;for(let[t,a]of Object.entries(e.headers))r+=`< ${t}: ${a}
`;r+=`<
`}return s.includeHeaders&&!s.verbose&&(r+=`HTTP/1.1 ${e.status} ${e.statusText}\r
`,r+=h(e.headers),r+=`\r
\r
`),s.headOnly?s.includeHeaders||s.verbose||(r+=`HTTP/1.1 ${e.status} ${e.statusText}\r
`,r+=h(e.headers),r+=`\r
`):r+=U(e.body),s.writeOut&&(r+=p(s.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.byteLength})),r}var K={name:"curl",async execute(s,e){if(b(s))return w($);let i=v(s);if("exitCode"in i)return i;let r=i;if(!r.url)return{stdout:"",stderr:`curl: no URL specified
`,exitCode:2};if(!e.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
`,exitCode:1};let t=r.url;t.match(/^https?:\/\//)||(t=`https://${t}`);try{let{body:a,contentType:o}=await H(r,e),n=k(r,o),l=await e.fetch(t,{method:r.method,headers:n,body:a,followRedirects:r.followRedirects,timeoutMs:r.timeoutMs});if(await C(r,l.headers,e),r.failSilently&&l.status>=400)return{stdout:"",stderr:r.showError||!r.silent?`curl: (22) The requested URL returned error: ${l.status}
`:"",exitCode:22};let d=x(r,l,t);if(r.outputFile||r.useRemoteName){let y=r.outputFile||S(t),R=e.fs.resolvePath(e.cwd,y);await e.fs.writeFile(R,r.headOnly?"":l.body),r.verbose||(d=""),r.writeOut&&(d=p(r.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.byteLength}))}return{stdout:d,stderr:"",exitCode:0,stdoutKind:"bytes"}}catch(a){let o=T(a),n=1;return o.includes("Network access denied")?n=7:o.includes("HTTP method")&&o.includes("not allowed")?n=3:o.includes("Redirect target not in allow-list")||o.includes("Too many redirects")?n=47:o.includes("aborted")&&(n=28),{stdout:"",stderr:!r.silent||r.showError?`curl: (${n}) ${o}
`:"",exitCode:n}}}};export{K as curlCommand};