botparty 0.0.70 → 0.0.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -175,7 +175,7 @@ ${r}
|
|
|
175
175
|
curl: try 'botparty curl --help' for more information
|
|
176
176
|
`),process.exit(2));let l={};if(i.header)for(let R of i.header){let I=R.indexOf(":");if(I>0){let L=R.slice(0,I).trim(),q=R.slice(I+1).trim();q===""?delete l[L]:l[L]=q}else R.endsWith(";")&&(l[R.slice(0,-1).trim()]="")}if(i.userAgent&&(l["User-Agent"]=i.userAgent),i.referer&&(l.Referer=i.referer),i.cookie&&(l.Cookie=i.cookie.join("; ")),i.user){let R=Buffer.from(i.user).toString("base64");l.Authorization=`Basic ${R}`}i.compressed&&(l["Accept-Encoding"]="gzip, deflate, br"),i.range&&(l.Range=`bytes=${i.range}`),i.json&&i.json.length>0&&(!l["Content-Type"]&&!l["content-type"]&&(l["Content-Type"]="application/json"),!l.Accept&&!l.accept&&(l.Accept="application/json"));let _=mN(i),d=dN(i),m=c;if(i.get&&d){let R=m.includes("?")?"&":"?";m=m+R+d,d=void 0}if(!d&&_d(i)){let R=new FormData,I=(L,q)=>{let Z=L.indexOf("=");if(Z<=0)return;let Ne=L.slice(0,Z),W=L.slice(Z+1);if(q&&W.startsWith("@"))try{let ze=zi(W.slice(1)),pt=new Blob([ze]);R.append(Ne,pt,lN(W.slice(1)))}catch{process.stderr.write(`curl: (26) Failed to open/read local data from file: ${W.slice(1)}
|
|
177
177
|
`),process.exit(26)}else R.append(Ne,W)};if(i.form)for(let L of i.form)I(L,!0);if(i.formString)for(let L of i.formString)I(L,!1);d=R}if(i.uploadFile&&!d)try{d=zi(i.uploadFile,"utf-8")}catch{process.stderr.write(`curl: (26) Failed to open/read local data from file: ${i.uploadFile}
|
|
178
|
-
`),process.exit(26)}d&&!l["Content-Type"]&&!l["content-type"]&&(i.json&&i.json.length>0?l["Content-Type"]="application/json":l["Content-Type"]="application/x-www-form-urlencoded"),s={url:m,method:_,headers:l,body:typeof d=="string"?d:void 0};let f=Date.now(),g=!1;try{let R=new URL(s.url);g=await sd(R.hostname,o.stateDir)}catch{}let y=i.retry?parseInt(i.retry,10):0,b=i.retryDelay?parseInt(i.retryDelay,10)*1e3:1e3,A=null,D=null;for(let R=0;R<=y;R++)try{if(g){let I=await o.generateToken(),L=new Headers(s.headers);if(L.set("Authorization",`Bearer ${I}`),D=await fetch(s.url,{method:s.method,headers:L,body:s.body}),D.status===401){
|
|
178
|
+
`),process.exit(26)}d&&!l["Content-Type"]&&!l["content-type"]&&(i.json&&i.json.length>0?l["Content-Type"]="application/json":l["Content-Type"]="application/x-www-form-urlencoded"),s={url:m,method:_,headers:l,body:typeof d=="string"?d:void 0};let f=Date.now(),g=!1;try{let R=new URL(s.url);g=await sd(R.hostname,o.stateDir)}catch{}let y=i.retry?parseInt(i.retry,10):0,b=i.retryDelay?parseInt(i.retryDelay,10)*1e3:1e3,A=null,D=null;for(let R=0;R<=y;R++)try{if(g){let I=await o.generateToken(),L=new Headers(s.headers);if(L.set("Authorization",`Bearer ${I}`),D=await fetch(s.url,{method:s.method,headers:L,body:s.body}),D.status===401){let q=await o.generateToken(),Z=new Headers(s.headers);Z.set("Authorization",`Bearer ${q}`),D=await fetch(s.url,{method:s.method,headers:Z,body:s.body})}}else D=await o.fetch(s.url,{method:s.method,headers:s.headers,body:s.body});if(D.status>=500&&R<y){A=new Error(`HTTP ${D.status}`),await new Promise(I=>setTimeout(I,b));continue}break}catch(I){if(A=I,R<y){await new Promise(L=>setTimeout(L,b));continue}throw I}if(!D)throw A;await cd(D,i,s.method,s.url,s.headers,f)}catch(o){if(i.silent&&!i.showError&&process.exit(1),ud(o)){if(i.waitOnAuthlink){process.stderr.write(`
|
|
179
179
|
`),process.stderr.write(` ${je("Authorization required:")} ${o.message}
|
|
180
180
|
`),process.stderr.write(` ${J("Auth URL:")} ${B(o.actionUrl)}
|
|
181
181
|
`),process.stderr.write(` ${J("Open this link to authorize, then the request will retry.")}
|