@polyv/chat 2.3.0-rc-20251204.1 → 2.4.0-rc-20251225.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1 -1
- package/index.es.js +2 -2
- package/index.umd.js +1 -1
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
18
18
|
* @license MIT
|
|
19
|
-
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,a,t){t.r(a),t.d(a,"ChatImageUpload",function(){return ut}),t.d(a,"defaultConfig",function(){return ht}),t.d(a,"allowAccept",function(){return Et}),t.d(a,"allowFileExtension",function(){return gt}),t.d(a,"FailError",function(){return rt}),t.d(a,"FailCode",function(){return H}),t.d(a,"ChatImage",function(){return xt}),t.d(a,"ImageStatus",function(){return et}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var O=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(O!=null)for(var M in O)M!=="__proto__"&&r(O,M)&&(C[M]=O[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function s(C,I){var O,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(O,Q)}for(O in C)r(C,O)&&(M=C[O],Array.isArray(M)?M.forEach(K):j(O,M));return $.join("&")}t(116),t(155);function u(C,I,O){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?s(I,O):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function c(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(O){if(O===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return O}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(O){if(O===null||(M=O,Function.toString.call(M).indexOf("[native code]")===-1))return O;var M;if(typeof O!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(O))return I.get(O);I.set(O,x)}function x(){return p(O,arguments,g(this).constructor)}return x.prototype=Object.create(O.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,O)})(C)}function p(C,I,O){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(O,M){return O.__proto__=M,O})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,O,M,x=(I=$,O=l(),function(){var j,K=g(I);if(O){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return c(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,O,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(st){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(st){return!(st===void 0||st>=200&&st<300||st===1223||st===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):O(J)}}var m=Object.create(null),_=0;function S(C,I,O,M){C.onload=b(C,I,O,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),_===Number.MAX_SAFE_INTEGER&&(_=0);var x=++_;return m[x]={xhr:C,options:I,resolve:O,reject:M},x}function w(C){delete m[C]}function E(C,I,O,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!O&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function k(C,I,O,M){var x,$,j;if(O!=null&&C!=="get")return M==="json"?(x=JSON.stringify(O),$="application/json; charset=utf-8"):(j=O,typeof(x=i.call(j)==="[object Object]"?s(O,{ignoreEmpty:!1}):O)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var O=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(st){var P=document.createElement("div");P.innerHTML='<a href="'+st+'"></a>';var G=P.firstChild,W=G.host!==location.host;return P=null,G=null,W}(C=function(st,P,G){return P!=null&&(st=u(st,P,{ignoreEmpty:!1})),G&&(st=u(st,{_:Date.now()})),st}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);O=S(J,I,function(st){w(O),M(st)},function(st){w(O),x(st)}),J.open($,C,!0,I.username,I.password);var N=k($,K,I.data,j);(function(st,P,G,W){P.timeout&&(st.timeout=P.timeout),G&&P.withCredentials!=null&&(st.withCredentials=!!P.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&st.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(O)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var O in C)I.append(O,C[O]);return I}function z(C,I,O){O===void 0&&(O=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return O?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,O){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){O(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var R,D,H,Z=(R=function(C,I){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,M){O.__proto__=M}||function(O,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(O[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function O(){this.constructor=C}R(C,I),C.prototype=I===null?Object.create(I):(O.prototype=I.prototype,new O)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var et,rt=function(C){function I(O){var M=C.call(this,O)||this,x=I.getFailErrorData(O);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(O){return{failCode:O,failMessage:I.failMessageVal[O]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),tt=function(){return(tt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},dt=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j;return dt(this,function(K){switch(K.label){case 0:return O=Date.now(),M=U()("upload_token_live"+I.channelId+O),x={channelId:I.channelId,ts:O,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j,K;return dt(this,function(Q){switch(Q.label){case 0:O={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(O),onUploadProgress:function(J){var N,st,P=I.onUploadProgress;typeof P=="function"&&P((N=J.loaded/J.total,st=2,Number(N.toFixed(st||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,O,M){var x=I;Object.keys(O).sort().forEach(function(j){O[j]&&(x+=j+String(O[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var O,M,x;return dt(this,function($){switch($.label){case 0:O=tt(tt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:tt(tt({},O),{sign:this.createSign("polyv_chat_api_innor",O)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(et||(et={}));var bt=function(){return(bt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},mt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ct=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},lt={width:500,height:500},xt=function(){function C(I){var O=I.callbackChange,M=O===void 0||O;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||et.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),mt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,st,P,G,W,X=this;return ct(this,function(at){switch(at.label){case 0:return O=this.uploadCtx,M=O.channelId,x=O.userId,$=O.bucket,this.status=et.UPLOADING,[4,O.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=at.sent(),!((K=this.file).size>1024*O.compressSizeLimit))return[3,5];at.label=2;case 2:return at.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=at.sent(),K=Q,[3,5];case 4:return at.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return at.trys.push([5,7,,8]),[4,B(K)];case 6:return J=at.sent(),N=J.width,st=J.height,this.size={width:N,height:st},[3,8];case 7:return at.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=lt),this.uploadProgress=0,P="",at.label=9;case 9:return at.trys.push([9,13,,14]),[4,O.uploadApi.uploadImage(bt(bt({},j),{file:K,fileName:this.fileName,onUploadProgress:function(kt){X.uploadProgress=kt,X.triggerChange()}}))];case 10:return P=at.sent(),this.fileUrl=P,O.enablePornChecking?[4,O.uploadApi.pornIdentify({channelId:M,url:"https:"+P})]:[3,12];case 11:at.sent(),at.label=12;case 12:return this.status=et.UPLOAD_SUCCESS,[3,14];case 13:return G=at.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?et.UPLOAD_FORBID:et.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(P),[2,P]}})})},C.prototype.compressImage=function(I){return mt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,st;return ct(this,function(P){switch(P.label){case 0:return O=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(O)];case 1:return j=P.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(st=N.getContext("2d"))?(st.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),_t=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var O=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<O;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(O){return O.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,O){return O.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Et=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],gt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],ht={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Et,allowFileExtension:gt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},wt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ut=function(){function C(I){I===void 0&&(I={});var O=I.channelId,M=O===void 0?ht.channelId:O,x=I.userId,$=x===void 0?ht.userId:x,j=I.sizeLimit,K=j===void 0?ht.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?ht.compressSizeLimit:Q,N=I.limit,st=N===void 0?ht.limit:N,P=I.maxWidth,G=P===void 0?ht.maxWidth:P,W=I.reUploadTimes,X=W===void 0?ht.reUploadTimes:W,at=I.source,kt=at===void 0?ht.source:at,Tt=I.bucket,Pt=Tt===void 0?ht.bucket:Tt,Ut=I.useBlobByCompress,nt=Ut===void 0?ht.useBlobByCompress:Ut,ft=I.allowAccept,vt=ft===void 0?ht.allowAccept:ft,It=I.allowFileExtension,Ct=It===void 0?ht.allowFileExtension:It,Ht=I.maxUploadNumber,Bt=Ht===void 0?ht.maxUploadNumber:Ht,Xt=I.apiHost,he=Xt===void 0?ht.apiHost:Xt,ge=I.onChange,ve=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=st,this.maxWidth=G,this.reUploadTimes=X,this.source=kt,this.bucket=Pt,this.useBlobByCompress=!!nt,this.allowAccept=vt,this.allowFileExtension=Ct,this.maxUploadNumber=Bt,this.onChange=ge,this.beforeStart=ve,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=he,this.uploadQueue=new _t({uploadCtx:this}),this.uploadApi=new pt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var O=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&O.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,O){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=O.length<this.limit?O.length:this.limit,Q=0;Q<K;Q++){var J=O[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var st=[];for(Q=0;Q<K;Q++){J=O[Q];var P=this.buildImageId(Q),G=new xt({imageId:P,uploadCtx:this,file:J,callbackChange:j});st.push(G)}typeof $=="function"&&$(st)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(O){return"."+O})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var O=this;if(Array.isArray(I))return I.forEach(function(x){O.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof xt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(O,M){I.choiceImageFile({callbackChange:!1,success:function(x){return wt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?O($):M(new rt(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(O){I.joinWaitQueue(O)}})},C.prototype.uploadImageFile=function(I){return wt(this,void 0,void 0,function(){var O;return q(this,function(M){switch(M.label){case 0:if(O=this.checkFile(I))throw new Error(O.failMessage);return[4,new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,O){return wt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:O!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return wt(this,void 0,void 0,function(){var O,M;return q(this,function(x){switch(x.label){case 0:if(!(O=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,O.upload()];case 2:return x.sent(),[2,O];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return rt.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return rt.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return rt.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var O=V(I);return this.allowFileExtension.includes(O)?void 0:rt.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var O=[];this.source&&O.push(this.source),this.channelId&&O.push(this.channelId),this.userId&&O.push(this.userId);var M=I!==void 0?"_"+I:"";return O.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class Ve extends jt{constructor(t){super(t);yt(this,"__uploadImgCtrl");yt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ge.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return it(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return it(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},s=[],u=[];return new Promise((f,c)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>it(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ee(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};s.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};u.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:s,failUploadImages:u})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),c(new Error(d.failMessage))}})})})}directUploadImage(t){return it(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return it(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return it(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),s=i[i.length-1].split(".")[0];if(r[s])return this.__genResourceUrl(`/default-img/donate-svga/${r[s]}`)})}}class $e{constructor(a,t={}){yt(this,"PolyvChatEvent",St);yt(this,"ChatMsgSource",ot);yt(this,"DonateType",Dt);yt(this,"RedpackType",qt);yt(this,"SystemMsgType",Vt);yt(this,"ChatRequestHistoryMode",Ft);yt(this,"ManageFailReason",Nt);yt(this,"TranslateLanguage",Jt);yt(this,"eventEmitter",new we);yt(this,"__socketFilter");yt(this,"__socketHandler");yt(this,"emotion");yt(this,"history");yt(this,"message");yt(this,"status");yt(this,"utils");yt(this,"sender");yt(this,"manage");yt(this,"online");yt(this,"download");yt(this,"like");yt(this,"ask");yt(this,"setuped",!1);this.plvSocket=a,this.config=t,this.emotion=new Le(this),this.history=new je(this),this.message=new De(this),this.status=new He(this),this.utils=new Ve(this),this.sender=new ze(this),this.manage=new Ue(this),this.online=new Be(this),this.download=new Re(this),this.like=new Ne(this),this.ask=new Me(this),this.__socketFilter=new ke(this),this.__socketHandler=new Ce(this)}setup(){return it(this,null,function*(){this.setuped=!0})}destroy(){return it(this,null,function*(){this.plvSocket.clearSocketHandles(At)})}}const Ke="PolyvChat";exports.ChatMsgSource=ot;exports.ChatRequestHistoryMode=Ft;exports.DonateType=Dt;exports.GlobalVariable=Ke;exports.ManageFailReason=Nt;exports.MotivationLikeType=Qt;exports.PolyvChat=$e;exports.PolyvChatEvent=St;exports.RedpackType=qt;exports.SystemMsgType=Vt;exports.TranslateLanguage=Jt;exports.canQuoteMsgSource=de;exports.canTopMsgSource=pe;exports.isServiceMsgMap=le;console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.3.0-rc-20251204.1]","[buildTime: 2025-12-04 02:19:40]");
|
|
19
|
+
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,a,t){t.r(a),t.d(a,"ChatImageUpload",function(){return ut}),t.d(a,"defaultConfig",function(){return ht}),t.d(a,"allowAccept",function(){return Et}),t.d(a,"allowFileExtension",function(){return gt}),t.d(a,"FailError",function(){return rt}),t.d(a,"FailCode",function(){return H}),t.d(a,"ChatImage",function(){return xt}),t.d(a,"ImageStatus",function(){return et}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var O=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(O!=null)for(var M in O)M!=="__proto__"&&r(O,M)&&(C[M]=O[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function s(C,I){var O,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(O,Q)}for(O in C)r(C,O)&&(M=C[O],Array.isArray(M)?M.forEach(K):j(O,M));return $.join("&")}t(116),t(155);function u(C,I,O){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?s(I,O):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function c(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(O){if(O===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return O}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(O){if(O===null||(M=O,Function.toString.call(M).indexOf("[native code]")===-1))return O;var M;if(typeof O!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(O))return I.get(O);I.set(O,x)}function x(){return p(O,arguments,g(this).constructor)}return x.prototype=Object.create(O.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,O)})(C)}function p(C,I,O){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(O,M){return O.__proto__=M,O})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,O,M,x=(I=$,O=l(),function(){var j,K=g(I);if(O){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return c(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,O,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(st){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(st){return!(st===void 0||st>=200&&st<300||st===1223||st===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):O(J)}}var m=Object.create(null),_=0;function S(C,I,O,M){C.onload=b(C,I,O,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),_===Number.MAX_SAFE_INTEGER&&(_=0);var x=++_;return m[x]={xhr:C,options:I,resolve:O,reject:M},x}function w(C){delete m[C]}function E(C,I,O,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!O&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function k(C,I,O,M){var x,$,j;if(O!=null&&C!=="get")return M==="json"?(x=JSON.stringify(O),$="application/json; charset=utf-8"):(j=O,typeof(x=i.call(j)==="[object Object]"?s(O,{ignoreEmpty:!1}):O)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var O=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(st){var P=document.createElement("div");P.innerHTML='<a href="'+st+'"></a>';var G=P.firstChild,W=G.host!==location.host;return P=null,G=null,W}(C=function(st,P,G){return P!=null&&(st=u(st,P,{ignoreEmpty:!1})),G&&(st=u(st,{_:Date.now()})),st}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);O=S(J,I,function(st){w(O),M(st)},function(st){w(O),x(st)}),J.open($,C,!0,I.username,I.password);var N=k($,K,I.data,j);(function(st,P,G,W){P.timeout&&(st.timeout=P.timeout),G&&P.withCredentials!=null&&(st.withCredentials=!!P.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&st.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(O)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var O in C)I.append(O,C[O]);return I}function z(C,I,O){O===void 0&&(O=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return O?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,O){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){O(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var R,D,H,Z=(R=function(C,I){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,M){O.__proto__=M}||function(O,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(O[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function O(){this.constructor=C}R(C,I),C.prototype=I===null?Object.create(I):(O.prototype=I.prototype,new O)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var et,rt=function(C){function I(O){var M=C.call(this,O)||this,x=I.getFailErrorData(O);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(O){return{failCode:O,failMessage:I.failMessageVal[O]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),tt=function(){return(tt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},dt=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j;return dt(this,function(K){switch(K.label){case 0:return O=Date.now(),M=U()("upload_token_live"+I.channelId+O),x={channelId:I.channelId,ts:O,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j,K;return dt(this,function(Q){switch(Q.label){case 0:O={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(O),onUploadProgress:function(J){var N,st,P=I.onUploadProgress;typeof P=="function"&&P((N=J.loaded/J.total,st=2,Number(N.toFixed(st||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,O,M){var x=I;Object.keys(O).sort().forEach(function(j){O[j]&&(x+=j+String(O[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var O,M,x;return dt(this,function($){switch($.label){case 0:O=tt(tt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:tt(tt({},O),{sign:this.createSign("polyv_chat_api_innor",O)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(et||(et={}));var bt=function(){return(bt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},mt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ct=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},lt={width:500,height:500},xt=function(){function C(I){var O=I.callbackChange,M=O===void 0||O;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||et.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),mt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,st,P,G,W,X=this;return ct(this,function(at){switch(at.label){case 0:return O=this.uploadCtx,M=O.channelId,x=O.userId,$=O.bucket,this.status=et.UPLOADING,[4,O.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=at.sent(),!((K=this.file).size>1024*O.compressSizeLimit))return[3,5];at.label=2;case 2:return at.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=at.sent(),K=Q,[3,5];case 4:return at.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return at.trys.push([5,7,,8]),[4,B(K)];case 6:return J=at.sent(),N=J.width,st=J.height,this.size={width:N,height:st},[3,8];case 7:return at.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=lt),this.uploadProgress=0,P="",at.label=9;case 9:return at.trys.push([9,13,,14]),[4,O.uploadApi.uploadImage(bt(bt({},j),{file:K,fileName:this.fileName,onUploadProgress:function(kt){X.uploadProgress=kt,X.triggerChange()}}))];case 10:return P=at.sent(),this.fileUrl=P,O.enablePornChecking?[4,O.uploadApi.pornIdentify({channelId:M,url:"https:"+P})]:[3,12];case 11:at.sent(),at.label=12;case 12:return this.status=et.UPLOAD_SUCCESS,[3,14];case 13:return G=at.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?et.UPLOAD_FORBID:et.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(P),[2,P]}})})},C.prototype.compressImage=function(I){return mt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,st;return ct(this,function(P){switch(P.label){case 0:return O=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(O)];case 1:return j=P.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(st=N.getContext("2d"))?(st.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),_t=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var O=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<O;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(O){return O.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,O){return O.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Et=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],gt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],ht={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Et,allowFileExtension:gt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},wt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ut=function(){function C(I){I===void 0&&(I={});var O=I.channelId,M=O===void 0?ht.channelId:O,x=I.userId,$=x===void 0?ht.userId:x,j=I.sizeLimit,K=j===void 0?ht.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?ht.compressSizeLimit:Q,N=I.limit,st=N===void 0?ht.limit:N,P=I.maxWidth,G=P===void 0?ht.maxWidth:P,W=I.reUploadTimes,X=W===void 0?ht.reUploadTimes:W,at=I.source,kt=at===void 0?ht.source:at,Tt=I.bucket,Pt=Tt===void 0?ht.bucket:Tt,Ut=I.useBlobByCompress,nt=Ut===void 0?ht.useBlobByCompress:Ut,ft=I.allowAccept,vt=ft===void 0?ht.allowAccept:ft,It=I.allowFileExtension,Ct=It===void 0?ht.allowFileExtension:It,Ht=I.maxUploadNumber,Bt=Ht===void 0?ht.maxUploadNumber:Ht,Xt=I.apiHost,he=Xt===void 0?ht.apiHost:Xt,ge=I.onChange,ve=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=st,this.maxWidth=G,this.reUploadTimes=X,this.source=kt,this.bucket=Pt,this.useBlobByCompress=!!nt,this.allowAccept=vt,this.allowFileExtension=Ct,this.maxUploadNumber=Bt,this.onChange=ge,this.beforeStart=ve,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=he,this.uploadQueue=new _t({uploadCtx:this}),this.uploadApi=new pt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var O=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&O.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,O){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=O.length<this.limit?O.length:this.limit,Q=0;Q<K;Q++){var J=O[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var st=[];for(Q=0;Q<K;Q++){J=O[Q];var P=this.buildImageId(Q),G=new xt({imageId:P,uploadCtx:this,file:J,callbackChange:j});st.push(G)}typeof $=="function"&&$(st)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(O){return"."+O})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var O=this;if(Array.isArray(I))return I.forEach(function(x){O.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof xt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(O,M){I.choiceImageFile({callbackChange:!1,success:function(x){return wt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?O($):M(new rt(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(O){I.joinWaitQueue(O)}})},C.prototype.uploadImageFile=function(I){return wt(this,void 0,void 0,function(){var O;return q(this,function(M){switch(M.label){case 0:if(O=this.checkFile(I))throw new Error(O.failMessage);return[4,new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,O){return wt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:O!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return wt(this,void 0,void 0,function(){var O,M;return q(this,function(x){switch(x.label){case 0:if(!(O=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,O.upload()];case 2:return x.sent(),[2,O];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return rt.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return rt.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return rt.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var O=V(I);return this.allowFileExtension.includes(O)?void 0:rt.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var O=[];this.source&&O.push(this.source),this.channelId&&O.push(this.channelId),this.userId&&O.push(this.userId);var M=I!==void 0?"_"+I:"";return O.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class Ve extends jt{constructor(t){super(t);yt(this,"__uploadImgCtrl");yt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ge.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return it(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return it(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},s=[],u=[];return new Promise((f,c)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>it(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ee(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};s.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};u.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:s,failUploadImages:u})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),c(new Error(d.failMessage))}})})})}directUploadImage(t){return it(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return it(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return it(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),s=i[i.length-1].split(".")[0];if(r[s])return this.__genResourceUrl(`/default-img/donate-svga/${r[s]}`)})}}class $e{constructor(a,t={}){yt(this,"PolyvChatEvent",St);yt(this,"ChatMsgSource",ot);yt(this,"DonateType",Dt);yt(this,"RedpackType",qt);yt(this,"SystemMsgType",Vt);yt(this,"ChatRequestHistoryMode",Ft);yt(this,"ManageFailReason",Nt);yt(this,"TranslateLanguage",Jt);yt(this,"eventEmitter",new we);yt(this,"__socketFilter");yt(this,"__socketHandler");yt(this,"emotion");yt(this,"history");yt(this,"message");yt(this,"status");yt(this,"utils");yt(this,"sender");yt(this,"manage");yt(this,"online");yt(this,"download");yt(this,"like");yt(this,"ask");yt(this,"setuped",!1);this.plvSocket=a,this.config=t,this.emotion=new Le(this),this.history=new je(this),this.message=new De(this),this.status=new He(this),this.utils=new Ve(this),this.sender=new ze(this),this.manage=new Ue(this),this.online=new Be(this),this.download=new Re(this),this.like=new Ne(this),this.ask=new Me(this),this.__socketFilter=new ke(this),this.__socketHandler=new Ce(this)}setup(){return it(this,null,function*(){this.setuped=!0})}destroy(){return it(this,null,function*(){this.plvSocket.clearSocketHandles(At)})}}const Ke="PolyvChat";exports.ChatMsgSource=ot;exports.ChatRequestHistoryMode=Ft;exports.DonateType=Dt;exports.GlobalVariable=Ke;exports.ManageFailReason=Nt;exports.MotivationLikeType=Qt;exports.PolyvChat=$e;exports.PolyvChatEvent=St;exports.RedpackType=qt;exports.SystemMsgType=Vt;exports.TranslateLanguage=Jt;exports.canQuoteMsgSource=de;exports.canTopMsgSource=pe;exports.isServiceMsgMap=le;console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.4.0-rc-20251225.2]","[buildTime: 2025-12-25 03:00:47]");
|
package/index.es.js
CHANGED
|
@@ -7359,8 +7359,8 @@ const We = "PolyvChat";
|
|
|
7359
7359
|
console.log(
|
|
7360
7360
|
"%c@polyv/chat",
|
|
7361
7361
|
"background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff",
|
|
7362
|
-
"[version: 2.
|
|
7363
|
-
"[buildTime: 2025-12-
|
|
7362
|
+
"[version: 2.4.0-rc-20251225.2]",
|
|
7363
|
+
"[buildTime: 2025-12-25 03:00:47]"
|
|
7364
7364
|
);
|
|
7365
7365
|
export {
|
|
7366
7366
|
ot as ChatMsgSource,
|
package/index.umd.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
18
18
|
* @license MIT
|
|
19
|
-
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,s,t){t.r(s),t.d(s,"ChatImageUpload",function(){return ct}),t.d(s,"defaultConfig",function(){return gt}),t.d(s,"allowAccept",function(){return kt}),t.d(s,"allowFileExtension",function(){return vt}),t.d(s,"FailError",function(){return rt}),t.d(s,"FailCode",function(){return H}),t.d(s,"ChatImage",function(){return Ot}),t.d(s,"ImageStatus",function(){return et}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var O=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(O!=null)for(var M in O)M!=="__proto__"&&r(O,M)&&(C[M]=O[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function a(C,I){var O,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(O,Q)}for(O in C)r(C,O)&&(M=C[O],Array.isArray(M)?M.forEach(K):j(O,M));return $.join("&")}t(116),t(155);function u(C,I,O){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?a(I,O):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function c(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(O){if(O===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return O}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(O){if(O===null||(M=O,Function.toString.call(M).indexOf("[native code]")===-1))return O;var M;if(typeof O!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(O))return I.get(O);I.set(O,x)}function x(){return p(O,arguments,g(this).constructor)}return x.prototype=Object.create(O.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,O)})(C)}function p(C,I,O){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(O,M){return O.__proto__=M,O})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,O,M,x=(I=$,O=l(),function(){var j,K=g(I);if(O){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return c(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,O,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(ut){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(ut){return!(ut===void 0||ut>=200&&ut<300||ut===1223||ut===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):O(J)}}var m=Object.create(null),_=0;function S(C,I,O,M){C.onload=b(C,I,O,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),_===Number.MAX_SAFE_INTEGER&&(_=0);var x=++_;return m[x]={xhr:C,options:I,resolve:O,reject:M},x}function w(C){delete m[C]}function E(C,I,O,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!O&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function k(C,I,O,M){var x,$,j;if(O!=null&&C!=="get")return M==="json"?(x=JSON.stringify(O),$="application/json; charset=utf-8"):(j=O,typeof(x=i.call(j)==="[object Object]"?a(O,{ignoreEmpty:!1}):O)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var O=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(ut){var P=document.createElement("div");P.innerHTML='<a href="'+ut+'"></a>';var G=P.firstChild,W=G.host!==location.host;return P=null,G=null,W}(C=function(ut,P,G){return P!=null&&(ut=u(ut,P,{ignoreEmpty:!1})),G&&(ut=u(ut,{_:Date.now()})),ut}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);O=S(J,I,function(ut){w(O),M(ut)},function(ut){w(O),x(ut)}),J.open($,C,!0,I.username,I.password);var N=k($,K,I.data,j);(function(ut,P,G,W){P.timeout&&(ut.timeout=P.timeout),G&&P.withCredentials!=null&&(ut.withCredentials=!!P.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&ut.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(O)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var O in C)I.append(O,C[O]);return I}function z(C,I,O){O===void 0&&(O=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return O?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,O){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){O(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var R,D,H,Z=(R=function(C,I){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,M){O.__proto__=M}||function(O,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(O[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function O(){this.constructor=C}R(C,I),C.prototype=I===null?Object.create(I):(O.prototype=I.prototype,new O)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var et,rt=function(C){function I(O){var M=C.call(this,O)||this,x=I.getFailErrorData(O);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(O){return{failCode:O,failMessage:I.failMessageVal[O]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),tt=function(){return(tt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ht=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},dt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j;return ht(this,function(K){switch(K.label){case 0:return O=Date.now(),M=U()("upload_token_live"+I.channelId+O),x={channelId:I.channelId,ts:O,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j,K;return ht(this,function(Q){switch(Q.label){case 0:O={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(O),onUploadProgress:function(J){var N,ut,P=I.onUploadProgress;typeof P=="function"&&P((N=J.loaded/J.total,ut=2,Number(N.toFixed(ut||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,O,M){var x=I;Object.keys(O).sort().forEach(function(j){O[j]&&(x+=j+String(O[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var O,M,x;return ht(this,function($){switch($.label){case 0:O=tt(tt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:tt(tt({},O),{sign:this.createSign("polyv_chat_api_innor",O)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(et||(et={}));var St=function(){return(St=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},bt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ft=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt={width:500,height:500},Ot=function(){function C(I){var O=I.callbackChange,M=O===void 0||O;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||et.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),bt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,ut,P,G,W,X=this;return ft(this,function(st){switch(st.label){case 0:return O=this.uploadCtx,M=O.channelId,x=O.userId,$=O.bucket,this.status=et.UPLOADING,[4,O.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=st.sent(),!((K=this.file).size>1024*O.compressSizeLimit))return[3,5];st.label=2;case 2:return st.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=st.sent(),K=Q,[3,5];case 4:return st.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return st.trys.push([5,7,,8]),[4,B(K)];case 6:return J=st.sent(),N=J.width,ut=J.height,this.size={width:N,height:ut},[3,8];case 7:return st.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=pt),this.uploadProgress=0,P="",st.label=9;case 9:return st.trys.push([9,13,,14]),[4,O.uploadApi.uploadImage(St(St({},j),{file:K,fileName:this.fileName,onUploadProgress:function(At){X.uploadProgress=At,X.triggerChange()}}))];case 10:return P=st.sent(),this.fileUrl=P,O.enablePornChecking?[4,O.uploadApi.pornIdentify({channelId:M,url:"https:"+P})]:[3,12];case 11:st.sent(),st.label=12;case 12:return this.status=et.UPLOAD_SUCCESS,[3,14];case 13:return G=st.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?et.UPLOAD_FORBID:et.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(P),[2,P]}})})},C.prototype.compressImage=function(I){return bt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,ut;return ft(this,function(P){switch(P.label){case 0:return O=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(O)];case 1:return j=P.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(ut=N.getContext("2d"))?(ut.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),Et=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var O=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<O;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(O){return O.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,O){return O.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),kt=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],vt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],gt={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:kt,allowFileExtension:vt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},xt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ct=function(){function C(I){I===void 0&&(I={});var O=I.channelId,M=O===void 0?gt.channelId:O,x=I.userId,$=x===void 0?gt.userId:x,j=I.sizeLimit,K=j===void 0?gt.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?gt.compressSizeLimit:Q,N=I.limit,ut=N===void 0?gt.limit:N,P=I.maxWidth,G=P===void 0?gt.maxWidth:P,W=I.reUploadTimes,X=W===void 0?gt.reUploadTimes:W,st=I.source,At=st===void 0?gt.source:st,Rt=I.bucket,jt=Rt===void 0?gt.bucket:Rt,Dt=I.useBlobByCompress,ot=Dt===void 0?gt.useBlobByCompress:Dt,lt=I.allowAccept,mt=lt===void 0?gt.allowAccept:lt,wt=I.allowFileExtension,Pt=wt===void 0?gt.allowFileExtension:wt,Qt=I.maxUploadNumber,Wt=Qt===void 0?gt.maxUploadNumber:Qt,de=I.apiHost,Be=de===void 0?gt.apiHost:de,ze=I.onChange,He=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=ut,this.maxWidth=G,this.reUploadTimes=X,this.source=At,this.bucket=jt,this.useBlobByCompress=!!ot,this.allowAccept=mt,this.allowFileExtension=Pt,this.maxUploadNumber=Wt,this.onChange=ze,this.beforeStart=He,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=Be,this.uploadQueue=new Et({uploadCtx:this}),this.uploadApi=new dt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var O=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&O.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,O){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=O.length<this.limit?O.length:this.limit,Q=0;Q<K;Q++){var J=O[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var ut=[];for(Q=0;Q<K;Q++){J=O[Q];var P=this.buildImageId(Q),G=new Ot({imageId:P,uploadCtx:this,file:J,callbackChange:j});ut.push(G)}typeof $=="function"&&$(ut)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(O){return"."+O})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var O=this;if(Array.isArray(I))return I.forEach(function(x){O.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof Ot&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(O,M){I.choiceImageFile({callbackChange:!1,success:function(x){return xt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?O($):M(new rt(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(O){I.joinWaitQueue(O)}})},C.prototype.uploadImageFile=function(I){return xt(this,void 0,void 0,function(){var O;return q(this,function(M){switch(M.label){case 0:if(O=this.checkFile(I))throw new Error(O.failMessage);return[4,new Ot({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,O){return xt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new Ot({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:O!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return xt(this,void 0,void 0,function(){var O,M;return q(this,function(x){switch(x.label){case 0:if(!(O=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,O.upload()];case 2:return x.sent(),[2,O];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return rt.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return rt.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return rt.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var O=V(I);return this.allowFileExtension.includes(O)?void 0:rt.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var O=[];this.source&&O.push(this.source),this.channelId&&O.push(this.channelId),this.userId&&O.push(this.userId);var M=I!==void 0?"_"+I:"";return O.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class Ue extends Ut{constructor(t){super(t);It(this,"__uploadImgCtrl");It(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ne.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return at(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return at(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},a=[],u=[];return new Promise((f,c)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>at(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ve(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};a.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};u.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:a,failUploadImages:u})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),c(new Error(d.failMessage))}})})})}directUploadImage(t){return at(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return at(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return at(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),a=i[i.length-1].split(".")[0];if(r[a])return this.__genResourceUrl(`/default-img/donate-svga/${r[a]}`)})}}class Fe{constructor(s,t={}){It(this,"PolyvChatEvent",it);It(this,"ChatMsgSource",nt);It(this,"DonateType",Gt);It(this,"RedpackType",Xt);It(this,"SystemMsgType",qt);It(this,"ChatRequestHistoryMode",zt);It(this,"ManageFailReason",_t);It(this,"TranslateLanguage",te);It(this,"eventEmitter",new Vt);It(this,"__socketFilter");It(this,"__socketHandler");It(this,"emotion");It(this,"history");It(this,"message");It(this,"status");It(this,"utils");It(this,"sender");It(this,"manage");It(this,"online");It(this,"download");It(this,"like");It(this,"ask");It(this,"setuped",!1);this.plvSocket=s,this.config=t,this.emotion=new ke(this),this.history=new Ce(this),this.message=new Pe(this),this.status=new je(this),this.utils=new Ue(this),this.sender=new Le(this),this.manage=new Me(this),this.online=new Re(this),this.download=new Oe(this),this.like=new Te(this),this.ask=new _e(this),this.__socketFilter=new Ie(this),this.__socketHandler=new Se(this)}setup(){return at(this,null,function*(){this.setuped=!0})}destroy(){return at(this,null,function*(){this.plvSocket.clearSocketHandles(Mt)})}}const De="PolyvChat";yt.ChatMsgSource=nt,yt.ChatRequestHistoryMode=zt,yt.DonateType=Gt,yt.GlobalVariable=De,yt.ManageFailReason=_t,yt.MotivationLikeType=Zt,yt.PolyvChat=Fe,yt.PolyvChatEvent=it,yt.RedpackType=Xt,yt.SystemMsgType=qt,yt.TranslateLanguage=te,yt.canQuoteMsgSource=pe,yt.canTopMsgSource=le,yt.isServiceMsgMap=fe,Object.defineProperty(yt,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.3.0-rc-20251204.1]","[buildTime: 2025-12-04 02:19:37]");
|
|
19
|
+
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,s,t){t.r(s),t.d(s,"ChatImageUpload",function(){return ct}),t.d(s,"defaultConfig",function(){return gt}),t.d(s,"allowAccept",function(){return kt}),t.d(s,"allowFileExtension",function(){return vt}),t.d(s,"FailError",function(){return rt}),t.d(s,"FailCode",function(){return H}),t.d(s,"ChatImage",function(){return Ot}),t.d(s,"ImageStatus",function(){return et}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var O=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(O!=null)for(var M in O)M!=="__proto__"&&r(O,M)&&(C[M]=O[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function a(C,I){var O,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(O,Q)}for(O in C)r(C,O)&&(M=C[O],Array.isArray(M)?M.forEach(K):j(O,M));return $.join("&")}t(116),t(155);function u(C,I,O){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?a(I,O):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function c(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(O){if(O===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return O}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(O){if(O===null||(M=O,Function.toString.call(M).indexOf("[native code]")===-1))return O;var M;if(typeof O!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(O))return I.get(O);I.set(O,x)}function x(){return p(O,arguments,g(this).constructor)}return x.prototype=Object.create(O.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,O)})(C)}function p(C,I,O){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(O,M){return O.__proto__=M,O})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,O,M,x=(I=$,O=l(),function(){var j,K=g(I);if(O){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return c(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,O,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(ut){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(ut){return!(ut===void 0||ut>=200&&ut<300||ut===1223||ut===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):O(J)}}var m=Object.create(null),_=0;function S(C,I,O,M){C.onload=b(C,I,O,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),_===Number.MAX_SAFE_INTEGER&&(_=0);var x=++_;return m[x]={xhr:C,options:I,resolve:O,reject:M},x}function w(C){delete m[C]}function E(C,I,O,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!O&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function k(C,I,O,M){var x,$,j;if(O!=null&&C!=="get")return M==="json"?(x=JSON.stringify(O),$="application/json; charset=utf-8"):(j=O,typeof(x=i.call(j)==="[object Object]"?a(O,{ignoreEmpty:!1}):O)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var O=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(ut){var P=document.createElement("div");P.innerHTML='<a href="'+ut+'"></a>';var G=P.firstChild,W=G.host!==location.host;return P=null,G=null,W}(C=function(ut,P,G){return P!=null&&(ut=u(ut,P,{ignoreEmpty:!1})),G&&(ut=u(ut,{_:Date.now()})),ut}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);O=S(J,I,function(ut){w(O),M(ut)},function(ut){w(O),x(ut)}),J.open($,C,!0,I.username,I.password);var N=k($,K,I.data,j);(function(ut,P,G,W){P.timeout&&(ut.timeout=P.timeout),G&&P.withCredentials!=null&&(ut.withCredentials=!!P.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&ut.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(O)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var O in C)I.append(O,C[O]);return I}function z(C,I,O){O===void 0&&(O=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return O?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,O){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){O(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var R,D,H,Z=(R=function(C,I){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(O,M){O.__proto__=M}||function(O,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(O[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function O(){this.constructor=C}R(C,I),C.prototype=I===null?Object.create(I):(O.prototype=I.prototype,new O)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var et,rt=function(C){function I(O){var M=C.call(this,O)||this,x=I.getFailErrorData(O);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(O){return{failCode:O,failMessage:I.failMessageVal[O]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),tt=function(){return(tt=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ht=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},dt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j;return ht(this,function(K){switch(K.label){case 0:return O=Date.now(),M=U()("upload_token_live"+I.channelId+O),x={channelId:I.channelId,ts:O,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new rt(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var O,M,x,$,j,K;return ht(this,function(Q){switch(Q.label){case 0:O={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(O),onUploadProgress:function(J){var N,ut,P=I.onUploadProgress;typeof P=="function"&&P((N=J.loaded/J.total,ut=2,Number(N.toFixed(ut||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new rt(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,O,M){var x=I;Object.keys(O).sort().forEach(function(j){O[j]&&(x+=j+String(O[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var O,M,x;return ht(this,function($){switch($.label){case 0:O=tt(tt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:tt(tt({},O),{sign:this.createSign("polyv_chat_api_innor",O)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new rt(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(et||(et={}));var St=function(){return(St=Object.assign||function(C){for(var I,O=1,M=arguments.length;O<M;O++)for(var x in I=arguments[O])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},bt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ft=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt={width:500,height:500},Ot=function(){function C(I){var O=I.callbackChange,M=O===void 0||O;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||et.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),bt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,ut,P,G,W,X=this;return ft(this,function(st){switch(st.label){case 0:return O=this.uploadCtx,M=O.channelId,x=O.userId,$=O.bucket,this.status=et.UPLOADING,[4,O.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=st.sent(),!((K=this.file).size>1024*O.compressSizeLimit))return[3,5];st.label=2;case 2:return st.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=st.sent(),K=Q,[3,5];case 4:return st.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return st.trys.push([5,7,,8]),[4,B(K)];case 6:return J=st.sent(),N=J.width,ut=J.height,this.size={width:N,height:ut},[3,8];case 7:return st.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=pt),this.uploadProgress=0,P="",st.label=9;case 9:return st.trys.push([9,13,,14]),[4,O.uploadApi.uploadImage(St(St({},j),{file:K,fileName:this.fileName,onUploadProgress:function(At){X.uploadProgress=At,X.triggerChange()}}))];case 10:return P=st.sent(),this.fileUrl=P,O.enablePornChecking?[4,O.uploadApi.pornIdentify({channelId:M,url:"https:"+P})]:[3,12];case 11:st.sent(),st.label=12;case 12:return this.status=et.UPLOAD_SUCCESS,[3,14];case 13:return G=st.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?et.UPLOAD_FORBID:et.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(P),[2,P]}})})},C.prototype.compressImage=function(I){return bt(this,void 0,void 0,function(){var O,M,x,$,j,K,Q,J,N,ut;return ft(this,function(P){switch(P.label){case 0:return O=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(O)];case 1:return j=P.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(ut=N.getContext("2d"))?(ut.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),Et=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var O=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<O;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(O){return O.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,O){return O.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),kt=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],vt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],gt={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:kt,allowFileExtension:vt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},xt=function(C,I,O,M){return new(O||(O=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof O?N:new O(function(ut){ut(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var O,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(O)throw new TypeError("Generator is already executing.");for(;j;)try{if(O=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ut){N=[6,ut],M=0}finally{O=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ct=function(){function C(I){I===void 0&&(I={});var O=I.channelId,M=O===void 0?gt.channelId:O,x=I.userId,$=x===void 0?gt.userId:x,j=I.sizeLimit,K=j===void 0?gt.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?gt.compressSizeLimit:Q,N=I.limit,ut=N===void 0?gt.limit:N,P=I.maxWidth,G=P===void 0?gt.maxWidth:P,W=I.reUploadTimes,X=W===void 0?gt.reUploadTimes:W,st=I.source,At=st===void 0?gt.source:st,Rt=I.bucket,jt=Rt===void 0?gt.bucket:Rt,Dt=I.useBlobByCompress,ot=Dt===void 0?gt.useBlobByCompress:Dt,lt=I.allowAccept,mt=lt===void 0?gt.allowAccept:lt,wt=I.allowFileExtension,Pt=wt===void 0?gt.allowFileExtension:wt,Qt=I.maxUploadNumber,Wt=Qt===void 0?gt.maxUploadNumber:Qt,de=I.apiHost,Be=de===void 0?gt.apiHost:de,ze=I.onChange,He=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=ut,this.maxWidth=G,this.reUploadTimes=X,this.source=At,this.bucket=jt,this.useBlobByCompress=!!ot,this.allowAccept=mt,this.allowFileExtension=Pt,this.maxUploadNumber=Wt,this.onChange=ze,this.beforeStart=He,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=Be,this.uploadQueue=new Et({uploadCtx:this}),this.uploadApi=new dt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var O=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&O.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,O){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=O.length<this.limit?O.length:this.limit,Q=0;Q<K;Q++){var J=O[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var ut=[];for(Q=0;Q<K;Q++){J=O[Q];var P=this.buildImageId(Q),G=new Ot({imageId:P,uploadCtx:this,file:J,callbackChange:j});ut.push(G)}typeof $=="function"&&$(ut)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(O){return"."+O})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var O=this;if(Array.isArray(I))return I.forEach(function(x){O.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof Ot&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(O,M){I.choiceImageFile({callbackChange:!1,success:function(x){return xt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?O($):M(new rt(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(O){I.joinWaitQueue(O)}})},C.prototype.uploadImageFile=function(I){return xt(this,void 0,void 0,function(){var O;return q(this,function(M){switch(M.label){case 0:if(O=this.checkFile(I))throw new Error(O.failMessage);return[4,new Ot({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,O){return xt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new Ot({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:O!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return xt(this,void 0,void 0,function(){var O,M;return q(this,function(x){switch(x.label){case 0:if(!(O=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,O.upload()];case 2:return x.sent(),[2,O];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return rt.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return rt.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return rt.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var O=V(I);return this.allowFileExtension.includes(O)?void 0:rt.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var O=[];this.source&&O.push(this.source),this.channelId&&O.push(this.channelId),this.userId&&O.push(this.userId);var M=I!==void 0?"_"+I:"";return O.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class Ue extends Ut{constructor(t){super(t);It(this,"__uploadImgCtrl");It(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ne.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return at(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return at(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},a=[],u=[];return new Promise((f,c)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>at(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ve(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};a.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};u.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:a,failUploadImages:u})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),c(new Error(d.failMessage))}})})})}directUploadImage(t){return at(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return at(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return at(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),a=i[i.length-1].split(".")[0];if(r[a])return this.__genResourceUrl(`/default-img/donate-svga/${r[a]}`)})}}class Fe{constructor(s,t={}){It(this,"PolyvChatEvent",it);It(this,"ChatMsgSource",nt);It(this,"DonateType",Gt);It(this,"RedpackType",Xt);It(this,"SystemMsgType",qt);It(this,"ChatRequestHistoryMode",zt);It(this,"ManageFailReason",_t);It(this,"TranslateLanguage",te);It(this,"eventEmitter",new Vt);It(this,"__socketFilter");It(this,"__socketHandler");It(this,"emotion");It(this,"history");It(this,"message");It(this,"status");It(this,"utils");It(this,"sender");It(this,"manage");It(this,"online");It(this,"download");It(this,"like");It(this,"ask");It(this,"setuped",!1);this.plvSocket=s,this.config=t,this.emotion=new ke(this),this.history=new Ce(this),this.message=new Pe(this),this.status=new je(this),this.utils=new Ue(this),this.sender=new Le(this),this.manage=new Me(this),this.online=new Re(this),this.download=new Oe(this),this.like=new Te(this),this.ask=new _e(this),this.__socketFilter=new Ie(this),this.__socketHandler=new Se(this)}setup(){return at(this,null,function*(){this.setuped=!0})}destroy(){return at(this,null,function*(){this.plvSocket.clearSocketHandles(Mt)})}}const De="PolyvChat";yt.ChatMsgSource=nt,yt.ChatRequestHistoryMode=zt,yt.DonateType=Gt,yt.GlobalVariable=De,yt.ManageFailReason=_t,yt.MotivationLikeType=Zt,yt.PolyvChat=Fe,yt.PolyvChatEvent=it,yt.RedpackType=Xt,yt.SystemMsgType=qt,yt.TranslateLanguage=te,yt.canQuoteMsgSource=pe,yt.canTopMsgSource=le,yt.isServiceMsgMap=fe,Object.defineProperty(yt,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.4.0-rc-20251225.2]","[buildTime: 2025-12-25 03:00:44]");
|