UNPKG

@tencentcloud/lite-chat

Version:

Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut

1 lines 58.7 kB
!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: