@hopeio/utils
Version:
javascript utils
2 lines (1 loc) • 6.86 kB
JavaScript
;var q=Object.defineProperty;var I=(e,t,s)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var l=(e,t,s)=>I(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./compatible-BKCYa6RY.js");require("crypto");const U=require("spark-md5");var u=(e=>(e.APIUser="api-user",e.WoHome="wohome",e.WoCloud="wocloud",e.Wostore="wostore",e))(u||{}),h=(e=>(e.Personal="0",e.Family="1",e.Private="4",e))(h||{});const m="XFmi9GS2hzk98jGX",p="1001000021";var C=(e=>(e[e.NameAsc=0]="NameAsc",e[e.NameDesc=1]="NameDesc",e[e.SizeAsc=2]="SizeAsc",e[e.SizeDesc=3]="SizeDesc",e[e.TimeAsc=4]="TimeAsc",e[e.TimeDesc=5]="TimeDesc",e))(C||{});const T={clientId:p},w={clientId:p,secret:!0},d={secret:!0},g=new Error("invalid psToken"),y=class y{constructor(){l(this,"_fetch",async function(t,s,r,o){const a=await fetch(t,{headers:r,body:JSON.stringify(o),method:s});return{status:a.status,data:await a.json(),headers:a.headers}});l(this,"_failCallback");l(this,"accessToken","");l(this,"accessKey","");l(this,"refreshToken","");l(this,"psToken","");l(this,"_proxy","");l(this,"iv","wNSOYIB1k1DjY5lA");l(this,"DefaultBaseURL","https://panservice.mail.wo.cn");l(this,"DefaultZoneURL","https://tjupload.pan.wo.cn");l(this,"DefaultPartSize",8*1024*1024)}static getInstance(){return y.instance||(y.instance=new y),y.instance}set fetch(t){this._fetch=t}set failCallback(t){this._failCallback=t}set proxy(t){this._proxy=t}setToken(t,s){this.accessToken=t,this.accessKey=t.slice(0,16),this.refreshToken=s}async request(t,s,r,o,a="dispatcher"){const c={"Content-Type":"application/json",Origin:"https://pan.wo.cn",Referer:"https://pan.wo.cn/"};this.accessToken!==""&&(c.Accesstoken=this.accessToken);let f=await this.newBody(t,r,o);s!==""&&(f={header:R(t,s),body:f});let D=u.WoHome;t!=u.WoHome&&(D=u.APIUser);let A=`${this.DefaultBaseURL}/${D}/${a}`;this._proxy!=""&&(c["Target-Url"]=this.DefaultBaseURL,c["Target-Origin"]="https://pan.wo.cn",c["Target-Referer"]="https://pan.wo.cn/",A=`${this._proxy}/${D}/${a}`);const{status:k,data:i}=await this._fetch(A,"POST",c,f);if(k>399)if(this._failCallback)this._failCallback(`request failed: ${k}, data: ${i}`);else throw new Error(`request failed: ${k}, data: ${i}`);if(i.STATUS!="200")if(this._failCallback)this._failCallback(`request failed with status: ${i.STATUS}, msg: ${i.MSG}`);else throw new Error(`request failed with status: ${i.STATUS}, msg: ${i.MSG}`);if(i.RSP.RSP_CODE!="0000")if(this._failCallback)this._failCallback(`request failed with rsp_code: ${i.RSP.RSP_CODE},rep_desc: ${i.RSP.RSP_DESC}`);else throw new Error(`request failed with rsp_code: ${i.RSP.RSP_CODE},rep_desc: ${i.RSP.RSP_DESC}`);return typeof i.RSP.DATA=="string"&&i.RSP.DATA!==""?JSON.parse(await this.decrypt(i.RSP.DATA,t)):i.RSP.DATA}requestApiUser(t,s,r){return this.request(u.APIUser,t,s,r)}requestWoStore(t,s,r){return this.request(u.Wostore,t,s,r)}requestWoHome(t,s,r){return this.request(u.WoHome,t,s,r)}async encrypt(t,s){try{let r=this.accessKey;return s!=u.WoHome&&(r=m),P.encrypt(t,r,this.iv)}catch(r){throw console.log(r),r}}async decrypt(t,s=u.WoHome){try{let r=this.accessKey;return s!=u.WoHome&&(r=m),await P.decrypt(t,r,this.iv)}catch(r){throw console.log(r),r}}async newBody(t,s,r){return{...r,param:s?await this.encrypt(JSON.stringify(s),t):""}}};l(y,"instance");let S=y;function R(e,t){const s=Date.now(),r=Math.floor(Math.random()*8999)+1e5,o="",a=U.hash(`${t}${s}${r}${e}${o}`);return{key:t,resTime:s,reqSeq:r,channel:e,sign:a,version:o}}const n=S.getInstance();function L(e,t){return n.requestApiUser("PcWebLogin",{phone:e,password:t,uuid:"",verifyCode:"",clientSecret:m},w)}async function $(e,t,s){const r=await n.requestApiUser("PcLoginVerifyCode",{phone:e,messageCode:s,verifyCode:null,uuid:null,clientSecret:m,password:t},w);return n.setToken(r.access_token,r.refresh_token),r}function b(){return n.requestApiUser("AppQueryUser",{accessToken:n.accessToken},w)}function v(){return n.requestWoStore("AppQueryUserV2",{psToken:n.psToken},w)}async function W(){const e=await n.requestApiUser("AppRefreshToken",{refreshToken:n.refreshToken,clientSecret:m},w);return n.setToken(e.access_token,e.refresh_token),e}function _(e){return n.request(u.APIUser,"",{operateType:"1",phone:e},{...T,func:"app_send"},"sendMessageCodeBase")}async function F(e,t){const s=await n.requestWoStore("AppLoginByMobile",{phone:e,smsCode:t,clientSecret:m},T);return n.setToken(s.access_token,s.refresh_token),s}function H(e,t,s,r,o,a){const c={spaceType:e,parentDirectoryId:t,pageNum:s,pageSize:r,sortRule:o,clientId:p};if(e==h.Family&&(c.familyId=a),e==h.Private){if(n.psToken=="")throw g;c.psToken=n.psToken}return n.requestWoHome("QueryAllFiles",c,d)}async function M(e){const t=await n.requestWoHome("PrivateSpaceLogin",{pwd:e,clientId:p},d);return n.psToken=t.psToken,t}function E(e){return n.requestWoHome("GetDownloadUrlV2",{type:"1",fidList:e,clientId:p},d)}function O(e,t){return n.requestWoHome("GetDownloadUrl",{fidList:t,spaceType:e,clientId:p},d)}function V(e,t,s,r,o,a,c){const f={targetDirId:s,sourceType:r,targetType:o,dirList:e,fileList:t,secret:!1,clientId:p};return r==h.Family&&(f.fromFamilyId=a),o==h.Family&&(f.familyId=c),n.requestWoHome("MoveFile",f,d)}function B(e,t,s,r,o,a,c){const f={targetDirId:s,sourceType:r,targetType:o,dirList:e,fileList:t,secret:!1,clientId:p};return r==h.Family&&(f.fromFamilyId=a),o==h.Family&&(f.familyId=c),n.requestWoHome("CopyFile",f,d)}function Q(e,t,s){return n.requestWoHome("DeleteFile",{spaceType:e,vipLevel:"0",dirList:t,fileList:s,clientId:p},d)}function G(){return n.requestWoHome("EmptyRecycleData",{clientId:p},d)}function J(){return n.requestWoHome("VerifySetPwd",{psToken:n.psToken},d)}function N(){return n.request(u.Wostore,"FCloudProductOrdListQry",{},{...d,qryType:"1"})}const j="https://tjtn.pan.wo.cn/compressed/preview?fid=",z="https://tjtn.pan.wo.cn/thumbnailsV3?fid=",x="https://du.smartont.net:8442/openapi/thumbnails?fid=";function K(e){return`${j}${encodeURIComponent(e)}`}function X(e){return`${z}${encodeURIComponent(e)}`}function Y(e){return`${x}${encodeURIComponent(e)}`}exports.AppLoginByMobile=F;exports.AppQueryUser=b;exports.AppQueryUser2=v;exports.AppRefreshToken=W;exports.Channel=u;exports.CopyFile=B;exports.DefaultClientID=p;exports.DefaultClientSecret=m;exports.DeleteFile=Q;exports.EmptyRecycleData=G;exports.ErrInvalidPsToken=g;exports.FCloudProductOrdListQry=N;exports.GetDownloadUrl=O;exports.GetDownloadUrlV2=E;exports.JsonClientID=T;exports.JsonClientIDSecret=w;exports.JsonSecret=d;exports.MoveFile=V;exports.PcLoginVerifyCode=$;exports.PcWebLogin=L;exports.PrivateSpaceLogin=M;exports.QueryAllFiles=H;exports.SortType=C;exports.SpaceType=h;exports.VerifySetPwd=J;exports.client=n;exports.preview=K;exports.sendMessageCodeBase=_;exports.thumbnails=Y;exports.thumbnailsV3=X;