!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.cloud={})}(this,function(e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}))(e,t)};function t(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var d=function(){return(d=Object.assign||function(e){for(var t,r=1,n=arguments.length;rs[0]&&t[1]>>2]>>>24-i%4*8&255;t[n+i>>>2]|=a<<24-(n+i)%4*8}else for(i=0;i>>2]=r[i>>>2];return this.sigBytes+=o,this},clamp:function(){var e=this.words,t=this.sigBytes;e[t>>>2]&=4294967295<<32-t%4*8,e.length=u.ceil(t/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r>16)&n)<<16)+(t=18e3*(65535&t)+(t>>16)&n)&n;return(e/4294967296+.5)*(.5>>2]>>>24-o%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new l.init(r,t/2)}},s=i.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(i))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new l.init(r,t)}},c=i.Utf8={stringify:function(e){try{return decodeURIComponent(escape(s.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return s.parse(unescape(encodeURIComponent(e)))}},d=n.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=c.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(e){var t=this._data,r=t.words,n=t.sigBytes,o=this.blockSize,i=n/(4*o),a=(i=e?u.ceil(i):u.max((0|i)-this._minBufferSize,0))*o,e=u.min(4*a,n);if(a){for(var s=0;s>>7)^(p<<14|p>>>18)^p>>>3;var f=x[d-2];var v=(f<<15|f>>>17)^(f<<13|f>>>19)^f>>>10;x[d]=h+x[d-7]+v+x[d-16]}var y=s&c^~s&u;var m=n&o^n&i^o&i;var g=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22);var b=(s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25);var w=l+b+y+A[d]+x[d];var _=g+m;l=u;u=c;c=s;s=a+w|0;a=i;i=o;o=n;n=w+_|0}r[0]=r[0]+n|0;r[1]=r[1]+o|0;r[2]=r[2]+i|0;r[3]=r[3]+a|0;r[4]=r[4]+s|0;r[5]=r[5]+c|0;r[6]=r[6]+u|0;r[7]=r[7]+l|0},_doFinalize:function(){var e=this._data;var t=e.words;var r=this._nDataBytes*8;var n=e.sigBytes*8;t[n>>>5]|=128<<24-n%32;t[(n+64>>>9<<4)+14]=o.floor(r/4294967296);t[(n+64>>>9<<4)+15]=r;e.sigBytes=t.length*4;this._process();return this._hash},clone:function(){var e=i.clone.call(this);e._hash=this._hash.clone();return e}});return t.SHA256=i._createHelper(p),t.HmacSHA256=i._createHmacHelper(p),e.SHA256}(l)}),i(function(e,t){var r,s;e.exports=(r=(e=l).lib.Base,s=e.enc.Utf8,void(e.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));for(var r=e.blockSize,n=4*r,e=((t=t.sigBytes>n?e.finalize(t):t).clamp(),this._oKey=t.clone()),t=this._iKey=t.clone(),o=e.words,i=t.words,a=0;a>>6-s%4*2,i[a>>>2]|=(n|o)<<24-a%4*8,a++);return c.create(i,a)}var c;e.exports=(c=(e=l).lib.WordArray,e.enc.Base64={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=this._map,o=(e.clamp(),[]),i=0;i>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,s=0;s<4&&i+.75*s>>6*(3-s)&63));var c=n.charAt(64);if(c)for(;o.length%4;)o.push(c);return o.join("")},parse:function(e){var t=e.length,r=this._map;if(!(n=this._reverseMap))for(var n=this._reverseMap=[],o=0;o>>24)&16711935|(o<<24|o>>>8)&4278255360}var i=this._hash.words;var a=e[t+0];var s=e[t+1];var c=e[t+2];var u=e[t+3];var l=e[t+4];var d=e[t+5];var p=e[t+6];var h=e[t+7];var f=e[t+8];var v=e[t+9];var y=e[t+10];var m=e[t+11];var g=e[t+12];var b=e[t+13];var w=e[t+14];var _=e[t+15];var A=i[0];var x=i[1];var q=i[2];var S=i[3];A=M(A,x,q,S,a,7,R[0]);S=M(S,A,x,q,s,12,R[1]);q=M(q,S,A,x,c,17,R[2]);x=M(x,q,S,A,u,22,R[3]);A=M(A,x,q,S,l,7,R[4]);S=M(S,A,x,q,d,12,R[5]);q=M(q,S,A,x,p,17,R[6]);x=M(x,q,S,A,h,22,R[7]);A=M(A,x,q,S,f,7,R[8]);S=M(S,A,x,q,v,12,R[9]);q=M(q,S,A,x,y,17,R[10]);x=M(x,q,S,A,m,22,R[11]);A=M(A,x,q,S,g,7,R[12]);S=M(S,A,x,q,b,12,R[13]);q=M(q,S,A,x,w,17,R[14]);x=M(x,q,S,A,_,22,R[15]);A=O(A,x,q,S,s,5,R[16]);S=O(S,A,x,q,p,9,R[17]);q=O(q,S,A,x,m,14,R[18]);x=O(x,q,S,A,a,20,R[19]);A=O(A,x,q,S,d,5,R[20]);S=O(S,A,x,q,y,9,R[21]);q=O(q,S,A,x,_,14,R[22]);x=O(x,q,S,A,l,20,R[23]);A=O(A,x,q,S,v,5,R[24]);S=O(S,A,x,q,w,9,R[25]);q=O(q,S,A,x,u,14,R[26]);x=O(x,q,S,A,f,20,R[27]);A=O(A,x,q,S,b,5,R[28]);S=O(S,A,x,q,c,9,R[29]);q=O(q,S,A,x,h,14,R[30]);x=O(x,q,S,A,g,20,R[31]);A=I(A,x,q,S,d,4,R[32]);S=I(S,A,x,q,f,11,R[33]);q=I(q,S,A,x,m,16,R[34]);x=I(x,q,S,A,w,23,R[35]);A=I(A,x,q,S,s,4,R[36]);S=I(S,A,x,q,l,11,R[37]);q=I(q,S,A,x,h,16,R[38]);x=I(x,q,S,A,y,23,R[39]);A=I(A,x,q,S,b,4,R[40]);S=I(S,A,x,q,a,11,R[41]);q=I(q,S,A,x,u,16,R[42]);x=I(x,q,S,A,p,23,R[43]);A=I(A,x,q,S,v,4,R[44]);S=I(S,A,x,q,g,11,R[45]);q=I(q,S,A,x,_,16,R[46]);x=I(x,q,S,A,c,23,R[47]);A=E(A,x,q,S,a,6,R[48]);S=E(S,A,x,q,h,10,R[49]);q=E(q,S,A,x,w,15,R[50]);x=E(x,q,S,A,d,21,R[51]);A=E(A,x,q,S,g,6,R[52]);S=E(S,A,x,q,u,10,R[53]);q=E(q,S,A,x,y,15,R[54]);x=E(x,q,S,A,s,21,R[55]);A=E(A,x,q,S,f,6,R[56]);S=E(S,A,x,q,_,10,R[57]);q=E(q,S,A,x,p,15,R[58]);x=E(x,q,S,A,b,21,R[59]);A=E(A,x,q,S,l,6,R[60]);S=E(S,A,x,q,m,10,R[61]);q=E(q,S,A,x,c,15,R[62]);x=E(x,q,S,A,v,21,R[63]);i[0]=i[0]+A|0;i[1]=i[1]+x|0;i[2]=i[2]+q|0;i[3]=i[3]+S|0},_doFinalize:function(){var e=this._data;var t=e.words;var r=this._nDataBytes*8;var n=e.sigBytes*8;t[n>>>5]|=128<<24-n%32;var o=l.floor(r/4294967296);var i=r;t[(n+64>>>9<<4)+15]=(o<<8|o>>>24)&16711935|(o<<24|o>>>8)&4278255360;t[(n+64>>>9<<4)+14]=(i<<8|i>>>24)&16711935|(i<<24|i>>>8)&4278255360;e.sigBytes=(t.length+1)*4;this._process();var a=this._hash;var s=a.words;for(var c=0;c<4;c++){var u=s[c];s[c]=(u<<8|u>>>24)&16711935|(u<<24|u>>>8)&4278255360}return a},clone:function(){var e=o.clone.call(this);e._hash=this._hash.clone();return e}});function M(e,t,r,n,o,i,a){var s=e+(t&r|~t&n)+o+a;return(s<>>32-i)+t}function O(e,t,r,n,o,i,a){var s=e+(t&n|r&~n)+o+a;return(s<>>32-i)+t}function I(e,t,r,n,o,i,a){var s=e+(t^r^n)+o+a;return(s<>>32-i)+t}function E(e,t,r,n,o,i,a){var s=e+(r^(t|~n))+o+a;return(s<>>32-i)+t}return t.MD5=o._createHelper(s),t.HmacMD5=o._createHmacHelper(s),e.MD5}(l)}),C=((D=u=u||{})[D.MTOP=1]="MTOP",D[D.MY=2]="MY",D[D.GATEWAY=3]="GATEWAY",t(p,a=Error),p);function p(){return null!==a&&a.apply(this,arguments)||this}function G(e){this.options=e||{},this.options.dataProxyGatewayUrl=this.options.dataProxyGatewayUrl||this.options.gatewayUrl}f.prototype.init=function(t,r){return c(this,void 0,void 0,function(){return m(this,function(e){return this.options=d({},t),this.proxy=r,this.tasks=[],this.inited=!0,[2]})})},f.getRequestType=function(e){return 0===e.indexOf("mtop.")?u.MTOP:0===e.indexOf("my.")?u.MY:u.GATEWAY},f.prototype.verifyResponse=function(t,r,n){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:if(g(n,"mc-code")||g(t,"errCode")||g(t,"error_response.code"),r.__is_retry_task__)return this.tryThrowError(t,n),[2,t];e.label=1;case 1:return e.trys.push([1,3,,4]),this.tryThrowError(t,n),[2,t];case 2:return[2,e.sent()];case 3:throw e.sent();case 4:return[2]}})})},f.prototype.tryThrowError=function(e,t){var r=g(t,"mc-msg")||g(e,"errMsg")||g(e,"error_response.msg"),t=g(t,"mc-code")||g(e,"errCode")||g(e,"error_response.code");if(t&&"200"!=t)throw(e=new C(t+":::"+r)).code=t,e.msg=r,e},f.prototype.sendGatewayRequest=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return r=this.createGatewayRequest(r),[4,this.proxy.apply(d({},r),u.GATEWAY)];case 1:return t=e.sent(),[4,this.verifyResponse(g(t,"data"),r,g(t,"headers"))];case 2:return[2,e.sent()]}})})},f.prototype.exec=function(t,r){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:if(r=r||f.getRequestType(t.url),this.inited)return t.data=t.data||{},r!==u.GATEWAY?[3,2]:[4,this.sendGatewayRequest(t)];throw new Error("请先调用cloud.init()");case 1:return[2,e.sent()];case 2:return[4,this.proxy.apply(t,r)];case 3:return[2,e.sent()]}})})},f.prototype.getHttpRequestSign=function(e,t,r,n,o){if(this.options.signSecret)return o=o,delete n["mc-sign"],t=t+"\n"+s.stringify(H(o))+"\napplication/json\n"+Object.keys(n).filter(function(e){return/^mc-/.test(e)}).sort().map(function(e){return e.toLowerCase()+":"+n[e]}).join("\n")+"\n"+e+(r?"?"+r:""),s.stringify(j(t,this.options.signSecret))},f.prototype.createGatewayRequest=function(e){var t=this.options,r=t.sessionKey,n=t.appKey,o=t.requestId,i=t.miniappId,a=t.openId,s=t.unionId,c=t.cloudId,t=t.sdkVersion,r=(e.method="POST",d(d({},e.headers),{"Content-Type":"application/json","mc-timestamp":""+Date.now(),"mc-session":r})),a=(a&&(r["mc-open-id"]=a),c&&(r["mc-cloud-id"]=c),s&&(r["mc-union-id"]=s),n&&(r["mc-appKey"]=n),i&&(r["mc-miniapp-id"]=i),o&&(r["mc-request-id"]=o),t&&(r["mc-sdk-version"]=t),e.env&&(r["mc-env"]=e.env),r["mc-session"]||delete r["mc-session"],e.rawData=e.rawData||e.data,"object"==typeof e.data&&(e.data=JSON.stringify(e.data)),this.getHttpRequestSign(e.url,e.method,"",r,e.data));return d(d({},e),{url:""+e.url,headers:d(d({},r),{sign:a,"eagleeye-traceid":o})})};var h=f;function f(){this.inited=!1}function v(e,t){this.request=t,this.options=e}new h;t(b,y=v),b.prototype.invoke=function(t,r,n,o){return void 0===n&&(n="main"),c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.fcRequest({fcName:t,handler:n,data:r,options:Object.assign(o||{},this.options)})];case 1:return[2,e.sent()]}})})},b.prototype.fcRequest=function(t){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.request.exec({env:this.options.env||"online",url:"fc",data:t},u.GATEWAY)];case 1:return[2,e.sent()]}})})},r([o()],b.prototype,"invoke",null);var y,U=b;function b(){return null!==y&&y.apply(this,arguments)||this}var w,z="1.5.5",N="mtop.taobao.miniapp.cloud.store.config.get",F="mtop.taobao.miniapp.cloud.store.config.v2.seller.get",W="mtop.taobao.miniapp.cloud.store.file.save",Y="mtop.taobao.miniapp.cloud.store.file.v2.seller.save",K="mtop.taobao.miniapp.cloud.store.file.delete",J="mtop.taobao.miniapp.cloud.store.file.v2.seller.delete",L="mtop.taobao.miniapp.cloud.store.file.list",V="mtop.taobao.miniapp.cloud.store.file.v2.seller.list",X="other",$=(t(_,w=v),_.prototype.parseUploadResult=function(e,t,r){return this.parsePostUploadResult(e,t,r)},_.prototype.parsePostUploadResult=function(e,t,r){var n;if(t.data)if(r)try{var o=(s=JSON.parse(t.data)).fileId,i=s.url,a=s.message}catch(e){console.log(e)}else try{var s=JSON.parse(t.data);switch(e){case"image":case"font":o=s.jsonData.fileId,i=s.jsonData.url,a=s.errorMessage;break;case"video":o=s.fileId,n=s.videoId,i=s.url,a=s.message;break;case"audio":o=s.fileId,n=s.videoId,i=s.url,a=s.message}}catch(e){}return{imageUrl:i,specialId:o,message:a,videoId:n}},_.prototype.uploadFile=function(y){return c(this,void 0,void 0,function(){var n,o,i,a,s,c,u,l,d,p,h,f,v;return m(this,function(e){switch(e.label){case 0:n=y.filePath,o=y.fileType,o=void 0===o?X:o,i=y.fileName,i=void 0===i?"miniappfile":i,a=y.seller,a=void 0!==a&&a,s=y.dirId,e.label=1;case 1:return e.trys.push([1,3,,4]),u=a?F:N,[4,this.storageRequest(u,{newContainer:!0,cloudPath:i,fileType:o,sellerSpace:a,dirId:s})];case 2:return c=e.sent(),[3,4];case 3:throw u=e.sent(),new Error("获取配置错误"+(u.message||u.toString()));case 4:return l=g(c,["data","model",o],{}),p=l.url,p=void 0===p?"":p,d=l.formData,d=void 0===d?null:d,l=l.headers,(p={url:p,fileType:o,header:void 0===l?null:l,formData:d,filePath:n,fileName:"file"}).formData=p.formData||{},p.header&&p.header.Authorization&&(p.formData.Authorization=p.header.Authorization),i&&(p.formData.localFileName=Date.now()+"-"+((t=i)?0<=(r=t.lastIndexOf("/"))?t.substr(r+1):t:"file")),p.header?"image"!==o&&(p.header.origin=p.header.origin||"https://miniapp-cloud.taobao.com",p.header.referer=p.header.referer||"https://miniapp-cloud.taobao.com"):delete p.header,[4,this.storageRequest("my.uploadFile",p)];case 5:if(l=e.sent(),console.log(l),d=this.parseUploadResult(o,l,a),p=d.imageUrl,f=d.specialId,h=d.message,v=d.videoId,(f={fileType:o,specialId:f||g(c,["data","model",o,"formData","key"],""),videoId:v,url:p,cloudPath:i,sellerSpace:a}).specialId)return[4,this.storageRequest(a?Y:W,f)];throw new Error(h||"上传文件失败");case 6:if(g(v=e.sent(),"data.model.fileId"))return[2,g(v,"data.model")];throw new Error(g(v,["result","msgInfo"],"上传文件失败"))}var t,r})})},_.prototype.deleteFile=function(o){return c(this,void 0,void 0,function(){var t,r,n;return m(this,function(e){switch(e.label){case 0:if(r=o.fileId,n=o.fileType,n=void 0===n?X:n,t=o.seller,t=void 0!==t&&t,r=Array.isArray(r)?r:[r],t)throw new Error("商家空间资源不允许使用接口删除");return r=JSON.stringify(r),[4,this.storageRequest(t?J:K,{fileType:n,fileIds:r,sellerSpace:t})];case 1:if(g(n=e.sent(),["data","model"]))return[2,!0];throw new Error(g(n,["data","msgInfo"]))}})})},_.prototype.getTempFileURL=function(n){return c(this,void 0,void 0,function(){var t,r;return m(this,function(e){switch(e.label){case 0:if(t=n.fileId,r=n.seller,r=void 0!==r&&r,t)return t=Array.isArray(t)?t:[t],t=JSON.stringify(t),[4,this.storageRequest(r?V:L,{fileIds:t,sellerSpace:r})];throw new Error("缺少fileId,请检查参数");case 1:if(t=e.sent(),r=g(t,["data","model"]))return[2,r];throw new Error(g(t,["data","msgInfo"]))}})})},_.prototype.downloadByFileId=function(s){return c(this,void 0,void 0,function(){var t,r,n,o,i,a;return m(this,function(e){switch(e.label){case 0:if(r=s.fileId,t=s.cache,r)return r=Array.isArray(r)?r:[r],[4,this.storageRequest(L,{fileIds:JSON.stringify(r)})];throw new Error("缺少fileId,请检查参数");case 1:r=e.sent(),n=g(r,["data","model"])||[],o=[],i=0,e.label=2;case 2:return i