@tencentcloud/lite-chat 4.1.1 → 4.1.3

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.
@@ -1 +1 @@
1
- function e(e,t){var i={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]]);return i}function t(e,a,n,l){return new(n=n||Promise)(function(i,t){function r(e){try{o(l.next(e))}catch(e){t(e)}}function s(e){try{o(l.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(r,s)}o((l=l.apply(e,a||[])).next())})}var i=new class{constructor(){this._name="WebRequest"}init(e){this._core=e}request(g,m){return t(this,void 0,void 0,function*(){let e,t=(null==(e=this._core)?void 0:e.utils).isEmpty,{downloadUrl:i="",method:r="PUT",url:s,qs:o,headers:a={},resources:n,dataType:l="text",uploadByIP:h,uploadIP:u}=g,d=s;if(o){let e=this._queryString(o);e&&(d+=(d.includes("?")?"&":"?")+e)}let p=new XMLHttpRequest;p.open(r.toUpperCase(),d,!0),p.responseType=l;var c=Object.assign({},a);if(h&&u&&(c.host=u),!t(c))for(let e in c)c.hasOwnProperty(e)&&!["content-length","user-agent","origin","host"].includes(e.toLowerCase())&&p.setRequestHeader(e,c[e]);return p.onload=()=>{var e=this._getResponseBody(p,i,h&&u),e=this._buildResponse(p,e);if(200===p.status)m(null,e);else{if(u&&!d.includes(u))return g.url=this._domainName2IP(d,u),g.uploadByIP=!0,this.request(g,m);m({code:p.status,message:JSON.stringify(p.responseText)},e)}},p.onerror=()=>{var e=this._getResponseBody(p,i,h&&u),e=this._buildResponse(p,e),t={code:p.status,message:0===p.status?"CORS blocked or network error":JSON.stringify(p.responseText)};m(t,e)},g.onProgress&&p.upload&&(p.upload.onprogress=e=>{var{total:e,loaded:t}=e,i=Math.min(Math.floor(100*t/e),100);g.onProgress({total:e,loaded:t,percent:i/100})}),p.send(n),p})}_buildResponse(e,t){let i={};return e.getAllResponseHeaders().trim().split("\n").forEach(e=>{var t;e&&([e,t]=e.split(":").map(e=>e.trim()),i[e.toLowerCase()]=t)}),{statusCode:e.status,statusMessage:e.statusText,headers:i,data:t}}_getResponseBody(e,t,i){return 200===e.status&&t?{location:t,uploadIP:i}:{response:e.responseText,uploadIP:i}}_queryString(i,r="&",s="="){var{isEmpty:e,isPlainObject:t}=null==(e=this._core)?void 0:e.utils;return e(i)?"":t(i)?Object.keys(i).map(e=>{let t=encodeURIComponent(e)+s;return Array.isArray(i[e])?i[e].map(e=>t+encodeURIComponent(e)).join(r):t+encodeURIComponent(i[e])}).filter(Boolean).join(r):void 0}_domainName2IP(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,`https://${t}/`)}};let o=["unknown","image","video","audio","log"];var w,r=new class{init(e){this._core=e}request(r,t){let{MINI_APP_NAMESPACE:s,IN_ALIPAY_MINI_APP:a,isUniIOSApp:n}=null==(g=this._core)?void 0:g.utils,{resources:l="",headers:h={},url:u,downloadUrl:d=""}=r,p=u,c=null;var g=d?d.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/):null;if(g){var g=decodeURIComponent(g[3]),g=g.includes("?")?g.split("?")[0]:g||"",g={key:r.fileKey||g,success_action_status:200,"Content-Type":""},m={};if(n()){let[e,t]=u.split("?sign=");t&&(p=e+"?sign="+encodeURIComponent(t),m.sign=decodeURIComponent(t),m.signature=decodeURIComponent(t))}let i={url:p,header:h,name:"file",filePath:l,formData:Object.assign(Object.assign({},g),m),timeout:r.timeout||3e5};if(a){let{}=i,t=e(i,["name"]);i=Object.assign(Object.assign({},t),{fileName:"file",fileType:r.fileType?o[r.fileType]:"image"})}return(c=s.uploadFile(Object.assign(Object.assign({},i),{success:e=>{this._handleResponse({response:e,downloadUrl:d,callback:t})},fail:e=>{this._handleResponse({response:e,downloadUrl:d,callback:t})}}))).onProgressUpdate&&c.onProgressUpdate(e=>{r.onProgress&&r.onProgress({total:e.totalBytesExpectedToSend||0,loaded:e.totalBytesSent||0,percent:e.progress?Math.floor(e.progress)/100:0})}),c}console.warn("message Invalid download URL format")}_handleResponse(e){var{downloadUrl:e,response:t,callback:i}=e,r={};if(t.header)for(let e in t.header)t.header.hasOwnProperty(e)&&(r[e.toLowerCase()]=t.header[e]);var s=+t.statusCode;200==s?i(null,{statusCode:s,headers:r,data:Object.assign(Object.assign({},t.data),{location:e})}):i({code:s,message:JSON.stringify(t.data)},{statusCode:s,headers:r,data:void 0})}};function s(e){return"file"===Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()}function n(e){e=e||99999999;return Math.round(Math.random()*e)}function a(e,t=!0,i=!0){var r=Date.now();return t?i?r-e+" ms":Math.round((r-e)/1e3)+" s":i?r-e:Math.round((r-e)/1e3)}function l(e){return Array.from({length:8},()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1)).join("")+"-"+e}function d(e,t){return Math.round(Number(e)*10**t)/10**t}function u(e){return e<1024?e+"B":e<1048576?Math.floor(e/1024)+"KB":Math.floor(e/1048576)+"MB"}function h(e){return e<=1048576?d(e/1024,1)+"KB/s":d(e/1048576,1)+"MB/s"}let c="TIMImageElem",p="TIMSoundElem",g="TIMFileElem",m="TIMVideoFileElem",f="RichMediaMessagePlugin",_=["rich.my-imcloud.com","imrich.qcloud.com"],v=1,I=2,y=3,U=255,b=(!function(e){e.UNSENT="unSend",e.SUCCESS="success",e.FAIL="fail"}(w=w||{}),{wechat:/^(wxfile:\/\/tmp_|http:\/\/temp\/|cloud:\/\/temp-)/,alipay:/^(https:\/\/resource\/|alipayfile:\/\/tmp\/)/,baidu:/^(http:\/\/tmp\/|swanfile:\/\/tmp_)/,bytedance:/^(ttfile:\/\/tmp_|\/(var|tmp)\/|tttemp:\/\/)/,qq:/^(qqfile:\/\/tmp_|http:\/\/qtemp\/)/}),F=Symbol("isCustomUpload");var S=new class{init(e){this._core=e}addAuthToUrl(e=""){return this._isMiniProgramTempFile(e)?e:(e=(e=e)?!e.startsWith("https://")&&e.startsWith("http://")?e.replace("http://","https://"):e:"",this.processResourceUrl(e))}removeAuthToUrl(i){{var[i,r]=i.split("?");if(!r)return i;let t=r.split("&").reduce((e,t)=>{var[t,i]=t.split("=");return t&&"authKey"!==t&&(e[t]=i||""),e},{}),e=Object.keys(t).map(e=>""+e+(t[e]?"="+t[e]:"")).join("&");return e?i+"?"+e:i}}_isMiniProgramTempFile(t){return!!this.getPlatformFlags().IN_MINI_APP&&Object.values(b).some(e=>e.test(t))}extractFileFromInput(e){var{isArray:t}=this._core["utils"];return s(e)?e:function(t){if("object"==typeof t&&null!==t){t=Object.getPrototypeOf(t);if(null===t)return 1;let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return t===e}}(e)&&"undefined"!=typeof uni?t(e.tempFiles)&&0<e.tempFiles.length?e.tempFiles[0]:t(e.files)?e.files[0]:e.tempFile||null:e instanceof HTMLInputElement&&e.files&&0<e.files.length?e.files[0]:null}probeImageWidthHeight(i){return t(this,void 0,void 0,function*(){var{IN_MINI_APP:e,IN_BROWSER:t}=(null==(e=this._core)?void 0:e.utils)||{};return this._shouldSkipProbing()?{width:0,height:0}:t?this._probeImageDimensionsWeb(i):e?this._probeImageDimensionsMiniApp(i):void 0})}isSimpleCos(){var e=((null==(e=this._core)?void 0:e.store.get("cloudConfig"))||{})["simple_cos"];return"0"!==e}getFileDNList(){let e,t=_;var i=((null==(e=this._core)?void 0:e.store.get("cloudConfig"))||{})["file_dn_list"];if(void 0!==i)try{JSON.parse(i).forEach(e=>{t.includes(e)||t.push(e)})}catch(e){console.warn(e),t=_}return t}getPlatform(){var e;return null==(e=this._core)?void 0:e.utils.platform}generateUUID(e,t){let i,r=`${this.getSDKAppID()}-${this.getCurrentUserID()}-`+(null==(i=this._core)?void 0:i.utils.randomString());return t?r+"."+t:(e=(t=e.name||e.value||e.url||e.tempFilePath)&&t.slice(t.lastIndexOf(".")+1),r=e?r+"."+e:r)}processResourceUrl(e){if(!e)return"";let t=e;var i=this.getFileDownloadProxy(),r=this.getAuthKey(),s=this.getFileDNList(),e=(i&&(e.startsWith("http://")?t=e.replace(/^http:\/\/[^/]+/,i):e.startsWith("https://")&&(t=e.replace(/^https:\/\/[^/]+/,i))),r&&-1===t.indexOf("authKey=")&&function(e,t){let i=!1;if(e){var e=e.match(/:\/\/([0-9]?\.)?(.[^/:]+)/),r=e&&e[2]||"";if(r.includes("rich-dev"))return!0;for(let e=0;e<t.length;e++)if(r.endsWith(t[e])){i=!0;break}}return i}(t,s));return t=e?-1<t.indexOf("?")?t+"&authKey="+r:t+"?authKey="+r:t}getCurrentUserID(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("login"))?void 0:e.userId}getSDKAppID(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.sdkAppId}getFileDownloadProxy(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.fileDownloadProxy)||""}getFileUploadProxy(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.fileUploadProxy)||""}getAuthKey(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("login"))?void 0:e.authKey)||""}isPrivateNetWork(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.proxyServer}getPlatformFlags(){var{IN_BROWSER:e,IN_MINI_APP:t,IN_RN_APP:i,IN_UNI_NATIVE_APP:r}=null==(e=this._core)?void 0:e.utils;return{IN_BROWSER:e,IN_MINI_APP:t,IN_RN_APP:i,IN_UNI_NATIVE_APP:r}}isEmpty(e){var t=(null==(t=this._core)?void 0:t.utils)["isEmpty"];return t(e)}generateURL(e,t){var{needAddAuthToUrl:t=!0}=t||{};return t?this.addAuthToUrl(e):e}_probeImageDimensionsMiniApp(e){let t,i=((null==(t=this._core)?void 0:t.utils)||{}).MINI_APP_NAMESPACE;return new Promise(t=>{i.getImageInfo({src:e,success:e=>t({width:e.width,height:e.height}),fail:()=>t({width:0,height:0})})})}_shouldSkipProbing(){var{IN_RN_APP:e,IS_IE:t,IE_VERSION:i,IN_WX_MINI_GAME:r}=(null==(e=this._core)?void 0:e.utils)||{};return e||t&&9===i||r}_probeImageDimensionsWeb(r){return new Promise(e=>{let t=new Image,i=()=>{t.onload=null,t.onerror=null,t.src=""};t.onload=()=>{e({width:t.width,height:t.height}),i()},t.onerror=()=>{e({width:0,height:0}),i()},t.src=r})}};function P(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var A,M={exports:{}},C=P(A?M.exports:(A=1,M.exports=function(){var r=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function l(e,t){var i=e[0],r=e[1],s=e[2],o=e[3],r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[0]-680876936|0)<<7|i>>>25)+r|0)&r|~i&s)+t[1]-389564586|0)<<12|o>>>20)+i|0)&i|~o&r)+t[2]+606105819|0)<<17|s>>>15)+o|0)&o|~s&i)+t[3]-1044525330|0)<<22|r>>>10)+s|0;r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[4]-176418897|0)<<7|i>>>25)+r|0)&r|~i&s)+t[5]+1200080426|0)<<12|o>>>20)+i|0)&i|~o&r)+t[6]-1473231341|0)<<17|s>>>15)+o|0)&o|~s&i)+t[7]-45705983|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[8]+1770035416|0)<<7|i>>>25)+r|0)&r|~i&s)+t[9]-1958414417|0)<<12|o>>>20)+i|0)&i|~o&r)+t[10]-42063|0)<<17|s>>>15)+o|0)&o|~s&i)+t[11]-1990404162|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[12]+1804603682|0)<<7|i>>>25)+r|0)&r|~i&s)+t[13]-40341101|0)<<12|o>>>20)+i|0)&i|~o&r)+t[14]-1502002290|0)<<17|s>>>15)+o|0)&o|~s&i)+t[15]+1236535329|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[1]-165796510|0)<<5|i>>>27)+r|0)&s|r&~s)+t[6]-1069501632|0)<<9|o>>>23)+i|0)&r|i&~r)+t[11]+643717713|0)<<14|s>>>18)+o|0)&i|o&~i)+t[0]-373897302|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[5]-701558691|0)<<5|i>>>27)+r|0)&s|r&~s)+t[10]+38016083|0)<<9|o>>>23)+i|0)&r|i&~r)+t[15]-660478335|0)<<14|s>>>18)+o|0)&i|o&~i)+t[4]-405537848|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[9]+568446438|0)<<5|i>>>27)+r|0)&s|r&~s)+t[14]-1019803690|0)<<9|o>>>23)+i|0)&r|i&~r)+t[3]-187363961|0)<<14|s>>>18)+o|0)&i|o&~i)+t[8]+1163531501|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[13]-1444681467|0)<<5|i>>>27)+r|0)&s|r&~s)+t[2]-51403784|0)<<9|o>>>23)+i|0)&r|i&~r)+t[7]+1735328473|0)<<14|s>>>18)+o|0)&i|o&~i)+t[12]-1926607734|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[5]-378558|0)<<4|i>>>28)+r|0)^r^s)+t[8]-2022574463|0)<<11|o>>>21)+i|0)^i^r)+t[11]+1839030562|0)<<16|s>>>16)+o|0)^o^i)+t[14]-35309556|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[1]-1530992060|0)<<4|i>>>28)+r|0)^r^s)+t[4]+1272893353|0)<<11|o>>>21)+i|0)^i^r)+t[7]-155497632|0)<<16|s>>>16)+o|0)^o^i)+t[10]-1094730640|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[13]+681279174|0)<<4|i>>>28)+r|0)^r^s)+t[0]-358537222|0)<<11|o>>>21)+i|0)^i^r)+t[3]-722521979|0)<<16|s>>>16)+o|0)^o^i)+t[6]+76029189|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[9]-640364487|0)<<4|i>>>28)+r|0)^r^s)+t[12]-421815835|0)<<11|o>>>21)+i|0)^i^r)+t[15]+530742520|0)<<16|s>>>16)+o|0)^o^i)+t[2]-995338651|0)<<23|r>>>9)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[0]-198630844|0)<<6|i>>>26)+r|0)|~s))+t[7]+1126891415|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[14]-1416354905|0)<<15|s>>>17)+o|0)|~i))+t[5]-57434055|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[12]+1700485571|0)<<6|i>>>26)+r|0)|~s))+t[3]-1894986606|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[10]-1051523|0)<<15|s>>>17)+o|0)|~i))+t[1]-2054922799|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[8]+1873313359|0)<<6|i>>>26)+r|0)|~s))+t[15]-30611744|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[6]-1560198380|0)<<15|s>>>17)+o|0)|~i))+t[13]+1309151649|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[4]-145523070|0)<<6|i>>>26)+r|0)|~s))+t[11]-1120210379|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[2]+718787259|0)<<15|s>>>17)+o|0)|~i))+t[9]-343485551|0)<<21|r>>>11)+s|0,e[0]=i+e[0]|0,e[1]=r+e[1]|0,e[2]=s+e[2]|0,e[3]=o+e[3]|0}function h(e){for(var t=[],i=0;i<64;i+=4)t[i>>2]=e.charCodeAt(i)+(e.charCodeAt(i+1)<<8)+(e.charCodeAt(i+2)<<16)+(e.charCodeAt(i+3)<<24);return t}function u(e){for(var t=[],i=0;i<64;i+=4)t[i>>2]=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24);return t}function i(e){for(var t,i,r,s,o=e.length,a=[1732584193,-271733879,-1732584194,271733878],n=64;n<=o;n+=64)l(a,h(e.substring(n-64,n)));for(t=(e=e.substring(n-64)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<t;n+=1)i[n>>2]|=e.charCodeAt(n)<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),55<n)for(l(a,i),n=0;n<16;n+=1)i[n]=0;return s=(s=8*o).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(s[2],16),s=parseInt(s[1],16)||0,i[14]=r,i[15]=s,l(a,i),a}function a(e){for(var t=0;t<e.length;t+=1)e[t]=function(e){for(var t="",i=0;i<4;i+=1)t+=r[e>>8*i+4&15]+r[e>>8*i&15];return t}(e[t]);return e.join("")}function s(e){return e=/[\u0080-\uFFFF]/.test(e)?unescape(encodeURIComponent(e)):e}function n(e){for(var t=[],i=e.length,r=0;r<i-1;r+=2)t.push(parseInt(e.substr(r,2),16));return String.fromCharCode.apply(String,t)}function o(){this.reset()}return a(i("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||(ArrayBuffer.prototype.slice=function(e,t){var i=this.byteLength,e=d(e,i),r=i;return(r=void 0!==t?d(t,i):r)<e?new ArrayBuffer(0):(t=r-e,i=new ArrayBuffer(t),r=new Uint8Array(i),e=new Uint8Array(this,e,t),r.set(e),i)}),o.prototype.append=function(e){return this.appendBinary(s(e)),this},o.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;for(var t=this._buff.length,i=64;i<=t;i+=64)l(this._hash,h(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},o.prototype.end=function(e){for(var t,i=this._buff,r=i.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=0;o<r;o+=1)s[o>>2]|=i.charCodeAt(o)<<(o%4<<3);return this._finish(s,r),t=a(this._hash),e&&(t=n(t)),this.reset(),t},o.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},o.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},o.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},o.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},o.prototype._finish=function(e,t){var i,r=t;if(e[r>>2]|=128<<(r%4<<3),55<r)for(l(this._hash,e),r=0;r<16;r+=1)e[r]=0;t=(t=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(t[2],16),t=parseInt(t[1],16)||0,e[14]=i,e[15]=t,l(this._hash,e)},o.hash=function(e,t){return o.hashBinary(s(e),t)},o.hashBinary=function(e,t){e=a(i(e));return t?n(e):e},(o.ArrayBuffer=function(){this.reset()}).prototype.append=function(e){i=this._buff.buffer,r=e,(s=new Uint8Array(i.byteLength+r.byteLength)).set(new Uint8Array(i)),s.set(new Uint8Array(r),i.byteLength);var t,i,r,s,o=s,a=o.length;for(this._length+=e.byteLength,t=64;t<=a;t+=64)l(this._hash,u(o.subarray(t-64,t)));return this._buff=t-64<a?new Uint8Array(o.buffer.slice(t-64)):new Uint8Array(0),this},o.ArrayBuffer.prototype.end=function(e){for(var t,i=this._buff,r=i.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=0;o<r;o+=1)s[o>>2]|=i[o]<<(o%4<<3);return this._finish(s,r),t=a(this._hash),e&&(t=n(t)),this.reset(),t},o.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},o.ArrayBuffer.prototype.getState=function(){var e,t=o.prototype.getState.call(this);return t.buff=(e=t.buff,String.fromCharCode.apply(null,new Uint8Array(e))),t},o.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){for(var i=e.length,r=new ArrayBuffer(i),s=new Uint8Array(r),o=0;o<i;o+=1)s[o]=e.charCodeAt(o);return t?s:r}(e.buff,!0),o.prototype.setState.call(this,e)},o.ArrayBuffer.prototype.destroy=o.prototype.destroy,o.ArrayBuffer.prototype._finish=o.prototype._finish,o.ArrayBuffer.hash=function(e,t){e=a(function(e){for(var t,i,r,s,o=e.length,a=[1732584193,-271733879,-1732584194,271733878],n=64;n<=o;n+=64)l(a,u(e.subarray(n-64,n)));for(t=(e=n-64<o?e.subarray(n-64):new Uint8Array(0)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<t;n+=1)i[n>>2]|=e[n]<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),55<n)for(l(a,i),n=0;n<16;n+=1)i[n]=0;return s=(s=8*o).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(s[2],16),s=parseInt(s[1],16)||0,i[14]=r,i[15]=s,l(a,i),a}(new Uint8Array(e)));return t?n(e):e},o;function d(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}}())),N=new class{constructor(){this.uploadFileTryCount=0,this.maxRetries=1,this.systemClockOffset=0,this.httpRequest=null,this.uploadFileType="",this.duration=900,this.fetchCosTryCount=0}init(e){var t=(this._core=e).utils["IN_MINI_APP"];this.httpRequest=t?r:i,null!=(t=this.httpRequest)&&t.init(e)}uploadToCOS(d){return t(this,void 0,void 0,function*(){let r=f+" uploadToCOS",{ssoLog:s,utils:{safeStringify:t}}=this._core,o=d["file"];this.uploadFileType=d.uploadFileType,s.debug("uploadToCOS",r+" options:"+t(d));try{let e=Date.now(),t=yield this._createCosOptions(d),i=t.fileExistsInCOS?{data:{location:t.downloadUrl}}:yield this._uploadFile(t);this._handleUploadError(i,d);var a=this._createUploadResult(o,i),n=Date.now()-e,l=`size:${u(o.size)} time:${n}ms speed:`+h(1e3*o.size/n);return s.debug("uploadToCOS",r+` ok. name:${o.name} `+l),{uploadOptions:t,response:a}}catch(e){throw s.warn("uploadToCOS",r+" failed, error:"+t(e)),e}})}_handleUploadError(e,t){var i=(null==(i=this._core)?void 0:i.helper)["ChatError"];if(403===e.statusCode)throw t.url,null!=(t=null==e?void 0:e.data)&&t.uploadIP&&e.data.uploadIP,new i({message:"Upload failed with status 403"})}_createUploadResult(e,t){return{fileName:e.name,fileSize:e.size,fileType:e.type.slice(e.type.indexOf("/")+1).toLowerCase(),location:t.data.location||"",uploadTime:a(Date.now(),!1),uploadSpeed:h(1e3*e.size/a(Date.now(),!1))}}_createCosOptions(c){return t(this,void 0,void 0,function*(){var{fileName:e,resources:t,uploadMethod:i}=yield this._prepareUploadParams(c),r=this._isC2CConversation(c.message.conversationID)?1:2;try{var s=yield this._fetchCosSignatureUrl({fileType:this.uploadFileType,fileName:e,uploadMethod:i,duration:this.duration,userID:c.message.from,conversationType:r}),{uploadUrl:o,downloadUrl:a,requestSnapshotUrl:n,thumbUrl:l,largeUrl:h,fileKey:u,existFlag:d}=s,p=!S.isPrivateNetWork()&&s.uploadIP;return{url:this._getRawOrUploadProxyUrl(o),fileType:this.uploadFileType,fileName:e,resources:t,downloadUrl:a,requestSnapshotUrl:n,thumbUrl:l,largeUrl:h,fileKey:u,uploadIP:p||"",fileExistsInCOS:1===d,onProgress:e=>this._handleUploadProgress(e,c)}}catch(e){throw console.error("Failed to create COS pre-signed URL options:",e),e}})}_prepareUploadParams(a){return t(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t,isEmpty:i}}=this._core,e=(e.debug("_prepareUploadParams"," prepareUploadParams:"+t(a)),a)["file"],{IN_MINI_APP:t,IN_RN_APP:r}=S.getPlatformFlags(),t=t||r,r=t&&a.message.type!==g,s=e["name"],s=s.slice(s.lastIndexOf(".")),o=""+n(999999)+s,r=r?e.name:o,o=yield this._generateHashFileName(e);return{fileName:i(o)?l(r):""+o+s,resources:t?e.url:e,uploadMethod:t?1:0}})}_generateHashFileName(n){return t(this,void 0,void 0,function*(){var{utils:{IN_MINI_APP:e,IN_BROWSER:t,IN_UNI_NATIVE_APP:i,isArray:r},ssoLog:s}=this._core,o=Date.now();let a="";return t&&(a=yield this._generateHashFileNameInWeb(n)),e&&(r(n.tempFiles)&&(n=n.tempFiles[0]),i||(a=yield this._generateFileNameInMiniProgram(n)),i)&&(a=yield this._generateFileNameInUNINativeApp(n)),s.info("_generateHashFileName",`hashFileName:${a} costTime:`+(Date.now()-o)),a})}_generateHashFileNameInWeb(p){return t(this,void 0,void 0,function*(){let{ssoLog:d,utils:{safeStringify:t}}=this._core,e="";try{e=yield new Promise((t,i)=>{let r=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,s=(r||(d.warn("_generateHashFileNameInWeb","Browser does not support file slicing"),t("")),10485760),o=Math.ceil(p.size/s),a=0,n=new C.ArrayBuffer,l=new FileReader,h=setTimeout(()=>{l.abort(),d.warn("_generateHashFileNameInWeb","File hash generation timeout"),t("")},2e3);function u(){var e=a*s,t=e+s>=p.size?p.size:e+s;l.readAsArrayBuffer(r.call(p,e,t))}l.onload=e=>{d.debug("_generateHashFileNameInWeb",`read chunk nr ${a+1} of `+o),n.append(e.target.result),++a<o?u():(d.debug("_generateHashFileNameInWeb","finished loading"),clearTimeout(h),t(n.end()))},l.onerror=e=>{clearTimeout(h),i(e)},u()})}catch(e){d.warn("_generateHashFileNameInWeb",t(e))}return e})}_generateFileNameInMiniProgram(s){return t(this,void 0,void 0,function*(){let{utils:{MINI_APP_NAMESPACE:e,safeStringify:t},ssoLog:i}=this._core,r="";try{r=yield new Promise((t,i)=>{e.getFileSystemManager().getFileInfo({filePath:s.tempFilePath,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){i.warn("_generateFileNameInMiniProgram",t(e))}return r})}_generateFileNameInUNINativeApp(r){return t(this,void 0,void 0,function*(){var{utils:{safeStringify:t},ssoLog:i}=this._core;let e="";try{e=yield new Promise((t,i)=>{plus.io.getFileInfo({filePath:r.tempFilePath,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){i.warn("_generateFileNameInMiniProgram",t(e))}return e})}_handleUploadProgress(e,t){if("function"==typeof t.onProgress)try{t.onProgress(e.percent)}catch(e){throw console.warn("Upload progress callback error:",e),e}}_fetchCosSignatureUrl(l){return t(this,void 0,void 0,function*(){var{ssoLog:i,utils:{safeStringify:r}}=this._core,s=S.isSimpleCos(),o=this._prepareCosRequestData(l),a=s?"im_cos_msg.simple_sig":"im_cos_msg.pre_sig";try{let e=yield function(s,o,a){return t(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=a,i=e.generateCosSpecifiedData({servcmd:s,data:o}),r=i.head.seq+s;return yield t.sendPacket(i,{requestId:r})}catch(e){throw console.warn("getCosSig error:",e),e}})}(a,o,this._core);this.fetchCosTryCount=0;var n=this._processResponse(e);return i.debug("_fetchCosSignatureUrl",` ok. isSimpleCos:${s} data:`+r(n)),n||{}}catch(e){if(this.fetchCosTryCount<1)return this.fetchCosTryCount++,this._fetchCosSignatureUrl(l);throw this.fetchCosTryCount=0,e}})}_processResponse(e){var t;let i=S.isSimpleCos(),l=i?null==(t=null==e?void 0:e.rpt_pre_sig)?void 0:t[0]:e;if(!l)return{};if(i){let{str_final_ip:e,rpt_pre_sig:t,uint32_file_id:i,uint32_exist_flag:r,str_download_url:s,str_upload_url:o,str_snapshot_url:a,str_file_key:n}=l;return{uploadIP:e,preSig:t,fileID:i,existFlag:r,downloadUrl:s,uploadUrl:o,requestSnapshotUrl:a,fileKey:n}}let{upload_url:r,download_url:s,snapshot_url:o,thumb_url:a,large_url:n,file_key:h}=l;return{uploadUrl:r,downloadUrl:s,requestSnapshotUrl:o,thumbUrl:a,largeUrl:n,fileKey:h}}_prepareCosRequestData(e){return S.isSimpleCos()?{uint32_upload_method:e.uploadMethod,uint32_platform:S.getPlatform(),uint32_sdkappid:S.getSDKAppID(),str_user_id:e.userID,uint32_scene:e.conversationType,rpt_upload_object:[{uint32_file_id:1,uint32_file_type:e.fileType,str_file_name:e.fileName}]}:{file_type:e.fileType,file_name:e.fileName,upload_method:e.uploadMethod,Duration:e.duration}}_uploadFile(s){return t(this,void 0,void 0,function*(){return new Promise((i,r)=>{this.httpRequest.request(s,(e,t)=>{e&&this.uploadFileTryCount<this.maxRetries&&this.shouldRetry(e)?(this.uploadFileTryCount++,this._uploadFile(s).then(i).catch(r)):(this.uploadFileTryCount=0,e?r(e):i(t))})})})}shouldRetry(e){return!(!e||5!==Math.floor(e.statusCode/100)&&(!this.isTimeRelatedError(e)||!this._isClockOutOfSync(e)||(this._syncSystemClock(e),0)))}isTimeRelatedError(e){var t,i;try{var r=null==(t=e.error)?void 0:t.Code,s=null==(i=e.error)?void 0:i.Message;return"RequestTimeTooSkewed"===r||"AccessDenied"===r&&"Request has expired"===s}catch(e){return!1}}_isClockOutOfSync(e){var t,e=(null==(t=e.headers)?void 0:t.date)||(null==(t=e.headers)?void 0:t.Date)||(null==(t=e.error)?void 0:t.ServerTime);return!!e&&(t=Date.now(),e=Date.parse(e),3e4<=Math.abs(t+this.systemClockOffset-e))}_syncSystemClock(e){var t,i=(null==(t=e.headers)?void 0:t.date)||(null==(t=e.headers)?void 0:t.Date)||(null==(t=e.error)?void 0:t.ServerTime);if(i){let e=Date.now(),t=Date.parse(i);this.systemClockOffset=t-e}}_getRawOrUploadProxyUrl(e){var t=S.getFileUploadProxy();let i=e;return i=t?e.replace(/^https:\/\/[^/]+/,t):i}_isC2CConversation(e){return"C2C"===e.slice(0,3)}};let O=2108,T=2251,E=2252,D=["jpg","jpeg","gif","png","bmp","image","webp"],z=20971520,R={JPG:1,JPEG:1,GIF:2,PNG:3,BMP:4,UNKNOWN:255};class ${constructor(e,t){this.instanceID=n(9999999),this.sizeType=e.type||0,this.type=0,this.size=e.size||0,this.width=e.width||0,this.height=e.height||0,this.imageUrl=S.addAuthToUrl(e.imageUrl||e.url||""),this.url=S.addAuthToUrl(e.url||t)}setSizeType(e){this.sizeType=e}setType(e){this.type=e}setImageUrl(e){e&&(this.imageUrl=S.addAuthToUrl(e))}getImageUrl(){return this.imageUrl}}function x(t){var{originUrl:t,originWidth:i,originHeight:r,min:s=198}=t,i=parseInt(i)||0,r=parseInt(r)||0,o={url:void 0,width:0,height:0};if((i<=r?i:r)<=s)o.url=t,o.width=i,o.height=r;else{r<=i?(o.width=Math.ceil(i*s/r),o.height=s):(o.width=s,o.height=Math.ceil(r*s/i));let e=t&&-1<t.indexOf("?")?t+"&":t+"?";o.url=198===s?e+"imageView2/3/w/198/h/198":e+"imageView2/3/w/720/h/720"}if(void 0!==t)return o;return e(o,["url"])}class W{constructor(e){this._imageMemoryURL="",this._percent=0,this.type=c;var{uuid:e,file:t,imageFormat:i,imageInfoArray:r=[],isCustomUpload:s=!1}=e;this._imageMemoryURL=this.createImageDataAsURL(t),this.content={imageFormat:i,uuid:e,imageInfoArray:[]},this[F]=s,this.initImageInfoArray(r),this.autoFixUrl()}static parseServerPushElement(e){let t=e["MsgContent"],{ImageFormat:i,ImageInfoArray:r,UUID:s}=t,o=r.map(e=>({size:e.Size,type:e.Type,width:e.Width,height:e.Height,url:e.URL}));return new W({imageFormat:i,imageInfoArray:o,uuid:s})}createImageDataAsURL(e){let t="";var{IN_MINI_APP:i,IN_RN_APP:r,IN_BROWSER:s}=S.getPlatformFlags();return t=e&&((i||r)&&(t=e.url),s)?window.URL.createObjectURL(e):t}initImageInfoArray(t=[]){var i={type:0,size:0,width:0,height:0,url:""};for(let e=0;e<3;e++){var r=t[e]||Object.assign({},i),r=new $(r,this._imageMemoryURL);r.setSizeType(e+1),r.setType(e),this.addImageInfo(r)}this.updateAccessSideImageInfoArray()}autoFixUrl(){let r=["http","https"];this.content.imageInfoArray.forEach(e=>{var t,i;e.url&&""!==e.imageUrl&&([t,...i]=e.imageUrl.split("://"),i=i.join("://"),r.includes(t)||e.setImageUrl("https://"+i))})}updatePercent(e){this._percent=Math.min(e,1)}updateImageFormat(e){this.content.imageFormat=R[e.toUpperCase()]||R.UNKNOWN}addImageInfo(e){3<=this.content.imageInfoArray.length||this.content.imageInfoArray.push(e)}updateImageInfoArray(t){var i,r=this.content.imageInfoArray.length;for(let e=0;e<r;e++)i=this.content.imageInfoArray[e],t[e].size&&(i.size=t[e].size),t[e].url&&i.setImageUrl(t[e].url),t[e].width&&(i.width=t[e].width),t[e].height&&(i.height=t[e].height)}updateAccessSideImageInfoArray(){var[e]=this.content.imageInfoArray;if(e&&0!==e.width&&0!==e.height){var t=this.content.imageInfoArray,i=t[2];t[2]=t[1],t[1]=i;for(let e=0;e<t.length;e++)t[e].setType(e);Object.assign(this.content.imageInfoArray[2],x({originWidth:e.width,originHeight:e.height,min:720}))}}validateBeforeSend(){var e;return this[F]?(delete this[F],{isValid:!0}):([e]=this.content.imageInfoArray,{isValid:e=!!e&&""!==e.imageUrl&&0!==e.size,error:e?null:{message:"content can not be empty"}})}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,imageFormat:t,imageInfoArray:i}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{ImageFormat:t,ImageInfoArray:this.parseImageInfoArray(i),UUID:e}}}parseImageInfoArray(e){return e.map(e=>({InstanceId:e.instanceID,Type:e.sizeType,MsgType:e.type,Size:e.size,Width:e.width,Height:e.height,URL:S.removeAuthToUrl(e.imageUrl)}))}}var j=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createImageMessage",context:this}),t.registerExperimentalAPI("createImageMessage",this,"createCustomUploadImageMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(c,W),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createImageMessage(e){var t,i,r;try{var s=null==(t=this._core.store.get("login"))?void 0:t.userId,o=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:s})),a=this._processImage(e),n=(e.payload.file=a,{imageFormat:R.UNKNOWN,uuid:S.generateUUID(a),file:a,imageInfoArray:[]}),l=new W(n);return o.setElement(l),this._messageOptionsMap.set(o.clientSequence,e),o}catch(e){throw e}}createCustomUploadImageMessage(e){var{store:t,utils:{isEmpty:i}}=this._core,t=null==(t=t.get("login"))?void 0:t.userId,r=null==(r=null==(r=this._core)?void 0:r.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:t})),{largeImageUuid:t,largeFileSize:s,largeImageWidth:o,largeImageHeight:a,largeImageUrl:n,originImageUuid:l,originFileSize:h,originImageWidth:u,originImageHeight:d,originImageUrl:p,thumbImageUuid:c,thumbFileSize:g,thumbImageWidth:m,thumbImageHeight:f,thumbImageUrl:_}=(null==(t=null==e?void 0:e.payload)?void 0:t.file)||{};if(i(p)||i(l))throw new Error("createImageMessageExperimental originImageUrl or originImageUuid is empty");i=new W({imageFormat:R.UNKNOWN,uuid:l,imageInfoArray:[{instanceID:l,size:h,width:u,height:d,imageUrl:p,url:p},{instanceID:t,size:s,width:o,height:a,imageUrl:n,url:n},{instanceID:c,size:g,width:m,height:f,imageUrl:_,url:_}],isCustomUpload:!0});return r.setElement(i),this._messageOptionsMap.set(r.clientSequence,e),r._skipUpload=!0,r}upload(r){return t(this,void 0,void 0,function*(){var e=r.getElements()[0],t=this._messageOptionsMap.get(r.clientSequence).payload["file"],t=(this._validateBeforeUploadImage(t),yield this._performImageUpload(e,r,t)),i=this._generateImageInfo(t);return e.updateImageFormat(null==t?void 0:t.fileType),e.updateImageInfoArray(i),r})}_performImageUpload(r,s,i){return t(this,void 0,void 0,function*(){var e=s["to"],e={uploadFileType:v,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}},{uploadOptions:e,response:t}=yield N.uploadToCOS(e);return this._parseResponse(e,t)})}_generateImageInfo(e){var{location:e,fileSize:t,width:i,height:r,smallImageUrl:s,smallImageWidth:o,smallImageHeight:a,largeImageUrl:n,largeImageWidth:l,largeImageHeight:h,imageInfoArray:u}=e,e=S.addAuthToUrl(e),d={size:t,url:e,width:i,height:r};return 0<(null==u?void 0:u.length)?this._processImageInfoArray(u,t):s&&n?[Object.assign({},d),{largeImageUrl:n,largeImageWidth:l,largeImageHeight:h},{smallImageUrl:s,smallImageWidth:o,smallImageHeight:a}]:[Object.assign({},d),this._generateThumbInfo(e,i,r,720),this._generateThumbInfo(e,i,r,198)]}_generateThumbInfo(e,t,i,r){return x({originUrl:e,originWidth:t,originHeight:i,min:r})}_processImageInfoArray(e,t){let i,r,s;for(var o of e)1===o.type?(r=o,r.size=t):2===o.type?(s=o,s.size=t):(i=o,i.size=t);return[Object.assign({},i),Object.assign({},s),Object.assign({},r)]}_parseResponse(r,s){return t(this,void 0,void 0,function*(){try{var{thumbUrl:e,largeUrl:t,downloadUrl:i}=r;if(e&&t&&(yield this._getImageInfoByUrl(e,s,"thumb"),yield this._getImageInfoByUrl(t,s,"large")),S.isSimpleCos()&&!S.isPrivateNetWork()&&(yield this._getImageInfoArray(i,s),null!=s)&&s.uploadIP){let e=this._extractDomainFromUrl(i);e&&(yield this._getDownloadIP(e,s))}return s}catch(e){throw e}})}_extractDomainFromUrl(t){var e;try{let e=t.match(/:\/\/([^\/]+)/);return e?e[1]:null}catch(t){return null!=(e=this._core)&&e.ssoLog.warn("_extractDomainFromUrl","Failed to extract domain from URL:"+t.message),null}}_getImageInfoByUrl(r,s,o){return t(this,void 0,void 0,function*(){var t;try{let e=S.addAuthToUrl(r),{width:t=0,height:i=0}=yield S.probeImageWidthHeight(e);s.width=t,s.height=i,"thumb"===o?(s.smallImageUrl=r,s.smallImageWidth=t,s.smallImageHeight=i):(s.largeImageUrl=r,s.largeImageWidth=t,s.largeImageHeight=i)}catch(e){null!=(t=this._core)&&t.ssoLog.warn("_getImageInfoByUrl",`Failed to get ${o} image info:`+e.message)}})}_validateBeforeUploadImage(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:T});this._checkImageType(e),this._checkImageSize(e)}_processImage(e){var t;try{var i=(null==(t=this._core)?void 0:t.utils)["IN_MINI_APP"],r=e.payload["file"];return i?this._processMiniAppImageFile(r):this._processWebImageFile(r)}catch(e){throw e}}_processMiniAppImageFile(e){s(e)&&console.warn("FileUnsupportedInMiniApp","createImageMessage");var t=e.tempFiles[0].path||e.tempFiles[0].tempFilePath;return{url:t,name:t.slice(t.lastIndexOf("/")+1),size:e.tempFiles&&e.tempFiles[0].size||1,type:t.slice(t.lastIndexOf(".")+1).toLowerCase()}}_processWebImageFile(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"],e=S.extractFileFromInput(e);if(e)return e;throw new t({message:"Invalid file. Pass either `e.target` (from file input) or a File object"})}_getDownloadIP(s,o){return t(this,void 0,void 0,function*(){var e=f+" getDownloadIP domainName: "+s;try{var i,r=yield function(a,n){return t(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=n,i="im_cos_msg.get_final_ip",r={str_domain:a},s=e.generateProtocolData({servcmd:i,data:r}),o=s.head.seq+i;return yield t.sendPacket(s,{requestId:o})}catch(e){throw console.warn("getFinalIP error:",e),e}})}(s,this._core);r&&r.str_final_ip&&(console.log(e+" ok. downloadIP:"+r),(i=o.location.split("/"))[0]=r.str_final_ip,o.location=i.join("/"))}catch(e){console.warn(e)}})}_getImageInfoArray(i,r){return t(this,void 0,void 0,function*(){try{var e=yield function(a,n){return t(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=n,i="im_cos_msg.get_imageinfo",r={str_image_url:a},s=e.generateProtocolData({servcmd:i,data:r}),o=s.head.seq+i;return yield t.sendPacket(s,{requestId:o})}catch(e){throw console.warn("getImageInfo error:",e),e}})}(i,this._core);return r.imageInfoArray=this._processImageInfoResponse(e),r}catch(e){throw r.imageInfoArray=void 0,e}})}_processImageInfoResponse(e){return e?(e=e["rpt_msg_image_info"],e.map(e=>({type:e.uint32_image_type,url:e.str_url,width:e.uint32_width,height:e.uint32_height,imageFormat:e.str_image_format}))):[]}_checkImageType(e){var{utils:t,helper:i}=this._core;let r="";if(t.IN_MINI_APP&&(r=e.url.slice(e.url.lastIndexOf(".")+1)),t.IN_BROWSER&&(r=e.name.slice(e.name.lastIndexOf(".")+1)),D.indexOf(r.toLowerCase())<0)throw new i.ChatError({code:E})}_checkImageSize(e){var{utils:t,helper:i}=this._core,r=0;if(t.IN_MINI_APP,0===(r=e.size))throw new i.ChatError({code:O});if(r>=z)throw new i.ChatError({message:"File size exceeds limit: "+u(z)})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let B=2108,V=2401,q="2.5.0",L="1.18.0",H=104857600;function k(e,t){let r=e.split("."),s=t.split("."),o=Math.max(r.length,s.length);for(;r.length<o;)r.push("0");for(;s.length<o;)s.push("0");for(let i=0;i<o;i++){let e=parseInt(r[i]),t=parseInt(s[i]);if(e>t)return 1;if(e<t)return-1}return 0}let K=new class{init(e){this.core=e}};class Y{constructor(e){this.type=g,this.uploadProgress=0,this[G]=!1;var t=this._getFileInfo(e);this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,fileUrl:S.generateURL(e.url||e.fileUrl,{needAddAuthToUrl:!this[F]})||"",uuid:e.uuid,fileName:t.name||"",fileSize:t.size||0}}static parseServerPushElement(e){var e=e["MsgContent"],{Download_Flag:e,Url:t,FileName:i,FileSize:r,UUID:s}=e;return new Y({downloadFlag:e,url:t,fileName:i,fileSize:r,uuid:s})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateFileUrl(e){this.content.fileUrl=e}validateBeforeSend(){var e;return this[F]?{isValid:!0}:{isValid:e=""!==this.content.fileUrl&&""!==this.content.fileName&&0<this.content.fileSize,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,downloadFlag:t,fileUrl:i,fileName:r,fileSize:s}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{Download_Flag:t,Url:S.removeAuthToUrl(i),FileName:r,FileSize:s,UUID:e}}}_getFileInfo(e){var t=K.core["utils"]["IN_UNI_NATIVE_APP"];return e.fileName&&e.fileSize?{size:e.fileSize,name:e.fileName}:(e=e["file"],e?(t&&this._processNativeAppFile(e),{size:e.size,name:e.name}):{size:0,name:""})}_processNativeAppFile(e){var t;e.path&&e.path.includes(".")&&(t=e.path.slice(e.path.lastIndexOf(".")+1).toLowerCase(),e.type=t,e.name||(e.name=n(999999)+"."+t)),e.name||(e.type="",e.name=e.path.slice(e.path.lastIndexOf("/")+1).toLowerCase()),e.suffix&&(e.type=e.suffix),e.url||(e.url=e.path)}}var G=F,J=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createFileMessage",context:this}),t.registerExperimentalAPI("createFileMessage",this,"createCustomUploadFileMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(g,Y),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createFileMessage(e){var t,i,r;try{this._checkVersion();var s=this._processFile(e.payload.file),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={uuid:S.generateUUID(s),file:s},l=new Y(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadFileMessage(e){var t,i,r;try{var{store:s,message:o,utils:{isEmpty:a}}=this._core,n=null==(t=s.get("login"))?void 0:t.userId,{url:l,uuid:h,fileSize:u,fileName:d=""}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{};if(a(l))throw new Error("url is required");var p=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:n})),c=new Y({url:l,uuid:h,file:{size:u,name:d},isCustomUpload:!0});return p.setElement(c),p}catch(e){throw e}}upload(i){return t(this,void 0,void 0,function*(){var e=this._messageOptionsMap.get(i.clientSequence).payload["file"],t=(this._validateBeforeUploadFile(e),i.getElements()[0]),e=yield this._performFileUpload(t,i,e),e=S.addAuthToUrl(null==e?void 0:e.location);return t.updateFileUrl(e),i})}_validateBeforeUploadFile(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:V});if(e.size>H)throw new t({message:"File size exceeds limit: "+u(H)});if(0===e.size)throw new t({code:B})}_performFileUpload(r,s,i){return t(this,void 0,void 0,function*(){var e=s["to"],e={uploadFileType:U,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}},e=(yield N.uploadToCOS(e))["response"];return e})}_processFile(t){var{IN_BROWSER:e,IN_RN_APP:i,IN_WX_MINI_APP:r,IN_QQ_MINI_APP:s,IN_UNI_NATIVE_APP:o}=null==(e=this._core)?void 0:e.utils,a=(null==(a=this._core)?void 0:a.helper)["ChatError"];if(e||o){let e=S.extractFileFromInput(t);if(e)return e;throw new a({message:"Invalid file. Pass either `e.target` (from file input) or a File object"})}if(r||s){let e=t["tempFiles"];return Object.assign(Object.assign({},e[0]),{url:e[0].path})}return i?Object.assign(Object.assign({},t),{url:t.uri}):t}_checkVersion(){var{MINI_APP_NAMESPACE:t,IN_MINI_APP:e,IN_WX_MINI_APP:i,IN_QQ_MINI_APP:r,IN_UNI_NATIVE_APP:s}=null==(e=this._core)?void 0:e.utils,o=(null==(o=this._core)?void 0:o.helper)["ChatError"];if(e){if(!(i||r||s))throw new o({message:"Unsupported mini app environment"});let e=t.getSystemInfoSync().SDKVersion;if(i&&k(e,q)<0)throw new o({message:`WXChooseMessageFile requires SDK version ${q} or higher`});if(r&&k(e,L)<0)throw new o({message:`QQChooseMessageFile requires SDK version ${L} or higher`})}}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let Q=2108,X=2352,Z=["mp4","quicktime","mov"],ee=104857600;class ie{constructor(e){this.type=m,this.uploadProgress=0,this[te]=!1;var t="number"==typeof(null==e?void 0:e.videoSecond)?null==e?void 0:e.videoSecond:0;this[F]=e.isCustomUpload||!1,this.content={remoteVideoUrl:S.addAuthToUrl(e.remoteVideoUrl||e.videoUrl||""),videoFormat:e.videoFormat,videoSecond:parseInt(null==t?void 0:t.toString(),10),videoSize:e.videoSize,videoUrl:S.addAuthToUrl(e.videoUrl),videoDownloadFlag:2,videoUUID:e.videoUUID,thumbUUID:e.thumbUUID,thumbFormat:e.thumbFormat,thumbWidth:e.thumbWidth,snapshotWidth:e.thumbWidth,thumbHeight:e.thumbHeight,snapshotHeight:e.thumbHeight,thumbSize:e.thumbSize,snapshotSize:e.thumbSize,thumbDownloadFlag:2,thumbUrl:S.addAuthToUrl(e.thumbUrl),snapshotUrl:S.addAuthToUrl(e.thumbUrl)}}static parseServerPushElement(e){var e=e["MsgContent"],{VideoUrl:e,VideoFormat:t,VideoSecond:i,VideoSize:r,VideoDownloadFlag:s,VideoUUID:o,ThumbUUID:a,ThumbFormat:n,ThumbWidth:l,SnapshotWidth:h,ThumbHeight:u,SnapshotHeight:d,ThumbSize:p,SnapshotSize:c,ThumbDownloadFlag:g,ThumbUrl:m,SnapshotUrl:f}=e;return new ie({videoUrl:e,videoFormat:t,videoSecond:i,videoSize:r,videoDownloadFlag:s,videoUUID:o,thumbUUID:a,thumbFormat:n,thumbWidth:l,snapshotWidth:h,thumbHeight:u,snapshotHeight:d,thumbSize:p,snapshotSize:c,thumbDownloadFlag:g,thumbUrl:m,snapshotUrl:f})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateVideoUrl(e){e&&(this.content.remoteVideoUrl=e)}updateSnapshotInfo(e){var{snapshotUrl:e,snapshotWidth:t,snapshotHeight:i}=e;S.isEmpty(e)||(this.content.thumbUrl=this.content.snapshotUrl=e),S.isEmpty(t)||(this.content.thumbWidth=this.content.snapshotWidth=Number(t)),S.isEmpty(i)||(this.content.thumbHeight=this.content.snapshotHeight=Number(i))}validateBeforeSend(){var e;return this[F]?{isValid:!0}:{isValid:e=""!==this.content.remoteVideoUrl,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{remoteVideoUrl:e,videoFormat:t,videoSecond:i,videoSize:r,videoDownloadFlag:s,videoUUID:o,thumbUUID:a,thumbFormat:n,thumbWidth:l,snapshotWidth:h,thumbHeight:u,snapshotHeight:d,thumbSize:p,snapshotSize:c,thumbDownloadFlag:g,thumbUrl:m,snapshotUrl:f}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{VideoUrl:S.removeAuthToUrl(e),VideoFormat:t,VideoSecond:i,VideoSize:r,VideoDownloadFlag:s,VideoUUID:o,ThumbUUID:a,ThumbFormat:n,ThumbWidth:l,SnapshotWidth:h,ThumbHeight:u,SnapshotHeight:d,ThumbSize:p,SnapshotSize:c,ThumbDownloadFlag:g,ThumbUrl:S.removeAuthToUrl(m),SnapshotUrl:S.removeAuthToUrl(f)}}}}var oe,te=F,re=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createVideoMessage",context:this}),t.registerExperimentalAPI("createVideoMessage",this,"createCustomUploadVideoMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(m,ie),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createVideoMessage(e){var t,i,r;try{var s=this._processVideo(e),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={videoFormat:s.videoFile.type,videoSecond:d(s.videoFile.second,0),videoSize:s.videoFile.size,remoteVideoUrl:"",videoUrl:s.videoFile.url,videoUUID:S.generateUUID(s.videoFile),thumbUUID:S.generateUUID(s.videoFile,"jpg"),thumbWidth:s.width||200,thumbHeight:s.height||200,thumbUrl:s.thumbUrl,thumbSize:s.thumbSize,thumbFormat:"jpg"},l=new ie(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadVideoMessage(e){var t,i,r;try{var{store:s,message:o}=this._core,a=(this._validateCustomUploadVideoMessage(e),null==(t=s.get("login"))?void 0:t.userId),{videoUrl:n,videoUuid:l,duration:h,snapshotUrl:u,snapshotUuid:d,videoFileSize:p,videoType:c,snapshotWidth:g,snapshotHeight:m,snapshotFileSize:f,snapshotType:_="jpg"}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{},v=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:a})),I=new ie({videoFormat:c,videoSecond:h||0,videoSize:p,remoteVideoUrl:n,videoUrl:n,videoUUID:l,thumbUUID:d,thumbWidth:g||200,thumbHeight:m||200,thumbUrl:u,thumbSize:f,thumbFormat:_,isCustomUpload:!0});return v.setElement(I),this._messageOptionsMap.set(v.clientSequence,e),v}catch(e){throw e}}upload(r){return t(this,void 0,void 0,function*(){var e=r.getElements()[0],t=this._messageOptionsMap.get(r.clientSequence).payload["file"],t=(this._validateBeforeUploadVideo(t),yield this._performVideoUpload(e,r,t)),{location:t,snapshotInfo:i}=t,t=S.addAuthToUrl(t);return e.updateVideoUrl(t),S.isEmpty(i)||e.updateSnapshotInfo(i),r})}_validateBeforeUploadVideo(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(e.videoFile.size>ee)throw new t({message:"File size exceeds limit: "+u(ee)});if(0===e.videoFile.size)throw new t({code:Q});if(-1===Z.indexOf(e.videoFile.type))throw new t({code:X})}_validateCustomUploadVideoMessage(e){var{isEmpty:t,isNumber:i}=this._core["utils"],{videoUrl:e,videoUuid:r,duration:s,snapshotUrl:o,snapshotUuid:a}=(null==(e=null==e?void 0:e.payload)?void 0:e.file)||{};if(t(e)||t(r)||!i(s)||t(o)||t(a))throw new Error("Invalid video message options: missing required fields (videoUrl, videoUuid, duration, snapshotUrl, snapshotUuid)")}_performVideoUpload(r,s,i){return t(this,void 0,void 0,function*(){var e=s["to"],e={uploadFileType:I,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}},{response:e,uploadOptions:t}=yield N.uploadToCOS(e);return{snapshotInfo:yield this._getSnapshotInfoByUrl(t.requestSnapshotUrl),location:e.location}})}_processVideo(e){var r,s;try{var o=(null==(r=this._core)?void 0:r.helper)["ChatError"],{IN_MINI_APP:a,IN_BROWSER:n}=null==(s=this._core)?void 0:s.utils;let t=e.payload["file"],i={};if(a&&(i=this._processMiniVideoFile(t),t.name=i.name,t.url=i.url,t.type=i.type),n){let e=S.extractFileFromInput(t);if(!e)throw new o({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});t=e,i=this._processWebVideoFile(t)}return t.videoFile=i,t.thumbUrl="",t.thumbSize=0,t}catch(e){throw console.warn(f+" _processFile error:",e),e}}_processMiniVideoFile(e){var{IN_ALIPAY_MINI_APP:t,IN_UNI_NATIVE_APP:i}=null==(t=this._core)?void 0:t.utils,r=(null==(r=this._core)?void 0:r.helper)["ChatError"];if(t)throw new r({message:"VideoUnsupportedInAlipay"});if(s(e))throw new r({message:"FileUnsupportedInMiniApp"});let o=(e=Array.isArray(e.tempFiles)?e.tempFiles[0]:e).tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase();return i&&(o=e.fileType||o),{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.size||1,second:e.duration||0,type:o}}_processWebVideoFile(e){var{name:t,size:i=1,duration:r=0,type:s}=e,s=s.split("/")[1];return{url:window.URL.createObjectURL(e),name:t,size:i,second:r,type:s}}_getSnapshotInfoByUrl(a){return t(this,void 0,void 0,function*(){var e=this._core["ssoLog"];try{e.debug("_getSnapshotInfoByUrl",f+" _getSnapshotInfoByUrl url:"+a);var i,r,s,o=((yield function(o,a){return t(this,void 0,void 0,function*(){try{var e="im_cos_msg.video_cover",{helper:t,channel:i}=a,r=t.generateCosSpecifiedData({servcmd:e,data:o}),s=r.head.seq+e;return yield i.sendPacket(r,{requestId:s})}catch(e){throw console.warn("getSnapshotInfo error:",e),e}})}({version:1,platform:S.getPlatform(),cover_name:l(n(99999)),snapshot_url:a},this._core))||{})["download_url"];return(e.debug("_getSnapshotInfoByUrl",f+" _getSnapshotInfoByUrl OK snapshotUrl:"+o),S.isEmpty(o))?{}:(i=S.addAuthToUrl(o),{width:r=0,height:s=0}=yield S.probeImageWidthHeight(i),{snapshotUrl:i,snapshotWidth:r,snapshotHeight:s})}catch(e){throw e}})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};class se{constructor(e){this.uploadProgress=0,this.type=p,this[oe]=!1,this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,second:e.second,size:e.size,url:S.generateURL(e.url,{needAddAuthToUrl:!this[F]}),remoteAudioUrl:S.addAuthToUrl(e.url||""),uuid:e.uuid}}static parseServerPushElement(e){var e=e["MsgContent"],{Url:e,Download_Flag:t,Second:i,Size:r,UUID:s}=e;return new se({url:e,downloadFlag:t,second:i,size:r,uuid:s})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateAudioUrl(e){this.content.remoteAudioUrl=e}validateBeforeSend(){var e;return this[F]?{isValid:!0}:{isValid:e=""!==this.content.remoteAudioUrl,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,downloadFlag:t,remoteAudioUrl:i,size:r,second:s}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{Url:S.removeAuthToUrl(i),Download_Flag:t,Second:s,Size:r,UUID:e}}}}oe=F;let ne=2108,ae=2300,le=20971520;var de=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createAudioMessage",context:this}),t.registerExperimentalAPI("createAudioMessage",this,"createCustomUploadAudioMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(p,se),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createAudioMessage(e){var t,i,r;try{var s=e.payload["file"],s=this._processAudioFile(e.payload.file),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={second:Math.floor((s.duration||s.second)/1e3),size:s.fileSize||s.size||1,url:s.tempFilePath||s.uri||s.url,uuid:S.generateUUID(s)},l=new se(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadAudioMessage(e){var t,i,r;try{this._validateCustomUploadOptions(e);var{store:s,message:o}=this._core,a=null==(t=s.get("login"))?void 0:t.userId,{url:n,uuid:l,duration:h,fileSize:u}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{},d=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:a})),p=new se({second:h,size:u||1,url:n,uuid:l,isCustomUpload:!0});return d.setElement(p),this._messageOptionsMap.set(d.clientSequence,e),d}catch(e){throw e}}upload(i){return t(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,e=(e.debug("upload",f+" uploadAudio message:"+t(i)),this._messageOptionsMap.get(i.clientSequence).payload)["file"],t=(this._validateBeforeUploadAudio(e),i.getElements()[0]),e=yield this._performAudioUpload(t,i,e),e=S.addAuthToUrl(null==e?void 0:e.location);return t.updateAudioUrl(e),i})}_validateBeforeUploadAudio(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:ae});if(e.size>le)throw new t({message:"File size exceeds limit: "+u(le)});if(0===e.size)throw new t({code:ne})}_performAudioUpload(r,s,i){return t(this,void 0,void 0,function*(){var e=s["to"],e={uploadFileType:y,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}},e=(yield N.uploadToCOS(e))["response"];return e})}_processAudioFile(e){var{IN_MINI_APP:t,IN_BROWSER:i}=null==(t=this._core)?void 0:t.utils;return t?this._processMiniFile(e):i?this._processWebFile(e):void 0}_processMiniFile(e){return{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.fileSize,second:e.duration,type:e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase()}}_processWebFile(e){var t;return e.tempFilePath||e.uri||(t=URL.createObjectURL(e),e.tempFilePath=t),e}_validateCustomUploadOptions(e){var t=this._core["utils"]["isEmpty"],{url:e,uuid:i,duration:r}=(null==(e=null==e?void 0:e.payload)?void 0:e.file)||{};if(t(e)||t(i)||t(r))throw new Error("Invalid audio message options")}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let ue={to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1},payload:{required:!0,rules:["object"],allowEmpty:!1},cloudCustomData:{required:!1,rules:["string"],allowEmpty:!1},priority:{required:!1,rules:["string"],allowEmpty:!1},customModerationConfigurationID:{required:!1,rules:["string"],allowEmpty:!1},onProgress:{required:!1,rules:["function"],allowEmpty:!1}},he={createImageMessage:ue,createAudioMessage:ue,createVideoMessage:ue,createFileMessage:ue},ce={createImageMessage:!0,createAudioMessage:!0,createVideoMessage:!0,createFileMessage:!0},pe={[c]:j,[g]:J,[m]:re,[p]:de};var ge=new class{constructor(){this.name="RichMediaMessage"}install(e){let{OuterConstant:{MSG_AUDIO:t,MSG_FILE:i,MSG_IMAGE:r,MSG_VIDEO:s}}=(this._core=e)["constants"];K.init(e),j.init(e),J.init(e),re.init(e),de.init(e),N.init(e),S.init(e),e.helper.registerApi({apiName:"sendMessage",context:this,matcher:e=>[t,i,r,s].includes(e[0].type)}),e.helper.registerValidateConfig({auth:ce,params:he})}sendMessage(r,s){return t(this,void 0,void 0,function*(){var e,t,i;try{return this._isCustomUpload(r)||(yield this._upload(r)),yield null==(i=null==(t=null==(e=this._core)?void 0:e.message)?void 0:t.messageSender)?void 0:i.sendMessage(r,s)}catch(e){throw e}})}_upload(i){return t(this,void 0,void 0,function*(){let{ssoLog:t,utils:{safeStringify:e}}=this._core;if(t.debug("_upload"," uploadFile message:"+e(i)),!0!==i._relayFlag)try{let e=pe[i.type];e&&(yield e.upload(i),t.info("_upload"," type:"+i.type))}catch(t){throw i.status=w.FAIL,t instanceof Error&&(t.data={message:i}),this._core.message.messageDataHandler.storeConversationMessage(i),t}})}_isCustomUpload(e){return!0===(null==(e=null==(e=e._elements)?void 0:e[0])?void 0:e[F])}};export{ge as default};
1
+ function e(e,t){var i={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(i[o[r]]=e[o[r]])}return i}function t(e,t,i,o){return new(i||(i=Promise))(function(r,s){function n(e){try{l(o.next(e))}catch(e){s(e)}}function a(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(n,a)}l((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var i=new class{constructor(){this._name="WebRequest"}init(e){this._core=e}request(e,i){return t(this,void 0,void 0,function*(){var t;const{isEmpty:o}=null===(t=this._core)||void 0===t?void 0:t.utils,{downloadUrl:r="",method:s="PUT",url:n,qs:a,headers:l={},resources:u,dataType:d="text",uploadByIP:h,uploadIP:c}=e;let p=n;if(a){const e=this._queryString(a);e&&(p+=`${p.includes("?")?"&":"?"}${e}`)}const g=new XMLHttpRequest;g.open(s.toUpperCase(),p,!0),g.responseType=d;const m=Object.assign({},l);if(h&&c&&(m.host=c),!o(m))for(const e in m)m.hasOwnProperty(e)&&!["content-length","user-agent","origin","host"].includes(e.toLowerCase())&&g.setRequestHeader(e,m[e]);return g.onload=()=>{const t=this._getResponseBody(g,r,h&&c),o=this._buildResponse(g,t);if(200===g.status)i(null,o);else{if(c&&!p.includes(c))return e.url=this._domainName2IP(p,c),e.uploadByIP=!0,this.request(e,i);i({code:g.status,message:JSON.stringify(g.responseText)},o)}},g.onerror=()=>{const e=this._getResponseBody(g,r,h&&c),t=this._buildResponse(g,e),o={code:g.status,message:0===g.status?"CORS blocked or network error":JSON.stringify(g.responseText)};i(o,t)},e.onProgress&&g.upload&&(g.upload.onprogress=t=>{const{total:i,loaded:o}=t,r=Math.min(Math.floor(100*o/i),100);e.onProgress({total:i,loaded:o,percent:r/100})}),g.send(u),g})}_buildResponse(e,t){const i={};return e.getAllResponseHeaders().trim().split("\n").forEach(e=>{if(e){const[t,o]=e.split(":").map(e=>e.trim());i[t.toLowerCase()]=o}}),{statusCode:e.status,statusMessage:e.statusText,headers:i,data:t}}_getResponseBody(e,t,i){return 200===e.status&&t?{location:t,uploadIP:i}:{response:e.responseText,uploadIP:i}}_queryString(e,t="&",i="="){var o;const{isEmpty:r,isPlainObject:s}=null===(o=this._core)||void 0===o?void 0:o.utils;return r(e)?"":s(e)?Object.keys(e).map(o=>{const r=encodeURIComponent(o)+i;return Array.isArray(e[o])?e[o].map(e=>r+encodeURIComponent(e)).join(t):r+encodeURIComponent(e[o])}).filter(Boolean).join(t):void 0}_domainName2IP(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,`https://${t}/`)}};const o=["unknown","image","video","audio","log"];var r=new class{init(e){this._core=e}request(t,i){var r;const{MINI_APP_NAMESPACE:s,IN_ALIPAY_MINI_APP:n,isUniIOSApp:a}=null===(r=this._core)||void 0===r?void 0:r.utils,{resources:l="",headers:u={},url:d,downloadUrl:h=""}=t;let c=d,p=null;const g=h?h.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/):null;if(!g)return void console.warn("message Invalid download URL format");const m=decodeURIComponent(g[3]),f=m.includes("?")?m.split("?")[0]:m||"",_={key:t.fileKey||f,success_action_status:200,"Content-Type":""},v={};if(a()){const[e,t]=d.split("?sign=");t&&(c=`${e}?sign=${encodeURIComponent(t)}`,v.sign=decodeURIComponent(t),v.signature=decodeURIComponent(t))}let I={url:c,header:u,name:"file",filePath:l,formData:Object.assign(Object.assign({},_),v),timeout:t.timeout||3e5};if(n){const{name:i}=I,r=e(I,["name"]);I=Object.assign(Object.assign({},r),{fileName:"file",fileType:t.fileType?o[t.fileType]:"image"})}return p=s.uploadFile(Object.assign(Object.assign({},I),{success:e=>{this._handleResponse({response:e,downloadUrl:h,callback:i})},fail:e=>{this._handleResponse({response:e,downloadUrl:h,callback:i})}})),p.onProgressUpdate&&p.onProgressUpdate(e=>{t.onProgress&&t.onProgress({total:e.totalBytesExpectedToSend||0,loaded:e.totalBytesSent||0,percent:e.progress?Math.floor(e.progress)/100:0})}),p}_handleResponse(e){const{downloadUrl:t,response:i,callback:o}=e,r={};if(i.header)for(const e in i.header)i.header.hasOwnProperty(e)&&(r[e.toLowerCase()]=i.header[e]);const s=+i.statusCode;200===s?o(null,{statusCode:s,headers:r,data:Object.assign(Object.assign({},i.data),{location:t})}):o({code:s,message:JSON.stringify(i.data)},{statusCode:s,headers:r,data:void 0})}};function s(e){return"file"===function(e){return Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()}(e)}function n(e){const t=e||99999999;return Math.round(Math.random()*t)}function a(e,t=!0,i=!0){const o=Date.now();return t?i?o-e+" ms":`${Math.round((o-e)/1e3)} s`:i?o-e:Math.round((o-e)/1e3)}function l(e){return`${Array.from({length:8},()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1)).join("")}-${e}`}function u(e,t){return Math.round(Number(e)*10**t)/10**t}function d(e){const t=1024,i=1048576;return e<t?`${e}B`:e<i?`${Math.floor(e/t)}KB`:`${Math.floor(e/i)}MB`}function h(e){if(e<=1048576){return`${u(e/1024,1)}KB/s`}return`${u(e/1048576,1)}MB/s`}const c="TIMImageElem",p="TIMSoundElem",g="TIMFileElem",m="TIMVideoFileElem",f="RichMediaMessagePlugin",_=["rich.my-imcloud.com","imrich.qcloud.com"],v=1,I=2,y=3,U=255;var w;!function(e){e.UNSENT="unSend",e.SUCCESS="success",e.FAIL="fail"}(w||(w={}));const b={wechat:/^(wxfile:\/\/tmp_|http:\/\/temp\/|cloud:\/\/temp-)/,alipay:/^(https:\/\/resource\/|alipayfile:\/\/tmp\/)/,baidu:/^(http:\/\/tmp\/|swanfile:\/\/tmp_)/,bytedance:/^(ttfile:\/\/tmp_|\/(var|tmp)\/|tttemp:\/\/)/,qq:/^(qqfile:\/\/tmp_|http:\/\/qtemp\/)/},F=Symbol("isCustomUpload");var S=new class{init(e){this._core=e}addAuthToUrl(e=""){if(this._isMiniProgramTempFile(e))return e;const t=function(e){return e?e.startsWith("https://")?e:e.startsWith("http://")?e.replace("http://","https://"):e:""}(e);return this.processResourceUrl(t)}removeAuthToUrl(e){return function(e,t){const[i,o]=e.split("?");if(!o)return i;const r=o.split("&").reduce((e,i)=>{const[o,r]=i.split("=");return o&&o!==t&&(e[o]=r||""),e},{}),s=Object.keys(r).map(e=>`${e}${r[e]?`=${r[e]}`:""}`).join("&");return s?`${i}?${s}`:i}(e,"authKey")}_isMiniProgramTempFile(e){return!!this.getPlatformFlags().IN_MINI_APP&&Object.values(b).some(t=>t.test(e))}extractFileFromInput(e){const{utils:{isArray:t}}=this._core;return s(e)?e:function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let i=t;for(;null!==Object.getPrototypeOf(i);)i=Object.getPrototypeOf(i);return t===i}(e)&&"undefined"!=typeof uni?t(e.tempFiles)&&e.tempFiles.length>0?e.tempFiles[0]:t(e.files)?e.files[0]:e.tempFile?e.tempFile:null:e instanceof HTMLInputElement&&e.files&&e.files.length>0?e.files[0]:null}probeImageWidthHeight(e){return t(this,void 0,void 0,function*(){var t;const{IN_MINI_APP:i,IN_BROWSER:o}=(null===(t=this._core)||void 0===t?void 0:t.utils)||{};return this._shouldSkipProbing()?{width:0,height:0}:o?this._probeImageDimensionsWeb(e):i?this._probeImageDimensionsMiniApp(e):void 0})}isSimpleCos(){var e;const t=(null===(e=this._core)||void 0===e?void 0:e.store.get("cloudConfig"))||{},{simple_cos:i}=t;return"0"!==i}getFileDNList(){var e;let t=_;const i=(null===(e=this._core)||void 0===e?void 0:e.store.get("cloudConfig"))||{},{file_dn_list:o}=i;if(void 0===o)return t;try{JSON.parse(o).forEach(e=>{t.includes(e)||t.push(e)})}catch(e){console.warn(e),t=_}return t}getPlatform(){var e;return null===(e=this._core)||void 0===e?void 0:e.utils.platform}generateUUID(e,t){var i;let o=`${this.getSDKAppID()}-${this.getCurrentUserID()}-${null===(i=this._core)||void 0===i?void 0:i.utils.randomString()}`;if(t)return`${o}.${t}`;const r=e.name||e.value||e.url||e.tempFilePath,s=r&&r.slice(r.lastIndexOf(".")+1);return s&&(o=`${o}.${s}`),o}processResourceUrl(e){if(!e)return"";let t=e;const i=this.getFileDownloadProxy(),o=this.getAuthKey(),r=this.getFileDNList();i&&(e.startsWith("http://")?t=e.replace(/^http:\/\/[^/]+/,i):e.startsWith("https://")&&(t=e.replace(/^https:\/\/[^/]+/,i)));const s=o&&-1===t.indexOf("authKey=")&&function(e,t){let i=!1;if(e){const o=e.match(/:\/\/([0-9]?\.)?(.[^/:]+)/),r=o&&o[2]||"";if(r.includes("rich-dev"))return!0;for(let e=0;e<t.length;e++)if(r.endsWith(t[e])){i=!0;break}}return i}(t,r);return s&&(t=t.indexOf("?")>-1?`${t}&authKey=${o}`:`${t}?authKey=${o}`),t}getCurrentUserID(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.userId}getSDKAppID(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.sdkAppId}getFileDownloadProxy(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.fileDownloadProxy)||""}getFileUploadProxy(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.fileUploadProxy)||""}getAuthKey(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.authKey)||""}isPrivateNetWork(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.proxyServer}getPlatformFlags(){var e;const{IN_BROWSER:t,IN_MINI_APP:i,IN_RN_APP:o,IN_UNI_NATIVE_APP:r}=null===(e=this._core)||void 0===e?void 0:e.utils;return{IN_BROWSER:t,IN_MINI_APP:i,IN_RN_APP:o,IN_UNI_NATIVE_APP:r}}isEmpty(e){var t;const{isEmpty:i}=null===(t=this._core)||void 0===t?void 0:t.utils;return i(e)}generateURL(e,t){const{needAddAuthToUrl:i=!0}=t||{};return i?this.addAuthToUrl(e):e}_probeImageDimensionsMiniApp(e){var t;const{MINI_APP_NAMESPACE:i}=(null===(t=this._core)||void 0===t?void 0:t.utils)||{};return new Promise(t=>{i.getImageInfo({src:e,success:e=>t({width:e.width,height:e.height}),fail:()=>t({width:0,height:0})})})}_shouldSkipProbing(){var e;const{IN_RN_APP:t,IS_IE:i,IE_VERSION:o,IN_WX_MINI_GAME:r}=(null===(e=this._core)||void 0===e?void 0:e.utils)||{};return t||i&&9===o||r}_probeImageDimensionsWeb(e){return new Promise(t=>{const i=new Image,o=()=>{i.onload=null,i.onerror=null,i.src=""};i.onload=()=>{t({width:i.width,height:i.height}),o()},i.onerror=()=>{t({width:0,height:0}),o()},i.src=e})}};function A(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var P,M={exports:{}};var N=A(P?M.exports:(P=1,M.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function i(e,t){var i=e[0],o=e[1],r=e[2],s=e[3];o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[0]-680876936|0)<<7|i>>>25)+o|0)&o|~i&r)+t[1]-389564586|0)<<12|s>>>20)+i|0)&i|~s&o)+t[2]+606105819|0)<<17|r>>>15)+s|0)&s|~r&i)+t[3]-1044525330|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[4]-176418897|0)<<7|i>>>25)+o|0)&o|~i&r)+t[5]+1200080426|0)<<12|s>>>20)+i|0)&i|~s&o)+t[6]-1473231341|0)<<17|r>>>15)+s|0)&s|~r&i)+t[7]-45705983|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[8]+1770035416|0)<<7|i>>>25)+o|0)&o|~i&r)+t[9]-1958414417|0)<<12|s>>>20)+i|0)&i|~s&o)+t[10]-42063|0)<<17|r>>>15)+s|0)&s|~r&i)+t[11]-1990404162|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[12]+1804603682|0)<<7|i>>>25)+o|0)&o|~i&r)+t[13]-40341101|0)<<12|s>>>20)+i|0)&i|~s&o)+t[14]-1502002290|0)<<17|r>>>15)+s|0)&s|~r&i)+t[15]+1236535329|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[1]-165796510|0)<<5|i>>>27)+o|0)&r|o&~r)+t[6]-1069501632|0)<<9|s>>>23)+i|0)&o|i&~o)+t[11]+643717713|0)<<14|r>>>18)+s|0)&i|s&~i)+t[0]-373897302|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[5]-701558691|0)<<5|i>>>27)+o|0)&r|o&~r)+t[10]+38016083|0)<<9|s>>>23)+i|0)&o|i&~o)+t[15]-660478335|0)<<14|r>>>18)+s|0)&i|s&~i)+t[4]-405537848|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[9]+568446438|0)<<5|i>>>27)+o|0)&r|o&~r)+t[14]-1019803690|0)<<9|s>>>23)+i|0)&o|i&~o)+t[3]-187363961|0)<<14|r>>>18)+s|0)&i|s&~i)+t[8]+1163531501|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[13]-1444681467|0)<<5|i>>>27)+o|0)&r|o&~r)+t[2]-51403784|0)<<9|s>>>23)+i|0)&o|i&~o)+t[7]+1735328473|0)<<14|r>>>18)+s|0)&i|s&~i)+t[12]-1926607734|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[5]-378558|0)<<4|i>>>28)+o|0)^o^r)+t[8]-2022574463|0)<<11|s>>>21)+i|0)^i^o)+t[11]+1839030562|0)<<16|r>>>16)+s|0)^s^i)+t[14]-35309556|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[1]-1530992060|0)<<4|i>>>28)+o|0)^o^r)+t[4]+1272893353|0)<<11|s>>>21)+i|0)^i^o)+t[7]-155497632|0)<<16|r>>>16)+s|0)^s^i)+t[10]-1094730640|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[13]+681279174|0)<<4|i>>>28)+o|0)^o^r)+t[0]-358537222|0)<<11|s>>>21)+i|0)^i^o)+t[3]-722521979|0)<<16|r>>>16)+s|0)^s^i)+t[6]+76029189|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[9]-640364487|0)<<4|i>>>28)+o|0)^o^r)+t[12]-421815835|0)<<11|s>>>21)+i|0)^i^o)+t[15]+530742520|0)<<16|r>>>16)+s|0)^s^i)+t[2]-995338651|0)<<23|o>>>9)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[0]-198630844|0)<<6|i>>>26)+o|0)|~r))+t[7]+1126891415|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[14]-1416354905|0)<<15|r>>>17)+s|0)|~i))+t[5]-57434055|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[12]+1700485571|0)<<6|i>>>26)+o|0)|~r))+t[3]-1894986606|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[10]-1051523|0)<<15|r>>>17)+s|0)|~i))+t[1]-2054922799|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[8]+1873313359|0)<<6|i>>>26)+o|0)|~r))+t[15]-30611744|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[6]-1560198380|0)<<15|r>>>17)+s|0)|~i))+t[13]+1309151649|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[4]-145523070|0)<<6|i>>>26)+o|0)|~r))+t[11]-1120210379|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[2]+718787259|0)<<15|r>>>17)+s|0)|~i))+t[9]-343485551|0)<<21|o>>>11)+r|0,e[0]=i+e[0]|0,e[1]=o+e[1]|0,e[2]=r+e[2]|0,e[3]=s+e[3]|0}function o(e){var t,i=[];for(t=0;t<64;t+=4)i[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return i}function r(e){var t,i=[];for(t=0;t<64;t+=4)i[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return i}function s(e){var t,r,s,n,a,l,u=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)i(d,o(e.substring(t-64,t)));for(r=(e=e.substring(t-64)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)s[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(i(d,s),t=0;t<16;t+=1)s[t]=0;return n=(n=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(n[2],16),l=parseInt(n[1],16)||0,s[14]=a,s[15]=l,i(d,s),d}function n(e){var t,o,s,n,a,l,u=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)i(d,r(e.subarray(t-64,t)));for(o=(e=t-64<u?e.subarray(t-64):new Uint8Array(0)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)s[t>>2]|=e[t]<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(i(d,s),t=0;t<16;t+=1)s[t]=0;return n=(n=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(n[2],16),l=parseInt(n[1],16)||0,s[14]=a,s[15]=l,i(d,s),d}function a(e){var i,o="";for(i=0;i<4;i+=1)o+=t[e>>8*i+4&15]+t[e>>8*i&15];return o}function l(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function d(e,t){var i,o=e.length,r=new ArrayBuffer(o),s=new Uint8Array(r);for(i=0;i<o;i+=1)s[i]=e.charCodeAt(i);return t?s:r}function h(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function c(e,t,i){var o=new Uint8Array(e.byteLength+t.byteLength);return o.set(new Uint8Array(e)),o.set(new Uint8Array(t),e.byteLength),o}function p(e){var t,i=[],o=e.length;for(t=0;t<o-1;t+=2)i.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,i)}function g(){this.reset()}return l(s("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(i,o){var r,s,n,a,l=this.byteLength,u=t(i,l),d=l;return o!==e&&(d=t(o,l)),u>d?new ArrayBuffer(0):(r=d-u,s=new ArrayBuffer(r),n=new Uint8Array(s),a=new Uint8Array(this,u,r),n.set(a),s)}}(),g.prototype.append=function(e){return this.appendBinary(u(e)),this},g.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,r=this._buff.length;for(t=64;t<=r;t+=64)i(this._hash,o(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},g.prototype.end=function(e){var t,i,o=this._buff,r=o.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<r;t+=1)s[t>>2]|=o.charCodeAt(t)<<(t%4<<3);return this._finish(s,r),i=l(this._hash),e&&(i=p(i)),this.reset(),i},g.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},g.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},g.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},g.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},g.prototype._finish=function(e,t){var o,r,s,n=t;if(e[n>>2]|=128<<(n%4<<3),n>55)for(i(this._hash,e),n=0;n<16;n+=1)e[n]=0;o=(o=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(o[2],16),s=parseInt(o[1],16)||0,e[14]=r,e[15]=s,i(this._hash,e)},g.hash=function(e,t){return g.hashBinary(u(e),t)},g.hashBinary=function(e,t){var i=l(s(e));return t?p(i):i},g.ArrayBuffer=function(){this.reset()},g.ArrayBuffer.prototype.append=function(e){var t,o=c(this._buff.buffer,e),s=o.length;for(this._length+=e.byteLength,t=64;t<=s;t+=64)i(this._hash,r(o.subarray(t-64,t)));return this._buff=t-64<s?new Uint8Array(o.buffer.slice(t-64)):new Uint8Array(0),this},g.ArrayBuffer.prototype.end=function(e){var t,i,o=this._buff,r=o.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<r;t+=1)s[t>>2]|=o[t]<<(t%4<<3);return this._finish(s,r),i=l(this._hash),e&&(i=p(i)),this.reset(),i},g.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},g.ArrayBuffer.prototype.getState=function(){var e=g.prototype.getState.call(this);return e.buff=h(e.buff),e},g.ArrayBuffer.prototype.setState=function(e){return e.buff=d(e.buff,!0),g.prototype.setState.call(this,e)},g.ArrayBuffer.prototype.destroy=g.prototype.destroy,g.ArrayBuffer.prototype._finish=g.prototype._finish,g.ArrayBuffer.hash=function(e,t){var i=l(n(new Uint8Array(e)));return t?p(i):i},g}()));var C=new class{constructor(){this.uploadFileTryCount=0,this.maxRetries=1,this.systemClockOffset=0,this.httpRequest=null,this.uploadFileType="",this.duration=900,this.fetchCosTryCount=0}init(e){var t;this._core=e;const{IN_MINI_APP:o}=e.utils;this.httpRequest=o?r:i,null===(t=this.httpRequest)||void 0===t||t.init(e)}uploadToCOS(e){return t(this,void 0,void 0,function*(){const t=`${f} uploadToCOS`,{ssoLog:i,utils:{safeStringify:o}}=this._core,{file:r}=e;this.uploadFileType=e.uploadFileType,i.debug("uploadToCOS",`${t} options:${o(e)}`);try{const o=Date.now(),s=yield this._createCosOptions(e),n=s.fileExistsInCOS?{data:{location:s.downloadUrl}}:yield this._uploadFile(s);this._handleUploadError(n,e);const a=this._createUploadResult(r,n),l=Date.now()-o,u=d(r.size),c=`size:${u} time:${l}ms speed:${h(1e3*r.size/l)}`;return i.debug("uploadToCOS",`${t} ok. name:${r.name} ${c}`),{uploadOptions:s,response:a}}catch(e){throw i.warn("uploadToCOS",`${t} failed, error:${o(e)}`),e}})}_handleUploadError(e,t){var i,o;const{ChatError:r}=null===(i=this._core)||void 0===i?void 0:i.helper;if(403===e.statusCode)throw t.url,(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.uploadIP)&&e.data.uploadIP,new r({message:"Upload failed with status 403"})}_createUploadResult(e,t){return{fileName:e.name,fileSize:e.size,fileType:e.type.slice(e.type.indexOf("/")+1).toLowerCase(),location:t.data.location||"",uploadTime:a(Date.now(),!1),uploadSpeed:h(1e3*e.size/a(Date.now(),!1))}}_createCosOptions(e){return t(this,void 0,void 0,function*(){const{fileName:t,resources:i,uploadMethod:o}=yield this._prepareUploadParams(e),r=this._isC2CConversation(e.message.conversationID)?1:2;try{const s=yield this._fetchCosSignatureUrl({fileType:this.uploadFileType,fileName:t,uploadMethod:o,duration:this.duration,userID:e.message.from,conversationType:r}),{uploadUrl:n,downloadUrl:a,requestSnapshotUrl:l,thumbUrl:u,largeUrl:d,fileKey:h,existFlag:c}=s,p=!S.isPrivateNetWork()&&s.uploadIP;return{url:this._getRawOrUploadProxyUrl(n),fileType:this.uploadFileType,fileName:t,resources:i,downloadUrl:a,requestSnapshotUrl:l,thumbUrl:u,largeUrl:d,fileKey:h,uploadIP:p||"",fileExistsInCOS:1===c,onProgress:t=>this._handleUploadProgress(t,e)}}catch(e){throw console.error("Failed to create COS pre-signed URL options:",e),e}})}_prepareUploadParams(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i,isEmpty:o}}=this._core;t.debug("_prepareUploadParams",` prepareUploadParams:${i(e)}`);const{file:r}=e,{IN_MINI_APP:s,IN_RN_APP:a}=S.getPlatformFlags(),u=s||a,d=u&&e.message.type!==g,{name:h}=r,c=h.slice(h.lastIndexOf(".")),p=`${n(999999)}${c}`,m=d?r.name:p,f=yield this._generateHashFileName(r);return{fileName:o(f)?l(m):`${f}${c}`,resources:u?r.url:r,uploadMethod:u?1:0}})}_generateHashFileName(e){return t(this,void 0,void 0,function*(){const{utils:{IN_MINI_APP:t,IN_BROWSER:i,IN_UNI_NATIVE_APP:o,isArray:r},ssoLog:s}=this._core,n=Date.now();let a="";return i&&(a=yield this._generateHashFileNameInWeb(e)),t&&(r(e.tempFiles)&&(e=e.tempFiles[0]),o||(a=yield this._generateFileNameInMiniProgram(e)),o&&(a=yield this._generateFileNameInUNINativeApp(e))),s.info("_generateHashFileName",`hashFileName:${a} costTime:${Date.now()-n}`),a})}_generateHashFileNameInWeb(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;let o="";try{o=yield new Promise((i,o)=>{const r=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice;r||(t.warn("_generateHashFileNameInWeb","Browser does not support file slicing"),i(""));const s=10485760,n=Math.ceil(e.size/s);let a=0;const l=new N.ArrayBuffer,u=new FileReader,d=setTimeout(()=>{u.abort(),t.warn("_generateHashFileNameInWeb","File hash generation timeout"),i("")},2e3);function h(){const t=a*s,i=t+s>=e.size?e.size:t+s;u.readAsArrayBuffer(r.call(e,t,i))}u.onload=e=>{t.debug("_generateHashFileNameInWeb",`read chunk nr ${a+1} of ${n}`),l.append(e.target.result),a++,a<n?h():(t.debug("_generateHashFileNameInWeb","finished loading"),clearTimeout(d),i(l.end()))},u.onerror=e=>{clearTimeout(d),o(e)},h()})}catch(e){t.warn("_generateHashFileNameInWeb",i(e))}return o})}_generateFileNameInMiniProgram(e){return t(this,void 0,void 0,function*(){const{utils:{MINI_APP_NAMESPACE:t,safeStringify:i,isEmpty:o},ssoLog:r}=this._core;let s="";if(o(e.url))return r.warn("_generateFileNameInMiniProgram","file.url is empty"),s;if("function"!=typeof(null==t?void 0:t.getFileSystemManager))return r.warn("_generateFileNameInUNINativeApp","getFileSystemManager is not a function"),s;try{s=yield new Promise((i,o)=>{t.getFileSystemManager().getFileInfo({filePath:e.url,success:e=>{i(e.digest)},fail:e=>{o(e)}})})}catch(e){r.warn("_generateFileNameInMiniProgram",i(e))}return s})}_generateFileNameInUNINativeApp(e){return t(this,void 0,void 0,function*(){var t;const{utils:{safeStringify:i,isEmpty:o},ssoLog:r}=this._core;let s="";if(o(e.url))return r.warn("_generateFileNameInUNINativeApp","file.url is empty"),s;if("function"!=typeof(null===(t=null===plus||void 0===plus?void 0:plus.io)||void 0===t?void 0:t.getFileInfo))return r.warn("_generateFileNameInUNINativeApp","plus.io.getFileInfo is not a function"),s;try{s=yield new Promise((t,i)=>{plus.io.getFileInfo({filePath:e.url,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){r.warn("_generateFileNameInMiniProgram",i(e))}return s})}_handleUploadProgress(e,t){if("function"==typeof t.onProgress)try{t.onProgress(e.percent)}catch(e){throw console.warn("Upload progress callback error:",e),e}}_fetchCosSignatureUrl(e){return t(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,r=S.isSimpleCos(),s=this._prepareCosRequestData(e),n=r?"im_cos_msg.simple_sig":"im_cos_msg.pre_sig";try{const e=yield function(e,i,o){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:r}=o,s=t.generateCosSpecifiedData({servcmd:e,data:i}),n=`${s.head.seq}${e}`;return yield r.sendPacket(s,{requestId:n})}catch(e){throw console.warn("getCosSig error:",e),e}})}(n,s,this._core);this.fetchCosTryCount=0;const a=this._processResponse(e);return i.debug("_fetchCosSignatureUrl",` ok. isSimpleCos:${r} data:${o(a)}`),a||{}}catch(t){if(this.fetchCosTryCount<1)return this.fetchCosTryCount++,this._fetchCosSignatureUrl(e);throw this.fetchCosTryCount=0,t}})}_processResponse(e){var t;const i=S.isSimpleCos(),o=i?null===(t=null==e?void 0:e.rpt_pre_sig)||void 0===t?void 0:t[0]:e;if(!o)return{};if(i){const{str_final_ip:e,rpt_pre_sig:t,uint32_file_id:i,uint32_exist_flag:r,str_download_url:s,str_upload_url:n,str_snapshot_url:a,str_file_key:l}=o;return{uploadIP:e,preSig:t,fileID:i,existFlag:r,downloadUrl:s,uploadUrl:n,requestSnapshotUrl:a,fileKey:l}}const{upload_url:r,download_url:s,snapshot_url:n,thumb_url:a,large_url:l,file_key:u}=o;return{uploadUrl:r,downloadUrl:s,requestSnapshotUrl:n,thumbUrl:a,largeUrl:l,fileKey:u}}_prepareCosRequestData(e){return S.isSimpleCos()?{uint32_upload_method:e.uploadMethod,uint32_platform:S.getPlatform(),uint32_sdkappid:S.getSDKAppID(),str_user_id:e.userID,uint32_scene:e.conversationType,rpt_upload_object:[{uint32_file_id:1,uint32_file_type:e.fileType,str_file_name:e.fileName}]}:{file_type:e.fileType,file_name:e.fileName,upload_method:e.uploadMethod,Duration:e.duration}}_uploadFile(e){return t(this,void 0,void 0,function*(){return new Promise((t,i)=>{this.httpRequest.request(e,(o,r)=>{o&&this.uploadFileTryCount<this.maxRetries&&this.shouldRetry(o)?(this.uploadFileTryCount++,this._uploadFile(e).then(t).catch(i)):(this.uploadFileTryCount=0,o?i(o):t(r))})})})}shouldRetry(e){if(!e)return!1;if(5===Math.floor(e.statusCode/100))return!0;return!(!this.isTimeRelatedError(e)||!this._isClockOutOfSync(e))&&(this._syncSystemClock(e),!0)}isTimeRelatedError(e){var t,i;try{const o=null===(t=e.error)||void 0===t?void 0:t.Code,r=null===(i=e.error)||void 0===i?void 0:i.Message;return"RequestTimeTooSkewed"===o||"AccessDenied"===o&&"Request has expired"===r}catch(e){return!1}}_isClockOutOfSync(e){var t,i,o;const r=(null===(t=e.headers)||void 0===t?void 0:t.date)||(null===(i=e.headers)||void 0===i?void 0:i.Date)||(null===(o=e.error)||void 0===o?void 0:o.ServerTime);if(!r)return!1;const s=Date.now(),n=Date.parse(r);return Math.abs(s+this.systemClockOffset-n)>=3e4}_syncSystemClock(e){var t,i,o;const r=(null===(t=e.headers)||void 0===t?void 0:t.date)||(null===(i=e.headers)||void 0===i?void 0:i.Date)||(null===(o=e.error)||void 0===o?void 0:o.ServerTime);if(r){const e=Date.now(),t=Date.parse(r);this.systemClockOffset=t-e}}_getRawOrUploadProxyUrl(e){const t=S.getFileUploadProxy();let i=e;return t&&(i=e.replace(/^https:\/\/[^/]+/,t)),i}_isC2CConversation(e){return"C2C"===e.slice(0,3)}};const O=2108,T=2251,E=2252,D=["jpg","jpeg","gif","png","bmp","image","webp"],z=20971520,R={JPG:1,JPEG:1,GIF:2,PNG:3,BMP:4,UNKNOWN:255};class ${constructor(e,t){this.instanceID=n(9999999),this.sizeType=e.type||0,this.type=0,this.size=e.size||0,this.width=e.width||0,this.height=e.height||0,this.imageUrl=S.addAuthToUrl(e.imageUrl||e.url||""),this.url=S.addAuthToUrl(e.url||t)}setSizeType(e){this.sizeType=e}setType(e){this.type=e}setImageUrl(e){e&&(this.imageUrl=S.addAuthToUrl(e))}getImageUrl(){return this.imageUrl}}function x(t){const{originUrl:i,originWidth:o,originHeight:r,min:s=198}=t,n=parseInt(o)||0,a=parseInt(r)||0,l={url:void 0,width:0,height:0};if((n<=a?n:a)<=s)l.url=i,l.width=n,l.height=a;else{a<=n?(l.width=Math.ceil(n*s/a),l.height=s):(l.width=s,l.height=Math.ceil(a*s/n));const e=i&&i.indexOf("?")>-1?`${i}&`:`${i}?`;l.url=198===s?`${e}imageView2/3/w/198/h/198`:`${e}imageView2/3/w/720/h/720`}if(void 0===i){const{url:t}=l;return e(l,["url"])}return l}class W{constructor(e){this._imageMemoryURL="",this._percent=0,this.type=c;const{uuid:t,file:i,imageFormat:o,imageInfoArray:r=[],isCustomUpload:s=!1}=e;this._imageMemoryURL=this.createImageDataAsURL(i),this.content={imageFormat:o,uuid:t,imageInfoArray:[]},this[F]=s,this.initImageInfoArray(r),this.autoFixUrl()}static parseServerPushElement(e){const{MsgContent:t}=e,{ImageFormat:i,ImageInfoArray:o,UUID:r}=t,s=function(e){return e.map(e=>({size:e.Size,type:e.Type,width:e.Width,height:e.Height,url:e.URL}))}(o);return new W({imageFormat:i,imageInfoArray:s,uuid:r})}createImageDataAsURL(e){let t="";const{IN_MINI_APP:i,IN_RN_APP:o,IN_BROWSER:r}=S.getPlatformFlags();return e?((i||o)&&(t=e.url),r&&(t=window.URL.createObjectURL(e)),t):t}initImageInfoArray(e=[]){const t={type:0,size:0,width:0,height:0,url:""};for(let i=0;i<3;i++){const o=e[i]||Object.assign({},t),r=new $(o,this._imageMemoryURL);r.setSizeType(i+1),r.setType(i),this.addImageInfo(r)}this.updateAccessSideImageInfoArray()}autoFixUrl(){const e=["http","https"];this.content.imageInfoArray.forEach(t=>{if(!t.url||""===t.imageUrl)return;const[i,...o]=t.imageUrl.split("://"),r=o.join("://");e.includes(i)||t.setImageUrl(`https://${r}`)})}updatePercent(e){this._percent=Math.min(e,1)}updateImageFormat(e){this.content.imageFormat=R[e.toUpperCase()]||R.UNKNOWN}addImageInfo(e){this.content.imageInfoArray.length>=3||this.content.imageInfoArray.push(e)}updateImageInfoArray(e){const t=this.content.imageInfoArray.length;let i;for(let o=0;o<t;o++)i=this.content.imageInfoArray[o],e[o].size&&(i.size=e[o].size),e[o].url&&i.setImageUrl(e[o].url),e[o].width&&(i.width=e[o].width),e[o].height&&(i.height=e[o].height)}updateAccessSideImageInfoArray(){const[e]=this.content.imageInfoArray;e&&0!==e.width&&0!==e.height&&(!function(e){const t=e[2];e[2]=e[1],e[1]=t;for(let t=0;t<e.length;t++)e[t].setType(t)}(this.content.imageInfoArray),Object.assign(this.content.imageInfoArray[2],x({originWidth:e.width,originHeight:e.height,min:720})))}validateBeforeSend(){if(this[F])return delete this[F],{isValid:!0};const[e]=this.content.imageInfoArray,t=!!e&&""!==e.imageUrl&&0!==e.size;return{isValid:t,error:t?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,imageFormat:r,imageInfoArray:s}=i;return{MsgType:this.type,MsgContent:{ImageFormat:r,ImageInfoArray:this.parseImageInfoArray(s),UUID:o}}}parseImageInfoArray(e){return e.map(e=>({InstanceId:e.instanceID,Type:e.sizeType,MsgType:e.type,Size:e.size,Width:e.width,Height:e.height,URL:S.removeAuthToUrl(e.imageUrl)}))}}var j=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createImageMessage",context:this}),o.registerExperimentalAPI("createImageMessage",this,"createCustomUploadImageMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(c,W),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createImageMessage(e){var t,i,o;try{const r=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,s=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:r})),n=this._processImage(e);e.payload.file=n;const a={imageFormat:R.UNKNOWN,uuid:S.generateUUID(n),file:n,imageInfoArray:[]},l=new W(a);return s.setElement(l),this._messageOptionsMap.set(s.clientSequence,e),s}catch(e){throw e}}createCustomUploadImageMessage(e){var t,i,o,r;const{store:s,utils:{isEmpty:n}}=this._core,a=null===(t=s.get("login"))||void 0===t?void 0:t.userId,l=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:a})),{largeImageUuid:u,largeFileSize:d,largeImageWidth:h,largeImageHeight:c,largeImageUrl:p,originImageUuid:g,originFileSize:m,originImageWidth:f,originImageHeight:_,originImageUrl:v,thumbImageUuid:I,thumbFileSize:y,thumbImageWidth:U,thumbImageHeight:w,thumbImageUrl:b}=(null===(r=null==e?void 0:e.payload)||void 0===r?void 0:r.file)||{};if(n(v)||n(g))throw new Error("createImageMessageExperimental originImageUrl or originImageUuid is empty");const F=new W({imageFormat:R.UNKNOWN,uuid:g,imageInfoArray:[{instanceID:g,size:m,width:f,height:_,imageUrl:v,url:v},{instanceID:u,size:d,width:h,height:c,imageUrl:p,url:p},{instanceID:I,size:y,width:U,height:w,imageUrl:b,url:b}],isCustomUpload:!0});return l.setElement(F),this._messageOptionsMap.set(l.clientSequence,e),l._skipUpload=!0,l}upload(e){return t(this,void 0,void 0,function*(){const t=e.getElements()[0],{file:i}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadImage(i);const o=yield this._performImageUpload(t,e,i),r=this._generateImageInfo(o);return t.updateImageFormat(null==o?void 0:o.fileType),t.updateImageInfoArray(r),e})}_performImageUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:v,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{uploadOptions:s,response:n}=yield C.uploadToCOS(r);return this._parseResponse(s,n)})}_generateImageInfo(e){const{location:t,fileSize:i,width:o,height:r,smallImageUrl:s,smallImageWidth:n,smallImageHeight:a,largeImageUrl:l,largeImageWidth:u,largeImageHeight:d,imageInfoArray:h}=e,c=S.addAuthToUrl(t),p={size:i,url:c,width:o,height:r};return(null==h?void 0:h.length)>0?this._processImageInfoArray(h,i):s&&l?[Object.assign({},p),{largeImageUrl:l,largeImageWidth:u,largeImageHeight:d},{smallImageUrl:s,smallImageWidth:n,smallImageHeight:a}]:[Object.assign({},p),this._generateThumbInfo(c,o,r,720),this._generateThumbInfo(c,o,r,198)]}_generateThumbInfo(e,t,i,o){return x({originUrl:e,originWidth:t,originHeight:i,min:o})}_processImageInfoArray(e,t){let i,o,r;for(const s of e)1===s.type?(o=s,o.size=t):2===s.type?(r=s,r.size=t):(i=s,i.size=t);return[Object.assign({},i),Object.assign({},r),Object.assign({},o)]}_parseResponse(e,i){return t(this,void 0,void 0,function*(){try{const{thumbUrl:t,largeUrl:o,downloadUrl:r}=e;t&&o&&(yield this._getImageInfoByUrl(t,i,"thumb"),yield this._getImageInfoByUrl(o,i,"large"));if(S.isSimpleCos()&&!S.isPrivateNetWork()&&(yield this._getImageInfoArray(r,i),null==i?void 0:i.uploadIP)){const e=this._extractDomainFromUrl(r);e&&(yield this._getDownloadIP(e,i))}return i}catch(e){throw e}})}_extractDomainFromUrl(e){var t;try{const t=e.match(/:\/\/([^\/]+)/);return t?t[1]:null}catch(e){return null===(t=this._core)||void 0===t||t.ssoLog.warn("_extractDomainFromUrl",`Failed to extract domain from URL:${e.message}`),null}}_getImageInfoByUrl(e,i,o){return t(this,void 0,void 0,function*(){var t;try{const t=S.addAuthToUrl(e),{width:r=0,height:s=0}=yield S.probeImageWidthHeight(t);i.width=r,i.height=s,"thumb"===o?(i.smallImageUrl=e,i.smallImageWidth=r,i.smallImageHeight=s):(i.largeImageUrl=e,i.largeImageWidth=r,i.largeImageHeight=s)}catch(e){null===(t=this._core)||void 0===t||t.ssoLog.warn("_getImageInfoByUrl",`Failed to get ${o} image info:${e.message}`)}})}_validateBeforeUploadImage(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:T});this._checkImageType(e),this._checkImageSize(e)}_processImage(e){var t;try{const{IN_MINI_APP:i}=null===(t=this._core)||void 0===t?void 0:t.utils;let{file:o}=e.payload;return o=i?this._processMiniAppImageFile(o):this._processWebImageFile(o),o}catch(e){throw e}}_processMiniAppImageFile(e){s(e)&&console.warn("FileUnsupportedInMiniApp","createImageMessage");const t=e.tempFiles[0].path||e.tempFiles[0].tempFilePath;return{url:t,name:t.slice(t.lastIndexOf("/")+1),size:e.tempFiles&&e.tempFiles[0].size||1,type:t.slice(t.lastIndexOf(".")+1).toLowerCase()}}_processWebImageFile(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper,o=S.extractFileFromInput(e);if(!o)throw new i({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});return o}_getDownloadIP(e,i){return t(this,void 0,void 0,function*(){const o=`${f} getDownloadIP domainName: ${e}`;try{const r=yield function(e,i){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:o}=i,r="im_cos_msg.get_final_ip",s={str_domain:e},n=t.generateProtocolData({servcmd:r,data:s}),a=`${n.head.seq}${r}`;return yield o.sendPacket(n,{requestId:a})}catch(e){throw console.warn("getFinalIP error:",e),e}})}(e,this._core);if(!r||!r.str_final_ip)return;console.log(`${o} ok. downloadIP:${r}`);const s=i.location.split("/");s[0]=r.str_final_ip,i.location=s.join("/")}catch(e){console.warn(e)}})}_getImageInfoArray(e,i){return t(this,void 0,void 0,function*(){try{const o=yield function(e,i){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:o}=i,r="im_cos_msg.get_imageinfo",s={str_image_url:e},n=t.generateProtocolData({servcmd:r,data:s}),a=`${n.head.seq}${r}`;return yield o.sendPacket(n,{requestId:a})}catch(e){throw console.warn("getImageInfo error:",e),e}})}(e,this._core);return i.imageInfoArray=this._processImageInfoResponse(o),i}catch(e){throw i.imageInfoArray=void 0,e}})}_processImageInfoResponse(e){if(!e)return[];const{rpt_msg_image_info:t}=e;return t.map(e=>({type:e.uint32_image_type,url:e.str_url,width:e.uint32_width,height:e.uint32_height,imageFormat:e.str_image_format}))}_checkImageType(e){const{utils:t,helper:i}=this._core;let o="";if(t.IN_MINI_APP&&(o=e.url.slice(e.url.lastIndexOf(".")+1)),t.IN_BROWSER&&(o=e.name.slice(e.name.lastIndexOf(".")+1)),D.indexOf(o.toLowerCase())<0)throw new i.ChatError({code:E})}_checkImageSize(e){const{utils:t,helper:i}=this._core;let o=0;if(o=(t.IN_MINI_APP,e.size),0===o)throw new i.ChatError({code:O});if(o>=z)throw new i.ChatError({message:`File size exceeds limit: ${d(z)}`})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const B=2108,V=2401,q="2.5.0",L="1.18.0",H=104857600;function k(e,t){const i=e.split("."),o=t.split("."),r=Math.max(i.length,o.length);for(;i.length<r;)i.push("0");for(;o.length<r;)o.push("0");for(let e=0;e<r;e++){const t=parseInt(i[e]),r=parseInt(o[e]);if(t>r)return 1;if(t<r)return-1}return 0}const K=new class{init(e){this.core=e}};var G;class Y{constructor(e){this.type=g,this.uploadProgress=0,this[G]=!1;const t=this._getFileInfo(e);this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,fileUrl:S.generateURL(e.url||e.fileUrl,{needAddAuthToUrl:!this[F]})||"",uuid:e.uuid,fileName:t.name||"",fileSize:t.size||0}}static parseServerPushElement(e){const{MsgContent:t}=e,{Download_Flag:i,Url:o,FileName:r,FileSize:s,UUID:n}=t;return new Y({downloadFlag:i,url:o,fileName:r,fileSize:s,uuid:n})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateFileUrl(e){this.content.fileUrl=e}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.fileUrl&&""!==this.content.fileName&&this.content.fileSize>0;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,downloadFlag:r,fileUrl:s,fileName:n,fileSize:a}=i;return{MsgType:this.type,MsgContent:{Download_Flag:r,Url:S.removeAuthToUrl(s),FileName:n,FileSize:a,UUID:o}}}_getFileInfo(e){const{utils:{IN_UNI_NATIVE_APP:t}}=K.core;if(e.fileName&&e.fileSize)return{size:e.fileSize,name:e.fileName};const{file:i}=e;return i?(t&&this._processNativeAppFile(i),{size:i.size,name:i.name}):{size:0,name:""}}_processNativeAppFile(e){if(e.path&&e.path.includes(".")){const t=e.path.slice(e.path.lastIndexOf(".")+1).toLowerCase();e.type=t,e.name||(e.name=`${n(999999)}.${t}`)}e.name||(e.type="",e.name=e.path.slice(e.path.lastIndexOf("/")+1).toLowerCase()),e.suffix&&(e.type=e.suffix),e.url||(e.url=e.path)}}G=F;var J=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createFileMessage",context:this}),o.registerExperimentalAPI("createFileMessage",this,"createCustomUploadFileMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(g,Y),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createFileMessage(e){var t,i,o;try{this._checkVersion();const r=this._processFile(e.payload.file);e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={uuid:S.generateUUID(r),file:r},l=new Y(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadFileMessage(e){var t,i,o;try{const{store:r,message:s,utils:{isEmpty:n}}=this._core,a=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{url:l,uuid:u,fileSize:d,fileName:h=""}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{};if(n(l))throw new Error("url is required");const c=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:a})),p=new Y({url:l,uuid:u,file:{size:d,name:h},isCustomUpload:!0});return c.setElement(p),c}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const{file:t}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadFile(t);const i=e.getElements()[0],o=yield this._performFileUpload(i,e,t),r=S.addAuthToUrl(null==o?void 0:o.location);return i.updateFileUrl(r),e})}_validateBeforeUploadFile(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:V});if(e.size>H)throw new i({message:`File size exceeds limit: ${d(H)}`});if(0===e.size)throw new i({code:B})}_performFileUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:U,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s}=yield C.uploadToCOS(r);return s})}_processFile(e){var t,i;const{IN_BROWSER:o,IN_RN_APP:r,IN_WX_MINI_APP:s,IN_QQ_MINI_APP:n,IN_UNI_NATIVE_APP:a}=null===(t=this._core)||void 0===t?void 0:t.utils,{ChatError:l}=null===(i=this._core)||void 0===i?void 0:i.helper;if(o||a){const t=S.extractFileFromInput(e);if(!t)throw new l({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});return t}if(s||n){const{tempFiles:t}=e;return Object.assign(Object.assign({},t[0]),{url:t[0].path})}return r?Object.assign(Object.assign({},e),{url:e.uri}):e}_checkVersion(){var e,t;const{MINI_APP_NAMESPACE:i,IN_MINI_APP:o,IN_WX_MINI_APP:r,IN_QQ_MINI_APP:s,IN_UNI_NATIVE_APP:n}=null===(e=this._core)||void 0===e?void 0:e.utils,{ChatError:a}=null===(t=this._core)||void 0===t?void 0:t.helper;if(o){if(!(r||s||n))throw new a({message:"Unsupported mini app environment"});const e=i.getSystemInfoSync().SDKVersion;if(r&&k(e,q)<0){throw new a({message:`WXChooseMessageFile requires SDK version ${q} or higher`})}if(s&&k(e,L)<0){throw new a({message:`QQChooseMessageFile requires SDK version ${L} or higher`})}}}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const Q=2108,X=2352,Z=["mp4","quicktime","mov"],ee=104857600;var te;class ie{constructor(e){this.type=m,this.uploadProgress=0,this[te]=!1;const t="number"==typeof(null==e?void 0:e.videoSecond)?null==e?void 0:e.videoSecond:0;this[F]=e.isCustomUpload||!1,this.content={remoteVideoUrl:S.addAuthToUrl(e.remoteVideoUrl||e.videoUrl||""),videoFormat:e.videoFormat,videoSecond:parseInt(null==t?void 0:t.toString(),10),videoSize:e.videoSize,videoUrl:S.addAuthToUrl(e.videoUrl),videoDownloadFlag:2,videoUUID:e.videoUUID,thumbUUID:e.thumbUUID,thumbFormat:e.thumbFormat,thumbWidth:e.thumbWidth,snapshotWidth:e.thumbWidth,thumbHeight:e.thumbHeight,snapshotHeight:e.thumbHeight,thumbSize:e.thumbSize,snapshotSize:e.thumbSize,thumbDownloadFlag:2,thumbUrl:S.addAuthToUrl(e.thumbUrl),snapshotUrl:S.addAuthToUrl(e.thumbUrl)}}static parseServerPushElement(e){const{MsgContent:t}=e,{VideoUrl:i,VideoFormat:o,VideoSecond:r,VideoSize:s,VideoDownloadFlag:n,VideoUUID:a,ThumbUUID:l,ThumbFormat:u,ThumbWidth:d,SnapshotWidth:h,ThumbHeight:c,SnapshotHeight:p,ThumbSize:g,SnapshotSize:m,ThumbDownloadFlag:f,ThumbUrl:_,SnapshotUrl:v}=t;return new ie({videoUrl:i,videoFormat:o,videoSecond:r,videoSize:s,videoDownloadFlag:n,videoUUID:a,thumbUUID:l,thumbFormat:u,thumbWidth:d,snapshotWidth:h,thumbHeight:c,snapshotHeight:p,thumbSize:g,snapshotSize:m,thumbDownloadFlag:f,thumbUrl:_,snapshotUrl:v})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateVideoUrl(e){e&&(this.content.remoteVideoUrl=e)}updateSnapshotInfo(e){const{snapshotUrl:t,snapshotWidth:i,snapshotHeight:o}=e;S.isEmpty(t)||(this.content.thumbUrl=this.content.snapshotUrl=t),S.isEmpty(i)||(this.content.thumbWidth=this.content.snapshotWidth=Number(i)),S.isEmpty(o)||(this.content.thumbHeight=this.content.snapshotHeight=Number(o))}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.remoteVideoUrl;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{remoteVideoUrl:o,videoFormat:r,videoSecond:s,videoSize:n,videoDownloadFlag:a,videoUUID:l,thumbUUID:u,thumbFormat:d,thumbWidth:h,snapshotWidth:c,thumbHeight:p,snapshotHeight:g,thumbSize:m,snapshotSize:f,thumbDownloadFlag:_,thumbUrl:v,snapshotUrl:I}=i;return{MsgType:this.type,MsgContent:{VideoUrl:S.removeAuthToUrl(o),VideoFormat:r,VideoSecond:s,VideoSize:n,VideoDownloadFlag:a,VideoUUID:l,ThumbUUID:u,ThumbFormat:d,ThumbWidth:h,SnapshotWidth:c,ThumbHeight:p,SnapshotHeight:g,ThumbSize:m,SnapshotSize:f,ThumbDownloadFlag:_,ThumbUrl:S.removeAuthToUrl(v),SnapshotUrl:S.removeAuthToUrl(I)}}}}te=F;var oe,re=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createVideoMessage",context:this}),o.registerExperimentalAPI("createVideoMessage",this,"createCustomUploadVideoMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(m,ie),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createVideoMessage(e){var t,i,o;try{const r=this._processVideo(e);e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={videoFormat:r.videoFile.type,videoSecond:u(r.videoFile.second,0),videoSize:r.videoFile.size,remoteVideoUrl:"",videoUrl:r.videoFile.url,videoUUID:S.generateUUID(r.videoFile),thumbUUID:S.generateUUID(r.videoFile,"jpg"),thumbWidth:r.width||200,thumbHeight:r.height||200,thumbUrl:r.thumbUrl,thumbSize:r.thumbSize,thumbFormat:"jpg"},l=new ie(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadVideoMessage(e){var t,i,o;try{const{store:r,message:s}=this._core;this._validateCustomUploadVideoMessage(e);const n=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{videoUrl:a,videoUuid:l,duration:u,snapshotUrl:d,snapshotUuid:h,videoFileSize:c,videoType:p,snapshotWidth:g,snapshotHeight:m,snapshotFileSize:f,snapshotType:_="jpg"}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{},v=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:n})),I=new ie({videoFormat:p,videoSecond:u||0,videoSize:c,remoteVideoUrl:a,videoUrl:a,videoUUID:l,thumbUUID:h,thumbWidth:g||200,thumbHeight:m||200,thumbUrl:d,thumbSize:f,thumbFormat:_,isCustomUpload:!0});return v.setElement(I),this._messageOptionsMap.set(v.clientSequence,e),v}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const t=e.getElements()[0],{file:i}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadVideo(i);const o=yield this._performVideoUpload(t,e,i),{location:r,snapshotInfo:s}=o,n=S.addAuthToUrl(r);return t.updateVideoUrl(n),S.isEmpty(s)||t.updateSnapshotInfo(s),e})}_validateBeforeUploadVideo(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(e.videoFile.size>ee)throw new i({message:`File size exceeds limit: ${d(ee)}`});if(0===e.videoFile.size)throw new i({code:Q});if(-1===Z.indexOf(e.videoFile.type))throw new i({code:X})}_validateCustomUploadVideoMessage(e){var t;const{utils:{isEmpty:i,isNumber:o}}=this._core,{videoUrl:r,videoUuid:s,duration:n,snapshotUrl:a,snapshotUuid:l}=(null===(t=null==e?void 0:e.payload)||void 0===t?void 0:t.file)||{};if(i(r)||i(s)||!o(n)||i(a)||i(l))throw new Error("Invalid video message options: missing required fields (videoUrl, videoUuid, duration, snapshotUrl, snapshotUuid)")}_performVideoUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:I,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s,uploadOptions:n}=yield C.uploadToCOS(r);return{snapshotInfo:yield this._getSnapshotInfoByUrl(n.requestSnapshotUrl),location:s.location}})}_processVideo(e){var t,i;try{const{ChatError:o}=null===(t=this._core)||void 0===t?void 0:t.helper,{IN_MINI_APP:r,IN_BROWSER:s}=null===(i=this._core)||void 0===i?void 0:i.utils;let{file:n}=e.payload,a={};if(r&&(a=this._processMiniVideoFile(n),n.name=a.name,n.url=a.url,n.type=a.type),s){const e=S.extractFileFromInput(n);if(!e)throw new o({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});n=e,a=this._processWebVideoFile(n)}return n.videoFile=a,n.thumbUrl="",n.thumbSize=0,n}catch(e){throw console.warn(`${f} _processFile error:`,e),e}}_processMiniVideoFile(e){var t,i;const{IN_ALIPAY_MINI_APP:o,IN_UNI_NATIVE_APP:r}=null===(t=this._core)||void 0===t?void 0:t.utils,{ChatError:n}=null===(i=this._core)||void 0===i?void 0:i.helper;if(o)throw new n({message:"VideoUnsupportedInAlipay"});if(s(e))throw new n({message:"FileUnsupportedInMiniApp"});Array.isArray(e.tempFiles)&&(e=e.tempFiles[0]);let a=e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase();return r&&(a=e.fileType||a),{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.size||1,second:e.duration||0,type:a}}_processWebVideoFile(e){const{name:t,size:i=1,duration:o=0,type:r}=e,s=r.split("/")[1];return{url:window.URL.createObjectURL(e),name:t,size:i,second:o,type:s}}_getSnapshotInfoByUrl(e){return t(this,void 0,void 0,function*(){const{ssoLog:i}=this._core;try{i.debug("_getSnapshotInfoByUrl",`${f} _getSnapshotInfoByUrl url:${e}`);const o={version:1,platform:S.getPlatform(),cover_name:l(n(99999)),snapshot_url:e},r=yield function(e,i){return t(this,void 0,void 0,function*(){try{const t="im_cos_msg.video_cover",{helper:o,channel:r}=i,s=o.generateCosSpecifiedData({servcmd:t,data:e}),n=`${s.head.seq}${t}`;return yield r.sendPacket(s,{requestId:n})}catch(e){throw console.warn("getSnapshotInfo error:",e),e}})}(o,this._core),{download_url:s}=r||{};if(i.debug("_getSnapshotInfoByUrl",`${f} _getSnapshotInfoByUrl OK snapshotUrl:${s}`),S.isEmpty(s))return{};const a=S.addAuthToUrl(s),{width:u=0,height:d=0}=yield S.probeImageWidthHeight(a);return{snapshotUrl:a,snapshotWidth:u,snapshotHeight:d}}catch(e){throw e}})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};class se{constructor(e){this.uploadProgress=0,this.type=p,this[oe]=!1,this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,second:e.second,size:e.size,url:S.generateURL(e.url,{needAddAuthToUrl:!this[F]}),remoteAudioUrl:S.addAuthToUrl(e.url||""),uuid:e.uuid}}static parseServerPushElement(e){const{MsgContent:t}=e,{Url:i,Download_Flag:o,Second:r,Size:s,UUID:n}=t;return new se({url:i,downloadFlag:o,second:r,size:s,uuid:n})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateAudioUrl(e){this.content.remoteAudioUrl=e}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.remoteAudioUrl;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,downloadFlag:r,remoteAudioUrl:s,size:n,second:a}=i;return{MsgType:this.type,MsgContent:{Url:S.removeAuthToUrl(s),Download_Flag:r,Second:a,Size:n,UUID:o}}}}oe=F;const ne=2108,ae=2300,le=20971520;var ue=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createAudioMessage",context:this}),o.registerExperimentalAPI("createAudioMessage",this,"createCustomUploadAudioMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(p,se),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createAudioMessage(e){var t,i,o;try{let{file:r}=e.payload;r=this._processAudioFile(e.payload.file),e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={second:Math.floor((r.duration||r.second)/1e3),size:r.fileSize||r.size||1,url:r.tempFilePath||r.uri||r.url,uuid:S.generateUUID(r)},l=new se(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadAudioMessage(e){var t,i,o;try{this._validateCustomUploadOptions(e);const{store:r,message:s}=this._core,n=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{url:a,uuid:l,duration:u,fileSize:d}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{},h=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:n})),c=new se({second:u,size:d||1,url:a,uuid:l,isCustomUpload:!0});return h.setElement(c),this._messageOptionsMap.set(h.clientSequence,e),h}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;t.debug("upload",`${f} uploadAudio message:${i(e)}`);const{file:o}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadAudio(o);const r=e.getElements()[0],s=yield this._performAudioUpload(r,e,o),n=S.addAuthToUrl(null==s?void 0:s.location);return r.updateAudioUrl(n),e})}_validateBeforeUploadAudio(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:ae});if(e.size>le)throw new i({message:`File size exceeds limit: ${d(le)}`});if(0===e.size)throw new i({code:ne})}_performAudioUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:y,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s}=yield C.uploadToCOS(r);return s})}_processAudioFile(e){var t;const{IN_MINI_APP:i,IN_BROWSER:o}=null===(t=this._core)||void 0===t?void 0:t.utils;return i?this._processMiniFile(e):o?this._processWebFile(e):void 0}_processMiniFile(e){return{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.fileSize,second:e.duration,type:e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase()}}_processWebFile(e){if(e.tempFilePath||e.uri)return e;const t=URL.createObjectURL(e);return e.tempFilePath=t,e}_validateCustomUploadOptions(e){var t;const{utils:{isEmpty:i}}=this._core,{url:o,uuid:r,duration:s}=(null===(t=null==e?void 0:e.payload)||void 0===t?void 0:t.file)||{};if(i(o)||i(r)||i(s))throw new Error("Invalid audio message options")}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const de={to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1},payload:{required:!0,rules:["object"],allowEmpty:!1},cloudCustomData:{required:!1,rules:["string"],allowEmpty:!1},priority:{required:!1,rules:["string"],allowEmpty:!1},customModerationConfigurationID:{required:!1,rules:["string"],allowEmpty:!1},onProgress:{required:!1,rules:["function"],allowEmpty:!1}},he={createImageMessage:de,createAudioMessage:de,createVideoMessage:de,createFileMessage:de},ce={createImageMessage:!0,createAudioMessage:!0,createVideoMessage:!0,createFileMessage:!0},pe={[c]:j,[g]:J,[m]:re,[p]:ue};var ge=new class{constructor(){this.name="RichMediaMessage"}install(e){this._core=e;const{constants:{OuterConstant:{MSG_AUDIO:t,MSG_FILE:i,MSG_IMAGE:o,MSG_VIDEO:r}}}=e;K.init(e),j.init(e),J.init(e),re.init(e),ue.init(e),C.init(e),S.init(e),e.helper.registerApi({apiName:"sendMessage",context:this,matcher:e=>[t,i,o,r].includes(e[0].type)}),e.helper.registerValidateConfig({auth:ce,params:he})}sendMessage(e,i){return t(this,void 0,void 0,function*(){var t,o,r;try{return this._isCustomUpload(e)||(yield this._upload(e)),yield null===(r=null===(o=null===(t=this._core)||void 0===t?void 0:t.message)||void 0===o?void 0:o.messageSender)||void 0===r?void 0:r.sendMessage(e,i)}catch(e){throw e}})}_upload(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;if(t.debug("_upload",` uploadFile message:${i(e)}`),!0!==e._relayFlag)try{const i=pe[e.type];i&&(yield i.upload(e),t.info("_upload",` type:${e.type}`))}catch(t){throw e.status=w.FAIL,t instanceof Error&&(t.data={message:e}),this._core.message.messageDataHandler.storeConversationMessage(e),t}})}_isCustomUpload(e){var t,i;return!0===(null===(i=null===(t=e._elements)||void 0===t?void 0:t[0])||void 0===i?void 0:i[F])}};export{ge as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatRich-media-message"]=t()}(this,function(){function g(e,t){var i={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]]);return i}function l(e,a,n,l){return new(n=n||Promise)(function(i,t){function r(e){try{o(l.next(e))}catch(e){t(e)}}function s(e){try{o(l.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(r,s)}o((l=l.apply(e,a||[])).next())})}var R=new class{constructor(){this._name="WebRequest"}init(e){this._core=e}request(g,m){return l(this,void 0,void 0,function*(){let e,t=(null==(e=this._core)?void 0:e.utils).isEmpty,{downloadUrl:i="",method:r="PUT",url:s,qs:o,headers:a={},resources:n,dataType:l="text",uploadByIP:h,uploadIP:u}=g,d=s;if(o){let e=this._queryString(o);e&&(d+=(d.includes("?")?"&":"?")+e)}let p=new XMLHttpRequest;p.open(r.toUpperCase(),d,!0),p.responseType=l;var c=Object.assign({},a);if(h&&u&&(c.host=u),!t(c))for(let e in c)c.hasOwnProperty(e)&&!["content-length","user-agent","origin","host"].includes(e.toLowerCase())&&p.setRequestHeader(e,c[e]);return p.onload=()=>{var e=this._getResponseBody(p,i,h&&u),e=this._buildResponse(p,e);if(200===p.status)m(null,e);else{if(u&&!d.includes(u))return g.url=this._domainName2IP(d,u),g.uploadByIP=!0,this.request(g,m);m({code:p.status,message:JSON.stringify(p.responseText)},e)}},p.onerror=()=>{var e=this._getResponseBody(p,i,h&&u),e=this._buildResponse(p,e),t={code:p.status,message:0===p.status?"CORS blocked or network error":JSON.stringify(p.responseText)};m(t,e)},g.onProgress&&p.upload&&(p.upload.onprogress=e=>{var{total:e,loaded:t}=e,i=Math.min(Math.floor(100*t/e),100);g.onProgress({total:e,loaded:t,percent:i/100})}),p.send(n),p})}_buildResponse(e,t){let i={};return e.getAllResponseHeaders().trim().split("\n").forEach(e=>{var t;e&&([e,t]=e.split(":").map(e=>e.trim()),i[e.toLowerCase()]=t)}),{statusCode:e.status,statusMessage:e.statusText,headers:i,data:t}}_getResponseBody(e,t,i){return 200===e.status&&t?{location:t,uploadIP:i}:{response:e.responseText,uploadIP:i}}_queryString(i,r="&",s="="){var{isEmpty:e,isPlainObject:t}=null==(e=this._core)?void 0:e.utils;return e(i)?"":t(i)?Object.keys(i).map(e=>{let t=encodeURIComponent(e)+s;return Array.isArray(i[e])?i[e].map(e=>t+encodeURIComponent(e)).join(r):t+encodeURIComponent(i[e])}).filter(Boolean).join(r):void 0}_domainName2IP(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,`https://${t}/`)}};let W=["unknown","image","video","audio","log"];var r,x=new class{init(e){this._core=e}request(i,r){let{MINI_APP_NAMESPACE:e,IN_ALIPAY_MINI_APP:s,isUniIOSApp:o}=null==(p=this._core)?void 0:p.utils,{resources:a="",headers:n={},url:l,downloadUrl:h=""}=i,u=l,d=null;var p=h?h.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/):null;if(p){var p=decodeURIComponent(p[3]),p=p.includes("?")?p.split("?")[0]:p||"",p={key:i.fileKey||p,success_action_status:200,"Content-Type":""},c={};if(o()){let[e,t]=l.split("?sign=");t&&(u=e+"?sign="+encodeURIComponent(t),c.sign=decodeURIComponent(t),c.signature=decodeURIComponent(t))}let t={url:u,header:n,name:"file",filePath:a,formData:Object.assign(Object.assign({},p),c),timeout:i.timeout||3e5};if(s){let{}=t,e=g(t,["name"]);t=Object.assign(Object.assign({},e),{fileName:"file",fileType:i.fileType?W[i.fileType]:"image"})}return(d=e.uploadFile(Object.assign(Object.assign({},t),{success:e=>{this._handleResponse({response:e,downloadUrl:h,callback:r})},fail:e=>{this._handleResponse({response:e,downloadUrl:h,callback:r})}}))).onProgressUpdate&&d.onProgressUpdate(e=>{i.onProgress&&i.onProgress({total:e.totalBytesExpectedToSend||0,loaded:e.totalBytesSent||0,percent:e.progress?Math.floor(e.progress)/100:0})}),d}console.warn("message Invalid download URL format")}_handleResponse(e){var{downloadUrl:e,response:t,callback:i}=e,r={};if(t.header)for(let e in t.header)t.header.hasOwnProperty(e)&&(r[e.toLowerCase()]=t.header[e]);var s=+t.statusCode;200==s?i(null,{statusCode:s,headers:r,data:Object.assign(Object.assign({},t.data),{location:e})}):i({code:s,message:JSON.stringify(t.data)},{statusCode:s,headers:r,data:void 0})}};function o(e){return"file"===Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()}function n(e){e=e||99999999;return Math.round(Math.random()*e)}function i(e,t=!0,i=!0){var r=Date.now();return t?i?r-e+" ms":Math.round((r-e)/1e3)+" s":i?r-e:Math.round((r-e)/1e3)}function h(e){return Array.from({length:8},()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1)).join("")+"-"+e}function u(e,t){return Math.round(Number(e)*10**t)/10**t}function d(e){return e<1024?e+"B":e<1048576?Math.floor(e/1024)+"KB":Math.floor(e/1048576)+"MB"}function p(e){return e<=1048576?u(e/1024,1)+"KB/s":u(e/1048576,1)+"MB/s"}let a="TIMImageElem",s="TIMSoundElem",c="TIMFileElem",m="TIMVideoFileElem",f="RichMediaMessagePlugin",_=["rich.my-imcloud.com","imrich.qcloud.com"],j=((e=r=r||{}).UNSENT="unSend",e.SUCCESS="success",e.FAIL="fail",{wechat:/^(wxfile:\/\/tmp_|http:\/\/temp\/|cloud:\/\/temp-)/,alipay:/^(https:\/\/resource\/|alipayfile:\/\/tmp\/)/,baidu:/^(http:\/\/tmp\/|swanfile:\/\/tmp_)/,bytedance:/^(ttfile:\/\/tmp_|\/(var|tmp)\/|tttemp:\/\/)/,qq:/^(qqfile:\/\/tmp_|http:\/\/qtemp\/)/}),v=Symbol("isCustomUpload");var I=new class{init(e){this._core=e}addAuthToUrl(e=""){return this._isMiniProgramTempFile(e)?e:(e=(e=e)?!e.startsWith("https://")&&e.startsWith("http://")?e.replace("http://","https://"):e:"",this.processResourceUrl(e))}removeAuthToUrl(i){{var[i,r]=i.split("?");if(!r)return i;let t=r.split("&").reduce((e,t)=>{var[t,i]=t.split("=");return t&&"authKey"!==t&&(e[t]=i||""),e},{}),e=Object.keys(t).map(e=>""+e+(t[e]?"="+t[e]:"")).join("&");return e?i+"?"+e:i}}_isMiniProgramTempFile(t){return!!this.getPlatformFlags().IN_MINI_APP&&Object.values(j).some(e=>e.test(t))}extractFileFromInput(e){var{isArray:t}=this._core["utils"];return o(e)?e:function(t){if("object"==typeof t&&null!==t){t=Object.getPrototypeOf(t);if(null===t)return 1;let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return t===e}}(e)&&"undefined"!=typeof uni?t(e.tempFiles)&&0<e.tempFiles.length?e.tempFiles[0]:t(e.files)?e.files[0]:e.tempFile||null:e instanceof HTMLInputElement&&e.files&&0<e.files.length?e.files[0]:null}probeImageWidthHeight(i){return l(this,void 0,void 0,function*(){var{IN_MINI_APP:e,IN_BROWSER:t}=(null==(e=this._core)?void 0:e.utils)||{};return this._shouldSkipProbing()?{width:0,height:0}:t?this._probeImageDimensionsWeb(i):e?this._probeImageDimensionsMiniApp(i):void 0})}isSimpleCos(){var e=((null==(e=this._core)?void 0:e.store.get("cloudConfig"))||{})["simple_cos"];return"0"!==e}getFileDNList(){let e,t=_;var i=((null==(e=this._core)?void 0:e.store.get("cloudConfig"))||{})["file_dn_list"];if(void 0!==i)try{JSON.parse(i).forEach(e=>{t.includes(e)||t.push(e)})}catch(e){console.warn(e),t=_}return t}getPlatform(){var e;return null==(e=this._core)?void 0:e.utils.platform}generateUUID(e,t){let i,r=`${this.getSDKAppID()}-${this.getCurrentUserID()}-`+(null==(i=this._core)?void 0:i.utils.randomString());return t?r+"."+t:(e=(t=e.name||e.value||e.url||e.tempFilePath)&&t.slice(t.lastIndexOf(".")+1),r=e?r+"."+e:r)}processResourceUrl(e){if(!e)return"";let t=e;var i=this.getFileDownloadProxy(),r=this.getAuthKey(),s=this.getFileDNList(),e=(i&&(e.startsWith("http://")?t=e.replace(/^http:\/\/[^/]+/,i):e.startsWith("https://")&&(t=e.replace(/^https:\/\/[^/]+/,i))),r&&-1===t.indexOf("authKey=")&&function(e,t){let i=!1;if(e){var e=e.match(/:\/\/([0-9]?\.)?(.[^/:]+)/),r=e&&e[2]||"";if(r.includes("rich-dev"))return!0;for(let e=0;e<t.length;e++)if(r.endsWith(t[e])){i=!0;break}}return i}(t,s));return t=e?-1<t.indexOf("?")?t+"&authKey="+r:t+"?authKey="+r:t}getCurrentUserID(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("login"))?void 0:e.userId}getSDKAppID(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.sdkAppId}getFileDownloadProxy(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.fileDownloadProxy)||""}getFileUploadProxy(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.fileUploadProxy)||""}getAuthKey(){var e;return(null==(e=null==(e=this._core)?void 0:e.store.get("login"))?void 0:e.authKey)||""}isPrivateNetWork(){var e;return null==(e=null==(e=this._core)?void 0:e.store.get("instance"))?void 0:e.proxyServer}getPlatformFlags(){var{IN_BROWSER:e,IN_MINI_APP:t,IN_RN_APP:i,IN_UNI_NATIVE_APP:r}=null==(e=this._core)?void 0:e.utils;return{IN_BROWSER:e,IN_MINI_APP:t,IN_RN_APP:i,IN_UNI_NATIVE_APP:r}}isEmpty(e){var t=(null==(t=this._core)?void 0:t.utils)["isEmpty"];return t(e)}generateURL(e,t){var{needAddAuthToUrl:t=!0}=t||{};return t?this.addAuthToUrl(e):e}_probeImageDimensionsMiniApp(e){let t,i=((null==(t=this._core)?void 0:t.utils)||{}).MINI_APP_NAMESPACE;return new Promise(t=>{i.getImageInfo({src:e,success:e=>t({width:e.width,height:e.height}),fail:()=>t({width:0,height:0})})})}_shouldSkipProbing(){var{IN_RN_APP:e,IS_IE:t,IE_VERSION:i,IN_WX_MINI_GAME:r}=(null==(e=this._core)?void 0:e.utils)||{};return e||t&&9===i||r}_probeImageDimensionsWeb(r){return new Promise(e=>{let t=new Image,i=()=>{t.onload=null,t.onerror=null,t.src=""};t.onload=()=>{e({width:t.width,height:t.height}),i()},t.onerror=()=>{e({width:0,height:0}),i()},t.src=r})}};y=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],S(F("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||(ArrayBuffer.prototype.slice=function(e,t){var i=this.byteLength,e=C(e,i),r=i;return(r=void 0!==t?C(t,i):r)<e?new ArrayBuffer(0):(t=r-e,i=new ArrayBuffer(t),r=new Uint8Array(i),e=new Uint8Array(this,e,t),r.set(e),i)}),M.prototype.append=function(e){return this.appendBinary(P(e)),this},M.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;for(var t=this._buff.length,i=64;i<=t;i+=64)U(this._hash,w(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},M.prototype.end=function(e){for(var t,i=this._buff,r=i.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=0;o<r;o+=1)s[o>>2]|=i.charCodeAt(o)<<(o%4<<3);return this._finish(s,r),t=S(this._hash),e&&(t=A(t)),this.reset(),t},M.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},M.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},M.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},M.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},M.prototype._finish=function(e,t){var i,r=t;if(e[r>>2]|=128<<(r%4<<3),55<r)for(U(this._hash,e),r=0;r<16;r+=1)e[r]=0;t=(t=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(t[2],16),t=parseInt(t[1],16)||0,e[14]=i,e[15]=t,U(this._hash,e)},M.hash=function(e,t){return M.hashBinary(P(e),t)},M.hashBinary=function(e,t){e=S(F(e));return t?A(e):e},(M.ArrayBuffer=function(){this.reset()}).prototype.append=function(e){i=this._buff.buffer,r=e,(s=new Uint8Array(i.byteLength+r.byteLength)).set(new Uint8Array(i)),s.set(new Uint8Array(r),i.byteLength);var t,i,r,s,o=s,a=o.length;for(this._length+=e.byteLength,t=64;t<=a;t+=64)U(this._hash,b(o.subarray(t-64,t)));return this._buff=t-64<a?new Uint8Array(o.buffer.slice(t-64)):new Uint8Array(0),this},M.ArrayBuffer.prototype.end=function(e){for(var t,i=this._buff,r=i.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],o=0;o<r;o+=1)s[o>>2]|=i[o]<<(o%4<<3);return this._finish(s,r),t=S(this._hash),e&&(t=A(t)),this.reset(),t},M.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},M.ArrayBuffer.prototype.getState=function(){var e,t=M.prototype.getState.call(this);return t.buff=(e=t.buff,String.fromCharCode.apply(null,new Uint8Array(e))),t},M.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){for(var i=e.length,r=new ArrayBuffer(i),s=new Uint8Array(r),o=0;o<i;o+=1)s[o]=e.charCodeAt(o);return t?s:r}(e.buff,!0),M.prototype.setState.call(this,e)},M.ArrayBuffer.prototype.destroy=M.prototype.destroy,M.ArrayBuffer.prototype._finish=M.prototype._finish,M.ArrayBuffer.hash=function(e,t){e=S(function(e){for(var t,i,r,s,o=e.length,a=[1732584193,-271733879,-1732584194,271733878],n=64;n<=o;n+=64)U(a,b(e.subarray(n-64,n)));for(t=(e=n-64<o?e.subarray(n-64):new Uint8Array(0)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<t;n+=1)i[n>>2]|=e[n]<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),55<n)for(U(a,i),n=0;n<16;n+=1)i[n]=0;return s=(s=8*o).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(s[2],16),s=parseInt(s[1],16)||0,i[14]=r,i[15]=s,U(a,i),a}(new Uint8Array(e)));return t?A(e):e};var e,y,B=(e=M)&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;function U(e,t){var i=e[0],r=e[1],s=e[2],o=e[3],r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[0]-680876936|0)<<7|i>>>25)+r|0)&r|~i&s)+t[1]-389564586|0)<<12|o>>>20)+i|0)&i|~o&r)+t[2]+606105819|0)<<17|s>>>15)+o|0)&o|~s&i)+t[3]-1044525330|0)<<22|r>>>10)+s|0;r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[4]-176418897|0)<<7|i>>>25)+r|0)&r|~i&s)+t[5]+1200080426|0)<<12|o>>>20)+i|0)&i|~o&r)+t[6]-1473231341|0)<<17|s>>>15)+o|0)&o|~s&i)+t[7]-45705983|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[8]+1770035416|0)<<7|i>>>25)+r|0)&r|~i&s)+t[9]-1958414417|0)<<12|o>>>20)+i|0)&i|~o&r)+t[10]-42063|0)<<17|s>>>15)+o|0)&o|~s&i)+t[11]-1990404162|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&s|~r&o)+t[12]+1804603682|0)<<7|i>>>25)+r|0)&r|~i&s)+t[13]-40341101|0)<<12|o>>>20)+i|0)&i|~o&r)+t[14]-1502002290|0)<<17|s>>>15)+o|0)&o|~s&i)+t[15]+1236535329|0)<<22|r>>>10)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[1]-165796510|0)<<5|i>>>27)+r|0)&s|r&~s)+t[6]-1069501632|0)<<9|o>>>23)+i|0)&r|i&~r)+t[11]+643717713|0)<<14|s>>>18)+o|0)&i|o&~i)+t[0]-373897302|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[5]-701558691|0)<<5|i>>>27)+r|0)&s|r&~s)+t[10]+38016083|0)<<9|o>>>23)+i|0)&r|i&~r)+t[15]-660478335|0)<<14|s>>>18)+o|0)&i|o&~i)+t[4]-405537848|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[9]+568446438|0)<<5|i>>>27)+r|0)&s|r&~s)+t[14]-1019803690|0)<<9|o>>>23)+i|0)&r|i&~r)+t[3]-187363961|0)<<14|s>>>18)+o|0)&i|o&~i)+t[8]+1163531501|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r&o|s&~o)+t[13]-1444681467|0)<<5|i>>>27)+r|0)&s|r&~s)+t[2]-51403784|0)<<9|o>>>23)+i|0)&r|i&~r)+t[7]+1735328473|0)<<14|s>>>18)+o|0)&i|o&~i)+t[12]-1926607734|0)<<20|r>>>12)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[5]-378558|0)<<4|i>>>28)+r|0)^r^s)+t[8]-2022574463|0)<<11|o>>>21)+i|0)^i^r)+t[11]+1839030562|0)<<16|s>>>16)+o|0)^o^i)+t[14]-35309556|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[1]-1530992060|0)<<4|i>>>28)+r|0)^r^s)+t[4]+1272893353|0)<<11|o>>>21)+i|0)^i^r)+t[7]-155497632|0)<<16|s>>>16)+o|0)^o^i)+t[10]-1094730640|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[13]+681279174|0)<<4|i>>>28)+r|0)^r^s)+t[0]-358537222|0)<<11|o>>>21)+i|0)^i^r)+t[3]-722521979|0)<<16|s>>>16)+o|0)^o^i)+t[6]+76029189|0)<<23|r>>>9)+s|0,r=((r+=((s=((s+=((o=((o+=((i=((i+=(r^s^o)+t[9]-640364487|0)<<4|i>>>28)+r|0)^r^s)+t[12]-421815835|0)<<11|o>>>21)+i|0)^i^r)+t[15]+530742520|0)<<16|s>>>16)+o|0)^o^i)+t[2]-995338651|0)<<23|r>>>9)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[0]-198630844|0)<<6|i>>>26)+r|0)|~s))+t[7]+1126891415|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[14]-1416354905|0)<<15|s>>>17)+o|0)|~i))+t[5]-57434055|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[12]+1700485571|0)<<6|i>>>26)+r|0)|~s))+t[3]-1894986606|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[10]-1051523|0)<<15|s>>>17)+o|0)|~i))+t[1]-2054922799|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[8]+1873313359|0)<<6|i>>>26)+r|0)|~s))+t[15]-30611744|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[6]-1560198380|0)<<15|s>>>17)+o|0)|~i))+t[13]+1309151649|0)<<21|r>>>11)+s|0,r=((r+=((o=((o+=(r^((i=((i+=(s^(r|~o))+t[4]-145523070|0)<<6|i>>>26)+r|0)|~s))+t[11]-1120210379|0)<<10|o>>>22)+i|0)^((s=((s+=(i^(o|~r))+t[2]+718787259|0)<<15|s>>>17)+o|0)|~i))+t[9]-343485551|0)<<21|r>>>11)+s|0,e[0]=i+e[0]|0,e[1]=r+e[1]|0,e[2]=s+e[2]|0,e[3]=o+e[3]|0}function w(e){for(var t=[],i=0;i<64;i+=4)t[i>>2]=e.charCodeAt(i)+(e.charCodeAt(i+1)<<8)+(e.charCodeAt(i+2)<<16)+(e.charCodeAt(i+3)<<24);return t}function b(e){for(var t=[],i=0;i<64;i+=4)t[i>>2]=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24);return t}function F(e){for(var t,i,r,s,o=e.length,a=[1732584193,-271733879,-1732584194,271733878],n=64;n<=o;n+=64)U(a,w(e.substring(n-64,n)));for(t=(e=e.substring(n-64)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<t;n+=1)i[n>>2]|=e.charCodeAt(n)<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),55<n)for(U(a,i),n=0;n<16;n+=1)i[n]=0;return s=(s=8*o).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(s[2],16),s=parseInt(s[1],16)||0,i[14]=r,i[15]=s,U(a,i),a}function S(e){for(var t=0;t<e.length;t+=1)e[t]=function(e){for(var t="",i=0;i<4;i+=1)t+=y[e>>8*i+4&15]+y[e>>8*i&15];return t}(e[t]);return e.join("")}function P(e){return e=/[\u0080-\uFFFF]/.test(e)?unescape(encodeURIComponent(e)):e}function A(e){for(var t=[],i=e.length,r=0;r<i-1;r+=2)t.push(parseInt(e.substr(r,2),16));return String.fromCharCode.apply(String,t)}function M(){this.reset()}function C(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}var N=new class{constructor(){this.uploadFileTryCount=0,this.maxRetries=1,this.systemClockOffset=0,this.httpRequest=null,this.uploadFileType="",this.duration=900,this.fetchCosTryCount=0}init(e){var t=(this._core=e).utils["IN_MINI_APP"];this.httpRequest=t?x:R,null!=(t=this.httpRequest)&&t.init(e)}uploadToCOS(h){return l(this,void 0,void 0,function*(){let r=f+" uploadToCOS",{ssoLog:s,utils:{safeStringify:t}}=this._core,o=h["file"];this.uploadFileType=h.uploadFileType,s.debug("uploadToCOS",r+" options:"+t(h));try{let e=Date.now(),t=yield this._createCosOptions(h),i=t.fileExistsInCOS?{data:{location:t.downloadUrl}}:yield this._uploadFile(t);this._handleUploadError(i,h);var a=this._createUploadResult(o,i),n=Date.now()-e,l=`size:${d(o.size)} time:${n}ms speed:`+p(1e3*o.size/n);return s.debug("uploadToCOS",r+` ok. name:${o.name} `+l),{uploadOptions:t,response:a}}catch(e){throw s.warn("uploadToCOS",r+" failed, error:"+t(e)),e}})}_handleUploadError(e,t){var i=(null==(i=this._core)?void 0:i.helper)["ChatError"];if(403===e.statusCode)throw t.url,null!=(t=null==e?void 0:e.data)&&t.uploadIP&&e.data.uploadIP,new i({message:"Upload failed with status 403"})}_createUploadResult(e,t){return{fileName:e.name,fileSize:e.size,fileType:e.type.slice(e.type.indexOf("/")+1).toLowerCase(),location:t.data.location||"",uploadTime:i(Date.now(),!1),uploadSpeed:p(1e3*e.size/i(Date.now(),!1))}}_createCosOptions(c){return l(this,void 0,void 0,function*(){var{fileName:e,resources:t,uploadMethod:i}=yield this._prepareUploadParams(c),r=this._isC2CConversation(c.message.conversationID)?1:2;try{var s=yield this._fetchCosSignatureUrl({fileType:this.uploadFileType,fileName:e,uploadMethod:i,duration:this.duration,userID:c.message.from,conversationType:r}),{uploadUrl:o,downloadUrl:a,requestSnapshotUrl:n,thumbUrl:l,largeUrl:h,fileKey:u,existFlag:d}=s,p=!I.isPrivateNetWork()&&s.uploadIP;return{url:this._getRawOrUploadProxyUrl(o),fileType:this.uploadFileType,fileName:e,resources:t,downloadUrl:a,requestSnapshotUrl:n,thumbUrl:l,largeUrl:h,fileKey:u,uploadIP:p||"",fileExistsInCOS:1===d,onProgress:e=>this._handleUploadProgress(e,c)}}catch(e){throw console.error("Failed to create COS pre-signed URL options:",e),e}})}_prepareUploadParams(a){return l(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t,isEmpty:i}}=this._core,e=(e.debug("_prepareUploadParams"," prepareUploadParams:"+t(a)),a)["file"],{IN_MINI_APP:t,IN_RN_APP:r}=I.getPlatformFlags(),t=t||r,r=t&&a.message.type!==c,s=e["name"],s=s.slice(s.lastIndexOf(".")),o=""+n(999999)+s,r=r?e.name:o,o=yield this._generateHashFileName(e);return{fileName:i(o)?h(r):""+o+s,resources:t?e.url:e,uploadMethod:t?1:0}})}_generateHashFileName(n){return l(this,void 0,void 0,function*(){var{utils:{IN_MINI_APP:e,IN_BROWSER:t,IN_UNI_NATIVE_APP:i,isArray:r},ssoLog:s}=this._core,o=Date.now();let a="";return t&&(a=yield this._generateHashFileNameInWeb(n)),e&&(r(n.tempFiles)&&(n=n.tempFiles[0]),i||(a=yield this._generateFileNameInMiniProgram(n)),i)&&(a=yield this._generateFileNameInUNINativeApp(n)),s.info("_generateHashFileName",`hashFileName:${a} costTime:`+(Date.now()-o)),a})}_generateHashFileNameInWeb(p){return l(this,void 0,void 0,function*(){let{ssoLog:d,utils:{safeStringify:t}}=this._core,e="";try{e=yield new Promise((t,i)=>{let r=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,s=(r||(d.warn("_generateHashFileNameInWeb","Browser does not support file slicing"),t("")),10485760),o=Math.ceil(p.size/s),a=0,n=new B.ArrayBuffer,l=new FileReader,h=setTimeout(()=>{l.abort(),d.warn("_generateHashFileNameInWeb","File hash generation timeout"),t("")},2e3);function u(){var e=a*s,t=e+s>=p.size?p.size:e+s;l.readAsArrayBuffer(r.call(p,e,t))}l.onload=e=>{d.debug("_generateHashFileNameInWeb",`read chunk nr ${a+1} of `+o),n.append(e.target.result),++a<o?u():(d.debug("_generateHashFileNameInWeb","finished loading"),clearTimeout(h),t(n.end()))},l.onerror=e=>{clearTimeout(h),i(e)},u()})}catch(e){d.warn("_generateHashFileNameInWeb",t(e))}return e})}_generateFileNameInMiniProgram(s){return l(this,void 0,void 0,function*(){let{utils:{MINI_APP_NAMESPACE:e,safeStringify:t},ssoLog:i}=this._core,r="";try{r=yield new Promise((t,i)=>{e.getFileSystemManager().getFileInfo({filePath:s.tempFilePath,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){i.warn("_generateFileNameInMiniProgram",t(e))}return r})}_generateFileNameInUNINativeApp(r){return l(this,void 0,void 0,function*(){var{utils:{safeStringify:t},ssoLog:i}=this._core;let e="";try{e=yield new Promise((t,i)=>{plus.io.getFileInfo({filePath:r.tempFilePath,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){i.warn("_generateFileNameInMiniProgram",t(e))}return e})}_handleUploadProgress(e,t){if("function"==typeof t.onProgress)try{t.onProgress(e.percent)}catch(e){throw console.warn("Upload progress callback error:",e),e}}_fetchCosSignatureUrl(n){return l(this,void 0,void 0,function*(){var{ssoLog:t,utils:{safeStringify:i}}=this._core,r=I.isSimpleCos(),s=this._prepareCosRequestData(n),o=r?"im_cos_msg.simple_sig":"im_cos_msg.pre_sig";try{let e=yield function(s,o,a){return l(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=a,i=e.generateCosSpecifiedData({servcmd:s,data:o}),r=i.head.seq+s;return yield t.sendPacket(i,{requestId:r})}catch(e){throw console.warn("getCosSig error:",e),e}})}(o,s,this._core);this.fetchCosTryCount=0;var a=this._processResponse(e);return t.debug("_fetchCosSignatureUrl",` ok. isSimpleCos:${r} data:`+i(a)),a||{}}catch(e){if(this.fetchCosTryCount<1)return this.fetchCosTryCount++,this._fetchCosSignatureUrl(n);throw this.fetchCosTryCount=0,e}})}_processResponse(e){var t;let i=I.isSimpleCos(),l=i?null==(t=null==e?void 0:e.rpt_pre_sig)?void 0:t[0]:e;if(!l)return{};if(i){let{str_final_ip:e,rpt_pre_sig:t,uint32_file_id:i,uint32_exist_flag:r,str_download_url:s,str_upload_url:o,str_snapshot_url:a,str_file_key:n}=l;return{uploadIP:e,preSig:t,fileID:i,existFlag:r,downloadUrl:s,uploadUrl:o,requestSnapshotUrl:a,fileKey:n}}let{upload_url:r,download_url:s,snapshot_url:o,thumb_url:a,large_url:n,file_key:h}=l;return{uploadUrl:r,downloadUrl:s,requestSnapshotUrl:o,thumbUrl:a,largeUrl:n,fileKey:h}}_prepareCosRequestData(e){return I.isSimpleCos()?{uint32_upload_method:e.uploadMethod,uint32_platform:I.getPlatform(),uint32_sdkappid:I.getSDKAppID(),str_user_id:e.userID,uint32_scene:e.conversationType,rpt_upload_object:[{uint32_file_id:1,uint32_file_type:e.fileType,str_file_name:e.fileName}]}:{file_type:e.fileType,file_name:e.fileName,upload_method:e.uploadMethod,Duration:e.duration}}_uploadFile(s){return l(this,void 0,void 0,function*(){return new Promise((i,r)=>{this.httpRequest.request(s,(e,t)=>{e&&this.uploadFileTryCount<this.maxRetries&&this.shouldRetry(e)?(this.uploadFileTryCount++,this._uploadFile(s).then(i).catch(r)):(this.uploadFileTryCount=0,e?r(e):i(t))})})})}shouldRetry(e){return!(!e||5!==Math.floor(e.statusCode/100)&&(!this.isTimeRelatedError(e)||!this._isClockOutOfSync(e)||(this._syncSystemClock(e),0)))}isTimeRelatedError(e){var t,i;try{var r=null==(t=e.error)?void 0:t.Code,s=null==(i=e.error)?void 0:i.Message;return"RequestTimeTooSkewed"===r||"AccessDenied"===r&&"Request has expired"===s}catch(e){return!1}}_isClockOutOfSync(e){var t,e=(null==(t=e.headers)?void 0:t.date)||(null==(t=e.headers)?void 0:t.Date)||(null==(t=e.error)?void 0:t.ServerTime);return!!e&&(t=Date.now(),e=Date.parse(e),3e4<=Math.abs(t+this.systemClockOffset-e))}_syncSystemClock(e){var t,i=(null==(t=e.headers)?void 0:t.date)||(null==(t=e.headers)?void 0:t.Date)||(null==(t=e.error)?void 0:t.ServerTime);if(i){let e=Date.now(),t=Date.parse(i);this.systemClockOffset=t-e}}_getRawOrUploadProxyUrl(e){var t=I.getFileUploadProxy();let i=e;return i=t?e.replace(/^https:\/\/[^/]+/,t):i}_isC2CConversation(e){return"C2C"===e.slice(0,3)}};let V=["jpg","jpeg","gif","png","bmp","image","webp"],q=20971520,O={JPG:1,JPEG:1,GIF:2,PNG:3,BMP:4,UNKNOWN:255};class L{constructor(e,t){this.instanceID=n(9999999),this.sizeType=e.type||0,this.type=0,this.size=e.size||0,this.width=e.width||0,this.height=e.height||0,this.imageUrl=I.addAuthToUrl(e.imageUrl||e.url||""),this.url=I.addAuthToUrl(e.url||t)}setSizeType(e){this.sizeType=e}setType(e){this.type=e}setImageUrl(e){e&&(this.imageUrl=I.addAuthToUrl(e))}getImageUrl(){return this.imageUrl}}function H(t){var{originUrl:t,originWidth:i,originHeight:r,min:s=198}=t,i=parseInt(i)||0,r=parseInt(r)||0,o={url:void 0,width:0,height:0};if((i<=r?i:r)<=s)o.url=t,o.width=i,o.height=r;else{r<=i?(o.width=Math.ceil(i*s/r),o.height=s):(o.width=s,o.height=Math.ceil(r*s/i));let e=t&&-1<t.indexOf("?")?t+"&":t+"?";o.url=198===s?e+"imageView2/3/w/198/h/198":e+"imageView2/3/w/720/h/720"}if(void 0!==t)return o;return g(o,["url"])}class T{constructor(e){this._imageMemoryURL="",this._percent=0,this.type=a;var{uuid:e,file:t,imageFormat:i,imageInfoArray:r=[],isCustomUpload:s=!1}=e;this._imageMemoryURL=this.createImageDataAsURL(t),this.content={imageFormat:i,uuid:e,imageInfoArray:[]},this[v]=s,this.initImageInfoArray(r),this.autoFixUrl()}static parseServerPushElement(e){let t=e["MsgContent"],{ImageFormat:i,ImageInfoArray:r,UUID:s}=t,o=r.map(e=>({size:e.Size,type:e.Type,width:e.Width,height:e.Height,url:e.URL}));return new T({imageFormat:i,imageInfoArray:o,uuid:s})}createImageDataAsURL(e){let t="";var{IN_MINI_APP:i,IN_RN_APP:r,IN_BROWSER:s}=I.getPlatformFlags();return t=e&&((i||r)&&(t=e.url),s)?window.URL.createObjectURL(e):t}initImageInfoArray(t=[]){var i={type:0,size:0,width:0,height:0,url:""};for(let e=0;e<3;e++){var r=t[e]||Object.assign({},i),r=new L(r,this._imageMemoryURL);r.setSizeType(e+1),r.setType(e),this.addImageInfo(r)}this.updateAccessSideImageInfoArray()}autoFixUrl(){let r=["http","https"];this.content.imageInfoArray.forEach(e=>{var t,i;e.url&&""!==e.imageUrl&&([t,...i]=e.imageUrl.split("://"),i=i.join("://"),r.includes(t)||e.setImageUrl("https://"+i))})}updatePercent(e){this._percent=Math.min(e,1)}updateImageFormat(e){this.content.imageFormat=O[e.toUpperCase()]||O.UNKNOWN}addImageInfo(e){3<=this.content.imageInfoArray.length||this.content.imageInfoArray.push(e)}updateImageInfoArray(t){var i,r=this.content.imageInfoArray.length;for(let e=0;e<r;e++)i=this.content.imageInfoArray[e],t[e].size&&(i.size=t[e].size),t[e].url&&i.setImageUrl(t[e].url),t[e].width&&(i.width=t[e].width),t[e].height&&(i.height=t[e].height)}updateAccessSideImageInfoArray(){var[e]=this.content.imageInfoArray;if(e&&0!==e.width&&0!==e.height){var t=this.content.imageInfoArray,i=t[2];t[2]=t[1],t[1]=i;for(let e=0;e<t.length;e++)t[e].setType(e);Object.assign(this.content.imageInfoArray[2],H({originWidth:e.width,originHeight:e.height,min:720}))}}validateBeforeSend(){var e;return this[v]?(delete this[v],{isValid:!0}):([e]=this.content.imageInfoArray,{isValid:e=!!e&&""!==e.imageUrl&&0!==e.size,error:e?null:{message:"content can not be empty"}})}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,imageFormat:t,imageInfoArray:i}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{ImageFormat:t,ImageInfoArray:this.parseImageInfoArray(i),UUID:e}}}parseImageInfoArray(e){return e.map(e=>({InstanceId:e.instanceID,Type:e.sizeType,MsgType:e.type,Size:e.size,Width:e.width,Height:e.height,URL:I.removeAuthToUrl(e.imageUrl)}))}}var k=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createImageMessage",context:this}),t.registerExperimentalAPI("createImageMessage",this,"createCustomUploadImageMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(a,T),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createImageMessage(e){var t,i,r;try{var s=null==(t=this._core.store.get("login"))?void 0:t.userId,o=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:s})),a=this._processImage(e),n=(e.payload.file=a,{imageFormat:O.UNKNOWN,uuid:I.generateUUID(a),file:a,imageInfoArray:[]}),l=new T(n);return o.setElement(l),this._messageOptionsMap.set(o.clientSequence,e),o}catch(e){throw e}}createCustomUploadImageMessage(e){var{store:t,utils:{isEmpty:i}}=this._core,t=null==(t=t.get("login"))?void 0:t.userId,r=null==(r=null==(r=this._core)?void 0:r.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:t})),{largeImageUuid:t,largeFileSize:s,largeImageWidth:o,largeImageHeight:a,largeImageUrl:n,originImageUuid:l,originFileSize:h,originImageWidth:u,originImageHeight:d,originImageUrl:p,thumbImageUuid:c,thumbFileSize:g,thumbImageWidth:m,thumbImageHeight:f,thumbImageUrl:_}=(null==(t=null==e?void 0:e.payload)?void 0:t.file)||{};if(i(p)||i(l))throw new Error("createImageMessageExperimental originImageUrl or originImageUuid is empty");i=new T({imageFormat:O.UNKNOWN,uuid:l,imageInfoArray:[{instanceID:l,size:h,width:u,height:d,imageUrl:p,url:p},{instanceID:t,size:s,width:o,height:a,imageUrl:n,url:n},{instanceID:c,size:g,width:m,height:f,imageUrl:_,url:_}],isCustomUpload:!0});return r.setElement(i),this._messageOptionsMap.set(r.clientSequence,e),r._skipUpload=!0,r}upload(r){return l(this,void 0,void 0,function*(){var e=r.getElements()[0],t=this._messageOptionsMap.get(r.clientSequence).payload["file"],t=(this._validateBeforeUploadImage(t),yield this._performImageUpload(e,r,t)),i=this._generateImageInfo(t);return e.updateImageFormat(null==t?void 0:t.fileType),e.updateImageInfoArray(i),r})}_performImageUpload(r,s,i){return l(this,void 0,void 0,function*(){var e=s["to"],{uploadOptions:e,response:t}=yield N.uploadToCOS({uploadFileType:1,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}});return this._parseResponse(e,t)})}_generateImageInfo(e){var{location:e,fileSize:t,width:i,height:r,smallImageUrl:s,smallImageWidth:o,smallImageHeight:a,largeImageUrl:n,largeImageWidth:l,largeImageHeight:h,imageInfoArray:u}=e,e=I.addAuthToUrl(e),d={size:t,url:e,width:i,height:r};return 0<(null==u?void 0:u.length)?this._processImageInfoArray(u,t):s&&n?[Object.assign({},d),{largeImageUrl:n,largeImageWidth:l,largeImageHeight:h},{smallImageUrl:s,smallImageWidth:o,smallImageHeight:a}]:[Object.assign({},d),this._generateThumbInfo(e,i,r,720),this._generateThumbInfo(e,i,r,198)]}_generateThumbInfo(e,t,i,r){return H({originUrl:e,originWidth:t,originHeight:i,min:r})}_processImageInfoArray(e,t){let i,r,s;for(var o of e)1===o.type?(r=o,r.size=t):2===o.type?(s=o,s.size=t):(i=o,i.size=t);return[Object.assign({},i),Object.assign({},s),Object.assign({},r)]}_parseResponse(r,s){return l(this,void 0,void 0,function*(){try{var{thumbUrl:e,largeUrl:t,downloadUrl:i}=r;if(e&&t&&(yield this._getImageInfoByUrl(e,s,"thumb"),yield this._getImageInfoByUrl(t,s,"large")),I.isSimpleCos()&&!I.isPrivateNetWork()&&(yield this._getImageInfoArray(i,s),null!=s)&&s.uploadIP){let e=this._extractDomainFromUrl(i);e&&(yield this._getDownloadIP(e,s))}return s}catch(e){throw e}})}_extractDomainFromUrl(t){var e;try{let e=t.match(/:\/\/([^\/]+)/);return e?e[1]:null}catch(t){return null!=(e=this._core)&&e.ssoLog.warn("_extractDomainFromUrl","Failed to extract domain from URL:"+t.message),null}}_getImageInfoByUrl(r,s,o){return l(this,void 0,void 0,function*(){var t;try{let e=I.addAuthToUrl(r),{width:t=0,height:i=0}=yield I.probeImageWidthHeight(e);s.width=t,s.height=i,"thumb"===o?(s.smallImageUrl=r,s.smallImageWidth=t,s.smallImageHeight=i):(s.largeImageUrl=r,s.largeImageWidth=t,s.largeImageHeight=i)}catch(e){null!=(t=this._core)&&t.ssoLog.warn("_getImageInfoByUrl",`Failed to get ${o} image info:`+e.message)}})}_validateBeforeUploadImage(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:2251});this._checkImageType(e),this._checkImageSize(e)}_processImage(e){var t;try{var i=(null==(t=this._core)?void 0:t.utils)["IN_MINI_APP"],r=e.payload["file"];return i?this._processMiniAppImageFile(r):this._processWebImageFile(r)}catch(e){throw e}}_processMiniAppImageFile(e){o(e)&&console.warn("FileUnsupportedInMiniApp","createImageMessage");var t=e.tempFiles[0].path||e.tempFiles[0].tempFilePath;return{url:t,name:t.slice(t.lastIndexOf("/")+1),size:e.tempFiles&&e.tempFiles[0].size||1,type:t.slice(t.lastIndexOf(".")+1).toLowerCase()}}_processWebImageFile(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"],e=I.extractFileFromInput(e);if(e)return e;throw new t({message:"Invalid file. Pass either `e.target` (from file input) or a File object"})}_getDownloadIP(r,s){return l(this,void 0,void 0,function*(){var e=f+" getDownloadIP domainName: "+r;try{var t,i=yield function(a,n){return l(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=n,i="im_cos_msg.get_final_ip",r={str_domain:a},s=e.generateProtocolData({servcmd:i,data:r}),o=s.head.seq+i;return yield t.sendPacket(s,{requestId:o})}catch(e){throw console.warn("getFinalIP error:",e),e}})}(r,this._core);i&&i.str_final_ip&&(console.log(e+" ok. downloadIP:"+i),(t=s.location.split("/"))[0]=i.str_final_ip,s.location=t.join("/"))}catch(e){console.warn(e)}})}_getImageInfoArray(t,i){return l(this,void 0,void 0,function*(){try{var e=yield function(a,n){return l(this,void 0,void 0,function*(){try{var{helper:e,channel:t}=n,i="im_cos_msg.get_imageinfo",r={str_image_url:a},s=e.generateProtocolData({servcmd:i,data:r}),o=s.head.seq+i;return yield t.sendPacket(s,{requestId:o})}catch(e){throw console.warn("getImageInfo error:",e),e}})}(t,this._core);return i.imageInfoArray=this._processImageInfoResponse(e),i}catch(e){throw i.imageInfoArray=void 0,e}})}_processImageInfoResponse(e){return e?(e=e["rpt_msg_image_info"],e.map(e=>({type:e.uint32_image_type,url:e.str_url,width:e.uint32_width,height:e.uint32_height,imageFormat:e.str_image_format}))):[]}_checkImageType(e){var{utils:t,helper:i}=this._core;let r="";if(t.IN_MINI_APP&&(r=e.url.slice(e.url.lastIndexOf(".")+1)),t.IN_BROWSER&&(r=e.name.slice(e.name.lastIndexOf(".")+1)),V.indexOf(r.toLowerCase())<0)throw new i.ChatError({code:2252})}_checkImageSize(e){var{utils:t,helper:i}=this._core,r=0;if(t.IN_MINI_APP,0===(r=e.size))throw new i.ChatError({code:2108});if(r>=q)throw new i.ChatError({message:"File size exceeds limit: "+d(q)})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let K="2.5.0",$="1.18.0",G=104857600;function Y(e,t){let r=e.split("."),s=t.split("."),o=Math.max(r.length,s.length);for(;r.length<o;)r.push("0");for(;s.length<o;)s.push("0");for(let i=0;i<o;i++){let e=parseInt(r[i]),t=parseInt(s[i]);if(e>t)return 1;if(e<t)return-1}return 0}let J=new class{init(e){this.core=e}};class E{constructor(e){this.type=c,this.uploadProgress=0,this[Q]=!1;var t=this._getFileInfo(e);this[v]=e.isCustomUpload||!1,this.content={downloadFlag:2,fileUrl:I.generateURL(e.url||e.fileUrl,{needAddAuthToUrl:!this[v]})||"",uuid:e.uuid,fileName:t.name||"",fileSize:t.size||0}}static parseServerPushElement(e){var e=e["MsgContent"],{Download_Flag:e,Url:t,FileName:i,FileSize:r,UUID:s}=e;return new E({downloadFlag:e,url:t,fileName:i,fileSize:r,uuid:s})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateFileUrl(e){this.content.fileUrl=e}validateBeforeSend(){var e;return this[v]?{isValid:!0}:{isValid:e=""!==this.content.fileUrl&&""!==this.content.fileName&&0<this.content.fileSize,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,downloadFlag:t,fileUrl:i,fileName:r,fileSize:s}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{Download_Flag:t,Url:I.removeAuthToUrl(i),FileName:r,FileSize:s,UUID:e}}}_getFileInfo(e){var t=J.core["utils"]["IN_UNI_NATIVE_APP"];return e.fileName&&e.fileSize?{size:e.fileSize,name:e.fileName}:(e=e["file"],e?(t&&this._processNativeAppFile(e),{size:e.size,name:e.name}):{size:0,name:""})}_processNativeAppFile(e){var t;e.path&&e.path.includes(".")&&(t=e.path.slice(e.path.lastIndexOf(".")+1).toLowerCase(),e.type=t,e.name||(e.name=n(999999)+"."+t)),e.name||(e.type="",e.name=e.path.slice(e.path.lastIndexOf("/")+1).toLowerCase()),e.suffix&&(e.type=e.suffix),e.url||(e.url=e.path)}}var Q=v,X=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createFileMessage",context:this}),t.registerExperimentalAPI("createFileMessage",this,"createCustomUploadFileMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(c,E),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createFileMessage(e){var t,i,r;try{this._checkVersion();var s=this._processFile(e.payload.file),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={uuid:I.generateUUID(s),file:s},l=new E(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadFileMessage(e){var t,i,r;try{var{store:s,message:o,utils:{isEmpty:a}}=this._core,n=null==(t=s.get("login"))?void 0:t.userId,{url:l,uuid:h,fileSize:u,fileName:d=""}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{};if(a(l))throw new Error("url is required");var p=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:n})),c=new E({url:l,uuid:h,file:{size:u,name:d},isCustomUpload:!0});return p.setElement(c),p}catch(e){throw e}}upload(i){return l(this,void 0,void 0,function*(){var e=this._messageOptionsMap.get(i.clientSequence).payload["file"],t=(this._validateBeforeUploadFile(e),i.getElements()[0]),e=yield this._performFileUpload(t,i,e),e=I.addAuthToUrl(null==e?void 0:e.location);return t.updateFileUrl(e),i})}_validateBeforeUploadFile(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:2401});if(e.size>G)throw new t({message:"File size exceeds limit: "+d(G)});if(0===e.size)throw new t({code:2108})}_performFileUpload(r,s,t){return l(this,void 0,void 0,function*(){var e=s["to"],e=(yield N.uploadToCOS({uploadFileType:255,file:t,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}}))["response"];return e})}_processFile(t){var{IN_BROWSER:e,IN_RN_APP:i,IN_WX_MINI_APP:r,IN_QQ_MINI_APP:s,IN_UNI_NATIVE_APP:o}=null==(e=this._core)?void 0:e.utils,a=(null==(a=this._core)?void 0:a.helper)["ChatError"];if(e||o){let e=I.extractFileFromInput(t);if(e)return e;throw new a({message:"Invalid file. Pass either `e.target` (from file input) or a File object"})}if(r||s){let e=t["tempFiles"];return Object.assign(Object.assign({},e[0]),{url:e[0].path})}return i?Object.assign(Object.assign({},t),{url:t.uri}):t}_checkVersion(){var{MINI_APP_NAMESPACE:t,IN_MINI_APP:e,IN_WX_MINI_APP:i,IN_QQ_MINI_APP:r,IN_UNI_NATIVE_APP:s}=null==(e=this._core)?void 0:e.utils,o=(null==(o=this._core)?void 0:o.helper)["ChatError"];if(e){if(!(i||r||s))throw new o({message:"Unsupported mini app environment"});let e=t.getSystemInfoSync().SDKVersion;if(i&&Y(e,K)<0)throw new o({message:`WXChooseMessageFile requires SDK version ${K} or higher`});if(r&&Y(e,$)<0)throw new o({message:`QQChooseMessageFile requires SDK version ${$} or higher`})}}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let Z=["mp4","quicktime","mov"],ee=104857600;class D{constructor(e){this.type=m,this.uploadProgress=0,this[ie]=!1;var t="number"==typeof(null==e?void 0:e.videoSecond)?null==e?void 0:e.videoSecond:0;this[v]=e.isCustomUpload||!1,this.content={remoteVideoUrl:I.addAuthToUrl(e.remoteVideoUrl||e.videoUrl||""),videoFormat:e.videoFormat,videoSecond:parseInt(null==t?void 0:t.toString(),10),videoSize:e.videoSize,videoUrl:I.addAuthToUrl(e.videoUrl),videoDownloadFlag:2,videoUUID:e.videoUUID,thumbUUID:e.thumbUUID,thumbFormat:e.thumbFormat,thumbWidth:e.thumbWidth,snapshotWidth:e.thumbWidth,thumbHeight:e.thumbHeight,snapshotHeight:e.thumbHeight,thumbSize:e.thumbSize,snapshotSize:e.thumbSize,thumbDownloadFlag:2,thumbUrl:I.addAuthToUrl(e.thumbUrl),snapshotUrl:I.addAuthToUrl(e.thumbUrl)}}static parseServerPushElement(e){var e=e["MsgContent"],{VideoUrl:e,VideoFormat:t,VideoSecond:i,VideoSize:r,VideoDownloadFlag:s,VideoUUID:o,ThumbUUID:a,ThumbFormat:n,ThumbWidth:l,SnapshotWidth:h,ThumbHeight:u,SnapshotHeight:d,ThumbSize:p,SnapshotSize:c,ThumbDownloadFlag:g,ThumbUrl:m,SnapshotUrl:f}=e;return new D({videoUrl:e,videoFormat:t,videoSecond:i,videoSize:r,videoDownloadFlag:s,videoUUID:o,thumbUUID:a,thumbFormat:n,thumbWidth:l,snapshotWidth:h,thumbHeight:u,snapshotHeight:d,thumbSize:p,snapshotSize:c,thumbDownloadFlag:g,thumbUrl:m,snapshotUrl:f})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateVideoUrl(e){e&&(this.content.remoteVideoUrl=e)}updateSnapshotInfo(e){var{snapshotUrl:e,snapshotWidth:t,snapshotHeight:i}=e;I.isEmpty(e)||(this.content.thumbUrl=this.content.snapshotUrl=e),I.isEmpty(t)||(this.content.thumbWidth=this.content.snapshotWidth=Number(t)),I.isEmpty(i)||(this.content.thumbHeight=this.content.snapshotHeight=Number(i))}validateBeforeSend(){var e;return this[v]?{isValid:!0}:{isValid:e=""!==this.content.remoteVideoUrl,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{remoteVideoUrl:e,videoFormat:t,videoSecond:i,videoSize:r,videoDownloadFlag:s,videoUUID:o,thumbUUID:a,thumbFormat:n,thumbWidth:l,snapshotWidth:h,thumbHeight:u,snapshotHeight:d,thumbSize:p,snapshotSize:c,thumbDownloadFlag:g,thumbUrl:m,snapshotUrl:f}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{VideoUrl:I.removeAuthToUrl(e),VideoFormat:t,VideoSecond:i,VideoSize:r,VideoDownloadFlag:s,VideoUUID:o,ThumbUUID:a,ThumbFormat:n,ThumbWidth:l,SnapshotWidth:h,ThumbHeight:u,SnapshotHeight:d,ThumbSize:p,SnapshotSize:c,ThumbDownloadFlag:g,ThumbUrl:I.removeAuthToUrl(m),SnapshotUrl:I.removeAuthToUrl(f)}}}}var te,ie=v,re=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createVideoMessage",context:this}),t.registerExperimentalAPI("createVideoMessage",this,"createCustomUploadVideoMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(m,D),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createVideoMessage(e){var t,i,r;try{var s=this._processVideo(e),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={videoFormat:s.videoFile.type,videoSecond:u(s.videoFile.second,0),videoSize:s.videoFile.size,remoteVideoUrl:"",videoUrl:s.videoFile.url,videoUUID:I.generateUUID(s.videoFile),thumbUUID:I.generateUUID(s.videoFile,"jpg"),thumbWidth:s.width||200,thumbHeight:s.height||200,thumbUrl:s.thumbUrl,thumbSize:s.thumbSize,thumbFormat:"jpg"},l=new D(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadVideoMessage(e){var t,i,r;try{var{store:s,message:o}=this._core,a=(this._validateCustomUploadVideoMessage(e),null==(t=s.get("login"))?void 0:t.userId),{videoUrl:n,videoUuid:l,duration:h,snapshotUrl:u,snapshotUuid:d,videoFileSize:p,videoType:c,snapshotWidth:g,snapshotHeight:m,snapshotFileSize:f,snapshotType:_="jpg"}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{},v=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:a})),I=new D({videoFormat:c,videoSecond:h||0,videoSize:p,remoteVideoUrl:n,videoUrl:n,videoUUID:l,thumbUUID:d,thumbWidth:g||200,thumbHeight:m||200,thumbUrl:u,thumbSize:f,thumbFormat:_,isCustomUpload:!0});return v.setElement(I),this._messageOptionsMap.set(v.clientSequence,e),v}catch(e){throw e}}upload(r){return l(this,void 0,void 0,function*(){var e=r.getElements()[0],t=this._messageOptionsMap.get(r.clientSequence).payload["file"],t=(this._validateBeforeUploadVideo(t),yield this._performVideoUpload(e,r,t)),{location:t,snapshotInfo:i}=t,t=I.addAuthToUrl(t);return e.updateVideoUrl(t),I.isEmpty(i)||e.updateSnapshotInfo(i),r})}_validateBeforeUploadVideo(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(e.videoFile.size>ee)throw new t({message:"File size exceeds limit: "+d(ee)});if(0===e.videoFile.size)throw new t({code:2108});if(-1===Z.indexOf(e.videoFile.type))throw new t({code:2352})}_validateCustomUploadVideoMessage(e){var{isEmpty:t,isNumber:i}=this._core["utils"],{videoUrl:e,videoUuid:r,duration:s,snapshotUrl:o,snapshotUuid:a}=(null==(e=null==e?void 0:e.payload)?void 0:e.file)||{};if(t(e)||t(r)||!i(s)||t(o)||t(a))throw new Error("Invalid video message options: missing required fields (videoUrl, videoUuid, duration, snapshotUrl, snapshotUuid)")}_performVideoUpload(r,s,i){return l(this,void 0,void 0,function*(){var e=s["to"],{response:e,uploadOptions:t}=yield N.uploadToCOS({uploadFileType:2,file:i,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}});return{snapshotInfo:yield this._getSnapshotInfoByUrl(t.requestSnapshotUrl),location:e.location}})}_processVideo(e){var r,s;try{var o=(null==(r=this._core)?void 0:r.helper)["ChatError"],{IN_MINI_APP:a,IN_BROWSER:n}=null==(s=this._core)?void 0:s.utils;let t=e.payload["file"],i={};if(a&&(i=this._processMiniVideoFile(t),t.name=i.name,t.url=i.url,t.type=i.type),n){let e=I.extractFileFromInput(t);if(!e)throw new o({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});t=e,i=this._processWebVideoFile(t)}return t.videoFile=i,t.thumbUrl="",t.thumbSize=0,t}catch(e){throw console.warn(f+" _processFile error:",e),e}}_processMiniVideoFile(e){var{IN_ALIPAY_MINI_APP:t,IN_UNI_NATIVE_APP:i}=null==(t=this._core)?void 0:t.utils,r=(null==(r=this._core)?void 0:r.helper)["ChatError"];if(t)throw new r({message:"VideoUnsupportedInAlipay"});if(o(e))throw new r({message:"FileUnsupportedInMiniApp"});let s=(e=Array.isArray(e.tempFiles)?e.tempFiles[0]:e).tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase();return i&&(s=e.fileType||s),{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.size||1,second:e.duration||0,type:s}}_processWebVideoFile(e){var{name:t,size:i=1,duration:r=0,type:s}=e,s=s.split("/")[1];return{url:window.URL.createObjectURL(e),name:t,size:i,second:r,type:s}}_getSnapshotInfoByUrl(o){return l(this,void 0,void 0,function*(){var e=this._core["ssoLog"];try{e.debug("_getSnapshotInfoByUrl",f+" _getSnapshotInfoByUrl url:"+o);var t,i,r,s=((yield function(o,a){return l(this,void 0,void 0,function*(){try{var e="im_cos_msg.video_cover",{helper:t,channel:i}=a,r=t.generateCosSpecifiedData({servcmd:e,data:o}),s=r.head.seq+e;return yield i.sendPacket(r,{requestId:s})}catch(e){throw console.warn("getSnapshotInfo error:",e),e}})}({version:1,platform:I.getPlatform(),cover_name:h(n(99999)),snapshot_url:o},this._core))||{})["download_url"];return(e.debug("_getSnapshotInfoByUrl",f+" _getSnapshotInfoByUrl OK snapshotUrl:"+s),I.isEmpty(s))?{}:(t=I.addAuthToUrl(s),{width:i=0,height:r=0}=yield I.probeImageWidthHeight(t),{snapshotUrl:t,snapshotWidth:i,snapshotHeight:r})}catch(e){throw e}})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};class z{constructor(e){this.uploadProgress=0,this.type=s,this[te]=!1,this[v]=e.isCustomUpload||!1,this.content={downloadFlag:2,second:e.second,size:e.size,url:I.generateURL(e.url,{needAddAuthToUrl:!this[v]}),remoteAudioUrl:I.addAuthToUrl(e.url||""),uuid:e.uuid}}static parseServerPushElement(e){var e=e["MsgContent"],{Url:e,Download_Flag:t,Second:i,Size:r,UUID:s}=e;return new z({url:e,downloadFlag:t,second:i,size:r,uuid:s})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateAudioUrl(e){this.content.remoteAudioUrl=e}validateBeforeSend(){var e;return this[v]?{isValid:!0}:{isValid:e=""!==this.content.remoteAudioUrl,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){var{isMergerMessage:e=!1}=e||{},{uuid:e,downloadFlag:t,remoteAudioUrl:i,size:r,second:s}=e?this.payload:this.content;return{MsgType:this.type,MsgContent:{Url:I.removeAuthToUrl(i),Download_Flag:t,Second:s,Size:r,UUID:e}}}}te=v;var se=new class{constructor(){this._messageOptionsMap=new Map}init(e){var{notificationCenter:e,helper:t,InnerEvent:i,message:r}=this._core=e;t.registerApi({apiName:"createAudioMessage",context:this}),t.registerExperimentalAPI("createAudioMessage",this,"createCustomUploadAudioMessage"),null!=(t=null==r?void 0:r.messageFactory)&&t.registerElementClass(s,z),e.subscribeInnerEvent(i.DESTROY,this._dispose,this)}createAudioMessage(e){var t,i,r;try{var s=e.payload["file"],s=this._processAudioFile(e.payload.file),o=(e.payload.file=s,null==(t=this._core.store.get("login"))?void 0:t.userId),a=null==(r=null==(i=this._core)?void 0:i.message.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:o})),n={second:Math.floor((s.duration||s.second)/1e3),size:s.fileSize||s.size||1,url:s.tempFilePath||s.uri||s.url,uuid:I.generateUUID(s)},l=new z(n);return a.setElement(l),this._messageOptionsMap.set(a.clientSequence,e),a}catch(e){throw e}}createCustomUploadAudioMessage(e){var t,i,r;try{this._validateCustomUploadOptions(e);var{store:s,message:o}=this._core,a=null==(t=s.get("login"))?void 0:t.userId,{url:n,uuid:l,duration:h,fileSize:u}=(null==(i=null==e?void 0:e.payload)?void 0:i.file)||{},d=null==(r=o.messageFactory)?void 0:r.createMessage(Object.assign(Object.assign({},e),{from:a})),p=new z({second:h,size:u||1,url:n,uuid:l,isCustomUpload:!0});return d.setElement(p),this._messageOptionsMap.set(d.clientSequence,e),d}catch(e){throw e}}upload(i){return l(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,e=(e.debug("upload",f+" uploadAudio message:"+t(i)),this._messageOptionsMap.get(i.clientSequence).payload)["file"],t=(this._validateBeforeUploadAudio(e),i.getElements()[0]),e=yield this._performAudioUpload(t,i,e),e=I.addAuthToUrl(null==e?void 0:e.location);return t.updateAudioUrl(e),i})}_validateBeforeUploadAudio(e){var t=(null==(t=this._core)?void 0:t.helper)["ChatError"];if(!e)throw new t({code:2300});if(20971520<e.size)throw new t({message:"File size exceeds limit: "+d(20971520)});if(0===e.size)throw new t({code:2108})}_performAudioUpload(r,s,t){return l(this,void 0,void 0,function*(){var e=s["to"],e=(yield N.uploadToCOS({uploadFileType:3,file:t,to:e,message:s,onProgress:e=>{var t,i;r.updatePercent(e),null!=(i=null==(t=this._messageOptionsMap.get(s.clientSequence))?void 0:t.onProgress)&&i.call(t,e)}}))["response"];return e})}_processAudioFile(e){var{IN_MINI_APP:t,IN_BROWSER:i}=null==(t=this._core)?void 0:t.utils;return t?this._processMiniFile(e):i?this._processWebFile(e):void 0}_processMiniFile(e){return{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.fileSize,second:e.duration,type:e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase()}}_processWebFile(e){var t;return e.tempFilePath||e.uri||(t=URL.createObjectURL(e),e.tempFilePath=t),e}_validateCustomUploadOptions(e){var t=this._core["utils"]["isEmpty"],{url:e,uuid:i,duration:r}=(null==(e=null==e?void 0:e.payload)?void 0:e.file)||{};if(t(e)||t(i)||t(r))throw new Error("Invalid audio message options")}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};let t={to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1},payload:{required:!0,rules:["object"],allowEmpty:!1},cloudCustomData:{required:!1,rules:["string"],allowEmpty:!1},priority:{required:!1,rules:["string"],allowEmpty:!1},customModerationConfigurationID:{required:!1,rules:["string"],allowEmpty:!1},onProgress:{required:!1,rules:["function"],allowEmpty:!1}},oe={createImageMessage:t,createAudioMessage:t,createVideoMessage:t,createFileMessage:t},ae={createImageMessage:!0,createAudioMessage:!0,createVideoMessage:!0,createFileMessage:!0},ne={TIMImageElem:k,TIMFileElem:X,TIMVideoFileElem:re,TIMSoundElem:se},le=new class{constructor(){this.name="RichMediaMessage"}install(e){let{OuterConstant:{MSG_AUDIO:t,MSG_FILE:i,MSG_IMAGE:r,MSG_VIDEO:s}}=(this._core=e)["constants"];J.init(e),k.init(e),X.init(e),re.init(e),se.init(e),N.init(e),I.init(e),e.helper.registerApi({apiName:"sendMessage",context:this,matcher:e=>[t,i,r,s].includes(e[0].type)}),e.helper.registerValidateConfig({auth:ae,params:oe})}sendMessage(r,s){return l(this,void 0,void 0,function*(){var e,t,i;try{return this._isCustomUpload(r)||(yield this._upload(r)),yield null==(i=null==(t=null==(e=this._core)?void 0:e.message)?void 0:t.messageSender)?void 0:i.sendMessage(r,s)}catch(e){throw e}})}_upload(i){return l(this,void 0,void 0,function*(){let{ssoLog:t,utils:{safeStringify:e}}=this._core;if(t.debug("_upload"," uploadFile message:"+e(i)),!0!==i._relayFlag)try{let e=ne[i.type];e&&(yield e.upload(i),t.info("_upload"," type:"+i.type))}catch(t){throw i.status=r.FAIL,t instanceof Error&&(t.data={message:i}),this._core.message.messageDataHandler.storeConversationMessage(i),t}})}_isCustomUpload(e){return!0===(null==(e=null==(e=e._elements)?void 0:e[0])?void 0:e[v])}};return le});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatRich-media-message"]=t()}(this,function(){"use strict";function e(e,t){var i={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(i[o[r]]=e[o[r]])}return i}function t(e,t,i,o){return new(i||(i=Promise))(function(r,s){function n(e){try{l(o.next(e))}catch(e){s(e)}}function a(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(n,a)}l((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var i=new class{constructor(){this._name="WebRequest"}init(e){this._core=e}request(e,i){return t(this,void 0,void 0,function*(){var t;const{isEmpty:o}=null===(t=this._core)||void 0===t?void 0:t.utils,{downloadUrl:r="",method:s="PUT",url:n,qs:a,headers:l={},resources:u,dataType:d="text",uploadByIP:h,uploadIP:c}=e;let p=n;if(a){const e=this._queryString(a);e&&(p+=`${p.includes("?")?"&":"?"}${e}`)}const g=new XMLHttpRequest;g.open(s.toUpperCase(),p,!0),g.responseType=d;const m=Object.assign({},l);if(h&&c&&(m.host=c),!o(m))for(const e in m)m.hasOwnProperty(e)&&!["content-length","user-agent","origin","host"].includes(e.toLowerCase())&&g.setRequestHeader(e,m[e]);return g.onload=()=>{const t=this._getResponseBody(g,r,h&&c),o=this._buildResponse(g,t);if(200===g.status)i(null,o);else{if(c&&!p.includes(c))return e.url=this._domainName2IP(p,c),e.uploadByIP=!0,this.request(e,i);i({code:g.status,message:JSON.stringify(g.responseText)},o)}},g.onerror=()=>{const e=this._getResponseBody(g,r,h&&c),t=this._buildResponse(g,e),o={code:g.status,message:0===g.status?"CORS blocked or network error":JSON.stringify(g.responseText)};i(o,t)},e.onProgress&&g.upload&&(g.upload.onprogress=t=>{const{total:i,loaded:o}=t,r=Math.min(Math.floor(100*o/i),100);e.onProgress({total:i,loaded:o,percent:r/100})}),g.send(u),g})}_buildResponse(e,t){const i={};return e.getAllResponseHeaders().trim().split("\n").forEach(e=>{if(e){const[t,o]=e.split(":").map(e=>e.trim());i[t.toLowerCase()]=o}}),{statusCode:e.status,statusMessage:e.statusText,headers:i,data:t}}_getResponseBody(e,t,i){return 200===e.status&&t?{location:t,uploadIP:i}:{response:e.responseText,uploadIP:i}}_queryString(e,t="&",i="="){var o;const{isEmpty:r,isPlainObject:s}=null===(o=this._core)||void 0===o?void 0:o.utils;return r(e)?"":s(e)?Object.keys(e).map(o=>{const r=encodeURIComponent(o)+i;return Array.isArray(e[o])?e[o].map(e=>r+encodeURIComponent(e)).join(t):r+encodeURIComponent(e[o])}).filter(Boolean).join(t):void 0}_domainName2IP(e,t){return e.replace(/^http(s)?:\/\/(.*?)\//,`https://${t}/`)}};const o=["unknown","image","video","audio","log"];var r=new class{init(e){this._core=e}request(t,i){var r;const{MINI_APP_NAMESPACE:s,IN_ALIPAY_MINI_APP:n,isUniIOSApp:a}=null===(r=this._core)||void 0===r?void 0:r.utils,{resources:l="",headers:u={},url:d,downloadUrl:h=""}=t;let c=d,p=null;const g=h?h.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/):null;if(!g)return void console.warn("message Invalid download URL format");const m=decodeURIComponent(g[3]),f=m.includes("?")?m.split("?")[0]:m||"",_={key:t.fileKey||f,success_action_status:200,"Content-Type":""},v={};if(a()){const[e,t]=d.split("?sign=");t&&(c=`${e}?sign=${encodeURIComponent(t)}`,v.sign=decodeURIComponent(t),v.signature=decodeURIComponent(t))}let I={url:c,header:u,name:"file",filePath:l,formData:Object.assign(Object.assign({},_),v),timeout:t.timeout||3e5};if(n){const{name:i}=I,r=e(I,["name"]);I=Object.assign(Object.assign({},r),{fileName:"file",fileType:t.fileType?o[t.fileType]:"image"})}return p=s.uploadFile(Object.assign(Object.assign({},I),{success:e=>{this._handleResponse({response:e,downloadUrl:h,callback:i})},fail:e=>{this._handleResponse({response:e,downloadUrl:h,callback:i})}})),p.onProgressUpdate&&p.onProgressUpdate(e=>{t.onProgress&&t.onProgress({total:e.totalBytesExpectedToSend||0,loaded:e.totalBytesSent||0,percent:e.progress?Math.floor(e.progress)/100:0})}),p}_handleResponse(e){const{downloadUrl:t,response:i,callback:o}=e,r={};if(i.header)for(const e in i.header)i.header.hasOwnProperty(e)&&(r[e.toLowerCase()]=i.header[e]);const s=+i.statusCode;200===s?o(null,{statusCode:s,headers:r,data:Object.assign(Object.assign({},i.data),{location:t})}):o({code:s,message:JSON.stringify(i.data)},{statusCode:s,headers:r,data:void 0})}};function s(e){return"file"===function(e){return Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()}(e)}function n(e){const t=e||99999999;return Math.round(Math.random()*t)}function a(e,t=!0,i=!0){const o=Date.now();return t?i?o-e+" ms":`${Math.round((o-e)/1e3)} s`:i?o-e:Math.round((o-e)/1e3)}function l(e){return`${Array.from({length:8},()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1)).join("")}-${e}`}function u(e,t){return Math.round(Number(e)*10**t)/10**t}function d(e){const t=1024,i=1048576;return e<t?`${e}B`:e<i?`${Math.floor(e/t)}KB`:`${Math.floor(e/i)}MB`}function h(e){if(e<=1048576){return`${u(e/1024,1)}KB/s`}return`${u(e/1048576,1)}MB/s`}const c="TIMImageElem",p="TIMSoundElem",g="TIMFileElem",m="TIMVideoFileElem",f="RichMediaMessagePlugin",_=["rich.my-imcloud.com","imrich.qcloud.com"],v=1,I=2,y=3,U=255;var w;!function(e){e.UNSENT="unSend",e.SUCCESS="success",e.FAIL="fail"}(w||(w={}));const b={wechat:/^(wxfile:\/\/tmp_|http:\/\/temp\/|cloud:\/\/temp-)/,alipay:/^(https:\/\/resource\/|alipayfile:\/\/tmp\/)/,baidu:/^(http:\/\/tmp\/|swanfile:\/\/tmp_)/,bytedance:/^(ttfile:\/\/tmp_|\/(var|tmp)\/|tttemp:\/\/)/,qq:/^(qqfile:\/\/tmp_|http:\/\/qtemp\/)/},F=Symbol("isCustomUpload");var S=new class{init(e){this._core=e}addAuthToUrl(e=""){if(this._isMiniProgramTempFile(e))return e;const t=function(e){return e?e.startsWith("https://")?e:e.startsWith("http://")?e.replace("http://","https://"):e:""}(e);return this.processResourceUrl(t)}removeAuthToUrl(e){return function(e,t){const[i,o]=e.split("?");if(!o)return i;const r=o.split("&").reduce((e,i)=>{const[o,r]=i.split("=");return o&&o!==t&&(e[o]=r||""),e},{}),s=Object.keys(r).map(e=>`${e}${r[e]?`=${r[e]}`:""}`).join("&");return s?`${i}?${s}`:i}(e,"authKey")}_isMiniProgramTempFile(e){return!!this.getPlatformFlags().IN_MINI_APP&&Object.values(b).some(t=>t.test(e))}extractFileFromInput(e){const{utils:{isArray:t}}=this._core;return s(e)?e:function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let i=t;for(;null!==Object.getPrototypeOf(i);)i=Object.getPrototypeOf(i);return t===i}(e)&&"undefined"!=typeof uni?t(e.tempFiles)&&e.tempFiles.length>0?e.tempFiles[0]:t(e.files)?e.files[0]:e.tempFile?e.tempFile:null:e instanceof HTMLInputElement&&e.files&&e.files.length>0?e.files[0]:null}probeImageWidthHeight(e){return t(this,void 0,void 0,function*(){var t;const{IN_MINI_APP:i,IN_BROWSER:o}=(null===(t=this._core)||void 0===t?void 0:t.utils)||{};return this._shouldSkipProbing()?{width:0,height:0}:o?this._probeImageDimensionsWeb(e):i?this._probeImageDimensionsMiniApp(e):void 0})}isSimpleCos(){var e;const t=(null===(e=this._core)||void 0===e?void 0:e.store.get("cloudConfig"))||{},{simple_cos:i}=t;return"0"!==i}getFileDNList(){var e;let t=_;const i=(null===(e=this._core)||void 0===e?void 0:e.store.get("cloudConfig"))||{},{file_dn_list:o}=i;if(void 0===o)return t;try{JSON.parse(o).forEach(e=>{t.includes(e)||t.push(e)})}catch(e){console.warn(e),t=_}return t}getPlatform(){var e;return null===(e=this._core)||void 0===e?void 0:e.utils.platform}generateUUID(e,t){var i;let o=`${this.getSDKAppID()}-${this.getCurrentUserID()}-${null===(i=this._core)||void 0===i?void 0:i.utils.randomString()}`;if(t)return`${o}.${t}`;const r=e.name||e.value||e.url||e.tempFilePath,s=r&&r.slice(r.lastIndexOf(".")+1);return s&&(o=`${o}.${s}`),o}processResourceUrl(e){if(!e)return"";let t=e;const i=this.getFileDownloadProxy(),o=this.getAuthKey(),r=this.getFileDNList();i&&(e.startsWith("http://")?t=e.replace(/^http:\/\/[^/]+/,i):e.startsWith("https://")&&(t=e.replace(/^https:\/\/[^/]+/,i)));const s=o&&-1===t.indexOf("authKey=")&&function(e,t){let i=!1;if(e){const o=e.match(/:\/\/([0-9]?\.)?(.[^/:]+)/),r=o&&o[2]||"";if(r.includes("rich-dev"))return!0;for(let e=0;e<t.length;e++)if(r.endsWith(t[e])){i=!0;break}}return i}(t,r);return s&&(t=t.indexOf("?")>-1?`${t}&authKey=${o}`:`${t}?authKey=${o}`),t}getCurrentUserID(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.userId}getSDKAppID(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.sdkAppId}getFileDownloadProxy(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.fileDownloadProxy)||""}getFileUploadProxy(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.fileUploadProxy)||""}getAuthKey(){var e,t;return(null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.authKey)||""}isPrivateNetWork(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("instance"))||void 0===t?void 0:t.proxyServer}getPlatformFlags(){var e;const{IN_BROWSER:t,IN_MINI_APP:i,IN_RN_APP:o,IN_UNI_NATIVE_APP:r}=null===(e=this._core)||void 0===e?void 0:e.utils;return{IN_BROWSER:t,IN_MINI_APP:i,IN_RN_APP:o,IN_UNI_NATIVE_APP:r}}isEmpty(e){var t;const{isEmpty:i}=null===(t=this._core)||void 0===t?void 0:t.utils;return i(e)}generateURL(e,t){const{needAddAuthToUrl:i=!0}=t||{};return i?this.addAuthToUrl(e):e}_probeImageDimensionsMiniApp(e){var t;const{MINI_APP_NAMESPACE:i}=(null===(t=this._core)||void 0===t?void 0:t.utils)||{};return new Promise(t=>{i.getImageInfo({src:e,success:e=>t({width:e.width,height:e.height}),fail:()=>t({width:0,height:0})})})}_shouldSkipProbing(){var e;const{IN_RN_APP:t,IS_IE:i,IE_VERSION:o,IN_WX_MINI_GAME:r}=(null===(e=this._core)||void 0===e?void 0:e.utils)||{};return t||i&&9===o||r}_probeImageDimensionsWeb(e){return new Promise(t=>{const i=new Image,o=()=>{i.onload=null,i.onerror=null,i.src=""};i.onload=()=>{t({width:i.width,height:i.height}),o()},i.onerror=()=>{t({width:0,height:0}),o()},i.src=e})}};function A(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var P,M={exports:{}};var N=A((P||(P=1,function(e){e.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function i(e,t){var i=e[0],o=e[1],r=e[2],s=e[3];o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[0]-680876936|0)<<7|i>>>25)+o|0)&o|~i&r)+t[1]-389564586|0)<<12|s>>>20)+i|0)&i|~s&o)+t[2]+606105819|0)<<17|r>>>15)+s|0)&s|~r&i)+t[3]-1044525330|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[4]-176418897|0)<<7|i>>>25)+o|0)&o|~i&r)+t[5]+1200080426|0)<<12|s>>>20)+i|0)&i|~s&o)+t[6]-1473231341|0)<<17|r>>>15)+s|0)&s|~r&i)+t[7]-45705983|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[8]+1770035416|0)<<7|i>>>25)+o|0)&o|~i&r)+t[9]-1958414417|0)<<12|s>>>20)+i|0)&i|~s&o)+t[10]-42063|0)<<17|r>>>15)+s|0)&s|~r&i)+t[11]-1990404162|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&r|~o&s)+t[12]+1804603682|0)<<7|i>>>25)+o|0)&o|~i&r)+t[13]-40341101|0)<<12|s>>>20)+i|0)&i|~s&o)+t[14]-1502002290|0)<<17|r>>>15)+s|0)&s|~r&i)+t[15]+1236535329|0)<<22|o>>>10)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[1]-165796510|0)<<5|i>>>27)+o|0)&r|o&~r)+t[6]-1069501632|0)<<9|s>>>23)+i|0)&o|i&~o)+t[11]+643717713|0)<<14|r>>>18)+s|0)&i|s&~i)+t[0]-373897302|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[5]-701558691|0)<<5|i>>>27)+o|0)&r|o&~r)+t[10]+38016083|0)<<9|s>>>23)+i|0)&o|i&~o)+t[15]-660478335|0)<<14|r>>>18)+s|0)&i|s&~i)+t[4]-405537848|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[9]+568446438|0)<<5|i>>>27)+o|0)&r|o&~r)+t[14]-1019803690|0)<<9|s>>>23)+i|0)&o|i&~o)+t[3]-187363961|0)<<14|r>>>18)+s|0)&i|s&~i)+t[8]+1163531501|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o&s|r&~s)+t[13]-1444681467|0)<<5|i>>>27)+o|0)&r|o&~r)+t[2]-51403784|0)<<9|s>>>23)+i|0)&o|i&~o)+t[7]+1735328473|0)<<14|r>>>18)+s|0)&i|s&~i)+t[12]-1926607734|0)<<20|o>>>12)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[5]-378558|0)<<4|i>>>28)+o|0)^o^r)+t[8]-2022574463|0)<<11|s>>>21)+i|0)^i^o)+t[11]+1839030562|0)<<16|r>>>16)+s|0)^s^i)+t[14]-35309556|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[1]-1530992060|0)<<4|i>>>28)+o|0)^o^r)+t[4]+1272893353|0)<<11|s>>>21)+i|0)^i^o)+t[7]-155497632|0)<<16|r>>>16)+s|0)^s^i)+t[10]-1094730640|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[13]+681279174|0)<<4|i>>>28)+o|0)^o^r)+t[0]-358537222|0)<<11|s>>>21)+i|0)^i^o)+t[3]-722521979|0)<<16|r>>>16)+s|0)^s^i)+t[6]+76029189|0)<<23|o>>>9)+r|0,o=((o+=((r=((r+=((s=((s+=((i=((i+=(o^r^s)+t[9]-640364487|0)<<4|i>>>28)+o|0)^o^r)+t[12]-421815835|0)<<11|s>>>21)+i|0)^i^o)+t[15]+530742520|0)<<16|r>>>16)+s|0)^s^i)+t[2]-995338651|0)<<23|o>>>9)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[0]-198630844|0)<<6|i>>>26)+o|0)|~r))+t[7]+1126891415|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[14]-1416354905|0)<<15|r>>>17)+s|0)|~i))+t[5]-57434055|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[12]+1700485571|0)<<6|i>>>26)+o|0)|~r))+t[3]-1894986606|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[10]-1051523|0)<<15|r>>>17)+s|0)|~i))+t[1]-2054922799|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[8]+1873313359|0)<<6|i>>>26)+o|0)|~r))+t[15]-30611744|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[6]-1560198380|0)<<15|r>>>17)+s|0)|~i))+t[13]+1309151649|0)<<21|o>>>11)+r|0,o=((o+=((s=((s+=(o^((i=((i+=(r^(o|~s))+t[4]-145523070|0)<<6|i>>>26)+o|0)|~r))+t[11]-1120210379|0)<<10|s>>>22)+i|0)^((r=((r+=(i^(s|~o))+t[2]+718787259|0)<<15|r>>>17)+s|0)|~i))+t[9]-343485551|0)<<21|o>>>11)+r|0,e[0]=i+e[0]|0,e[1]=o+e[1]|0,e[2]=r+e[2]|0,e[3]=s+e[3]|0}function o(e){var t,i=[];for(t=0;t<64;t+=4)i[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return i}function r(e){var t,i=[];for(t=0;t<64;t+=4)i[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return i}function s(e){var t,r,s,n,a,l,u=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)i(d,o(e.substring(t-64,t)));for(r=(e=e.substring(t-64)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)s[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(i(d,s),t=0;t<16;t+=1)s[t]=0;return n=(n=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(n[2],16),l=parseInt(n[1],16)||0,s[14]=a,s[15]=l,i(d,s),d}function n(e){var t,o,s,n,a,l,u=e.length,d=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)i(d,r(e.subarray(t-64,t)));for(o=(e=t-64<u?e.subarray(t-64):new Uint8Array(0)).length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)s[t>>2]|=e[t]<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(i(d,s),t=0;t<16;t+=1)s[t]=0;return n=(n=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(n[2],16),l=parseInt(n[1],16)||0,s[14]=a,s[15]=l,i(d,s),d}function a(e){var i,o="";for(i=0;i<4;i+=1)o+=t[e>>8*i+4&15]+t[e>>8*i&15];return o}function l(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function d(e,t){var i,o=e.length,r=new ArrayBuffer(o),s=new Uint8Array(r);for(i=0;i<o;i+=1)s[i]=e.charCodeAt(i);return t?s:r}function h(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function c(e,t,i){var o=new Uint8Array(e.byteLength+t.byteLength);return o.set(new Uint8Array(e)),o.set(new Uint8Array(t),e.byteLength),o}function p(e){var t,i=[],o=e.length;for(t=0;t<o-1;t+=2)i.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,i)}function g(){this.reset()}return l(s("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(i,o){var r,s,n,a,l=this.byteLength,u=t(i,l),d=l;return o!==e&&(d=t(o,l)),u>d?new ArrayBuffer(0):(r=d-u,s=new ArrayBuffer(r),n=new Uint8Array(s),a=new Uint8Array(this,u,r),n.set(a),s)}}(),g.prototype.append=function(e){return this.appendBinary(u(e)),this},g.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,r=this._buff.length;for(t=64;t<=r;t+=64)i(this._hash,o(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},g.prototype.end=function(e){var t,i,o=this._buff,r=o.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<r;t+=1)s[t>>2]|=o.charCodeAt(t)<<(t%4<<3);return this._finish(s,r),i=l(this._hash),e&&(i=p(i)),this.reset(),i},g.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},g.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},g.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},g.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},g.prototype._finish=function(e,t){var o,r,s,n=t;if(e[n>>2]|=128<<(n%4<<3),n>55)for(i(this._hash,e),n=0;n<16;n+=1)e[n]=0;o=(o=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(o[2],16),s=parseInt(o[1],16)||0,e[14]=r,e[15]=s,i(this._hash,e)},g.hash=function(e,t){return g.hashBinary(u(e),t)},g.hashBinary=function(e,t){var i=l(s(e));return t?p(i):i},g.ArrayBuffer=function(){this.reset()},g.ArrayBuffer.prototype.append=function(e){var t,o=c(this._buff.buffer,e),s=o.length;for(this._length+=e.byteLength,t=64;t<=s;t+=64)i(this._hash,r(o.subarray(t-64,t)));return this._buff=t-64<s?new Uint8Array(o.buffer.slice(t-64)):new Uint8Array(0),this},g.ArrayBuffer.prototype.end=function(e){var t,i,o=this._buff,r=o.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<r;t+=1)s[t>>2]|=o[t]<<(t%4<<3);return this._finish(s,r),i=l(this._hash),e&&(i=p(i)),this.reset(),i},g.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},g.ArrayBuffer.prototype.getState=function(){var e=g.prototype.getState.call(this);return e.buff=h(e.buff),e},g.ArrayBuffer.prototype.setState=function(e){return e.buff=d(e.buff,!0),g.prototype.setState.call(this,e)},g.ArrayBuffer.prototype.destroy=g.prototype.destroy,g.ArrayBuffer.prototype._finish=g.prototype._finish,g.ArrayBuffer.hash=function(e,t){var i=l(n(new Uint8Array(e)));return t?p(i):i},g}()}(M)),M.exports));var C=new class{constructor(){this.uploadFileTryCount=0,this.maxRetries=1,this.systemClockOffset=0,this.httpRequest=null,this.uploadFileType="",this.duration=900,this.fetchCosTryCount=0}init(e){var t;this._core=e;const{IN_MINI_APP:o}=e.utils;this.httpRequest=o?r:i,null===(t=this.httpRequest)||void 0===t||t.init(e)}uploadToCOS(e){return t(this,void 0,void 0,function*(){const t=`${f} uploadToCOS`,{ssoLog:i,utils:{safeStringify:o}}=this._core,{file:r}=e;this.uploadFileType=e.uploadFileType,i.debug("uploadToCOS",`${t} options:${o(e)}`);try{const o=Date.now(),s=yield this._createCosOptions(e),n=s.fileExistsInCOS?{data:{location:s.downloadUrl}}:yield this._uploadFile(s);this._handleUploadError(n,e);const a=this._createUploadResult(r,n),l=Date.now()-o,u=d(r.size),c=`size:${u} time:${l}ms speed:${h(1e3*r.size/l)}`;return i.debug("uploadToCOS",`${t} ok. name:${r.name} ${c}`),{uploadOptions:s,response:a}}catch(e){throw i.warn("uploadToCOS",`${t} failed, error:${o(e)}`),e}})}_handleUploadError(e,t){var i,o;const{ChatError:r}=null===(i=this._core)||void 0===i?void 0:i.helper;if(403===e.statusCode)throw t.url,(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.uploadIP)&&e.data.uploadIP,new r({message:"Upload failed with status 403"})}_createUploadResult(e,t){return{fileName:e.name,fileSize:e.size,fileType:e.type.slice(e.type.indexOf("/")+1).toLowerCase(),location:t.data.location||"",uploadTime:a(Date.now(),!1),uploadSpeed:h(1e3*e.size/a(Date.now(),!1))}}_createCosOptions(e){return t(this,void 0,void 0,function*(){const{fileName:t,resources:i,uploadMethod:o}=yield this._prepareUploadParams(e),r=this._isC2CConversation(e.message.conversationID)?1:2;try{const s=yield this._fetchCosSignatureUrl({fileType:this.uploadFileType,fileName:t,uploadMethod:o,duration:this.duration,userID:e.message.from,conversationType:r}),{uploadUrl:n,downloadUrl:a,requestSnapshotUrl:l,thumbUrl:u,largeUrl:d,fileKey:h,existFlag:c}=s,p=!S.isPrivateNetWork()&&s.uploadIP;return{url:this._getRawOrUploadProxyUrl(n),fileType:this.uploadFileType,fileName:t,resources:i,downloadUrl:a,requestSnapshotUrl:l,thumbUrl:u,largeUrl:d,fileKey:h,uploadIP:p||"",fileExistsInCOS:1===c,onProgress:t=>this._handleUploadProgress(t,e)}}catch(e){throw console.error("Failed to create COS pre-signed URL options:",e),e}})}_prepareUploadParams(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i,isEmpty:o}}=this._core;t.debug("_prepareUploadParams",` prepareUploadParams:${i(e)}`);const{file:r}=e,{IN_MINI_APP:s,IN_RN_APP:a}=S.getPlatformFlags(),u=s||a,d=u&&e.message.type!==g,{name:h}=r,c=h.slice(h.lastIndexOf(".")),p=`${n(999999)}${c}`,m=d?r.name:p,f=yield this._generateHashFileName(r);return{fileName:o(f)?l(m):`${f}${c}`,resources:u?r.url:r,uploadMethod:u?1:0}})}_generateHashFileName(e){return t(this,void 0,void 0,function*(){const{utils:{IN_MINI_APP:t,IN_BROWSER:i,IN_UNI_NATIVE_APP:o,isArray:r},ssoLog:s}=this._core,n=Date.now();let a="";return i&&(a=yield this._generateHashFileNameInWeb(e)),t&&(r(e.tempFiles)&&(e=e.tempFiles[0]),o||(a=yield this._generateFileNameInMiniProgram(e)),o&&(a=yield this._generateFileNameInUNINativeApp(e))),s.info("_generateHashFileName",`hashFileName:${a} costTime:${Date.now()-n}`),a})}_generateHashFileNameInWeb(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;let o="";try{o=yield new Promise((i,o)=>{const r=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice;r||(t.warn("_generateHashFileNameInWeb","Browser does not support file slicing"),i(""));const s=10485760,n=Math.ceil(e.size/s);let a=0;const l=new N.ArrayBuffer,u=new FileReader,d=setTimeout(()=>{u.abort(),t.warn("_generateHashFileNameInWeb","File hash generation timeout"),i("")},2e3);function h(){const t=a*s,i=t+s>=e.size?e.size:t+s;u.readAsArrayBuffer(r.call(e,t,i))}u.onload=e=>{t.debug("_generateHashFileNameInWeb",`read chunk nr ${a+1} of ${n}`),l.append(e.target.result),a++,a<n?h():(t.debug("_generateHashFileNameInWeb","finished loading"),clearTimeout(d),i(l.end()))},u.onerror=e=>{clearTimeout(d),o(e)},h()})}catch(e){t.warn("_generateHashFileNameInWeb",i(e))}return o})}_generateFileNameInMiniProgram(e){return t(this,void 0,void 0,function*(){const{utils:{MINI_APP_NAMESPACE:t,safeStringify:i,isEmpty:o},ssoLog:r}=this._core;let s="";if(o(e.url))return r.warn("_generateFileNameInMiniProgram","file.url is empty"),s;if("function"!=typeof(null==t?void 0:t.getFileSystemManager))return r.warn("_generateFileNameInUNINativeApp","getFileSystemManager is not a function"),s;try{s=yield new Promise((i,o)=>{t.getFileSystemManager().getFileInfo({filePath:e.url,success:e=>{i(e.digest)},fail:e=>{o(e)}})})}catch(e){r.warn("_generateFileNameInMiniProgram",i(e))}return s})}_generateFileNameInUNINativeApp(e){return t(this,void 0,void 0,function*(){var t;const{utils:{safeStringify:i,isEmpty:o},ssoLog:r}=this._core;let s="";if(o(e.url))return r.warn("_generateFileNameInUNINativeApp","file.url is empty"),s;if("function"!=typeof(null===(t=null===plus||void 0===plus?void 0:plus.io)||void 0===t?void 0:t.getFileInfo))return r.warn("_generateFileNameInUNINativeApp","plus.io.getFileInfo is not a function"),s;try{s=yield new Promise((t,i)=>{plus.io.getFileInfo({filePath:e.url,success:e=>{t(e.digest)},fail:e=>{i(e)}})})}catch(e){r.warn("_generateFileNameInMiniProgram",i(e))}return s})}_handleUploadProgress(e,t){if("function"==typeof t.onProgress)try{t.onProgress(e.percent)}catch(e){throw console.warn("Upload progress callback error:",e),e}}_fetchCosSignatureUrl(e){return t(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,r=S.isSimpleCos(),s=this._prepareCosRequestData(e),n=r?"im_cos_msg.simple_sig":"im_cos_msg.pre_sig";try{const e=yield function(e,i,o){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:r}=o,s=t.generateCosSpecifiedData({servcmd:e,data:i}),n=`${s.head.seq}${e}`;return yield r.sendPacket(s,{requestId:n})}catch(e){throw console.warn("getCosSig error:",e),e}})}(n,s,this._core);this.fetchCosTryCount=0;const a=this._processResponse(e);return i.debug("_fetchCosSignatureUrl",` ok. isSimpleCos:${r} data:${o(a)}`),a||{}}catch(t){if(this.fetchCosTryCount<1)return this.fetchCosTryCount++,this._fetchCosSignatureUrl(e);throw this.fetchCosTryCount=0,t}})}_processResponse(e){var t;const i=S.isSimpleCos(),o=i?null===(t=null==e?void 0:e.rpt_pre_sig)||void 0===t?void 0:t[0]:e;if(!o)return{};if(i){const{str_final_ip:e,rpt_pre_sig:t,uint32_file_id:i,uint32_exist_flag:r,str_download_url:s,str_upload_url:n,str_snapshot_url:a,str_file_key:l}=o;return{uploadIP:e,preSig:t,fileID:i,existFlag:r,downloadUrl:s,uploadUrl:n,requestSnapshotUrl:a,fileKey:l}}const{upload_url:r,download_url:s,snapshot_url:n,thumb_url:a,large_url:l,file_key:u}=o;return{uploadUrl:r,downloadUrl:s,requestSnapshotUrl:n,thumbUrl:a,largeUrl:l,fileKey:u}}_prepareCosRequestData(e){return S.isSimpleCos()?{uint32_upload_method:e.uploadMethod,uint32_platform:S.getPlatform(),uint32_sdkappid:S.getSDKAppID(),str_user_id:e.userID,uint32_scene:e.conversationType,rpt_upload_object:[{uint32_file_id:1,uint32_file_type:e.fileType,str_file_name:e.fileName}]}:{file_type:e.fileType,file_name:e.fileName,upload_method:e.uploadMethod,Duration:e.duration}}_uploadFile(e){return t(this,void 0,void 0,function*(){return new Promise((t,i)=>{this.httpRequest.request(e,(o,r)=>{o&&this.uploadFileTryCount<this.maxRetries&&this.shouldRetry(o)?(this.uploadFileTryCount++,this._uploadFile(e).then(t).catch(i)):(this.uploadFileTryCount=0,o?i(o):t(r))})})})}shouldRetry(e){if(!e)return!1;if(5===Math.floor(e.statusCode/100))return!0;return!(!this.isTimeRelatedError(e)||!this._isClockOutOfSync(e))&&(this._syncSystemClock(e),!0)}isTimeRelatedError(e){var t,i;try{const o=null===(t=e.error)||void 0===t?void 0:t.Code,r=null===(i=e.error)||void 0===i?void 0:i.Message;return"RequestTimeTooSkewed"===o||"AccessDenied"===o&&"Request has expired"===r}catch(e){return!1}}_isClockOutOfSync(e){var t,i,o;const r=(null===(t=e.headers)||void 0===t?void 0:t.date)||(null===(i=e.headers)||void 0===i?void 0:i.Date)||(null===(o=e.error)||void 0===o?void 0:o.ServerTime);if(!r)return!1;const s=Date.now(),n=Date.parse(r);return Math.abs(s+this.systemClockOffset-n)>=3e4}_syncSystemClock(e){var t,i,o;const r=(null===(t=e.headers)||void 0===t?void 0:t.date)||(null===(i=e.headers)||void 0===i?void 0:i.Date)||(null===(o=e.error)||void 0===o?void 0:o.ServerTime);if(r){const e=Date.now(),t=Date.parse(r);this.systemClockOffset=t-e}}_getRawOrUploadProxyUrl(e){const t=S.getFileUploadProxy();let i=e;return t&&(i=e.replace(/^https:\/\/[^/]+/,t)),i}_isC2CConversation(e){return"C2C"===e.slice(0,3)}};const O=2108,T=2251,E=2252,D=["jpg","jpeg","gif","png","bmp","image","webp"],z=20971520,R={JPG:1,JPEG:1,GIF:2,PNG:3,BMP:4,UNKNOWN:255};class ${constructor(e,t){this.instanceID=n(9999999),this.sizeType=e.type||0,this.type=0,this.size=e.size||0,this.width=e.width||0,this.height=e.height||0,this.imageUrl=S.addAuthToUrl(e.imageUrl||e.url||""),this.url=S.addAuthToUrl(e.url||t)}setSizeType(e){this.sizeType=e}setType(e){this.type=e}setImageUrl(e){e&&(this.imageUrl=S.addAuthToUrl(e))}getImageUrl(){return this.imageUrl}}function x(t){const{originUrl:i,originWidth:o,originHeight:r,min:s=198}=t,n=parseInt(o)||0,a=parseInt(r)||0,l={url:void 0,width:0,height:0};if((n<=a?n:a)<=s)l.url=i,l.width=n,l.height=a;else{a<=n?(l.width=Math.ceil(n*s/a),l.height=s):(l.width=s,l.height=Math.ceil(a*s/n));const e=i&&i.indexOf("?")>-1?`${i}&`:`${i}?`;l.url=198===s?`${e}imageView2/3/w/198/h/198`:`${e}imageView2/3/w/720/h/720`}if(void 0===i){const{url:t}=l;return e(l,["url"])}return l}class W{constructor(e){this._imageMemoryURL="",this._percent=0,this.type=c;const{uuid:t,file:i,imageFormat:o,imageInfoArray:r=[],isCustomUpload:s=!1}=e;this._imageMemoryURL=this.createImageDataAsURL(i),this.content={imageFormat:o,uuid:t,imageInfoArray:[]},this[F]=s,this.initImageInfoArray(r),this.autoFixUrl()}static parseServerPushElement(e){const{MsgContent:t}=e,{ImageFormat:i,ImageInfoArray:o,UUID:r}=t,s=function(e){return e.map(e=>({size:e.Size,type:e.Type,width:e.Width,height:e.Height,url:e.URL}))}(o);return new W({imageFormat:i,imageInfoArray:s,uuid:r})}createImageDataAsURL(e){let t="";const{IN_MINI_APP:i,IN_RN_APP:o,IN_BROWSER:r}=S.getPlatformFlags();return e?((i||o)&&(t=e.url),r&&(t=window.URL.createObjectURL(e)),t):t}initImageInfoArray(e=[]){const t={type:0,size:0,width:0,height:0,url:""};for(let i=0;i<3;i++){const o=e[i]||Object.assign({},t),r=new $(o,this._imageMemoryURL);r.setSizeType(i+1),r.setType(i),this.addImageInfo(r)}this.updateAccessSideImageInfoArray()}autoFixUrl(){const e=["http","https"];this.content.imageInfoArray.forEach(t=>{if(!t.url||""===t.imageUrl)return;const[i,...o]=t.imageUrl.split("://"),r=o.join("://");e.includes(i)||t.setImageUrl(`https://${r}`)})}updatePercent(e){this._percent=Math.min(e,1)}updateImageFormat(e){this.content.imageFormat=R[e.toUpperCase()]||R.UNKNOWN}addImageInfo(e){this.content.imageInfoArray.length>=3||this.content.imageInfoArray.push(e)}updateImageInfoArray(e){const t=this.content.imageInfoArray.length;let i;for(let o=0;o<t;o++)i=this.content.imageInfoArray[o],e[o].size&&(i.size=e[o].size),e[o].url&&i.setImageUrl(e[o].url),e[o].width&&(i.width=e[o].width),e[o].height&&(i.height=e[o].height)}updateAccessSideImageInfoArray(){const[e]=this.content.imageInfoArray;e&&0!==e.width&&0!==e.height&&(!function(e){const t=e[2];e[2]=e[1],e[1]=t;for(let t=0;t<e.length;t++)e[t].setType(t)}(this.content.imageInfoArray),Object.assign(this.content.imageInfoArray[2],x({originWidth:e.width,originHeight:e.height,min:720})))}validateBeforeSend(){if(this[F])return delete this[F],{isValid:!0};const[e]=this.content.imageInfoArray,t=!!e&&""!==e.imageUrl&&0!==e.size;return{isValid:t,error:t?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,imageFormat:r,imageInfoArray:s}=i;return{MsgType:this.type,MsgContent:{ImageFormat:r,ImageInfoArray:this.parseImageInfoArray(s),UUID:o}}}parseImageInfoArray(e){return e.map(e=>({InstanceId:e.instanceID,Type:e.sizeType,MsgType:e.type,Size:e.size,Width:e.width,Height:e.height,URL:S.removeAuthToUrl(e.imageUrl)}))}}var j=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createImageMessage",context:this}),o.registerExperimentalAPI("createImageMessage",this,"createCustomUploadImageMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(c,W),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createImageMessage(e){var t,i,o;try{const r=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,s=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:r})),n=this._processImage(e);e.payload.file=n;const a={imageFormat:R.UNKNOWN,uuid:S.generateUUID(n),file:n,imageInfoArray:[]},l=new W(a);return s.setElement(l),this._messageOptionsMap.set(s.clientSequence,e),s}catch(e){throw e}}createCustomUploadImageMessage(e){var t,i,o,r;const{store:s,utils:{isEmpty:n}}=this._core,a=null===(t=s.get("login"))||void 0===t?void 0:t.userId,l=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:a})),{largeImageUuid:u,largeFileSize:d,largeImageWidth:h,largeImageHeight:c,largeImageUrl:p,originImageUuid:g,originFileSize:m,originImageWidth:f,originImageHeight:_,originImageUrl:v,thumbImageUuid:I,thumbFileSize:y,thumbImageWidth:U,thumbImageHeight:w,thumbImageUrl:b}=(null===(r=null==e?void 0:e.payload)||void 0===r?void 0:r.file)||{};if(n(v)||n(g))throw new Error("createImageMessageExperimental originImageUrl or originImageUuid is empty");const F=new W({imageFormat:R.UNKNOWN,uuid:g,imageInfoArray:[{instanceID:g,size:m,width:f,height:_,imageUrl:v,url:v},{instanceID:u,size:d,width:h,height:c,imageUrl:p,url:p},{instanceID:I,size:y,width:U,height:w,imageUrl:b,url:b}],isCustomUpload:!0});return l.setElement(F),this._messageOptionsMap.set(l.clientSequence,e),l._skipUpload=!0,l}upload(e){return t(this,void 0,void 0,function*(){const t=e.getElements()[0],{file:i}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadImage(i);const o=yield this._performImageUpload(t,e,i),r=this._generateImageInfo(o);return t.updateImageFormat(null==o?void 0:o.fileType),t.updateImageInfoArray(r),e})}_performImageUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:v,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{uploadOptions:s,response:n}=yield C.uploadToCOS(r);return this._parseResponse(s,n)})}_generateImageInfo(e){const{location:t,fileSize:i,width:o,height:r,smallImageUrl:s,smallImageWidth:n,smallImageHeight:a,largeImageUrl:l,largeImageWidth:u,largeImageHeight:d,imageInfoArray:h}=e,c=S.addAuthToUrl(t),p={size:i,url:c,width:o,height:r};return(null==h?void 0:h.length)>0?this._processImageInfoArray(h,i):s&&l?[Object.assign({},p),{largeImageUrl:l,largeImageWidth:u,largeImageHeight:d},{smallImageUrl:s,smallImageWidth:n,smallImageHeight:a}]:[Object.assign({},p),this._generateThumbInfo(c,o,r,720),this._generateThumbInfo(c,o,r,198)]}_generateThumbInfo(e,t,i,o){return x({originUrl:e,originWidth:t,originHeight:i,min:o})}_processImageInfoArray(e,t){let i,o,r;for(const s of e)1===s.type?(o=s,o.size=t):2===s.type?(r=s,r.size=t):(i=s,i.size=t);return[Object.assign({},i),Object.assign({},r),Object.assign({},o)]}_parseResponse(e,i){return t(this,void 0,void 0,function*(){try{const{thumbUrl:t,largeUrl:o,downloadUrl:r}=e;t&&o&&(yield this._getImageInfoByUrl(t,i,"thumb"),yield this._getImageInfoByUrl(o,i,"large"));if(S.isSimpleCos()&&!S.isPrivateNetWork()&&(yield this._getImageInfoArray(r,i),null==i?void 0:i.uploadIP)){const e=this._extractDomainFromUrl(r);e&&(yield this._getDownloadIP(e,i))}return i}catch(e){throw e}})}_extractDomainFromUrl(e){var t;try{const t=e.match(/:\/\/([^\/]+)/);return t?t[1]:null}catch(e){return null===(t=this._core)||void 0===t||t.ssoLog.warn("_extractDomainFromUrl",`Failed to extract domain from URL:${e.message}`),null}}_getImageInfoByUrl(e,i,o){return t(this,void 0,void 0,function*(){var t;try{const t=S.addAuthToUrl(e),{width:r=0,height:s=0}=yield S.probeImageWidthHeight(t);i.width=r,i.height=s,"thumb"===o?(i.smallImageUrl=e,i.smallImageWidth=r,i.smallImageHeight=s):(i.largeImageUrl=e,i.largeImageWidth=r,i.largeImageHeight=s)}catch(e){null===(t=this._core)||void 0===t||t.ssoLog.warn("_getImageInfoByUrl",`Failed to get ${o} image info:${e.message}`)}})}_validateBeforeUploadImage(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:T});this._checkImageType(e),this._checkImageSize(e)}_processImage(e){var t;try{const{IN_MINI_APP:i}=null===(t=this._core)||void 0===t?void 0:t.utils;let{file:o}=e.payload;return o=i?this._processMiniAppImageFile(o):this._processWebImageFile(o),o}catch(e){throw e}}_processMiniAppImageFile(e){s(e)&&console.warn("FileUnsupportedInMiniApp","createImageMessage");const t=e.tempFiles[0].path||e.tempFiles[0].tempFilePath;return{url:t,name:t.slice(t.lastIndexOf("/")+1),size:e.tempFiles&&e.tempFiles[0].size||1,type:t.slice(t.lastIndexOf(".")+1).toLowerCase()}}_processWebImageFile(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper,o=S.extractFileFromInput(e);if(!o)throw new i({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});return o}_getDownloadIP(e,i){return t(this,void 0,void 0,function*(){const o=`${f} getDownloadIP domainName: ${e}`;try{const r=yield function(e,i){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:o}=i,r="im_cos_msg.get_final_ip",s={str_domain:e},n=t.generateProtocolData({servcmd:r,data:s}),a=`${n.head.seq}${r}`;return yield o.sendPacket(n,{requestId:a})}catch(e){throw console.warn("getFinalIP error:",e),e}})}(e,this._core);if(!r||!r.str_final_ip)return;console.log(`${o} ok. downloadIP:${r}`);const s=i.location.split("/");s[0]=r.str_final_ip,i.location=s.join("/")}catch(e){console.warn(e)}})}_getImageInfoArray(e,i){return t(this,void 0,void 0,function*(){try{const o=yield function(e,i){return t(this,void 0,void 0,function*(){try{const{helper:t,channel:o}=i,r="im_cos_msg.get_imageinfo",s={str_image_url:e},n=t.generateProtocolData({servcmd:r,data:s}),a=`${n.head.seq}${r}`;return yield o.sendPacket(n,{requestId:a})}catch(e){throw console.warn("getImageInfo error:",e),e}})}(e,this._core);return i.imageInfoArray=this._processImageInfoResponse(o),i}catch(e){throw i.imageInfoArray=void 0,e}})}_processImageInfoResponse(e){if(!e)return[];const{rpt_msg_image_info:t}=e;return t.map(e=>({type:e.uint32_image_type,url:e.str_url,width:e.uint32_width,height:e.uint32_height,imageFormat:e.str_image_format}))}_checkImageType(e){const{utils:t,helper:i}=this._core;let o="";if(t.IN_MINI_APP&&(o=e.url.slice(e.url.lastIndexOf(".")+1)),t.IN_BROWSER&&(o=e.name.slice(e.name.lastIndexOf(".")+1)),D.indexOf(o.toLowerCase())<0)throw new i.ChatError({code:E})}_checkImageSize(e){const{utils:t,helper:i}=this._core;let o=0;if(o=(t.IN_MINI_APP,e.size),0===o)throw new i.ChatError({code:O});if(o>=z)throw new i.ChatError({message:`File size exceeds limit: ${d(z)}`})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const B=2108,V=2401,q="2.5.0",L="1.18.0",H=104857600;function k(e,t){const i=e.split("."),o=t.split("."),r=Math.max(i.length,o.length);for(;i.length<r;)i.push("0");for(;o.length<r;)o.push("0");for(let e=0;e<r;e++){const t=parseInt(i[e]),r=parseInt(o[e]);if(t>r)return 1;if(t<r)return-1}return 0}const K=new class{init(e){this.core=e}};var G;class Y{constructor(e){this.type=g,this.uploadProgress=0,this[G]=!1;const t=this._getFileInfo(e);this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,fileUrl:S.generateURL(e.url||e.fileUrl,{needAddAuthToUrl:!this[F]})||"",uuid:e.uuid,fileName:t.name||"",fileSize:t.size||0}}static parseServerPushElement(e){const{MsgContent:t}=e,{Download_Flag:i,Url:o,FileName:r,FileSize:s,UUID:n}=t;return new Y({downloadFlag:i,url:o,fileName:r,fileSize:s,uuid:n})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateFileUrl(e){this.content.fileUrl=e}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.fileUrl&&""!==this.content.fileName&&this.content.fileSize>0;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,downloadFlag:r,fileUrl:s,fileName:n,fileSize:a}=i;return{MsgType:this.type,MsgContent:{Download_Flag:r,Url:S.removeAuthToUrl(s),FileName:n,FileSize:a,UUID:o}}}_getFileInfo(e){const{utils:{IN_UNI_NATIVE_APP:t}}=K.core;if(e.fileName&&e.fileSize)return{size:e.fileSize,name:e.fileName};const{file:i}=e;return i?(t&&this._processNativeAppFile(i),{size:i.size,name:i.name}):{size:0,name:""}}_processNativeAppFile(e){if(e.path&&e.path.includes(".")){const t=e.path.slice(e.path.lastIndexOf(".")+1).toLowerCase();e.type=t,e.name||(e.name=`${n(999999)}.${t}`)}e.name||(e.type="",e.name=e.path.slice(e.path.lastIndexOf("/")+1).toLowerCase()),e.suffix&&(e.type=e.suffix),e.url||(e.url=e.path)}}G=F;var J=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createFileMessage",context:this}),o.registerExperimentalAPI("createFileMessage",this,"createCustomUploadFileMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(g,Y),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createFileMessage(e){var t,i,o;try{this._checkVersion();const r=this._processFile(e.payload.file);e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={uuid:S.generateUUID(r),file:r},l=new Y(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadFileMessage(e){var t,i,o;try{const{store:r,message:s,utils:{isEmpty:n}}=this._core,a=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{url:l,uuid:u,fileSize:d,fileName:h=""}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{};if(n(l))throw new Error("url is required");const c=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:a})),p=new Y({url:l,uuid:u,file:{size:d,name:h},isCustomUpload:!0});return c.setElement(p),c}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const{file:t}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadFile(t);const i=e.getElements()[0],o=yield this._performFileUpload(i,e,t),r=S.addAuthToUrl(null==o?void 0:o.location);return i.updateFileUrl(r),e})}_validateBeforeUploadFile(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:V});if(e.size>H)throw new i({message:`File size exceeds limit: ${d(H)}`});if(0===e.size)throw new i({code:B})}_performFileUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:U,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s}=yield C.uploadToCOS(r);return s})}_processFile(e){var t,i;const{IN_BROWSER:o,IN_RN_APP:r,IN_WX_MINI_APP:s,IN_QQ_MINI_APP:n,IN_UNI_NATIVE_APP:a}=null===(t=this._core)||void 0===t?void 0:t.utils,{ChatError:l}=null===(i=this._core)||void 0===i?void 0:i.helper;if(o||a){const t=S.extractFileFromInput(e);if(!t)throw new l({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});return t}if(s||n){const{tempFiles:t}=e;return Object.assign(Object.assign({},t[0]),{url:t[0].path})}return r?Object.assign(Object.assign({},e),{url:e.uri}):e}_checkVersion(){var e,t;const{MINI_APP_NAMESPACE:i,IN_MINI_APP:o,IN_WX_MINI_APP:r,IN_QQ_MINI_APP:s,IN_UNI_NATIVE_APP:n}=null===(e=this._core)||void 0===e?void 0:e.utils,{ChatError:a}=null===(t=this._core)||void 0===t?void 0:t.helper;if(o){if(!(r||s||n))throw new a({message:"Unsupported mini app environment"});const e=i.getSystemInfoSync().SDKVersion;if(r&&k(e,q)<0){throw new a({message:`WXChooseMessageFile requires SDK version ${q} or higher`})}if(s&&k(e,L)<0){throw new a({message:`QQChooseMessageFile requires SDK version ${L} or higher`})}}}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const Q=2108,X=2352,Z=["mp4","quicktime","mov"],ee=104857600;var te;class ie{constructor(e){this.type=m,this.uploadProgress=0,this[te]=!1;const t="number"==typeof(null==e?void 0:e.videoSecond)?null==e?void 0:e.videoSecond:0;this[F]=e.isCustomUpload||!1,this.content={remoteVideoUrl:S.addAuthToUrl(e.remoteVideoUrl||e.videoUrl||""),videoFormat:e.videoFormat,videoSecond:parseInt(null==t?void 0:t.toString(),10),videoSize:e.videoSize,videoUrl:S.addAuthToUrl(e.videoUrl),videoDownloadFlag:2,videoUUID:e.videoUUID,thumbUUID:e.thumbUUID,thumbFormat:e.thumbFormat,thumbWidth:e.thumbWidth,snapshotWidth:e.thumbWidth,thumbHeight:e.thumbHeight,snapshotHeight:e.thumbHeight,thumbSize:e.thumbSize,snapshotSize:e.thumbSize,thumbDownloadFlag:2,thumbUrl:S.addAuthToUrl(e.thumbUrl),snapshotUrl:S.addAuthToUrl(e.thumbUrl)}}static parseServerPushElement(e){const{MsgContent:t}=e,{VideoUrl:i,VideoFormat:o,VideoSecond:r,VideoSize:s,VideoDownloadFlag:n,VideoUUID:a,ThumbUUID:l,ThumbFormat:u,ThumbWidth:d,SnapshotWidth:h,ThumbHeight:c,SnapshotHeight:p,ThumbSize:g,SnapshotSize:m,ThumbDownloadFlag:f,ThumbUrl:_,SnapshotUrl:v}=t;return new ie({videoUrl:i,videoFormat:o,videoSecond:r,videoSize:s,videoDownloadFlag:n,videoUUID:a,thumbUUID:l,thumbFormat:u,thumbWidth:d,snapshotWidth:h,thumbHeight:c,snapshotHeight:p,thumbSize:g,snapshotSize:m,thumbDownloadFlag:f,thumbUrl:_,snapshotUrl:v})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateVideoUrl(e){e&&(this.content.remoteVideoUrl=e)}updateSnapshotInfo(e){const{snapshotUrl:t,snapshotWidth:i,snapshotHeight:o}=e;S.isEmpty(t)||(this.content.thumbUrl=this.content.snapshotUrl=t),S.isEmpty(i)||(this.content.thumbWidth=this.content.snapshotWidth=Number(i)),S.isEmpty(o)||(this.content.thumbHeight=this.content.snapshotHeight=Number(o))}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.remoteVideoUrl;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{remoteVideoUrl:o,videoFormat:r,videoSecond:s,videoSize:n,videoDownloadFlag:a,videoUUID:l,thumbUUID:u,thumbFormat:d,thumbWidth:h,snapshotWidth:c,thumbHeight:p,snapshotHeight:g,thumbSize:m,snapshotSize:f,thumbDownloadFlag:_,thumbUrl:v,snapshotUrl:I}=i;return{MsgType:this.type,MsgContent:{VideoUrl:S.removeAuthToUrl(o),VideoFormat:r,VideoSecond:s,VideoSize:n,VideoDownloadFlag:a,VideoUUID:l,ThumbUUID:u,ThumbFormat:d,ThumbWidth:h,SnapshotWidth:c,ThumbHeight:p,SnapshotHeight:g,ThumbSize:m,SnapshotSize:f,ThumbDownloadFlag:_,ThumbUrl:S.removeAuthToUrl(v),SnapshotUrl:S.removeAuthToUrl(I)}}}}te=F;var oe,re=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createVideoMessage",context:this}),o.registerExperimentalAPI("createVideoMessage",this,"createCustomUploadVideoMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(m,ie),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createVideoMessage(e){var t,i,o;try{const r=this._processVideo(e);e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={videoFormat:r.videoFile.type,videoSecond:u(r.videoFile.second,0),videoSize:r.videoFile.size,remoteVideoUrl:"",videoUrl:r.videoFile.url,videoUUID:S.generateUUID(r.videoFile),thumbUUID:S.generateUUID(r.videoFile,"jpg"),thumbWidth:r.width||200,thumbHeight:r.height||200,thumbUrl:r.thumbUrl,thumbSize:r.thumbSize,thumbFormat:"jpg"},l=new ie(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadVideoMessage(e){var t,i,o;try{const{store:r,message:s}=this._core;this._validateCustomUploadVideoMessage(e);const n=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{videoUrl:a,videoUuid:l,duration:u,snapshotUrl:d,snapshotUuid:h,videoFileSize:c,videoType:p,snapshotWidth:g,snapshotHeight:m,snapshotFileSize:f,snapshotType:_="jpg"}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{},v=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:n})),I=new ie({videoFormat:p,videoSecond:u||0,videoSize:c,remoteVideoUrl:a,videoUrl:a,videoUUID:l,thumbUUID:h,thumbWidth:g||200,thumbHeight:m||200,thumbUrl:d,thumbSize:f,thumbFormat:_,isCustomUpload:!0});return v.setElement(I),this._messageOptionsMap.set(v.clientSequence,e),v}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const t=e.getElements()[0],{file:i}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadVideo(i);const o=yield this._performVideoUpload(t,e,i),{location:r,snapshotInfo:s}=o,n=S.addAuthToUrl(r);return t.updateVideoUrl(n),S.isEmpty(s)||t.updateSnapshotInfo(s),e})}_validateBeforeUploadVideo(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(e.videoFile.size>ee)throw new i({message:`File size exceeds limit: ${d(ee)}`});if(0===e.videoFile.size)throw new i({code:Q});if(-1===Z.indexOf(e.videoFile.type))throw new i({code:X})}_validateCustomUploadVideoMessage(e){var t;const{utils:{isEmpty:i,isNumber:o}}=this._core,{videoUrl:r,videoUuid:s,duration:n,snapshotUrl:a,snapshotUuid:l}=(null===(t=null==e?void 0:e.payload)||void 0===t?void 0:t.file)||{};if(i(r)||i(s)||!o(n)||i(a)||i(l))throw new Error("Invalid video message options: missing required fields (videoUrl, videoUuid, duration, snapshotUrl, snapshotUuid)")}_performVideoUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:I,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s,uploadOptions:n}=yield C.uploadToCOS(r);return{snapshotInfo:yield this._getSnapshotInfoByUrl(n.requestSnapshotUrl),location:s.location}})}_processVideo(e){var t,i;try{const{ChatError:o}=null===(t=this._core)||void 0===t?void 0:t.helper,{IN_MINI_APP:r,IN_BROWSER:s}=null===(i=this._core)||void 0===i?void 0:i.utils;let{file:n}=e.payload,a={};if(r&&(a=this._processMiniVideoFile(n),n.name=a.name,n.url=a.url,n.type=a.type),s){const e=S.extractFileFromInput(n);if(!e)throw new o({message:"Invalid file. Pass either `e.target` (from file input) or a File object"});n=e,a=this._processWebVideoFile(n)}return n.videoFile=a,n.thumbUrl="",n.thumbSize=0,n}catch(e){throw console.warn(`${f} _processFile error:`,e),e}}_processMiniVideoFile(e){var t,i;const{IN_ALIPAY_MINI_APP:o,IN_UNI_NATIVE_APP:r}=null===(t=this._core)||void 0===t?void 0:t.utils,{ChatError:n}=null===(i=this._core)||void 0===i?void 0:i.helper;if(o)throw new n({message:"VideoUnsupportedInAlipay"});if(s(e))throw new n({message:"FileUnsupportedInMiniApp"});Array.isArray(e.tempFiles)&&(e=e.tempFiles[0]);let a=e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase();return r&&(a=e.fileType||a),{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.size||1,second:e.duration||0,type:a}}_processWebVideoFile(e){const{name:t,size:i=1,duration:o=0,type:r}=e,s=r.split("/")[1];return{url:window.URL.createObjectURL(e),name:t,size:i,second:o,type:s}}_getSnapshotInfoByUrl(e){return t(this,void 0,void 0,function*(){const{ssoLog:i}=this._core;try{i.debug("_getSnapshotInfoByUrl",`${f} _getSnapshotInfoByUrl url:${e}`);const o={version:1,platform:S.getPlatform(),cover_name:l(n(99999)),snapshot_url:e},r=yield function(e,i){return t(this,void 0,void 0,function*(){try{const t="im_cos_msg.video_cover",{helper:o,channel:r}=i,s=o.generateCosSpecifiedData({servcmd:t,data:e}),n=`${s.head.seq}${t}`;return yield r.sendPacket(s,{requestId:n})}catch(e){throw console.warn("getSnapshotInfo error:",e),e}})}(o,this._core),{download_url:s}=r||{};if(i.debug("_getSnapshotInfoByUrl",`${f} _getSnapshotInfoByUrl OK snapshotUrl:${s}`),S.isEmpty(s))return{};const a=S.addAuthToUrl(s),{width:u=0,height:d=0}=yield S.probeImageWidthHeight(a);return{snapshotUrl:a,snapshotWidth:u,snapshotHeight:d}}catch(e){throw e}})}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};class se{constructor(e){this.uploadProgress=0,this.type=p,this[oe]=!1,this[F]=e.isCustomUpload||!1,this.content={downloadFlag:2,second:e.second,size:e.size,url:S.generateURL(e.url,{needAddAuthToUrl:!this[F]}),remoteAudioUrl:S.addAuthToUrl(e.url||""),uuid:e.uuid}}static parseServerPushElement(e){const{MsgContent:t}=e,{Url:i,Download_Flag:o,Second:r,Size:s,UUID:n}=t;return new se({url:i,downloadFlag:o,second:r,size:s,uuid:n})}updatePercent(e){this.uploadProgress=Math.min(e,1)}updateAudioUrl(e){this.content.remoteAudioUrl=e}validateBeforeSend(){if(this[F])return{isValid:!0};const e=""!==this.content.remoteAudioUrl;return{isValid:e,error:e?null:{message:"content can not be empty"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},i=t?this.payload:this.content,{uuid:o,downloadFlag:r,remoteAudioUrl:s,size:n,second:a}=i;return{MsgType:this.type,MsgContent:{Url:S.removeAuthToUrl(s),Download_Flag:r,Second:a,Size:n,UUID:o}}}}oe=F;const ne=2108,ae=2300,le=20971520;var ue=new class{constructor(){this._messageOptionsMap=new Map}init(e){var t;this._core=e;const{notificationCenter:i,helper:o,InnerEvent:r,message:s}=e;o.registerApi({apiName:"createAudioMessage",context:this}),o.registerExperimentalAPI("createAudioMessage",this,"createCustomUploadAudioMessage"),null===(t=null==s?void 0:s.messageFactory)||void 0===t||t.registerElementClass(p,se),i.subscribeInnerEvent(r.DESTROY,this._dispose,this)}createAudioMessage(e){var t,i,o;try{let{file:r}=e.payload;r=this._processAudioFile(e.payload.file),e.payload.file=r;const s=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,n=null===(o=null===(i=this._core)||void 0===i?void 0:i.message.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:s})),a={second:Math.floor((r.duration||r.second)/1e3),size:r.fileSize||r.size||1,url:r.tempFilePath||r.uri||r.url,uuid:S.generateUUID(r)},l=new se(a);return n.setElement(l),this._messageOptionsMap.set(n.clientSequence,e),n}catch(e){throw e}}createCustomUploadAudioMessage(e){var t,i,o;try{this._validateCustomUploadOptions(e);const{store:r,message:s}=this._core,n=null===(t=r.get("login"))||void 0===t?void 0:t.userId,{url:a,uuid:l,duration:u,fileSize:d}=(null===(i=null==e?void 0:e.payload)||void 0===i?void 0:i.file)||{},h=null===(o=s.messageFactory)||void 0===o?void 0:o.createMessage(Object.assign(Object.assign({},e),{from:n})),c=new se({second:u,size:d||1,url:a,uuid:l,isCustomUpload:!0});return h.setElement(c),this._messageOptionsMap.set(h.clientSequence,e),h}catch(e){throw e}}upload(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;t.debug("upload",`${f} uploadAudio message:${i(e)}`);const{file:o}=this._messageOptionsMap.get(e.clientSequence).payload;this._validateBeforeUploadAudio(o);const r=e.getElements()[0],s=yield this._performAudioUpload(r,e,o),n=S.addAuthToUrl(null==s?void 0:s.location);return r.updateAudioUrl(n),e})}_validateBeforeUploadAudio(e){var t;const{ChatError:i}=null===(t=this._core)||void 0===t?void 0:t.helper;if(!e)throw new i({code:ae});if(e.size>le)throw new i({message:`File size exceeds limit: ${d(le)}`});if(0===e.size)throw new i({code:ne})}_performAudioUpload(e,i,o){return t(this,void 0,void 0,function*(){const{to:t}=i,r={uploadFileType:y,file:o,to:t,message:i,onProgress:t=>{var o,r;e.updatePercent(t),null===(r=null===(o=this._messageOptionsMap.get(i.clientSequence))||void 0===o?void 0:o.onProgress)||void 0===r||r.call(o,t)}},{response:s}=yield C.uploadToCOS(r);return s})}_processAudioFile(e){var t;const{IN_MINI_APP:i,IN_BROWSER:o}=null===(t=this._core)||void 0===t?void 0:t.utils;return i?this._processMiniFile(e):o?this._processWebFile(e):void 0}_processMiniFile(e){return{url:e.tempFilePath,name:e.tempFilePath.slice(e.tempFilePath.lastIndexOf("/")+1),size:e.fileSize,second:e.duration,type:e.tempFilePath.slice(e.tempFilePath.lastIndexOf(".")+1).toLowerCase()}}_processWebFile(e){if(e.tempFilePath||e.uri)return e;const t=URL.createObjectURL(e);return e.tempFilePath=t,e}_validateCustomUploadOptions(e){var t;const{utils:{isEmpty:i}}=this._core,{url:o,uuid:r,duration:s}=(null===(t=null==e?void 0:e.payload)||void 0===t?void 0:t.file)||{};if(i(o)||i(r)||i(s))throw new Error("Invalid audio message options")}_reset(){this._messageOptionsMap.clear()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const de={to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1},payload:{required:!0,rules:["object"],allowEmpty:!1},cloudCustomData:{required:!1,rules:["string"],allowEmpty:!1},priority:{required:!1,rules:["string"],allowEmpty:!1},customModerationConfigurationID:{required:!1,rules:["string"],allowEmpty:!1},onProgress:{required:!1,rules:["function"],allowEmpty:!1}},he={createImageMessage:de,createAudioMessage:de,createVideoMessage:de,createFileMessage:de},ce={createImageMessage:!0,createAudioMessage:!0,createVideoMessage:!0,createFileMessage:!0},pe={[c]:j,[g]:J,[m]:re,[p]:ue};var ge=new class{constructor(){this.name="RichMediaMessage"}install(e){this._core=e;const{constants:{OuterConstant:{MSG_AUDIO:t,MSG_FILE:i,MSG_IMAGE:o,MSG_VIDEO:r}}}=e;K.init(e),j.init(e),J.init(e),re.init(e),ue.init(e),C.init(e),S.init(e),e.helper.registerApi({apiName:"sendMessage",context:this,matcher:e=>[t,i,o,r].includes(e[0].type)}),e.helper.registerValidateConfig({auth:ce,params:he})}sendMessage(e,i){return t(this,void 0,void 0,function*(){var t,o,r;try{return this._isCustomUpload(e)||(yield this._upload(e)),yield null===(r=null===(o=null===(t=this._core)||void 0===t?void 0:t.message)||void 0===o?void 0:o.messageSender)||void 0===r?void 0:r.sendMessage(e,i)}catch(e){throw e}})}_upload(e){return t(this,void 0,void 0,function*(){const{ssoLog:t,utils:{safeStringify:i}}=this._core;if(t.debug("_upload",` uploadFile message:${i(e)}`),!0!==e._relayFlag)try{const i=pe[e.type];i&&(yield i.upload(e),t.info("_upload",` type:${e.type}`))}catch(t){throw e.status=w.FAIL,t instanceof Error&&(t.data={message:e}),this._core.message.messageDataHandler.storeConversationMessage(e),t}})}_isCustomUpload(e){var t,i;return!0===(null===(i=null===(t=e._elements)||void 0===t?void 0:t[0])||void 0===i?void 0:i[F])}};return ge});