k2-im 0.2.12 → 0.2.14
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/README.md +6 -0
- package/dist/chat-kit-pinia.d.ts +2 -2
- package/dist/chat-kit.d.ts +1 -1
- package/dist/crypto.worker.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/modules/im-browser/src/media/media-preview-preparation-executor.js +1 -1
- package/dist/modules/im-core/src/mapping/search-text.js +1 -1
- package/dist/modules/im-core/src/media-thumbnail-policy.js +1 -1
- package/dist/modules/im-core/src/message-flow/media/media-sender.js +1 -1
- package/dist/modules/im-sdk/src/runtime/media-upload-recovery.js +1 -1
- package/dist/sdk.d.ts +1 -1
- package/package.json +10 -1
- package/dist/modules/im-browser/src/media/thumbnail-pixel-profile.js +0 -1
package/README.md
CHANGED
|
@@ -20,6 +20,12 @@ Chat Kit Core 与 Core-only 入口不依赖 Vue/Pinia/路由,也不自行获
|
|
|
20
20
|
|
|
21
21
|
ESM 与声明构建均包含所需 workspace 实现,crypto Worker、WASM 和 Speex 运行时资产也随包提供。ESM 保留模块之间的导入与导出,使宿主能够删除未使用的实现;`dist/modules` 是包内实现,不是公开导入入口。开发期本地同步不压缩并保留 source map;公共 npm 发布压缩 JavaScript 与 Speex、保留纯调用标记,并且不包含 `.map` 文件。workspace 版本用于源码开发,正式制品版本由发布命令指定;本地构建不表示已上传 Registry。
|
|
22
22
|
|
|
23
|
+
SDK 的 JavaScript 浏览器目标维护在本包 `package.json` 的 `browserslist.js`:Chromium / Edge 93+、Firefox 91+、Safari / iOS 15+,独立于宿主 CSS 框架。聚合包、拆分包和私有 classic Worker 通过构建期的 `browserslist-to-esbuild` 读取同一范围;聚合包与拆分包保留 ES2020 语法上限,Worker 保留 ES2017 语法上限。TypeScript 类型在构建时移除,运行时只交付转换后的 JavaScript。
|
|
24
|
+
|
|
25
|
+
请求加密模块保留顶层 `await`,由宿主打包器处理异步模块。独立的 `@k2/crypto` 拆包保留已有 JS/WASM 封装,不经过上述转译,其语法与运行能力仍须检查。`browserslist` 只声明目标,不会自行转换文件;构建时必须显式接入编译器,消费者也不能据此认定原始 ESM 可在所有 ES2020 浏览器直接运行。
|
|
26
|
+
|
|
27
|
+
第三方 external 依赖由宿主安装和打包,也必须纳入最终产物检查。语法转换不会补齐 `Array.at`、`findLast`、Web Locks 等运行时 API 或 WebAssembly 能力;它们需要按实际浏览器基线分别检查。SDK 构建成功不等于这些能力都可用,也不代表已经通过真机验收。
|
|
28
|
+
|
|
23
29
|
运行 `pnpm check:im-tree-shaking` 可以用真实生产消费者验证轻量 API 的体积与运行结果。该检查不等于完整客户端按功能裁剪:`createImClient()` 仍装配当前支持的会话与产品能力,未调用某个方法不会自动移除相应功能。
|
|
24
30
|
|
|
25
31
|
发布候选已通过独立 Rspack clean-consumer Gate:AWS 仅在首次上传时加载,crypto WASM 与 Speex 由 dist 自持,fixture 不需要 Node shim、WASM loader、asset copy 或 postinstall。该证据只证明普通 Rspack 消费者可以编译,不等于 H5 已同步当前 tarball 或真实媒体链路已验收;H5 开发期通过本地同步脚本完成自身 typecheck/Rspack 验证,上线准备阶段使用已发布 npm 精确版本完成 Docker/Jenkins 验证。
|
package/dist/chat-kit-pinia.d.ts
CHANGED
|
@@ -5557,7 +5557,7 @@ interface ImMediaTasksApi {
|
|
|
5557
5557
|
*
|
|
5558
5558
|
* 返回的对象可以**原样**作为 `localPreviewMetadata` 交给 `sendImage` / `sendVideo` /
|
|
5559
5559
|
* `sendMediaAlbum`:发送链路会复用可用元信息;合集项超出其可用消息空间时重新生成封面。
|
|
5560
|
-
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多
|
|
5560
|
+
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多 480px,目标 8 KiB、硬上限 24 KiB);includeDisplayPoster 可在同一次解码中额外生成
|
|
5561
5561
|
* 仅供页面显示的高清 displayPoster(长边最多 960),不得绕过发送校验直接用它替换 posterData。
|
|
5562
5562
|
*
|
|
5563
5563
|
* @param input.kind 按文件类型选解码路径;`'video'` 才会抽首帧与读时长。
|
|
@@ -7901,7 +7901,7 @@ interface ImExpressionStoreActions {
|
|
|
7901
7901
|
loadRecent: (kind: RecentKind) => Promise<ImExpressionOperationResult>;
|
|
7902
7902
|
reportRecent: (input: ImExpressionRecentInput) => Promise<ImExpressionOperationResult>;
|
|
7903
7903
|
rememberEmoji: (entry: ImEmojiRecentEntry) => Promise<ImExpressionOperationResult>;
|
|
7904
|
-
/** refreshAfterReport
|
|
7904
|
+
/** 批量记录并上报普通表情;默认刷新服务端列表,refreshAfterReport 为 false 时保留本地最近记录。 */
|
|
7905
7905
|
rememberEmojis: (entries: readonly ImEmojiRecentEntry[], options?: {
|
|
7906
7906
|
refreshAfterReport?: boolean;
|
|
7907
7907
|
}) => Promise<ImExpressionOperationResult>;
|
package/dist/chat-kit.d.ts
CHANGED
|
@@ -5668,7 +5668,7 @@ interface ImMediaTasksApi {
|
|
|
5668
5668
|
*
|
|
5669
5669
|
* 返回的对象可以**原样**作为 `localPreviewMetadata` 交给 `sendImage` / `sendVideo` /
|
|
5670
5670
|
* `sendMediaAlbum`:发送链路会复用可用元信息;合集项超出其可用消息空间时重新生成封面。
|
|
5671
|
-
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多
|
|
5671
|
+
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多 480px,目标 8 KiB、硬上限 24 KiB);includeDisplayPoster 可在同一次解码中额外生成
|
|
5672
5672
|
* 仅供页面显示的高清 displayPoster(长边最多 960),不得绕过发送校验直接用它替换 posterData。
|
|
5673
5673
|
*
|
|
5674
5674
|
* @param input.kind 按文件类型选解码路径;`'video'` 才会抽首帧与读时长。
|
package/dist/crypto.worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Ya=Object.defineProperty,$a=Object.defineProperties;var ja=Object.getOwnPropertyDescriptors;var ar=Object.getOwnPropertySymbols;var Za=Object.prototype.hasOwnProperty,Ja=Object.prototype.propertyIsEnumerable;var ir=(ue,J,ae)=>J in ue?Ya(ue,J,{enumerable:!0,configurable:!0,writable:!0,value:ae}):ue[J]=ae,nr=(ue,J)=>{for(var ae in J||(J={}))Za.call(J,ae)&&ir(ue,ae,J[ae]);if(ar)for(var ae of ar(J))Ja.call(J,ae)&&ir(ue,ae,J[ae]);return ue},sr=(ue,J)=>$a(ue,ja(J));(function(){"use strict";function or(i){if(i===null||typeof i!="object")return!1;const e=i;return e.version===1&&Number.isSafeInteger(e.generation)&&e.generation>=0&&typeof e.operationId=="string"&&e.operationId.length<=256}function ur(i){if(!or(i))return!1;if(i.kind==="init")return i.operationId==="";if(i.operationId==="")return!1;if(i.kind==="cancel"||i.kind==="promote")return!0;if(i.kind==="decrypt-tea"||i.kind==="encrypt-tea"){const e=i.kind==="encrypt-tea"?i.plain:i.cipherData;return i.teaKey instanceof ArrayBuffer&&i.teaKey.byteLength===16&&e instanceof ArrayBuffer&&e.byteLength<=262144&&(i.priority==="foreground"||i.priority==="background")}if(i.kind==="decrypt-batch"){if(!((i.priority==="foreground"||i.priority==="background")&&Array.isArray(i.keys)&&i.keys.every(g=>typeof g=="string")&&Array.isArray(i.items)&&i.items.length>0&&i.items.length<=8&&i.keys.length<=i.items.length&&i.items.every(g=>g!==null&&typeof g=="object"&&Number.isSafeInteger(g.itemIndex)&&g.itemIndex>=0&&Number.isSafeInteger(g.keyIndex)&&g.keyIndex>=0&&g.keyIndex<i.keys.length&&g.secretKey instanceof ArrayBuffer&&g.cipherData instanceof ArrayBuffer)))return!1;const{keys:t,items:u}=i,I=t.reduce((g,s)=>g+s.length*2,0)+u.reduce((g,s)=>g+s.secretKey.byteLength+s.cipherData.byteLength,0);return new Set(t).size===t.length&&new Set(u.map(g=>g.itemIndex)).size===u.length&&new Set(u.map(g=>g.keyIndex)).size===t.length&&(u.length===1||I<=262144)}return i.kind==="decrypt-rsa"&&i.data instanceof ArrayBuffer&&typeof i.privateKey=="string"&&(i.priority==="foreground"||i.priority==="background")}var fr=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function Ie(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}function lr(i){if(Object.prototype.hasOwnProperty.call(i,"__esModule"))return i;var e=i.default;if(typeof e=="function"){var t=function u(){var I=!1;try{I=this instanceof u}catch(g){}return I?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(i).forEach(function(u){var I=Object.getOwnPropertyDescriptor(i,u);Object.defineProperty(t,u,I.get?I:{enumerable:!0,get:function(){return i[u]}})}),t}var Ae={exports:{}},Be,ot;function H(){return ot||(ot=1,Be={options:{usePureJavaScript:!1}}),Be}var be={exports:{}},Ne,ut;function cr(){if(ut)return Ne;ut=1;var i={};Ne=i;var e={};i.encode=function(u,I,g){if(typeof I!="string")throw new TypeError('"alphabet" must be a string.');if(g!==void 0&&typeof g!="number")throw new TypeError('"maxline" must be a number.');var s="";if(!(u instanceof Uint8Array))s=t(u,I);else{var o=0,d=I.length,c=I.charAt(0),T=[0];for(o=0;o<u.length;++o){for(var R=0,x=u[o];R<T.length;++R)x+=T[R]<<8,T[R]=x%d,x=x/d|0;for(;x>0;)T.push(x%d),x=x/d|0}for(o=0;u[o]===0&&o<u.length-1;++o)s+=c;for(o=T.length-1;o>=0;--o)s+=I[T[o]]}if(g){var y=new RegExp(".{1,"+g+"}","g");s=s.match(y).join(`\r
|
|
2
2
|
`)}return s},i.decode=function(u,I){if(typeof u!="string")throw new TypeError('"input" must be a string.');if(typeof I!="string")throw new TypeError('"alphabet" must be a string.');var g=e[I];if(!g){g=e[I]=[];for(var s=0;s<I.length;++s)g[I.charCodeAt(s)]=s}u=u.replace(/\s/g,"");for(var o=I.length,d=I.charAt(0),c=[0],s=0;s<u.length;s++){var T=g[u.charCodeAt(s)];if(T===void 0)return;for(var R=0,x=T;R<c.length;++R)x+=c[R]*o,c[R]=x&255,x>>=8;for(;x>0;)c.push(x&255),x>>=8}for(var y=0;u[y]===d&&y<u.length-1;++y)c.push(0);return typeof Buffer!="undefined"?Buffer.from(c.reverse()):new Uint8Array(c.reverse())};function t(u,I){var g=0,s=I.length,o=I.charAt(0),d=[0];for(g=0;g<u.length();++g){for(var c=0,T=u.at(g);c<d.length;++c)T+=d[c]<<8,d[c]=T%s,T=T/s|0;for(;T>0;)d.push(T%s),T=T/s|0}var R="";for(g=0;u.at(g)===0&&g<u.length()-1;++g)R+=o;for(g=d.length-1;g>=0;--g)R+=I[d[g]];return R}return Ne}var ft;function X(){if(ft)return be.exports;ft=1;var i=H(),e=cr(),t=be.exports=i.util=i.util||{};(function(){if(typeof process!="undefined"&&process.nextTick&&!process.browser){t.nextTick=process.nextTick,typeof setImmediate=="function"?t.setImmediate=setImmediate:t.setImmediate=t.nextTick;return}if(typeof setImmediate=="function"){t.setImmediate=function(){return setImmediate.apply(void 0,arguments)},t.nextTick=function(r){return setImmediate(r)};return}if(t.setImmediate=function(r){setTimeout(r,0)},typeof window!="undefined"&&typeof window.postMessage=="function"){let r=function(f){if(f.source===window&&f.data===a){f.stopPropagation();var S=l.slice();l.length=0,S.forEach(function(w){w()})}};var a="forge.setImmediate",l=[];t.setImmediate=function(f){l.push(f),l.length===1&&window.postMessage(a,"*")},window.addEventListener("message",r,!0)}if(typeof MutationObserver!="undefined"){var h=Date.now(),A=!0,b=document.createElement("div"),l=[];new MutationObserver(function(){var f=l.slice();l.length=0,f.forEach(function(S){S()})}).observe(b,{attributes:!0});var n=t.setImmediate;t.setImmediate=function(f){Date.now()-h>15?(h=Date.now(),n(f)):(l.push(f),l.length===1&&b.setAttribute("a",A=!A))}}t.nextTick=t.setImmediate})(),t.isNodejs=typeof process!="undefined"&&process.versions&&process.versions.node,t.globalScope=(function(){return t.isNodejs?fr:typeof self=="undefined"?window:self})(),t.isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},t.isArrayBuffer=function(a){return typeof ArrayBuffer!="undefined"&&a instanceof ArrayBuffer},t.isArrayBufferView=function(a){return a&&t.isArrayBuffer(a.buffer)&&a.byteLength!==void 0};function u(a){if(!(a===8||a===16||a===24||a===32))throw new Error("Only 8, 16, 24, or 32 bits supported: "+a)}t.ByteBuffer=I;function I(a){if(this.data="",this.read=0,typeof a=="string")this.data=a;else if(t.isArrayBuffer(a)||t.isArrayBufferView(a))if(typeof Buffer!="undefined"&&a instanceof Buffer)this.data=a.toString("binary");else{var l=new Uint8Array(a);try{this.data=String.fromCharCode.apply(null,l)}catch(A){for(var h=0;h<l.length;++h)this.putByte(l[h])}}else(a instanceof I||typeof a=="object"&&typeof a.data=="string"&&typeof a.read=="number")&&(this.data=a.data,this.read=a.read);this._constructedStringLength=0}t.ByteStringBuffer=I;var g=4096;t.ByteStringBuffer.prototype._optimizeConstructedString=function(a){this._constructedStringLength+=a,this._constructedStringLength>g&&(this.data.substr(0,1),this._constructedStringLength=0)},t.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read},t.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0},t.ByteStringBuffer.prototype.putByte=function(a){return this.putBytes(String.fromCharCode(a))},t.ByteStringBuffer.prototype.fillWithByte=function(a,l){a=String.fromCharCode(a);for(var h=this.data;l>0;)l&1&&(h+=a),l>>>=1,l>0&&(a+=a);return this.data=h,this._optimizeConstructedString(l),this},t.ByteStringBuffer.prototype.putBytes=function(a){return this.data+=a,this._optimizeConstructedString(a.length),this},t.ByteStringBuffer.prototype.putString=function(a){return this.putBytes(t.encodeUtf8(a))},t.ByteStringBuffer.prototype.putInt16=function(a){return this.putBytes(String.fromCharCode(a>>8&255)+String.fromCharCode(a&255))},t.ByteStringBuffer.prototype.putInt24=function(a){return this.putBytes(String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255))},t.ByteStringBuffer.prototype.putInt32=function(a){return this.putBytes(String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255))},t.ByteStringBuffer.prototype.putInt16Le=function(a){return this.putBytes(String.fromCharCode(a&255)+String.fromCharCode(a>>8&255))},t.ByteStringBuffer.prototype.putInt24Le=function(a){return this.putBytes(String.fromCharCode(a&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a>>16&255))},t.ByteStringBuffer.prototype.putInt32Le=function(a){return this.putBytes(String.fromCharCode(a&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>24&255))},t.ByteStringBuffer.prototype.putInt=function(a,l){u(l);var h="";do l-=8,h+=String.fromCharCode(a>>l&255);while(l>0);return this.putBytes(h)},t.ByteStringBuffer.prototype.putSignedInt=function(a,l){return a<0&&(a+=2<<l-1),this.putInt(a,l)},t.ByteStringBuffer.prototype.putBuffer=function(a){return this.putBytes(a.getBytes())},t.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)},t.ByteStringBuffer.prototype.getInt16=function(){var a=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,a},t.ByteStringBuffer.prototype.getInt24=function(){var a=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,a},t.ByteStringBuffer.prototype.getInt32=function(){var a=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,a},t.ByteStringBuffer.prototype.getInt16Le=function(){var a=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,a},t.ByteStringBuffer.prototype.getInt24Le=function(){var a=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,a},t.ByteStringBuffer.prototype.getInt32Le=function(){var a=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,a},t.ByteStringBuffer.prototype.getInt=function(a){u(a);var l=0;do l=(l<<8)+this.data.charCodeAt(this.read++),a-=8;while(a>0);return l},t.ByteStringBuffer.prototype.getSignedInt=function(a){var l=this.getInt(a),h=2<<a-2;return l>=h&&(l-=h<<1),l},t.ByteStringBuffer.prototype.getBytes=function(a){var l;return a?(a=Math.min(this.length(),a),l=this.data.slice(this.read,this.read+a),this.read+=a):a===0?l="":(l=this.read===0?this.data:this.data.slice(this.read),this.clear()),l},t.ByteStringBuffer.prototype.bytes=function(a){return typeof a=="undefined"?this.data.slice(this.read):this.data.slice(this.read,this.read+a)},t.ByteStringBuffer.prototype.at=function(a){return this.data.charCodeAt(this.read+a)},t.ByteStringBuffer.prototype.setAt=function(a,l){return this.data=this.data.substr(0,this.read+a)+String.fromCharCode(l)+this.data.substr(this.read+a+1),this},t.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)},t.ByteStringBuffer.prototype.copy=function(){var a=t.createBuffer(this.data);return a.read=this.read,a},t.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this},t.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this},t.ByteStringBuffer.prototype.truncate=function(a){var l=Math.max(0,this.length()-a);return this.data=this.data.substr(this.read,l),this.read=0,this},t.ByteStringBuffer.prototype.toHex=function(){for(var a="",l=this.read;l<this.data.length;++l){var h=this.data.charCodeAt(l);h<16&&(a+="0"),a+=h.toString(16)}return a},t.ByteStringBuffer.prototype.toString=function(){return t.decodeUtf8(this.bytes())};function s(a,l){l=l||{},this.read=l.readOffset||0,this.growSize=l.growSize||1024;var h=t.isArrayBuffer(a),A=t.isArrayBufferView(a);if(h||A){h?this.data=new DataView(a):this.data=new DataView(a.buffer,a.byteOffset,a.byteLength),this.write="writeOffset"in l?l.writeOffset:this.data.byteLength;return}this.data=new DataView(new ArrayBuffer(0)),this.write=0,a!=null&&this.putBytes(a),"writeOffset"in l&&(this.write=l.writeOffset)}t.DataBuffer=s,t.DataBuffer.prototype.length=function(){return this.write-this.read},t.DataBuffer.prototype.isEmpty=function(){return this.length()<=0},t.DataBuffer.prototype.accommodate=function(a,l){if(this.length()>=a)return this;l=Math.max(l||this.growSize,a);var h=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),A=new Uint8Array(this.length()+l);return A.set(h),this.data=new DataView(A.buffer),this},t.DataBuffer.prototype.putByte=function(a){return this.accommodate(1),this.data.setUint8(this.write++,a),this},t.DataBuffer.prototype.fillWithByte=function(a,l){this.accommodate(l);for(var h=0;h<l;++h)this.data.setUint8(a);return this},t.DataBuffer.prototype.putBytes=function(a,l){if(t.isArrayBufferView(a)){var h=new Uint8Array(a.buffer,a.byteOffset,a.byteLength),A=h.byteLength-h.byteOffset;this.accommodate(A);var b=new Uint8Array(this.data.buffer,this.write);return b.set(h),this.write+=A,this}if(t.isArrayBuffer(a)){var h=new Uint8Array(a);this.accommodate(h.byteLength);var b=new Uint8Array(this.data.buffer);return b.set(h,this.write),this.write+=h.byteLength,this}if(a instanceof t.DataBuffer||typeof a=="object"&&typeof a.read=="number"&&typeof a.write=="number"&&t.isArrayBufferView(a.data)){var h=new Uint8Array(a.data.byteLength,a.read,a.length());this.accommodate(h.byteLength);var b=new Uint8Array(a.data.byteLength,this.write);return b.set(h),this.write+=h.byteLength,this}if(a instanceof t.ByteStringBuffer&&(a=a.data,l="binary"),l=l||"binary",typeof a=="string"){var n;if(l==="hex")return this.accommodate(Math.ceil(a.length/2)),n=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.hex.decode(a,n,this.write),this;if(l==="base64")return this.accommodate(Math.ceil(a.length/4)*3),n=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.base64.decode(a,n,this.write),this;if(l==="utf8"&&(a=t.encodeUtf8(a),l="binary"),l==="binary"||l==="raw")return this.accommodate(a.length),n=new Uint8Array(this.data.buffer,this.write),this.write+=t.binary.raw.decode(n),this;if(l==="utf16")return this.accommodate(a.length*2),n=new Uint16Array(this.data.buffer,this.write),this.write+=t.text.utf16.encode(n),this;throw new Error("Invalid encoding: "+l)}throw Error("Invalid parameter: "+a)},t.DataBuffer.prototype.putBuffer=function(a){return this.putBytes(a),a.clear(),this},t.DataBuffer.prototype.putString=function(a){return this.putBytes(a,"utf16")},t.DataBuffer.prototype.putInt16=function(a){return this.accommodate(2),this.data.setInt16(this.write,a),this.write+=2,this},t.DataBuffer.prototype.putInt24=function(a){return this.accommodate(3),this.data.setInt16(this.write,a>>8&65535),this.data.setInt8(this.write,a>>16&255),this.write+=3,this},t.DataBuffer.prototype.putInt32=function(a){return this.accommodate(4),this.data.setInt32(this.write,a),this.write+=4,this},t.DataBuffer.prototype.putInt16Le=function(a){return this.accommodate(2),this.data.setInt16(this.write,a,!0),this.write+=2,this},t.DataBuffer.prototype.putInt24Le=function(a){return this.accommodate(3),this.data.setInt8(this.write,a>>16&255),this.data.setInt16(this.write,a>>8&65535,!0),this.write+=3,this},t.DataBuffer.prototype.putInt32Le=function(a){return this.accommodate(4),this.data.setInt32(this.write,a,!0),this.write+=4,this},t.DataBuffer.prototype.putInt=function(a,l){u(l),this.accommodate(l/8);do l-=8,this.data.setInt8(this.write++,a>>l&255);while(l>0);return this},t.DataBuffer.prototype.putSignedInt=function(a,l){return u(l),this.accommodate(l/8),a<0&&(a+=2<<l-1),this.putInt(a,l)},t.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)},t.DataBuffer.prototype.getInt16=function(){var a=this.data.getInt16(this.read);return this.read+=2,a},t.DataBuffer.prototype.getInt24=function(){var a=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,a},t.DataBuffer.prototype.getInt32=function(){var a=this.data.getInt32(this.read);return this.read+=4,a},t.DataBuffer.prototype.getInt16Le=function(){var a=this.data.getInt16(this.read,!0);return this.read+=2,a},t.DataBuffer.prototype.getInt24Le=function(){var a=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,a},t.DataBuffer.prototype.getInt32Le=function(){var a=this.data.getInt32(this.read,!0);return this.read+=4,a},t.DataBuffer.prototype.getInt=function(a){u(a);var l=0;do l=(l<<8)+this.data.getInt8(this.read++),a-=8;while(a>0);return l},t.DataBuffer.prototype.getSignedInt=function(a){var l=this.getInt(a),h=2<<a-2;return l>=h&&(l-=h<<1),l},t.DataBuffer.prototype.getBytes=function(a){var l;return a?(a=Math.min(this.length(),a),l=this.data.slice(this.read,this.read+a),this.read+=a):a===0?l="":(l=this.read===0?this.data:this.data.slice(this.read),this.clear()),l},t.DataBuffer.prototype.bytes=function(a){return typeof a=="undefined"?this.data.slice(this.read):this.data.slice(this.read,this.read+a)},t.DataBuffer.prototype.at=function(a){return this.data.getUint8(this.read+a)},t.DataBuffer.prototype.setAt=function(a,l){return this.data.setUint8(a,l),this},t.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)},t.DataBuffer.prototype.copy=function(){return new t.DataBuffer(this)},t.DataBuffer.prototype.compact=function(){if(this.read>0){var a=new Uint8Array(this.data.buffer,this.read),l=new Uint8Array(a.byteLength);l.set(a),this.data=new DataView(l),this.write-=this.read,this.read=0}return this},t.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this},t.DataBuffer.prototype.truncate=function(a){return this.write=Math.max(0,this.length()-a),this.read=Math.min(this.read,this.write),this},t.DataBuffer.prototype.toHex=function(){for(var a="",l=this.read;l<this.data.byteLength;++l){var h=this.data.getUint8(l);h<16&&(a+="0"),a+=h.toString(16)}return a},t.DataBuffer.prototype.toString=function(a){var l=new Uint8Array(this.data,this.read,this.length());if(a=a||"utf8",a==="binary"||a==="raw")return t.binary.raw.encode(l);if(a==="hex")return t.binary.hex.encode(l);if(a==="base64")return t.binary.base64.encode(l);if(a==="utf8")return t.text.utf8.decode(l);if(a==="utf16")return t.text.utf16.decode(l);throw new Error("Invalid encoding: "+a)},t.createBuffer=function(a,l){return l=l||"raw",a!==void 0&&l==="utf8"&&(a=t.encodeUtf8(a)),new t.ByteBuffer(a)},t.fillString=function(a,l){for(var h="";l>0;)l&1&&(h+=a),l>>>=1,l>0&&(a+=a);return h},t.xorBytes=function(a,l,h){for(var A="",b="",n="",r=0,f=0;h>0;--h,++r)b=a.charCodeAt(r)^l.charCodeAt(r),f>=10&&(A+=n,n="",f=0),n+=String.fromCharCode(b),++f;return A+=n,A},t.hexToBytes=function(a){var l="",h=0;for(a.length&!0&&(h=1,l+=String.fromCharCode(parseInt(a[0],16)));h<a.length;h+=2)l+=String.fromCharCode(parseInt(a.substr(h,2),16));return l},t.bytesToHex=function(a){return t.createBuffer(a).toHex()},t.int32ToBytes=function(a){return String.fromCharCode(a>>24&255)+String.fromCharCode(a>>16&255)+String.fromCharCode(a>>8&255)+String.fromCharCode(a&255)};var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],c="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";t.encode64=function(a,l){for(var h="",A="",b,n,r,f=0;f<a.length;)b=a.charCodeAt(f++),n=a.charCodeAt(f++),r=a.charCodeAt(f++),h+=o.charAt(b>>2),h+=o.charAt((b&3)<<4|n>>4),isNaN(n)?h+="==":(h+=o.charAt((n&15)<<2|r>>6),h+=isNaN(r)?"=":o.charAt(r&63)),l&&h.length>l&&(A+=h.substr(0,l)+`\r
|
|
3
3
|
`,h=h.substr(l));return A+=h,A},t.decode64=function(a){a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var l="",h,A,b,n,r=0;r<a.length;)h=d[a.charCodeAt(r++)-43],A=d[a.charCodeAt(r++)-43],b=d[a.charCodeAt(r++)-43],n=d[a.charCodeAt(r++)-43],l+=String.fromCharCode(h<<2|A>>4),b!==64&&(l+=String.fromCharCode((A&15)<<4|b>>2),n!==64&&(l+=String.fromCharCode((b&3)<<6|n)));return l},t.encodeUtf8=function(a){return unescape(encodeURIComponent(a))},t.decodeUtf8=function(a){return decodeURIComponent(escape(a))},t.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:e.encode,decode:e.decode}},t.binary.raw.encode=function(a){return String.fromCharCode.apply(null,a)},t.binary.raw.decode=function(a,l,h){var A=l;A||(A=new Uint8Array(a.length)),h=h||0;for(var b=h,n=0;n<a.length;++n)A[b++]=a.charCodeAt(n);return l?b-h:A},t.binary.hex.encode=t.bytesToHex,t.binary.hex.decode=function(a,l,h){var A=l;A||(A=new Uint8Array(Math.ceil(a.length/2))),h=h||0;var b=0,n=h;for(a.length&1&&(b=1,A[n++]=parseInt(a[0],16));b<a.length;b+=2)A[n++]=parseInt(a.substr(b,2),16);return l?n-h:A},t.binary.base64.encode=function(a,l){for(var h="",A="",b,n,r,f=0;f<a.byteLength;)b=a[f++],n=a[f++],r=a[f++],h+=o.charAt(b>>2),h+=o.charAt((b&3)<<4|n>>4),isNaN(n)?h+="==":(h+=o.charAt((n&15)<<2|r>>6),h+=isNaN(r)?"=":o.charAt(r&63)),l&&h.length>l&&(A+=h.substr(0,l)+`\r
|
|
4
|
-
`,h=h.substr(l));return A+=h,A},t.binary.base64.decode=function(a,l,h){var A=l;A||(A=new Uint8Array(Math.ceil(a.length/4)*3)),a=a.replace(/[^A-Za-z0-9\+\/\=]/g,""),h=h||0;for(var b,n,r,f,S=0,w=h;S<a.length;)b=d[a.charCodeAt(S++)-43],n=d[a.charCodeAt(S++)-43],r=d[a.charCodeAt(S++)-43],f=d[a.charCodeAt(S++)-43],A[w++]=b<<2|n>>4,r!==64&&(A[w++]=(n&15)<<4|r>>2,f!==64&&(A[w++]=(r&3)<<6|f));return l?w-h:A.subarray(0,w)},t.binary.base58.encode=function(a,l){return t.binary.baseN.encode(a,c,l)},t.binary.base58.decode=function(a,l){return t.binary.baseN.decode(a,c,l)},t.text={utf8:{},utf16:{}},t.text.utf8.encode=function(a,l,h){a=t.encodeUtf8(a);var A=l;A||(A=new Uint8Array(a.length)),h=h||0;for(var b=h,n=0;n<a.length;++n)A[b++]=a.charCodeAt(n);return l?b-h:A},t.text.utf8.decode=function(a){return t.decodeUtf8(String.fromCharCode.apply(null,a))},t.text.utf16.encode=function(a,l,h){var A=l;A||(A=new Uint8Array(a.length*2));var b=new Uint16Array(A.buffer);h=h||0;for(var n=h,r=h,f=0;f<a.length;++f)b[r++]=a.charCodeAt(f),n+=2;return l?n-h:A},t.text.utf16.decode=function(a){return String.fromCharCode.apply(null,new Uint16Array(a.buffer))},t.deflate=function(a,l,h){if(l=t.decode64(a.deflate(t.encode64(l)).rval),h){var A=2,b=l.charCodeAt(1);b&32&&(A=6),l=l.substring(A,l.length-4)}return l},t.inflate=function(a,l,h){var A=a.inflate(t.encode64(l)).rval;return A===null?null:t.decode64(A)};var T=function(a,l,h){if(!a)throw new Error("WebStorage not available.");var A;if(h===null?A=a.removeItem(l):(h=t.encode64(JSON.stringify(h)),A=a.setItem(l,h)),typeof A!="undefined"&&A.rval!==!0){var b=new Error(A.error.message);throw b.id=A.error.id,b.name=A.error.name,b}},R=function(a,l){if(!a)throw new Error("WebStorage not available.");var h=a.getItem(l);if(a.init)if(h.rval===null){if(h.error){var A=new Error(h.error.message);throw A.id=h.error.id,A.name=h.error.name,A}h=null}else h=h.rval;return h!==null&&(h=JSON.parse(t.decode64(h))),h},x=function(a,l,h,A){var b=R(a,l);b===null&&(b={}),b[h]=A,T(a,l,b)},y=function(a,l,h){var A=R(a,l);return A!==null&&(A=h in A?A[h]:null),A},E=function(a,l,h){var A=R(a,l);if(A!==null&&h in A){delete A[h];var b=!0;for(var n in A){b=!1;break}b&&(A=null),T(a,l,A)}},v=function(a,l){T(a,l,null)},m=function(a,l,h){var A=null;typeof h=="undefined"&&(h=["web","flash"]);var b,n=!1,r=null;for(var f in h){b=h[f];try{if(b==="flash"||b==="both"){if(l[0]===null)throw new Error("Flash local storage not available.");A=a.apply(this,l),n=b==="flash"}(b==="web"||b==="both")&&(l[0]=localStorage,A=a.apply(this,l),n=!0)}catch(S){r=S}if(n)break}if(!n)throw r;return A};return t.setItem=function(a,l,h,A,b){m(x,arguments,b)},t.getItem=function(a,l,h,A){return m(y,arguments,A)},t.removeItem=function(a,l,h,A){m(E,arguments,A)},t.clearItems=function(a,l,h){m(v,arguments,h)},t.isEmpty=function(a){for(var l in a)if(a.hasOwnProperty(l))return!1;return!0},t.format=function(a){for(var l=/%./g,h,A,b=0,n=[],r=0;h=l.exec(a);){A=a.substring(r,l.lastIndex-2),A.length>0&&n.push(A),r=l.lastIndex;var f=h[0][1];switch(f){case"s":case"o":b<arguments.length?n.push(arguments[b+++1]):n.push("<?>");break;case"%":n.push("%");break;default:n.push("<%"+f+"?>")}}return n.push(a.substring(r)),n.join("")},t.formatNumber=function(a,l,h,A){var b=a,n=isNaN(l=Math.abs(l))?2:l,r=h===void 0?",":h,f=A===void 0?".":A,S=b<0?"-":"",w=parseInt(b=Math.abs(+b||0).toFixed(n),10)+"",U=w.length>3?w.length%3:0;return S+(U?w.substr(0,U)+f:"")+w.substr(U).replace(/(\d{3})(?=\d)/g,"$1"+f)+(n?r+Math.abs(b-w).toFixed(n).slice(2):"")},t.formatSize=function(a){return a>=1073741824?a=t.formatNumber(a/1073741824,2,".","")+" GiB":a>=1048576?a=t.formatNumber(a/1048576,2,".","")+" MiB":a>=1024?a=t.formatNumber(a/1024,0)+" KiB":a=t.formatNumber(a,0)+" bytes",a},t.bytesFromIP=function(a){return a.indexOf(".")!==-1?t.bytesFromIPv4(a):a.indexOf(":")!==-1?t.bytesFromIPv6(a):null},t.bytesFromIPv4=function(a){if(a=a.split("."),a.length!==4)return null;for(var l=t.createBuffer(),h=0;h<a.length;++h){var A=parseInt(a[h],10);if(isNaN(A))return null;l.putByte(A)}return l.getBytes()},t.bytesFromIPv6=function(a){var l=0;a=a.split(":").filter(function(r){return r.length===0&&++l,!0});for(var h=(8-a.length+l)*2,A=t.createBuffer(),b=0;b<8;++b){if(!a[b]||a[b].length===0){A.fillWithByte(0,h),h=0;continue}var n=t.hexToBytes(a[b]);n.length<2&&A.putByte(0),A.putBytes(n)}return A.getBytes()},t.bytesToIP=function(a){return a.length===4?t.bytesToIPv4(a):a.length===16?t.bytesToIPv6(a):null},t.bytesToIPv4=function(a){if(a.length!==4)return null;for(var l=[],h=0;h<a.length;++h)l.push(a.charCodeAt(h));return l.join(".")},t.bytesToIPv6=function(a){if(a.length!==16)return null;for(var l=[],h=[],A=0,b=0;b<a.length;b+=2){for(var n=t.bytesToHex(a[b]+a[b+1]);n[0]==="0"&&n!=="0";)n=n.substr(1);if(n==="0"){var r=h[h.length-1],f=l.length;!r||f!==r.end+1?h.push({start:f,end:f}):(r.end=f,r.end-r.start>h[A].end-h[A].start&&(A=h.length-1))}l.push(n)}if(h.length>0){var S=h[A];S.end-S.start>0&&(l.splice(S.start,S.end-S.start+1,""),S.start===0&&l.unshift(""),S.end===7&&l.push(""))}return l.join(":")},t.estimateCores=function(a,l){if(typeof a=="function"&&(l=a,a={}),a=a||{},"cores"in t&&!a.update)return l(null,t.cores);if(typeof navigator!="undefined"&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return t.cores=navigator.hardwareConcurrency,l(null,t.cores);if(typeof Worker=="undefined")return t.cores=1,l(null,t.cores);if(typeof Blob=="undefined")return t.cores=2,l(null,t.cores);var h=URL.createObjectURL(new Blob(["(",function(){self.addEventListener("message",function(r){var f=Date.now(),S=f+4;self.postMessage({st:f,et:S})})}.toString(),")()"],{type:"application/javascript"}));A([],5,16);function A(r,f,S){if(f===0){var w=Math.floor(r.reduce(function(U,N){return U+N},0)/r.length);return t.cores=Math.max(1,w),URL.revokeObjectURL(h),l(null,t.cores)}b(S,function(U,N){r.push(n(S,N)),A(r,f-1,S)})}function b(r,f){for(var S=[],w=[],U=0;U<r;++U){var N=new Worker(h);N.addEventListener("message",function(L){if(w.push(L.data),w.length===r){for(var P=0;P<r;++P)S[P].terminate();f(null,w)}}),S.push(N)}for(var U=0;U<r;++U)S[U].postMessage(U)}function n(r,f){for(var S=[],w=0;w<r;++w)for(var U=f[w],N=S[w]=[],L=0;L<r;++L)if(w!==L){var P=f[L];(U.st>P.st&&U.st<P.et||P.st>U.st&&P.st<U.et)&&N.push(L)}return S.reduce(function(_,k){return Math.max(_,k.length)},0)}},be.exports}var Re={exports:{}},lt;function he(){if(lt)return Re.exports;lt=1;var i=H();i.pki=i.pki||{};var e=Re.exports=i.pki.oids=i.oids=i.oids||{};function t(I,g){e[I]=g,e[g]=I}function u(I,g){e[I]=g}return t("1.2.840.113549.1.1.1","rsaEncryption"),t("1.2.840.113549.1.1.4","md5WithRSAEncryption"),t("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),t("1.2.840.113549.1.1.7","RSAES-OAEP"),t("1.2.840.113549.1.1.8","mgf1"),t("1.2.840.113549.1.1.9","pSpecified"),t("1.2.840.113549.1.1.10","RSASSA-PSS"),t("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),t("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),t("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),t("1.3.101.112","EdDSA25519"),t("1.2.840.10040.4.3","dsa-with-sha1"),t("1.3.14.3.2.7","desCBC"),t("1.3.14.3.2.26","sha1"),t("1.3.14.3.2.29","sha1WithRSASignature"),t("2.16.840.1.101.3.4.2.1","sha256"),t("2.16.840.1.101.3.4.2.2","sha384"),t("2.16.840.1.101.3.4.2.3","sha512"),t("2.16.840.1.101.3.4.2.4","sha224"),t("2.16.840.1.101.3.4.2.5","sha512-224"),t("2.16.840.1.101.3.4.2.6","sha512-256"),t("1.2.840.113549.2.2","md2"),t("1.2.840.113549.2.5","md5"),t("1.2.840.113549.1.7.1","data"),t("1.2.840.113549.1.7.2","signedData"),t("1.2.840.113549.1.7.3","envelopedData"),t("1.2.840.113549.1.7.4","signedAndEnvelopedData"),t("1.2.840.113549.1.7.5","digestedData"),t("1.2.840.113549.1.7.6","encryptedData"),t("1.2.840.113549.1.9.1","emailAddress"),t("1.2.840.113549.1.9.2","unstructuredName"),t("1.2.840.113549.1.9.3","contentType"),t("1.2.840.113549.1.9.4","messageDigest"),t("1.2.840.113549.1.9.5","signingTime"),t("1.2.840.113549.1.9.6","counterSignature"),t("1.2.840.113549.1.9.7","challengePassword"),t("1.2.840.113549.1.9.8","unstructuredAddress"),t("1.2.840.113549.1.9.14","extensionRequest"),t("1.2.840.113549.1.9.20","friendlyName"),t("1.2.840.113549.1.9.21","localKeyId"),t("1.2.840.113549.1.9.22.1","x509Certificate"),t("1.2.840.113549.1.12.10.1.1","keyBag"),t("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),t("1.2.840.113549.1.12.10.1.3","certBag"),t("1.2.840.113549.1.12.10.1.4","crlBag"),t("1.2.840.113549.1.12.10.1.5","secretBag"),t("1.2.840.113549.1.12.10.1.6","safeContentsBag"),t("1.2.840.113549.1.5.13","pkcs5PBES2"),t("1.2.840.113549.1.5.12","pkcs5PBKDF2"),t("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),t("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),t("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),t("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),t("1.2.840.113549.2.7","hmacWithSHA1"),t("1.2.840.113549.2.8","hmacWithSHA224"),t("1.2.840.113549.2.9","hmacWithSHA256"),t("1.2.840.113549.2.10","hmacWithSHA384"),t("1.2.840.113549.2.11","hmacWithSHA512"),t("1.2.840.113549.3.7","des-EDE3-CBC"),t("2.16.840.1.101.3.4.1.2","aes128-CBC"),t("2.16.840.1.101.3.4.1.22","aes192-CBC"),t("2.16.840.1.101.3.4.1.42","aes256-CBC"),t("2.5.4.3","commonName"),t("2.5.4.4","surname"),t("2.5.4.5","serialNumber"),t("2.5.4.6","countryName"),t("2.5.4.7","localityName"),t("2.5.4.8","stateOrProvinceName"),t("2.5.4.9","streetAddress"),t("2.5.4.10","organizationName"),t("2.5.4.11","organizationalUnitName"),t("2.5.4.12","title"),t("2.5.4.13","description"),t("2.5.4.15","businessCategory"),t("2.5.4.17","postalCode"),t("2.5.4.42","givenName"),t("2.5.4.65","pseudonym"),t("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),t("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),t("2.16.840.1.113730.1.1","nsCertType"),t("2.16.840.1.113730.1.13","nsComment"),u("2.5.29.1","authorityKeyIdentifier"),u("2.5.29.2","keyAttributes"),u("2.5.29.3","certificatePolicies"),u("2.5.29.4","keyUsageRestriction"),u("2.5.29.5","policyMapping"),u("2.5.29.6","subtreesConstraint"),u("2.5.29.7","subjectAltName"),u("2.5.29.8","issuerAltName"),u("2.5.29.9","subjectDirectoryAttributes"),u("2.5.29.10","basicConstraints"),u("2.5.29.11","nameConstraints"),u("2.5.29.12","policyConstraints"),u("2.5.29.13","basicConstraints"),t("2.5.29.14","subjectKeyIdentifier"),t("2.5.29.15","keyUsage"),u("2.5.29.16","privateKeyUsagePeriod"),t("2.5.29.17","subjectAltName"),t("2.5.29.18","issuerAltName"),t("2.5.29.19","basicConstraints"),u("2.5.29.20","cRLNumber"),u("2.5.29.21","cRLReason"),u("2.5.29.22","expirationDate"),u("2.5.29.23","instructionCode"),u("2.5.29.24","invalidityDate"),u("2.5.29.25","cRLDistributionPoints"),u("2.5.29.26","issuingDistributionPoint"),u("2.5.29.27","deltaCRLIndicator"),u("2.5.29.28","issuingDistributionPoint"),u("2.5.29.29","certificateIssuer"),u("2.5.29.30","nameConstraints"),t("2.5.29.31","cRLDistributionPoints"),t("2.5.29.32","certificatePolicies"),u("2.5.29.33","policyMappings"),u("2.5.29.34","policyConstraints"),t("2.5.29.35","authorityKeyIdentifier"),u("2.5.29.36","policyConstraints"),t("2.5.29.37","extKeyUsage"),u("2.5.29.46","freshestCRL"),u("2.5.29.54","inhibitAnyPolicy"),t("1.3.6.1.4.1.11129.2.4.2","timestampList"),t("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),t("1.3.6.1.5.5.7.3.1","serverAuth"),t("1.3.6.1.5.5.7.3.2","clientAuth"),t("1.3.6.1.5.5.7.3.3","codeSigning"),t("1.3.6.1.5.5.7.3.4","emailProtection"),t("1.3.6.1.5.5.7.3.8","timeStamping"),Re.exports}var ct;function ce(){if(ct)return Ae.exports;ct=1;var i=H();X(),he();var e=Ae.exports=i.asn1=i.asn1||{};e.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},e.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},e.maxDepth=256,e.create=function(s,o,d,c,T){if(i.util.isArray(c)){for(var R=[],x=0;x<c.length;++x)c[x]!==void 0&&R.push(c[x]);c=R}var y={tagClass:s,type:o,constructed:d,composed:d||i.util.isArray(c),value:c};return T&&"bitStringContents"in T&&(y.bitStringContents=T.bitStringContents,y.original=e.copy(y)),y},e.copy=function(s,o){var d;if(i.util.isArray(s)){d=[];for(var c=0;c<s.length;++c)d.push(e.copy(s[c],o));return d}return typeof s=="string"?s:(d={tagClass:s.tagClass,type:s.type,constructed:s.constructed,composed:s.composed,value:e.copy(s.value,o)},o&&!o.excludeBitStringContents&&(d.bitStringContents=s.bitStringContents),d)},e.equals=function(s,o,d){if(i.util.isArray(s)){if(!i.util.isArray(o)||s.length!==o.length)return!1;for(var c=0;c<s.length;++c)if(!e.equals(s[c],o[c]))return!1;return!0}if(typeof s!=typeof o)return!1;if(typeof s=="string")return s===o;var T=s.tagClass===o.tagClass&&s.type===o.type&&s.constructed===o.constructed&&s.composed===o.composed&&e.equals(s.value,o.value);return d&&d.includeBitStringContents&&(T=T&&s.bitStringContents===o.bitStringContents),T},e.getBerValueLength=function(s){var o=s.getByte();if(o!==128){var d,c=o&128;return c?d=s.getInt((o&127)<<3):d=o,d}};function t(s,o,d){if(d>o){var c=new Error("Too few bytes to parse DER.");throw c.available=s.length(),c.remaining=o,c.requested=d,c}}var u=function(s,o){var d=s.getByte();if(o--,d!==128){var c,T=d&128;if(!T)c=d;else{var R=d&127;t(s,o,R),c=s.getInt(R<<3)}if(c<0)throw new Error("Negative length: "+c);return c}};e.fromDer=function(s,o){o===void 0&&(o={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),typeof o=="boolean"&&(o={strict:o,parseAllBytes:!0,decodeBitStrings:!0}),"strict"in o||(o.strict=!0),"parseAllBytes"in o||(o.parseAllBytes=!0),"decodeBitStrings"in o||(o.decodeBitStrings=!0),"maxDepth"in o||(o.maxDepth=e.maxDepth),typeof s=="string"&&(s=i.util.createBuffer(s));var d=s.length(),c=I(s,s.length(),0,o);if(o.parseAllBytes&&s.length()!==0){var T=new Error("Unparsed DER bytes remain after ASN.1 parsing.");throw T.byteCount=d,T.remaining=s.length(),T}return c};function I(s,o,d,c){if(d>=c.maxDepth)throw new Error("ASN.1 parsing error: Max depth exceeded.");var T;t(s,o,2);var R=s.getByte();o--;var x=R&192,y=R&31;T=s.length();var E=u(s,o);if(o-=T-s.length(),E!==void 0&&E>o){if(c.strict){var v=new Error("Too few bytes to read ASN.1 value.");throw v.available=s.length(),v.remaining=o,v.requested=E,v}E=o}var m,a,l=(R&32)===32;if(l)if(m=[],E===void 0)for(;;){if(t(s,o,2),s.bytes(2)==="\0\0"){s.getBytes(2),o-=2;break}T=s.length(),m.push(I(s,o,d+1,c)),o-=T-s.length()}else for(;E>0;)T=s.length(),m.push(I(s,E,d+1,c)),o-=T-s.length(),E-=T-s.length();if(m===void 0&&x===e.Class.UNIVERSAL&&y===e.Type.BITSTRING&&(a=s.bytes(E)),m===void 0&&c.decodeBitStrings&&x===e.Class.UNIVERSAL&&y===e.Type.BITSTRING&&E>1){var h=s.read,A=o,b=0;if(y===e.Type.BITSTRING&&(t(s,o,1),b=s.getByte(),o--),b===0)try{T=s.length();var n={strict:!0,decodeBitStrings:!0},r=I(s,o,d+1,n),f=T-s.length();o-=f,y==e.Type.BITSTRING&&f++;var S=r.tagClass;f===E&&(S===e.Class.UNIVERSAL||S===e.Class.CONTEXT_SPECIFIC)&&(m=[r])}catch(U){}m===void 0&&(s.read=h,o=A)}if(m===void 0){if(E===void 0){if(c.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");E=o}if(y===e.Type.BMPSTRING)for(m="";E>0;E-=2)t(s,o,2),m+=String.fromCharCode(s.getInt16()),o-=2;else m=s.getBytes(E),o-=E}var w=a===void 0?null:{bitStringContents:a};return e.create(x,y,l,m,w)}e.toDer=function(s){var o=i.util.createBuffer(),d=s.tagClass|s.type,c=i.util.createBuffer(),T=!1;if("bitStringContents"in s&&(T=!0,s.original&&(T=e.equals(s,s.original))),T)c.putBytes(s.bitStringContents);else if(s.composed){s.constructed?d|=32:c.putByte(0);for(var R=0;R<s.value.length;++R)s.value[R]!==void 0&&c.putBuffer(e.toDer(s.value[R]))}else if(s.type===e.Type.BMPSTRING)for(var R=0;R<s.value.length;++R)c.putInt16(s.value.charCodeAt(R));else s.type===e.Type.INTEGER&&s.value.length>1&&(s.value.charCodeAt(0)===0&&(s.value.charCodeAt(1)&128)===0||s.value.charCodeAt(0)===255&&(s.value.charCodeAt(1)&128)===128)?c.putBytes(s.value.substr(1)):c.putBytes(s.value);if(o.putByte(d),c.length()<=127)o.putByte(c.length()&127);else{var x=c.length(),y="";do y+=String.fromCharCode(x&255),x=x>>>8;while(x>0);o.putByte(y.length|128);for(var R=y.length-1;R>=0;--R)o.putByte(y.charCodeAt(R))}return o.putBuffer(c),o},e.oidToDer=function(s){var o=s.split("."),d=i.util.createBuffer();d.putByte(40*parseInt(o[0],10)+parseInt(o[1],10));for(var c,T,R,x,y=2;y<o.length;++y){if(c=!0,T=[],R=parseInt(o[y],10),R>4294967295)throw new Error("OID value too large; max is 32-bits.");do x=R&127,R=R>>>7,c||(x|=128),T.push(x),c=!1;while(R>0);for(var E=T.length-1;E>=0;--E)d.putByte(T[E])}return d},e.derToOid=function(s){var o;typeof s=="string"&&(s=i.util.createBuffer(s));var d=s.getByte();o=Math.floor(d/40)+"."+d%40;for(var c=0;s.length()>0;){if(c>70368744177663)throw new Error("OID value too large; max is 53-bits.");d=s.getByte(),c=c*128,d&128?c+=d&127:(o+="."+(c+d),c=0)}return o},e.utcTimeToDate=function(s){var o=new Date,d=parseInt(s.substr(0,2),10);d=d>=50?1900+d:2e3+d;var c=parseInt(s.substr(2,2),10)-1,T=parseInt(s.substr(4,2),10),R=parseInt(s.substr(6,2),10),x=parseInt(s.substr(8,2),10),y=0;if(s.length>11){var E=s.charAt(10),v=10;E!=="+"&&E!=="-"&&(y=parseInt(s.substr(10,2),10),v+=2)}if(o.setUTCFullYear(d,c,T),o.setUTCHours(R,x,y,0),v&&(E=s.charAt(v),E==="+"||E==="-")){var m=parseInt(s.substr(v+1,2),10),a=parseInt(s.substr(v+4,2),10),l=m*60+a;l*=6e4,E==="+"?o.setTime(+o-l):o.setTime(+o+l)}return o},e.generalizedTimeToDate=function(s){var o=new Date,d=parseInt(s.substr(0,4),10),c=parseInt(s.substr(4,2),10)-1,T=parseInt(s.substr(6,2),10),R=parseInt(s.substr(8,2),10),x=parseInt(s.substr(10,2),10),y=parseInt(s.substr(12,2),10),E=0,v=0,m=!1;s.charAt(s.length-1)==="Z"&&(m=!0);var a=s.length-5,l=s.charAt(a);if(l==="+"||l==="-"){var h=parseInt(s.substr(a+1,2),10),A=parseInt(s.substr(a+4,2),10);v=h*60+A,v*=6e4,l==="+"&&(v*=-1),m=!0}return s.charAt(14)==="."&&(E=parseFloat(s.substr(14),10)*1e3),m?(o.setUTCFullYear(d,c,T),o.setUTCHours(R,x,y,E),o.setTime(+o+v)):(o.setFullYear(d,c,T),o.setHours(R,x,y,E)),o},e.dateToUtcTime=function(s){if(typeof s=="string")return s;var o="",d=[];d.push((""+s.getUTCFullYear()).substr(2)),d.push(""+(s.getUTCMonth()+1)),d.push(""+s.getUTCDate()),d.push(""+s.getUTCHours()),d.push(""+s.getUTCMinutes()),d.push(""+s.getUTCSeconds());for(var c=0;c<d.length;++c)d[c].length<2&&(o+="0"),o+=d[c];return o+="Z",o},e.dateToGeneralizedTime=function(s){if(typeof s=="string")return s;var o="",d=[];d.push(""+s.getUTCFullYear()),d.push(""+(s.getUTCMonth()+1)),d.push(""+s.getUTCDate()),d.push(""+s.getUTCHours()),d.push(""+s.getUTCMinutes()),d.push(""+s.getUTCSeconds());for(var c=0;c<d.length;++c)d[c].length<2&&(o+="0"),o+=d[c];return o+="Z",o},e.integerToDer=function(s){var o=i.util.createBuffer();if(s>=-128&&s<128)return o.putSignedInt(s,8);if(s>=-32768&&s<32768)return o.putSignedInt(s,16);if(s>=-8388608&&s<8388608)return o.putSignedInt(s,24);if(s>=-2147483648&&s<2147483648)return o.putSignedInt(s,32);var d=new Error("Integer too large; max is 32-bits.");throw d.integer=s,d},e.derToInteger=function(s){typeof s=="string"&&(s=i.util.createBuffer(s));var o=s.length()*8;if(o>32)throw new Error("Integer too large; max is 32-bits.");return s.getSignedInt(o)},e.validate=function(s,o,d,c){var T=!1;if((s.tagClass===o.tagClass||typeof o.tagClass=="undefined")&&(s.type===o.type||typeof o.type=="undefined"))if(s.constructed===o.constructed||typeof o.constructed=="undefined"){if(T=!0,o.value&&i.util.isArray(o.value))for(var R=0,x=0;T&&x<o.value.length;++x){var y=o.value[x];T=!!y.optional;var E=s.value[R];if(!E){y.optional||(T=!1,c&&c.push("["+o.name+'] Missing required element. Expected tag class "'+y.tagClass+'", type "'+y.type+'"'));continue}var v=typeof y.tagClass!="undefined"&&typeof y.type!="undefined";if(v&&(E.tagClass!==y.tagClass||E.type!==y.type))if(y.optional){T=!0;continue}else{T=!1,c&&c.push("["+o.name+"] Tag mismatch. Expected ("+y.tagClass+","+y.type+"), got ("+E.tagClass+","+E.type+")");break}var m=e.validate(E,y,d,c);if(m)++R,T=!0;else if(y.optional)T=!0;else{T=!1;break}}if(T&&d&&(o.capture&&(d[o.capture]=s.value),o.captureAsn1&&(d[o.captureAsn1]=s),o.captureBitStringContents&&"bitStringContents"in s&&(d[o.captureBitStringContents]=s.bitStringContents),o.captureBitStringValue&&"bitStringContents"in s))if(s.bitStringContents.length<2)d[o.captureBitStringValue]="";else{var a=s.bitStringContents.charCodeAt(0);if(a!==0)throw new Error("captureBitStringValue only supported for zero unused bits");d[o.captureBitStringValue]=s.bitStringContents.slice(1)}}else c&&c.push("["+o.name+'] Expected constructed "'+o.constructed+'", got "'+s.constructed+'"');else c&&(s.tagClass!==o.tagClass&&c.push("["+o.name+'] Expected tag class "'+o.tagClass+'", got "'+s.tagClass+'"'),s.type!==o.type&&c.push("["+o.name+'] Expected type "'+o.type+'", got "'+s.type+'"'));return T};var g=/[^\\u0000-\\u00ff]/;return e.prettyPrint=function(s,o,d){var c="";o=o||0,d=d||2,o>0&&(c+=`
|
|
4
|
+
`,h=h.substr(l));return A+=h,A},t.binary.base64.decode=function(a,l,h){var A=l;A||(A=new Uint8Array(Math.ceil(a.length/4)*3)),a=a.replace(/[^A-Za-z0-9\+\/\=]/g,""),h=h||0;for(var b,n,r,f,S=0,w=h;S<a.length;)b=d[a.charCodeAt(S++)-43],n=d[a.charCodeAt(S++)-43],r=d[a.charCodeAt(S++)-43],f=d[a.charCodeAt(S++)-43],A[w++]=b<<2|n>>4,r!==64&&(A[w++]=(n&15)<<4|r>>2,f!==64&&(A[w++]=(r&3)<<6|f));return l?w-h:A.subarray(0,w)},t.binary.base58.encode=function(a,l){return t.binary.baseN.encode(a,c,l)},t.binary.base58.decode=function(a,l){return t.binary.baseN.decode(a,c,l)},t.text={utf8:{},utf16:{}},t.text.utf8.encode=function(a,l,h){a=t.encodeUtf8(a);var A=l;A||(A=new Uint8Array(a.length)),h=h||0;for(var b=h,n=0;n<a.length;++n)A[b++]=a.charCodeAt(n);return l?b-h:A},t.text.utf8.decode=function(a){return t.decodeUtf8(String.fromCharCode.apply(null,a))},t.text.utf16.encode=function(a,l,h){var A=l;A||(A=new Uint8Array(a.length*2));var b=new Uint16Array(A.buffer);h=h||0;for(var n=h,r=h,f=0;f<a.length;++f)b[r++]=a.charCodeAt(f),n+=2;return l?n-h:A},t.text.utf16.decode=function(a){return String.fromCharCode.apply(null,new Uint16Array(a.buffer))},t.deflate=function(a,l,h){if(l=t.decode64(a.deflate(t.encode64(l)).rval),h){var A=2,b=l.charCodeAt(1);b&32&&(A=6),l=l.substring(A,l.length-4)}return l},t.inflate=function(a,l,h){var A=a.inflate(t.encode64(l)).rval;return A===null?null:t.decode64(A)};var T=function(a,l,h){if(!a)throw new Error("WebStorage not available.");var A;if(h===null?A=a.removeItem(l):(h=t.encode64(JSON.stringify(h)),A=a.setItem(l,h)),typeof A!="undefined"&&A.rval!==!0){var b=new Error(A.error.message);throw b.id=A.error.id,b.name=A.error.name,b}},R=function(a,l){if(!a)throw new Error("WebStorage not available.");var h=a.getItem(l);if(a.init)if(h.rval===null){if(h.error){var A=new Error(h.error.message);throw A.id=h.error.id,A.name=h.error.name,A}h=null}else h=h.rval;return h!==null&&(h=JSON.parse(t.decode64(h))),h},x=function(a,l,h,A){var b=R(a,l);b===null&&(b={}),b[h]=A,T(a,l,b)},y=function(a,l,h){var A=R(a,l);return A!==null&&(A=h in A?A[h]:null),A},E=function(a,l,h){var A=R(a,l);if(A!==null&&h in A){delete A[h];var b=!0;for(var n in A){b=!1;break}b&&(A=null),T(a,l,A)}},v=function(a,l){T(a,l,null)},m=function(a,l,h){var A=null;typeof h=="undefined"&&(h=["web","flash"]);var b,n=!1,r=null;for(var f in h){b=h[f];try{if(b==="flash"||b==="both"){if(l[0]===null)throw new Error("Flash local storage not available.");A=a.apply(this,l),n=b==="flash"}(b==="web"||b==="both")&&(l[0]=localStorage,A=a.apply(this,l),n=!0)}catch(S){r=S}if(n)break}if(!n)throw r;return A};return t.setItem=function(a,l,h,A,b){m(x,arguments,b)},t.getItem=function(a,l,h,A){return m(y,arguments,A)},t.removeItem=function(a,l,h,A){m(E,arguments,A)},t.clearItems=function(a,l,h){m(v,arguments,h)},t.isEmpty=function(a){for(var l in a)if(a.hasOwnProperty(l))return!1;return!0},t.format=function(a){for(var l=/%./g,h,A,b=0,n=[],r=0;h=l.exec(a);){A=a.substring(r,l.lastIndex-2),A.length>0&&n.push(A),r=l.lastIndex;var f=h[0][1];switch(f){case"s":case"o":b<arguments.length?n.push(arguments[b+++1]):n.push("<?>");break;case"%":n.push("%");break;default:n.push("<%"+f+"?>")}}return n.push(a.substring(r)),n.join("")},t.formatNumber=function(a,l,h,A){var b=a,n=isNaN(l=Math.abs(l))?2:l,r=h===void 0?",":h,f=A===void 0?".":A,S=b<0?"-":"",w=parseInt(b=Math.abs(+b||0).toFixed(n),10)+"",U=w.length>3?w.length%3:0;return S+(U?w.substr(0,U)+f:"")+w.substr(U).replace(/(\d{3})(?=\d)/g,"$1"+f)+(n?r+Math.abs(b-w).toFixed(n).slice(2):"")},t.formatSize=function(a){return a>=1073741824?a=t.formatNumber(a/1073741824,2,".","")+" GiB":a>=1048576?a=t.formatNumber(a/1048576,2,".","")+" MiB":a>=1024?a=t.formatNumber(a/1024,0)+" KiB":a=t.formatNumber(a,0)+" bytes",a},t.bytesFromIP=function(a){return a.indexOf(".")!==-1?t.bytesFromIPv4(a):a.indexOf(":")!==-1?t.bytesFromIPv6(a):null},t.bytesFromIPv4=function(a){if(a=a.split("."),a.length!==4)return null;for(var l=t.createBuffer(),h=0;h<a.length;++h){var A=parseInt(a[h],10);if(isNaN(A))return null;l.putByte(A)}return l.getBytes()},t.bytesFromIPv6=function(a){var l=0;a=a.split(":").filter(function(r){return r.length===0&&++l,!0});for(var h=(8-a.length+l)*2,A=t.createBuffer(),b=0;b<8;++b){if(!a[b]||a[b].length===0){A.fillWithByte(0,h),h=0;continue}var n=t.hexToBytes(a[b]);n.length<2&&A.putByte(0),A.putBytes(n)}return A.getBytes()},t.bytesToIP=function(a){return a.length===4?t.bytesToIPv4(a):a.length===16?t.bytesToIPv6(a):null},t.bytesToIPv4=function(a){if(a.length!==4)return null;for(var l=[],h=0;h<a.length;++h)l.push(a.charCodeAt(h));return l.join(".")},t.bytesToIPv6=function(a){if(a.length!==16)return null;for(var l=[],h=[],A=0,b=0;b<a.length;b+=2){for(var n=t.bytesToHex(a[b]+a[b+1]);n[0]==="0"&&n!=="0";)n=n.substr(1);if(n==="0"){var r=h[h.length-1],f=l.length;!r||f!==r.end+1?h.push({start:f,end:f}):(r.end=f,r.end-r.start>h[A].end-h[A].start&&(A=h.length-1))}l.push(n)}if(h.length>0){var S=h[A];S.end-S.start>0&&(l.splice(S.start,S.end-S.start+1,""),S.start===0&&l.unshift(""),S.end===7&&l.push(""))}return l.join(":")},t.estimateCores=function(a,l){if(typeof a=="function"&&(l=a,a={}),a=a||{},"cores"in t&&!a.update)return l(null,t.cores);if(typeof navigator!="undefined"&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return t.cores=navigator.hardwareConcurrency,l(null,t.cores);if(typeof Worker=="undefined")return t.cores=1,l(null,t.cores);if(typeof Blob=="undefined")return t.cores=2,l(null,t.cores);var h=URL.createObjectURL(new Blob(["(",(function(){self.addEventListener("message",function(r){var f=Date.now(),S=f+4;self.postMessage({st:f,et:S})})}).toString(),")()"],{type:"application/javascript"}));A([],5,16);function A(r,f,S){if(f===0){var w=Math.floor(r.reduce(function(U,N){return U+N},0)/r.length);return t.cores=Math.max(1,w),URL.revokeObjectURL(h),l(null,t.cores)}b(S,function(U,N){r.push(n(S,N)),A(r,f-1,S)})}function b(r,f){for(var S=[],w=[],U=0;U<r;++U){var N=new Worker(h);N.addEventListener("message",function(L){if(w.push(L.data),w.length===r){for(var P=0;P<r;++P)S[P].terminate();f(null,w)}}),S.push(N)}for(var U=0;U<r;++U)S[U].postMessage(U)}function n(r,f){for(var S=[],w=0;w<r;++w)for(var U=f[w],N=S[w]=[],L=0;L<r;++L)if(w!==L){var P=f[L];(U.st>P.st&&U.st<P.et||P.st>U.st&&P.st<U.et)&&N.push(L)}return S.reduce(function(_,k){return Math.max(_,k.length)},0)}},be.exports}var Re={exports:{}},lt;function he(){if(lt)return Re.exports;lt=1;var i=H();i.pki=i.pki||{};var e=Re.exports=i.pki.oids=i.oids=i.oids||{};function t(I,g){e[I]=g,e[g]=I}function u(I,g){e[I]=g}return t("1.2.840.113549.1.1.1","rsaEncryption"),t("1.2.840.113549.1.1.4","md5WithRSAEncryption"),t("1.2.840.113549.1.1.5","sha1WithRSAEncryption"),t("1.2.840.113549.1.1.7","RSAES-OAEP"),t("1.2.840.113549.1.1.8","mgf1"),t("1.2.840.113549.1.1.9","pSpecified"),t("1.2.840.113549.1.1.10","RSASSA-PSS"),t("1.2.840.113549.1.1.11","sha256WithRSAEncryption"),t("1.2.840.113549.1.1.12","sha384WithRSAEncryption"),t("1.2.840.113549.1.1.13","sha512WithRSAEncryption"),t("1.3.101.112","EdDSA25519"),t("1.2.840.10040.4.3","dsa-with-sha1"),t("1.3.14.3.2.7","desCBC"),t("1.3.14.3.2.26","sha1"),t("1.3.14.3.2.29","sha1WithRSASignature"),t("2.16.840.1.101.3.4.2.1","sha256"),t("2.16.840.1.101.3.4.2.2","sha384"),t("2.16.840.1.101.3.4.2.3","sha512"),t("2.16.840.1.101.3.4.2.4","sha224"),t("2.16.840.1.101.3.4.2.5","sha512-224"),t("2.16.840.1.101.3.4.2.6","sha512-256"),t("1.2.840.113549.2.2","md2"),t("1.2.840.113549.2.5","md5"),t("1.2.840.113549.1.7.1","data"),t("1.2.840.113549.1.7.2","signedData"),t("1.2.840.113549.1.7.3","envelopedData"),t("1.2.840.113549.1.7.4","signedAndEnvelopedData"),t("1.2.840.113549.1.7.5","digestedData"),t("1.2.840.113549.1.7.6","encryptedData"),t("1.2.840.113549.1.9.1","emailAddress"),t("1.2.840.113549.1.9.2","unstructuredName"),t("1.2.840.113549.1.9.3","contentType"),t("1.2.840.113549.1.9.4","messageDigest"),t("1.2.840.113549.1.9.5","signingTime"),t("1.2.840.113549.1.9.6","counterSignature"),t("1.2.840.113549.1.9.7","challengePassword"),t("1.2.840.113549.1.9.8","unstructuredAddress"),t("1.2.840.113549.1.9.14","extensionRequest"),t("1.2.840.113549.1.9.20","friendlyName"),t("1.2.840.113549.1.9.21","localKeyId"),t("1.2.840.113549.1.9.22.1","x509Certificate"),t("1.2.840.113549.1.12.10.1.1","keyBag"),t("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),t("1.2.840.113549.1.12.10.1.3","certBag"),t("1.2.840.113549.1.12.10.1.4","crlBag"),t("1.2.840.113549.1.12.10.1.5","secretBag"),t("1.2.840.113549.1.12.10.1.6","safeContentsBag"),t("1.2.840.113549.1.5.13","pkcs5PBES2"),t("1.2.840.113549.1.5.12","pkcs5PBKDF2"),t("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4"),t("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4"),t("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC"),t("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC"),t("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC"),t("1.2.840.113549.2.7","hmacWithSHA1"),t("1.2.840.113549.2.8","hmacWithSHA224"),t("1.2.840.113549.2.9","hmacWithSHA256"),t("1.2.840.113549.2.10","hmacWithSHA384"),t("1.2.840.113549.2.11","hmacWithSHA512"),t("1.2.840.113549.3.7","des-EDE3-CBC"),t("2.16.840.1.101.3.4.1.2","aes128-CBC"),t("2.16.840.1.101.3.4.1.22","aes192-CBC"),t("2.16.840.1.101.3.4.1.42","aes256-CBC"),t("2.5.4.3","commonName"),t("2.5.4.4","surname"),t("2.5.4.5","serialNumber"),t("2.5.4.6","countryName"),t("2.5.4.7","localityName"),t("2.5.4.8","stateOrProvinceName"),t("2.5.4.9","streetAddress"),t("2.5.4.10","organizationName"),t("2.5.4.11","organizationalUnitName"),t("2.5.4.12","title"),t("2.5.4.13","description"),t("2.5.4.15","businessCategory"),t("2.5.4.17","postalCode"),t("2.5.4.42","givenName"),t("2.5.4.65","pseudonym"),t("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName"),t("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName"),t("2.16.840.1.113730.1.1","nsCertType"),t("2.16.840.1.113730.1.13","nsComment"),u("2.5.29.1","authorityKeyIdentifier"),u("2.5.29.2","keyAttributes"),u("2.5.29.3","certificatePolicies"),u("2.5.29.4","keyUsageRestriction"),u("2.5.29.5","policyMapping"),u("2.5.29.6","subtreesConstraint"),u("2.5.29.7","subjectAltName"),u("2.5.29.8","issuerAltName"),u("2.5.29.9","subjectDirectoryAttributes"),u("2.5.29.10","basicConstraints"),u("2.5.29.11","nameConstraints"),u("2.5.29.12","policyConstraints"),u("2.5.29.13","basicConstraints"),t("2.5.29.14","subjectKeyIdentifier"),t("2.5.29.15","keyUsage"),u("2.5.29.16","privateKeyUsagePeriod"),t("2.5.29.17","subjectAltName"),t("2.5.29.18","issuerAltName"),t("2.5.29.19","basicConstraints"),u("2.5.29.20","cRLNumber"),u("2.5.29.21","cRLReason"),u("2.5.29.22","expirationDate"),u("2.5.29.23","instructionCode"),u("2.5.29.24","invalidityDate"),u("2.5.29.25","cRLDistributionPoints"),u("2.5.29.26","issuingDistributionPoint"),u("2.5.29.27","deltaCRLIndicator"),u("2.5.29.28","issuingDistributionPoint"),u("2.5.29.29","certificateIssuer"),u("2.5.29.30","nameConstraints"),t("2.5.29.31","cRLDistributionPoints"),t("2.5.29.32","certificatePolicies"),u("2.5.29.33","policyMappings"),u("2.5.29.34","policyConstraints"),t("2.5.29.35","authorityKeyIdentifier"),u("2.5.29.36","policyConstraints"),t("2.5.29.37","extKeyUsage"),u("2.5.29.46","freshestCRL"),u("2.5.29.54","inhibitAnyPolicy"),t("1.3.6.1.4.1.11129.2.4.2","timestampList"),t("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),t("1.3.6.1.5.5.7.3.1","serverAuth"),t("1.3.6.1.5.5.7.3.2","clientAuth"),t("1.3.6.1.5.5.7.3.3","codeSigning"),t("1.3.6.1.5.5.7.3.4","emailProtection"),t("1.3.6.1.5.5.7.3.8","timeStamping"),Re.exports}var ct;function ce(){if(ct)return Ae.exports;ct=1;var i=H();X(),he();var e=Ae.exports=i.asn1=i.asn1||{};e.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192},e.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30},e.maxDepth=256,e.create=function(s,o,d,c,T){if(i.util.isArray(c)){for(var R=[],x=0;x<c.length;++x)c[x]!==void 0&&R.push(c[x]);c=R}var y={tagClass:s,type:o,constructed:d,composed:d||i.util.isArray(c),value:c};return T&&"bitStringContents"in T&&(y.bitStringContents=T.bitStringContents,y.original=e.copy(y)),y},e.copy=function(s,o){var d;if(i.util.isArray(s)){d=[];for(var c=0;c<s.length;++c)d.push(e.copy(s[c],o));return d}return typeof s=="string"?s:(d={tagClass:s.tagClass,type:s.type,constructed:s.constructed,composed:s.composed,value:e.copy(s.value,o)},o&&!o.excludeBitStringContents&&(d.bitStringContents=s.bitStringContents),d)},e.equals=function(s,o,d){if(i.util.isArray(s)){if(!i.util.isArray(o)||s.length!==o.length)return!1;for(var c=0;c<s.length;++c)if(!e.equals(s[c],o[c]))return!1;return!0}if(typeof s!=typeof o)return!1;if(typeof s=="string")return s===o;var T=s.tagClass===o.tagClass&&s.type===o.type&&s.constructed===o.constructed&&s.composed===o.composed&&e.equals(s.value,o.value);return d&&d.includeBitStringContents&&(T=T&&s.bitStringContents===o.bitStringContents),T},e.getBerValueLength=function(s){var o=s.getByte();if(o!==128){var d,c=o&128;return c?d=s.getInt((o&127)<<3):d=o,d}};function t(s,o,d){if(d>o){var c=new Error("Too few bytes to parse DER.");throw c.available=s.length(),c.remaining=o,c.requested=d,c}}var u=function(s,o){var d=s.getByte();if(o--,d!==128){var c,T=d&128;if(!T)c=d;else{var R=d&127;t(s,o,R),c=s.getInt(R<<3)}if(c<0)throw new Error("Negative length: "+c);return c}};e.fromDer=function(s,o){o===void 0&&(o={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),typeof o=="boolean"&&(o={strict:o,parseAllBytes:!0,decodeBitStrings:!0}),"strict"in o||(o.strict=!0),"parseAllBytes"in o||(o.parseAllBytes=!0),"decodeBitStrings"in o||(o.decodeBitStrings=!0),"maxDepth"in o||(o.maxDepth=e.maxDepth),typeof s=="string"&&(s=i.util.createBuffer(s));var d=s.length(),c=I(s,s.length(),0,o);if(o.parseAllBytes&&s.length()!==0){var T=new Error("Unparsed DER bytes remain after ASN.1 parsing.");throw T.byteCount=d,T.remaining=s.length(),T}return c};function I(s,o,d,c){if(d>=c.maxDepth)throw new Error("ASN.1 parsing error: Max depth exceeded.");var T;t(s,o,2);var R=s.getByte();o--;var x=R&192,y=R&31;T=s.length();var E=u(s,o);if(o-=T-s.length(),E!==void 0&&E>o){if(c.strict){var v=new Error("Too few bytes to read ASN.1 value.");throw v.available=s.length(),v.remaining=o,v.requested=E,v}E=o}var m,a,l=(R&32)===32;if(l)if(m=[],E===void 0)for(;;){if(t(s,o,2),s.bytes(2)==="\0\0"){s.getBytes(2),o-=2;break}T=s.length(),m.push(I(s,o,d+1,c)),o-=T-s.length()}else for(;E>0;)T=s.length(),m.push(I(s,E,d+1,c)),o-=T-s.length(),E-=T-s.length();if(m===void 0&&x===e.Class.UNIVERSAL&&y===e.Type.BITSTRING&&(a=s.bytes(E)),m===void 0&&c.decodeBitStrings&&x===e.Class.UNIVERSAL&&y===e.Type.BITSTRING&&E>1){var h=s.read,A=o,b=0;if(y===e.Type.BITSTRING&&(t(s,o,1),b=s.getByte(),o--),b===0)try{T=s.length();var n={strict:!0,decodeBitStrings:!0},r=I(s,o,d+1,n),f=T-s.length();o-=f,y==e.Type.BITSTRING&&f++;var S=r.tagClass;f===E&&(S===e.Class.UNIVERSAL||S===e.Class.CONTEXT_SPECIFIC)&&(m=[r])}catch(U){}m===void 0&&(s.read=h,o=A)}if(m===void 0){if(E===void 0){if(c.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");E=o}if(y===e.Type.BMPSTRING)for(m="";E>0;E-=2)t(s,o,2),m+=String.fromCharCode(s.getInt16()),o-=2;else m=s.getBytes(E),o-=E}var w=a===void 0?null:{bitStringContents:a};return e.create(x,y,l,m,w)}e.toDer=function(s){var o=i.util.createBuffer(),d=s.tagClass|s.type,c=i.util.createBuffer(),T=!1;if("bitStringContents"in s&&(T=!0,s.original&&(T=e.equals(s,s.original))),T)c.putBytes(s.bitStringContents);else if(s.composed){s.constructed?d|=32:c.putByte(0);for(var R=0;R<s.value.length;++R)s.value[R]!==void 0&&c.putBuffer(e.toDer(s.value[R]))}else if(s.type===e.Type.BMPSTRING)for(var R=0;R<s.value.length;++R)c.putInt16(s.value.charCodeAt(R));else s.type===e.Type.INTEGER&&s.value.length>1&&(s.value.charCodeAt(0)===0&&(s.value.charCodeAt(1)&128)===0||s.value.charCodeAt(0)===255&&(s.value.charCodeAt(1)&128)===128)?c.putBytes(s.value.substr(1)):c.putBytes(s.value);if(o.putByte(d),c.length()<=127)o.putByte(c.length()&127);else{var x=c.length(),y="";do y+=String.fromCharCode(x&255),x=x>>>8;while(x>0);o.putByte(y.length|128);for(var R=y.length-1;R>=0;--R)o.putByte(y.charCodeAt(R))}return o.putBuffer(c),o},e.oidToDer=function(s){var o=s.split("."),d=i.util.createBuffer();d.putByte(40*parseInt(o[0],10)+parseInt(o[1],10));for(var c,T,R,x,y=2;y<o.length;++y){if(c=!0,T=[],R=parseInt(o[y],10),R>4294967295)throw new Error("OID value too large; max is 32-bits.");do x=R&127,R=R>>>7,c||(x|=128),T.push(x),c=!1;while(R>0);for(var E=T.length-1;E>=0;--E)d.putByte(T[E])}return d},e.derToOid=function(s){var o;typeof s=="string"&&(s=i.util.createBuffer(s));var d=s.getByte();o=Math.floor(d/40)+"."+d%40;for(var c=0;s.length()>0;){if(c>70368744177663)throw new Error("OID value too large; max is 53-bits.");d=s.getByte(),c=c*128,d&128?c+=d&127:(o+="."+(c+d),c=0)}return o},e.utcTimeToDate=function(s){var o=new Date,d=parseInt(s.substr(0,2),10);d=d>=50?1900+d:2e3+d;var c=parseInt(s.substr(2,2),10)-1,T=parseInt(s.substr(4,2),10),R=parseInt(s.substr(6,2),10),x=parseInt(s.substr(8,2),10),y=0;if(s.length>11){var E=s.charAt(10),v=10;E!=="+"&&E!=="-"&&(y=parseInt(s.substr(10,2),10),v+=2)}if(o.setUTCFullYear(d,c,T),o.setUTCHours(R,x,y,0),v&&(E=s.charAt(v),E==="+"||E==="-")){var m=parseInt(s.substr(v+1,2),10),a=parseInt(s.substr(v+4,2),10),l=m*60+a;l*=6e4,E==="+"?o.setTime(+o-l):o.setTime(+o+l)}return o},e.generalizedTimeToDate=function(s){var o=new Date,d=parseInt(s.substr(0,4),10),c=parseInt(s.substr(4,2),10)-1,T=parseInt(s.substr(6,2),10),R=parseInt(s.substr(8,2),10),x=parseInt(s.substr(10,2),10),y=parseInt(s.substr(12,2),10),E=0,v=0,m=!1;s.charAt(s.length-1)==="Z"&&(m=!0);var a=s.length-5,l=s.charAt(a);if(l==="+"||l==="-"){var h=parseInt(s.substr(a+1,2),10),A=parseInt(s.substr(a+4,2),10);v=h*60+A,v*=6e4,l==="+"&&(v*=-1),m=!0}return s.charAt(14)==="."&&(E=parseFloat(s.substr(14),10)*1e3),m?(o.setUTCFullYear(d,c,T),o.setUTCHours(R,x,y,E),o.setTime(+o+v)):(o.setFullYear(d,c,T),o.setHours(R,x,y,E)),o},e.dateToUtcTime=function(s){if(typeof s=="string")return s;var o="",d=[];d.push((""+s.getUTCFullYear()).substr(2)),d.push(""+(s.getUTCMonth()+1)),d.push(""+s.getUTCDate()),d.push(""+s.getUTCHours()),d.push(""+s.getUTCMinutes()),d.push(""+s.getUTCSeconds());for(var c=0;c<d.length;++c)d[c].length<2&&(o+="0"),o+=d[c];return o+="Z",o},e.dateToGeneralizedTime=function(s){if(typeof s=="string")return s;var o="",d=[];d.push(""+s.getUTCFullYear()),d.push(""+(s.getUTCMonth()+1)),d.push(""+s.getUTCDate()),d.push(""+s.getUTCHours()),d.push(""+s.getUTCMinutes()),d.push(""+s.getUTCSeconds());for(var c=0;c<d.length;++c)d[c].length<2&&(o+="0"),o+=d[c];return o+="Z",o},e.integerToDer=function(s){var o=i.util.createBuffer();if(s>=-128&&s<128)return o.putSignedInt(s,8);if(s>=-32768&&s<32768)return o.putSignedInt(s,16);if(s>=-8388608&&s<8388608)return o.putSignedInt(s,24);if(s>=-2147483648&&s<2147483648)return o.putSignedInt(s,32);var d=new Error("Integer too large; max is 32-bits.");throw d.integer=s,d},e.derToInteger=function(s){typeof s=="string"&&(s=i.util.createBuffer(s));var o=s.length()*8;if(o>32)throw new Error("Integer too large; max is 32-bits.");return s.getSignedInt(o)},e.validate=function(s,o,d,c){var T=!1;if((s.tagClass===o.tagClass||typeof o.tagClass=="undefined")&&(s.type===o.type||typeof o.type=="undefined"))if(s.constructed===o.constructed||typeof o.constructed=="undefined"){if(T=!0,o.value&&i.util.isArray(o.value))for(var R=0,x=0;T&&x<o.value.length;++x){var y=o.value[x];T=!!y.optional;var E=s.value[R];if(!E){y.optional||(T=!1,c&&c.push("["+o.name+'] Missing required element. Expected tag class "'+y.tagClass+'", type "'+y.type+'"'));continue}var v=typeof y.tagClass!="undefined"&&typeof y.type!="undefined";if(v&&(E.tagClass!==y.tagClass||E.type!==y.type))if(y.optional){T=!0;continue}else{T=!1,c&&c.push("["+o.name+"] Tag mismatch. Expected ("+y.tagClass+","+y.type+"), got ("+E.tagClass+","+E.type+")");break}var m=e.validate(E,y,d,c);if(m)++R,T=!0;else if(y.optional)T=!0;else{T=!1;break}}if(T&&d&&(o.capture&&(d[o.capture]=s.value),o.captureAsn1&&(d[o.captureAsn1]=s),o.captureBitStringContents&&"bitStringContents"in s&&(d[o.captureBitStringContents]=s.bitStringContents),o.captureBitStringValue&&"bitStringContents"in s))if(s.bitStringContents.length<2)d[o.captureBitStringValue]="";else{var a=s.bitStringContents.charCodeAt(0);if(a!==0)throw new Error("captureBitStringValue only supported for zero unused bits");d[o.captureBitStringValue]=s.bitStringContents.slice(1)}}else c&&c.push("["+o.name+'] Expected constructed "'+o.constructed+'", got "'+s.constructed+'"');else c&&(s.tagClass!==o.tagClass&&c.push("["+o.name+'] Expected tag class "'+o.tagClass+'", got "'+s.tagClass+'"'),s.type!==o.type&&c.push("["+o.name+'] Expected type "'+o.type+'", got "'+s.type+'"'));return T};var g=/[^\\u0000-\\u00ff]/;return e.prettyPrint=function(s,o,d){var c="";o=o||0,d=d||2,o>0&&(c+=`
|
|
5
5
|
`);for(var T="",R=0;R<o*d;++R)T+=" ";switch(c+=T+"Tag: ",s.tagClass){case e.Class.UNIVERSAL:c+="Universal:";break;case e.Class.APPLICATION:c+="Application:";break;case e.Class.CONTEXT_SPECIFIC:c+="Context-Specific:";break;case e.Class.PRIVATE:c+="Private:";break}if(s.tagClass===e.Class.UNIVERSAL)switch(c+=s.type,s.type){case e.Type.NONE:c+=" (None)";break;case e.Type.BOOLEAN:c+=" (Boolean)";break;case e.Type.INTEGER:c+=" (Integer)";break;case e.Type.BITSTRING:c+=" (Bit string)";break;case e.Type.OCTETSTRING:c+=" (Octet string)";break;case e.Type.NULL:c+=" (Null)";break;case e.Type.OID:c+=" (Object Identifier)";break;case e.Type.ODESC:c+=" (Object Descriptor)";break;case e.Type.EXTERNAL:c+=" (External or Instance of)";break;case e.Type.REAL:c+=" (Real)";break;case e.Type.ENUMERATED:c+=" (Enumerated)";break;case e.Type.EMBEDDED:c+=" (Embedded PDV)";break;case e.Type.UTF8:c+=" (UTF8)";break;case e.Type.ROID:c+=" (Relative Object Identifier)";break;case e.Type.SEQUENCE:c+=" (Sequence)";break;case e.Type.SET:c+=" (Set)";break;case e.Type.PRINTABLESTRING:c+=" (Printable String)";break;case e.Type.IA5String:c+=" (IA5String (ASCII))";break;case e.Type.UTCTIME:c+=" (UTC time)";break;case e.Type.GENERALIZEDTIME:c+=" (Generalized time)";break;case e.Type.BMPSTRING:c+=" (BMP String)";break}else c+=s.type;if(c+=`
|
|
6
6
|
`,c+=T+"Constructed: "+s.constructed+`
|
|
7
7
|
`,s.composed){for(var x=0,y="",R=0;R<s.value.length;++R)s.value[R]!==void 0&&(x+=1,y+=e.prettyPrint(s.value[R],o+1,d),R+1<s.value.length&&(y+=","));c+=T+"Sub values: "+x+y}else{if(c+=T+"Value: ",s.type===e.Type.OID){var E=e.derToOid(s.value);c+=E,i.pki&&i.pki.oids&&E in i.pki.oids&&(c+=" ("+i.pki.oids[E]+") ")}if(s.type===e.Type.INTEGER)try{c+=e.derToInteger(s.value)}catch(m){c+="0x"+i.util.bytesToHex(s.value)}else if(s.type===e.Type.BITSTRING){if(s.value.length>1?c+="0x"+i.util.bytesToHex(s.value.slice(1)):c+="(none)",s.value.length>0){var v=s.value.charCodeAt(0);v==1?c+=" (1 unused bit shown)":v>1&&(c+=" ("+v+" unused bits shown)")}}else if(s.type===e.Type.OCTETSTRING)g.test(s.value)||(c+="("+s.value+") "),c+="0x"+i.util.bytesToHex(s.value);else if(s.type===e.Type.UTF8)try{c+=i.util.decodeUtf8(s.value)}catch(m){if(m.message==="URI malformed")c+="0x"+i.util.bytesToHex(s.value)+" (malformed UTF8)";else throw m}else s.type===e.Type.PRINTABLESTRING||s.type===e.Type.IA5String?c+=s.value:g.test(s.value)?c+="0x"+i.util.bytesToHex(s.value):s.value.length===0?c+="[null]":c+=s.value}return c},Ae.exports}var hr=ce();const pr=Ie(hr);var we={exports:{}},Ue,ht;function pt(){if(ht)return Ue;ht=1;var i=H();X(),Ue=i.cipher=i.cipher||{},i.cipher.algorithms=i.cipher.algorithms||{},i.cipher.createCipher=function(t,u){var I=t;if(typeof I=="string"&&(I=i.cipher.getAlgorithm(I),I&&(I=I())),!I)throw new Error("Unsupported algorithm: "+t);return new i.cipher.BlockCipher({algorithm:I,key:u,decrypt:!1})},i.cipher.createDecipher=function(t,u){var I=t;if(typeof I=="string"&&(I=i.cipher.getAlgorithm(I),I&&(I=I())),!I)throw new Error("Unsupported algorithm: "+t);return new i.cipher.BlockCipher({algorithm:I,key:u,decrypt:!0})},i.cipher.registerAlgorithm=function(t,u){t=t.toUpperCase(),i.cipher.algorithms[t]=u},i.cipher.getAlgorithm=function(t){return t=t.toUpperCase(),t in i.cipher.algorithms?i.cipher.algorithms[t]:null};var e=i.cipher.BlockCipher=function(t){this.algorithm=t.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=t.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=t.decrypt,this.algorithm.initialize(t)};return e.prototype.start=function(t){t=t||{};var u={};for(var I in t)u[I]=t[I];u.decrypt=this._decrypt,this._finish=!1,this._input=i.util.createBuffer(),this.output=t.output||i.util.createBuffer(),this.mode.start(u)},e.prototype.update=function(t){for(t&&this._input.putBuffer(t);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()},e.prototype.finish=function(t){t&&(this.mode.name==="ECB"||this.mode.name==="CBC")&&(this.mode.pad=function(I){return t(this.blockSize,I,!1)},this.mode.unpad=function(I){return t(this.blockSize,I,!0)});var u={};return u.decrypt=this._decrypt,u.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,u)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,u))||this.mode.afterFinish&&!this.mode.afterFinish(this.output,u))},Ue}var Le={exports:{}},dt;function yt(){if(dt)return Le.exports;dt=1;var i=H();X(),i.cipher=i.cipher||{};var e=Le.exports=i.cipher.modes=i.cipher.modes||{};e.ecb=function(g){g=g||{},this.name="ECB",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},e.ecb.prototype.start=function(g){},e.ecb.prototype.encrypt=function(g,s,o){if(g.length()<this.blockSize&&!(o&&g.length()>0))return!0;for(var d=0;d<this._ints;++d)this._inBlock[d]=g.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var d=0;d<this._ints;++d)s.putInt32(this._outBlock[d])},e.ecb.prototype.decrypt=function(g,s,o){if(g.length()<this.blockSize&&!(o&&g.length()>0))return!0;for(var d=0;d<this._ints;++d)this._inBlock[d]=g.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var d=0;d<this._ints;++d)s.putInt32(this._outBlock[d])},e.ecb.prototype.pad=function(g,s){var o=g.length()===this.blockSize?this.blockSize:this.blockSize-g.length();return g.fillWithByte(o,o),!0},e.ecb.prototype.unpad=function(g,s){if(s.overflow>0)return!1;var o=g.length(),d=g.at(o-1);return d>this.blockSize<<2?!1:(g.truncate(d),!0)},e.cbc=function(g){g=g||{},this.name="CBC",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)},e.cbc.prototype.start=function(g){if(g.iv===null){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else if("iv"in g)this._iv=t(g.iv,this.blockSize),this._prev=this._iv.slice(0);else throw new Error("Invalid IV parameter.")},e.cbc.prototype.encrypt=function(g,s,o){if(g.length()<this.blockSize&&!(o&&g.length()>0))return!0;for(var d=0;d<this._ints;++d)this._inBlock[d]=this._prev[d]^g.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var d=0;d<this._ints;++d)s.putInt32(this._outBlock[d]);this._prev=this._outBlock},e.cbc.prototype.decrypt=function(g,s,o){if(g.length()<this.blockSize&&!(o&&g.length()>0))return!0;for(var d=0;d<this._ints;++d)this._inBlock[d]=g.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var d=0;d<this._ints;++d)s.putInt32(this._prev[d]^this._outBlock[d]);this._prev=this._inBlock.slice(0)},e.cbc.prototype.pad=function(g,s){var o=g.length()===this.blockSize?this.blockSize:this.blockSize-g.length();return g.fillWithByte(o,o),!0},e.cbc.prototype.unpad=function(g,s){if(s.overflow>0)return!1;var o=g.length(),d=g.at(o-1);return d>this.blockSize<<2?!1:(g.truncate(d),!0)},e.cfb=function(g){g=g||{},this.name="CFB",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},e.cfb.prototype.start=function(g){if(!("iv"in g))throw new Error("Invalid IV parameter.");this._iv=t(g.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.cfb.prototype.encrypt=function(g,s,o){var d=g.length();if(d===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&d>=this.blockSize){for(var c=0;c<this._ints;++c)this._inBlock[c]=g.getInt32()^this._outBlock[c],s.putInt32(this._inBlock[c]);return}var T=(this.blockSize-d)%this.blockSize;T>0&&(T=this.blockSize-T),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialBlock[c]=g.getInt32()^this._outBlock[c],this._partialOutput.putInt32(this._partialBlock[c]);if(T>0)g.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._partialBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),T>0&&!o)return s.putBytes(this._partialOutput.getBytes(T-this._partialBytes)),this._partialBytes=T,!0;s.putBytes(this._partialOutput.getBytes(d-this._partialBytes)),this._partialBytes=0},e.cfb.prototype.decrypt=function(g,s,o){var d=g.length();if(d===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&d>=this.blockSize){for(var c=0;c<this._ints;++c)this._inBlock[c]=g.getInt32(),s.putInt32(this._inBlock[c]^this._outBlock[c]);return}var T=(this.blockSize-d)%this.blockSize;T>0&&(T=this.blockSize-T),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialBlock[c]=g.getInt32(),this._partialOutput.putInt32(this._partialBlock[c]^this._outBlock[c]);if(T>0)g.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._partialBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),T>0&&!o)return s.putBytes(this._partialOutput.getBytes(T-this._partialBytes)),this._partialBytes=T,!0;s.putBytes(this._partialOutput.getBytes(d-this._partialBytes)),this._partialBytes=0},e.ofb=function(g){g=g||{},this.name="OFB",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},e.ofb.prototype.start=function(g){if(!("iv"in g))throw new Error("Invalid IV parameter.");this._iv=t(g.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.ofb.prototype.encrypt=function(g,s,o){var d=g.length();if(g.length()===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&d>=this.blockSize){for(var c=0;c<this._ints;++c)s.putInt32(g.getInt32()^this._outBlock[c]),this._inBlock[c]=this._outBlock[c];return}var T=(this.blockSize-d)%this.blockSize;T>0&&(T=this.blockSize-T),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(g.getInt32()^this._outBlock[c]);if(T>0)g.read-=this.blockSize;else for(var c=0;c<this._ints;++c)this._inBlock[c]=this._outBlock[c];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),T>0&&!o)return s.putBytes(this._partialOutput.getBytes(T-this._partialBytes)),this._partialBytes=T,!0;s.putBytes(this._partialOutput.getBytes(d-this._partialBytes)),this._partialBytes=0},e.ofb.prototype.decrypt=e.ofb.prototype.encrypt,e.ctr=function(g){g=g||{},this.name="CTR",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0},e.ctr.prototype.start=function(g){if(!("iv"in g))throw new Error("Invalid IV parameter.");this._iv=t(g.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0},e.ctr.prototype.encrypt=function(g,s,o){var d=g.length();if(d===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&d>=this.blockSize)for(var c=0;c<this._ints;++c)s.putInt32(g.getInt32()^this._outBlock[c]);else{var T=(this.blockSize-d)%this.blockSize;T>0&&(T=this.blockSize-T),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(g.getInt32()^this._outBlock[c]);if(T>0&&(g.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),T>0&&!o)return s.putBytes(this._partialOutput.getBytes(T-this._partialBytes)),this._partialBytes=T,!0;s.putBytes(this._partialOutput.getBytes(d-this._partialBytes)),this._partialBytes=0}u(this._inBlock)},e.ctr.prototype.decrypt=e.ctr.prototype.encrypt,e.gcm=function(g){g=g||{},this.name="GCM",this.cipher=g.cipher,this.blockSize=g.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=i.util.createBuffer(),this._partialBytes=0,this._R=3774873600},e.gcm.prototype.start=function(g){if(!("iv"in g))throw new Error("Invalid IV parameter.");var s=i.util.createBuffer(g.iv);this._cipherLength=0;var o;if("additionalData"in g?o=i.util.createBuffer(g.additionalData):o=i.util.createBuffer(),"tagLength"in g?this._tagLength=g.tagLength:this._tagLength=128,this._tag=null,g.decrypt&&(this._tag=i.util.createBuffer(g.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var d=s.length();if(d===12)this._j0=[s.getInt32(),s.getInt32(),s.getInt32(),1];else{for(this._j0=[0,0,0,0];s.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[s.getInt32(),s.getInt32(),s.getInt32(),s.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(I(d*8)))}this._inBlock=this._j0.slice(0),u(this._inBlock),this._partialBytes=0,o=i.util.createBuffer(o),this._aDataLength=I(o.length()*8);var c=o.length()%this.blockSize;for(c&&o.fillWithByte(0,this.blockSize-c),this._s=[0,0,0,0];o.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[o.getInt32(),o.getInt32(),o.getInt32(),o.getInt32()])},e.gcm.prototype.encrypt=function(g,s,o){var d=g.length();if(d===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&d>=this.blockSize){for(var c=0;c<this._ints;++c)s.putInt32(this._outBlock[c]^=g.getInt32());this._cipherLength+=this.blockSize}else{var T=(this.blockSize-d)%this.blockSize;T>0&&(T=this.blockSize-T),this._partialOutput.clear();for(var c=0;c<this._ints;++c)this._partialOutput.putInt32(g.getInt32()^this._outBlock[c]);if(T<=0||o){if(o){var R=d%this.blockSize;this._cipherLength+=R,this._partialOutput.truncate(this.blockSize-R)}else this._cipherLength+=this.blockSize;for(var c=0;c<this._ints;++c)this._outBlock[c]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),T>0&&!o)return g.read-=this.blockSize,s.putBytes(this._partialOutput.getBytes(T-this._partialBytes)),this._partialBytes=T,!0;s.putBytes(this._partialOutput.getBytes(d-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),u(this._inBlock)},e.gcm.prototype.decrypt=function(g,s,o){var d=g.length();if(d<this.blockSize&&!(o&&d>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),u(this._inBlock),this._hashBlock[0]=g.getInt32(),this._hashBlock[1]=g.getInt32(),this._hashBlock[2]=g.getInt32(),this._hashBlock[3]=g.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var c=0;c<this._ints;++c)s.putInt32(this._outBlock[c]^this._hashBlock[c]);d<this.blockSize?this._cipherLength+=d%this.blockSize:this._cipherLength+=this.blockSize},e.gcm.prototype.afterFinish=function(g,s){var o=!0;s.decrypt&&s.overflow&&g.truncate(this.blockSize-s.overflow),this.tag=i.util.createBuffer();var d=this._aDataLength.concat(I(this._cipherLength*8));this._s=this.ghash(this._hashSubkey,this._s,d);var c=[];this.cipher.encrypt(this._j0,c);for(var T=0;T<this._ints;++T)this.tag.putInt32(this._s[T]^c[T]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),s.decrypt&&this.tag.bytes()!==this._tag&&(o=!1),o},e.gcm.prototype.multiply=function(g,s){for(var o=[0,0,0,0],d=s.slice(0),c=0;c<128;++c){var T=g[c/32|0]&1<<31-c%32;T&&(o[0]^=d[0],o[1]^=d[1],o[2]^=d[2],o[3]^=d[3]),this.pow(d,d)}return o},e.gcm.prototype.pow=function(g,s){for(var o=g[3]&1,d=3;d>0;--d)s[d]=g[d]>>>1|(g[d-1]&1)<<31;s[0]=g[0]>>>1,o&&(s[0]^=this._R)},e.gcm.prototype.tableMultiply=function(g){for(var s=[0,0,0,0],o=0;o<32;++o){var d=o/8|0,c=g[d]>>>(7-o%8)*4&15,T=this._m[o][c];s[0]^=T[0],s[1]^=T[1],s[2]^=T[2],s[3]^=T[3]}return s},e.gcm.prototype.ghash=function(g,s,o){return s[0]^=o[0],s[1]^=o[1],s[2]^=o[2],s[3]^=o[3],this.tableMultiply(s)},e.gcm.prototype.generateHashTable=function(g,s){for(var o=8/s,d=4*o,c=16*o,T=new Array(c),R=0;R<c;++R){var x=[0,0,0,0],y=R/d|0,E=(d-1-R%d)*s;x[y]=1<<s-1<<E,T[R]=this.generateSubHashTable(this.multiply(x,g),s)}return T},e.gcm.prototype.generateSubHashTable=function(g,s){var o=1<<s,d=o>>>1,c=new Array(o);c[d]=g.slice(0);for(var T=d>>>1;T>0;)this.pow(c[2*T],c[T]=[]),T>>=1;for(T=2;T<d;){for(var R=1;R<T;++R){var x=c[T],y=c[R];c[T+R]=[x[0]^y[0],x[1]^y[1],x[2]^y[2],x[3]^y[3]]}T*=2}for(c[0]=[0,0,0,0],T=d+1;T<o;++T){var E=c[T^d];c[T]=[g[0]^E[0],g[1]^E[1],g[2]^E[2],g[3]^E[3]]}return c};function t(g,s){if(typeof g=="string"&&(g=i.util.createBuffer(g)),i.util.isArray(g)&&g.length>4){var o=g;g=i.util.createBuffer();for(var d=0;d<o.length;++d)g.putByte(o[d])}if(g.length()<s)throw new Error("Invalid IV length; got "+g.length()+" bytes and expected "+s+" bytes.");if(!i.util.isArray(g)){for(var c=[],T=s/4,d=0;d<T;++d)c.push(g.getInt32());g=c}return g}function u(g){g[g.length-1]=g[g.length-1]+1&4294967295}function I(g){return[g/4294967296|0,g&4294967295]}return Le.exports}var De,gt;function _e(){if(gt)return De;gt=1;var i=H();pt(),yt(),X(),De=i.aes=i.aes||{},i.aes.startEncrypting=function(y,E,v,m){var a=x({key:y,output:v,decrypt:!1,mode:m});return a.start(E),a},i.aes.createEncryptionCipher=function(y,E){return x({key:y,output:null,decrypt:!1,mode:E})},i.aes.startDecrypting=function(y,E,v,m){var a=x({key:y,output:v,decrypt:!0,mode:m});return a.start(E),a},i.aes.createDecryptionCipher=function(y,E){return x({key:y,output:null,decrypt:!0,mode:E})},i.aes.Algorithm=function(y,E){t||c();var v=this;v.name=y,v.mode=new E({blockSize:16,cipher:{encrypt:function(m,a){return R(v._w,m,a,!1)},decrypt:function(m,a){return R(v._w,m,a,!0)}}}),v._init=!1},i.aes.Algorithm.prototype.initialize=function(y){if(!this._init){var E=y.key,v;if(typeof E=="string"&&(E.length===16||E.length===24||E.length===32))E=i.util.createBuffer(E);else if(i.util.isArray(E)&&(E.length===16||E.length===24||E.length===32)){v=E,E=i.util.createBuffer();for(var m=0;m<v.length;++m)E.putByte(v[m])}if(!i.util.isArray(E)){v=E,E=[];var a=v.length();if(a===16||a===24||a===32){a=a>>>2;for(var m=0;m<a;++m)E.push(v.getInt32())}}if(!i.util.isArray(E)||!(E.length===4||E.length===6||E.length===8))throw new Error("Invalid key parameter.");var l=this.mode.name,h=["CFB","OFB","CTR","GCM"].indexOf(l)!==-1;this._w=T(E,y.decrypt&&!h),this._init=!0}},i.aes._expandKey=function(y,E){return t||c(),T(y,E)},i.aes._updateBlock=R,e("AES-ECB",i.cipher.modes.ecb),e("AES-CBC",i.cipher.modes.cbc),e("AES-CFB",i.cipher.modes.cfb),e("AES-OFB",i.cipher.modes.ofb),e("AES-CTR",i.cipher.modes.ctr),e("AES-GCM",i.cipher.modes.gcm);function e(y,E){var v=function(){return new i.aes.Algorithm(y,E)};i.cipher.registerAlgorithm(y,v)}var t=!1,u=4,I,g,s,o,d;function c(){t=!0,s=[0,1,2,4,8,16,32,64,128,27,54];for(var y=new Array(256),E=0;E<128;++E)y[E]=E<<1,y[E+128]=E+128<<1^283;I=new Array(256),g=new Array(256),o=new Array(4),d=new Array(4);for(var E=0;E<4;++E)o[E]=new Array(256),d[E]=new Array(256);for(var v=0,m=0,a,l,h,A,b,n,r,E=0;E<256;++E){A=m^m<<1^m<<2^m<<3^m<<4,A=A>>8^A&255^99,I[v]=A,g[A]=v,b=y[A],a=y[v],l=y[a],h=y[l],n=b<<24^A<<16^A<<8^(A^b),r=(a^l^h)<<24^(v^h)<<16^(v^l^h)<<8^(v^a^h);for(var f=0;f<4;++f)o[f][v]=n,d[f][A]=r,n=n<<24|n>>>8,r=r<<24|r>>>8;v===0?v=m=1:(v=a^y[y[y[a^h]]],m^=y[y[m]])}}function T(y,E){for(var v=y.slice(0),m,a=1,l=v.length,h=l+6+1,A=u*h,b=l;b<A;++b)m=v[b-1],b%l===0?(m=I[m>>>16&255]<<24^I[m>>>8&255]<<16^I[m&255]<<8^I[m>>>24]^s[a]<<24,a++):l>6&&b%l===4&&(m=I[m>>>24]<<24^I[m>>>16&255]<<16^I[m>>>8&255]<<8^I[m&255]),v[b]=v[b-l]^m;if(E){var n,r=d[0],f=d[1],S=d[2],w=d[3],U=v.slice(0);A=v.length;for(var b=0,N=A-u;b<A;b+=u,N-=u)if(b===0||b===A-u)U[b]=v[N],U[b+1]=v[N+3],U[b+2]=v[N+2],U[b+3]=v[N+1];else for(var L=0;L<u;++L)n=v[N+L],U[b+(3&-L)]=r[I[n>>>24]]^f[I[n>>>16&255]]^S[I[n>>>8&255]]^w[I[n&255]];v=U}return v}function R(y,E,v,m){var a=y.length/4-1,l,h,A,b,n;m?(l=d[0],h=d[1],A=d[2],b=d[3],n=g):(l=o[0],h=o[1],A=o[2],b=o[3],n=I);var r,f,S,w,U,N,L;r=E[0]^y[0],f=E[m?3:1]^y[1],S=E[2]^y[2],w=E[m?1:3]^y[3];for(var P=3,_=1;_<a;++_)U=l[r>>>24]^h[f>>>16&255]^A[S>>>8&255]^b[w&255]^y[++P],N=l[f>>>24]^h[S>>>16&255]^A[w>>>8&255]^b[r&255]^y[++P],L=l[S>>>24]^h[w>>>16&255]^A[r>>>8&255]^b[f&255]^y[++P],w=l[w>>>24]^h[r>>>16&255]^A[f>>>8&255]^b[S&255]^y[++P],r=U,f=N,S=L;v[0]=n[r>>>24]<<24^n[f>>>16&255]<<16^n[S>>>8&255]<<8^n[w&255]^y[++P],v[m?3:1]=n[f>>>24]<<24^n[S>>>16&255]<<16^n[w>>>8&255]<<8^n[r&255]^y[++P],v[2]=n[S>>>24]<<24^n[w>>>16&255]<<16^n[r>>>8&255]<<8^n[f&255]^y[++P],v[m?1:3]=n[w>>>24]<<24^n[r>>>16&255]<<16^n[f>>>8&255]<<8^n[S&255]^y[++P]}function x(y){y=y||{};var E=(y.mode||"CBC").toUpperCase(),v="AES-"+E,m;y.decrypt?m=i.cipher.createDecipher(v,y.key):m=i.cipher.createCipher(v,y.key);var a=m.start;return m.start=function(l,h){var A=null;h instanceof i.util.ByteBuffer&&(A=h,h={}),h=h||{},h.output=A,h.iv=l,a.call(m,h)},m}return De}var Pe,vt;function Ct(){if(vt)return Pe;vt=1;var i=H();pt(),yt(),X(),Pe=i.des=i.des||{},i.des.startEncrypting=function(y,E,v,m){var a=x({key:y,output:v,decrypt:!1,mode:m||(E===null?"ECB":"CBC")});return a.start(E),a},i.des.createEncryptionCipher=function(y,E){return x({key:y,output:null,decrypt:!1,mode:E})},i.des.startDecrypting=function(y,E,v,m){var a=x({key:y,output:v,decrypt:!0,mode:m||(E===null?"ECB":"CBC")});return a.start(E),a},i.des.createDecryptionCipher=function(y,E){return x({key:y,output:null,decrypt:!0,mode:E})},i.des.Algorithm=function(y,E){var v=this;v.name=y,v.mode=new E({blockSize:8,cipher:{encrypt:function(m,a){return R(v._keys,m,a,!1)},decrypt:function(m,a){return R(v._keys,m,a,!0)}}}),v._init=!1},i.des.Algorithm.prototype.initialize=function(y){if(!this._init){var E=i.util.createBuffer(y.key);if(this.name.indexOf("3DES")===0&&E.length()!==24)throw new Error("Invalid Triple-DES key size: "+E.length()*8);this._keys=T(E),this._init=!0}},e("DES-ECB",i.cipher.modes.ecb),e("DES-CBC",i.cipher.modes.cbc),e("DES-CFB",i.cipher.modes.cfb),e("DES-OFB",i.cipher.modes.ofb),e("DES-CTR",i.cipher.modes.ctr),e("3DES-ECB",i.cipher.modes.ecb),e("3DES-CBC",i.cipher.modes.cbc),e("3DES-CFB",i.cipher.modes.cfb),e("3DES-OFB",i.cipher.modes.ofb),e("3DES-CTR",i.cipher.modes.ctr);function e(y,E){var v=function(){return new i.des.Algorithm(y,E)};i.cipher.registerAlgorithm(y,v)}var t=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],u=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],I=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],g=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],s=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],o=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],d=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],c=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function T(y){for(var E=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],v=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],m=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],a=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],l=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],h=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],A=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],b=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],n=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578],r=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488],f=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800],S=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],w=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],U=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],N=y.length()>8?3:1,L=[],P=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],_=0,k,F=0;F<N;F++){var K=y.getInt32(),G=y.getInt32();k=(K>>>4^G)&252645135,G^=k,K^=k<<4,k=(G>>>-16^K)&65535,K^=k,G^=k<<-16,k=(K>>>2^G)&858993459,G^=k,K^=k<<2,k=(G>>>-16^K)&65535,K^=k,G^=k<<-16,k=(K>>>1^G)&1431655765,G^=k,K^=k<<1,k=(G>>>8^K)&16711935,K^=k,G^=k<<8,k=(K>>>1^G)&1431655765,G^=k,K^=k<<1,k=K<<8|G>>>20&240,K=G<<24|G<<8&16711680|G>>>8&65280|G>>>24&240,G=k;for(var z=0;z<P.length;++z){P[z]?(K=K<<2|K>>>26,G=G<<2|G>>>26):(K=K<<1|K>>>27,G=G<<1|G>>>27),K&=-15,G&=-15;var Q=E[K>>>28]|v[K>>>24&15]|m[K>>>20&15]|a[K>>>16&15]|l[K>>>12&15]|h[K>>>8&15]|A[K>>>4&15],Y=b[G>>>28]|n[G>>>24&15]|r[G>>>20&15]|f[G>>>16&15]|S[G>>>12&15]|w[G>>>8&15]|U[G>>>4&15];k=(Y>>>16^Q)&65535,L[_++]=Q^k,L[_++]=Y^k<<16}}return L}function R(y,E,v,m){var a=y.length===32?3:9,l;a===3?l=m?[30,-2,-2]:[0,32,2]:l=m?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var h,A=E[0],b=E[1];h=(A>>>4^b)&252645135,b^=h,A^=h<<4,h=(A>>>16^b)&65535,b^=h,A^=h<<16,h=(b>>>2^A)&858993459,A^=h,b^=h<<2,h=(b>>>8^A)&16711935,A^=h,b^=h<<8,h=(A>>>1^b)&1431655765,b^=h,A^=h<<1,A=A<<1|A>>>31,b=b<<1|b>>>31;for(var n=0;n<a;n+=3){for(var r=l[n+1],f=l[n+2],S=l[n];S!=r;S+=f){var w=b^y[S],U=(b>>>4|b<<28)^y[S+1];h=A,A=b,b=h^(u[w>>>24&63]|g[w>>>16&63]|o[w>>>8&63]|c[w&63]|t[U>>>24&63]|I[U>>>16&63]|s[U>>>8&63]|d[U&63])}h=A,A=b,b=h}A=A>>>1|A<<31,b=b>>>1|b<<31,h=(A>>>1^b)&1431655765,b^=h,A^=h<<1,h=(b>>>8^A)&16711935,A^=h,b^=h<<8,h=(b>>>2^A)&858993459,A^=h,b^=h<<2,h=(A>>>16^b)&65535,b^=h,A^=h<<16,h=(A>>>4^b)&252645135,b^=h,A^=h<<4,v[0]=A,v[1]=b}function x(y){y=y||{};var E=(y.mode||"CBC").toUpperCase(),v="DES-"+E,m;y.decrypt?m=i.cipher.createDecipher(v,y.key):m=i.cipher.createCipher(v,y.key);var a=m.start;return m.start=function(l,h){var A=null;h instanceof i.util.ByteBuffer&&(A=h,h={}),h=h||{},h.output=A,h.iv=l,a.call(m,h)},m}return Pe}var ke,Et;function pe(){if(Et)return ke;Et=1;var i=H();return ke=i.md=i.md||{},i.md.algorithms=i.md.algorithms||{},ke}var Oe={exports:{}},mt;function xt(){if(mt)return Oe.exports;mt=1;var i=H();pe(),X();var e=Oe.exports=i.hmac=i.hmac||{};return e.create=function(){var t=null,u=null,I=null,g=null,s={};return s.start=function(o,d){if(o!==null)if(typeof o=="string")if(o=o.toLowerCase(),o in i.md.algorithms)u=i.md.algorithms[o].create();else throw new Error('Unknown hash algorithm "'+o+'"');else u=o;if(d===null)d=t;else{if(typeof d=="string")d=i.util.createBuffer(d);else if(i.util.isArray(d)){var c=d;d=i.util.createBuffer();for(var T=0;T<c.length;++T)d.putByte(c[T])}var R=d.length();R>u.blockLength&&(u.start(),u.update(d.bytes()),d=u.digest()),I=i.util.createBuffer(),g=i.util.createBuffer(),R=d.length();for(var T=0;T<R;++T){var c=d.at(T);I.putByte(54^c),g.putByte(92^c)}if(R<u.blockLength)for(var c=u.blockLength-R,T=0;T<c;++T)I.putByte(54),g.putByte(92);t=d,I=I.bytes(),g=g.bytes()}u.start(),u.update(I)},s.update=function(o){u.update(o)},s.getMac=function(){var o=u.digest().bytes();return u.start(),u.update(g),u.update(o),u.digest()},s.digest=s.getMac,s},Oe.exports}const Ve=lr(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Fe,St;function Tt(){if(St)return Fe;St=1;var i=H();xt(),pe(),X();var e=i.pkcs5=i.pkcs5||{},t;return i.util.isNodejs&&!i.options.usePureJavaScript&&(t=Ve),Fe=i.pbkdf2=e.pbkdf2=function(u,I,g,s,o,d){if(typeof o=="function"&&(d=o,o=null),i.util.isNodejs&&!i.options.usePureJavaScript&&t.pbkdf2&&(o===null||typeof o!="object")&&(t.pbkdf2Sync.length>4||!o||o==="sha1"))return typeof o!="string"&&(o="sha1"),u=Buffer.from(u,"binary"),I=Buffer.from(I,"binary"),d?t.pbkdf2Sync.length===4?t.pbkdf2(u,I,g,s,function(n,r){if(n)return d(n);d(null,r.toString("binary"))}):t.pbkdf2(u,I,g,s,o,function(n,r){if(n)return d(n);d(null,r.toString("binary"))}):t.pbkdf2Sync.length===4?t.pbkdf2Sync(u,I,g,s).toString("binary"):t.pbkdf2Sync(u,I,g,s,o).toString("binary");if((typeof o=="undefined"||o===null)&&(o="sha1"),typeof o=="string"){if(!(o in i.md.algorithms))throw new Error("Unknown hash algorithm: "+o);o=i.md[o].create()}var c=o.digestLength;if(s>4294967295*c){var T=new Error("Derived key is too long.");if(d)return d(T);throw T}var R=Math.ceil(s/c),x=s-(R-1)*c,y=i.hmac.create();y.start(o,u);var E="",v,m,a;if(!d){for(var l=1;l<=R;++l){y.start(null,null),y.update(I),y.update(i.util.int32ToBytes(l)),v=a=y.digest().getBytes();for(var h=2;h<=g;++h)y.start(null,null),y.update(a),m=y.digest().getBytes(),v=i.util.xorBytes(v,m,c),a=m;E+=l<R?v:v.substr(0,x)}return E}var l=1,h;function A(){if(l>R)return d(null,E);y.start(null,null),y.update(I),y.update(i.util.int32ToBytes(l)),v=a=y.digest().getBytes(),h=2,b()}function b(){if(h<=g)return y.start(null,null),y.update(a),m=y.digest().getBytes(),v=i.util.xorBytes(v,m,c),a=m,++h,i.util.setImmediate(b);E+=l<R?v:v.substr(0,x),++l,A()}A()},Fe}var Ke={exports:{}},It;function Me(){if(It)return Ke.exports;It=1;var i=H();X();var e=Ke.exports=i.pem=i.pem||{};e.encode=function(I,g){g=g||{};var s="-----BEGIN "+I.type+`-----\r
|
package/dist/index.d.ts
CHANGED
|
@@ -6240,7 +6240,7 @@ interface ImMediaTasksApi {
|
|
|
6240
6240
|
*
|
|
6241
6241
|
* 返回的对象可以**原样**作为 `localPreviewMetadata` 交给 `sendImage` / `sendVideo` /
|
|
6242
6242
|
* `sendMediaAlbum`:发送链路会复用可用元信息;合集项超出其可用消息空间时重新生成封面。
|
|
6243
|
-
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多
|
|
6243
|
+
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多 480px,目标 8 KiB、硬上限 24 KiB);includeDisplayPoster 可在同一次解码中额外生成
|
|
6244
6244
|
* 仅供页面显示的高清 displayPoster(长边最多 960),不得绕过发送校验直接用它替换 posterData。
|
|
6245
6245
|
*
|
|
6246
6246
|
* @param input.kind 按文件类型选解码路径;`'video'` 才会抽首帧与读时长。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readImageDimensionsFromHeader as
|
|
1
|
+
var t=Object.defineProperty,e=(e,i,r)=>((e,i,r)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[i]=r)(e,"symbol"!=typeof i?i+"":i,r);import{readImageDimensionsFromHeader as i}from"./image-header-dimensions.js";import{compressCanvasPng as r}from"./png-lossless-compression.js";import{resolveMediaThumbnailPolicy as a}from"../../../im-core/src/media-thumbnail-policy.js";const n=a();function o(t){const e={active:0,disposed:!1},i=[];function r(){for(;!e.disposed&&e.active<t&&i.length>0;){const t=i.shift();if(t.signal?.aborted){t.reject(new DOMException("媒体预览准备已取消","AbortError"));continue}void 0!==t.onAbort&&t.signal?.removeEventListener("abort",t.onAbort),e.active+=1;let a=!1;t.resolve(()=>{a||(a=!0,e.active-=1,r())})}}return{acquire:t=>e.disposed?Promise.reject(new Error("媒体预览执行器已释放")):new Promise((e,a)=>{const n={resolve:e,reject:a,...void 0===t?{}:{signal:t}};void 0!==t&&(n.onAbort=()=>{const t=i.indexOf(n);t>=0&&i.splice(t,1),a(new DOMException("媒体预览准备已取消","AbortError"))},t.addEventListener("abort",n.onAbort,{once:!0})),i.push(n),r()}),dispose(){e.disposed=!0;for(const t of i.splice(0))void 0!==t.onAbort&&t.signal?.removeEventListener("abort",t.onAbort),t.reject(new Error("媒体预览执行器已释放"))}}}function s(t){if(t?.aborted)throw new DOMException("媒体预览准备已取消","AbortError")}const h=16777216;function c(t,e,i){const r=Math.min(1,i/Math.max(t,e));return function(t,e){const i=Math.min(1,4096/Math.max(t,e));let r=Math.max(1,Math.round(t*i)),a=Math.max(1,Math.round(e*i));const n=r*a;if(n>h){const t=Math.sqrt(h/n);r=Math.max(1,Math.floor(r*t)),a=Math.max(1,Math.floor(a*t))}return{width:r,height:a}}(Math.max(1,Math.round(t*r)),Math.max(1,Math.round(e*r)))}async function d(t,e){s(e);const i=await new Promise(e=>t.toBlob(e,"image/png"));if(s(e),null===i)throw new Error("媒体预览准备失败:Canvas 编码返回空结果");return await r(await i.arrayBuffer(),e)}async function l(t,e,i){s(i);const r=await new Promise(i=>t.toBlob(i,"image/jpeg",e));if(s(i),null===r)throw new Error("媒体预览准备失败:Canvas 编码返回空结果");return await r.arrayBuffer()}function f(t,e){if(!Number.isInteger(t)||t<=0)throw new RangeError(`${e}必须是正整数`)}function m(t,e){if(!Number.isFinite(t)||t<=0||t>1)throw new RangeError(`${e}必须大于 0 且不超过 1`)}function u(t){const e="video"===t.kind?"视频封面":"图片缩略图",i=t.maxSize??n.maxSize,r=t.maxBytes??n.maxBytes,a=t.targetBytes??Math.min(n.targetBytes,r),o=t.quality??Math.max(.72,t.minQuality??0),s=t.minQuality??Math.min(o,.55);if(f(i,`${e}最大边长`),f(a,`${e}目标字节数`),f(r,`${e}最大字节数`),m(o,`${e}初始质量`),m(s,`${e}最低质量`),a>r)throw new RangeError(`${e}目标字节数不能超过最大字节数`);if(s>o)throw new RangeError(`${e}最低质量不能高于初始质量`);return{label:e,maxSize:i,targetBytes:a,maxBytes:r,initialQuality:o,minQuality:s}}class w extends Error{constructor(){super(...arguments),e(this,"name","ThumbnailByteLimitError")}}async function g(t,e,i,r,a){const{label:n,maxSize:o,targetBytes:h,maxBytes:f,initialQuality:m,minQuality:g}=u(r),y="video"===r.kind;s(a);const v=document.createElement("canvas");try{const u=v.getContext("2d");if(null===u)throw new Error("媒体预览准备失败:无法创建 Canvas 2D 上下文");let b;const M=e=>{s(a),v.width=e.width,v.height=e.height,void 0!==b&&(u.fillStyle=b,u.fillRect(0,0,e.width,e.height)),u.drawImage(t,0,0,e.width,e.height)},p=c(e,i,o);let x=p;const E=Math.min(o<=320?240:320,Math.max(x.width,x.height));M(x);const L=y?void 0:u.getImageData(0,0,x.width,x.height).data;let B,P=!1;if(void 0!==L)for(let t=3;t<L.length;t+=4)if(L[t]<255){P=!0;break}if(P){let t;for(let r=0;r<4;r+=1){const n=await d(v,a);if((void 0===t||n.byteLength<t.byteLength)&&(t=n),n.byteLength<=h)return n;const o=Math.max(x.width,x.height);if(o<=E||3===r)break;const s=Math.min(.8,Math.max(.35,.9*Math.sqrt(h/n.byteLength)));x=c(e,i,Math.max(E,Math.floor(o*s))),M(x)}if(void 0!==t&&t.byteLength<=f)return t;b=function(t,e){const i=[128,64,192],r=i.map(()=>0),a=4*e;for(let n=0;n<t.length;n+=4){const o=t[n+3];if(0===o)continue;const s=n/4%e;if(!(s>0&&t[n-1]<o||s+1<e&&t[n+7]<o||n>=a&&t[n-a+3]<o||n+a+3<t.length&&t[n+a+3]<o))continue;const h=o/255;for(let e=0;e<i.length;e+=1){const a=i[e],o=Math.max(Math.abs(t[n]-a),Math.abs(t[n+1]-a),Math.abs(t[n+2]-a))*h;r[e]=r[e]+Math.min(64,o)}}let n=0;for(let t=1;t<i.length;t+=1)r[t]>r[n]&&(n=t);return`#${i[n].toString(16).padStart(2,"0").repeat(3)}`}(L,p.width),x=p,M(x)}const R=[.../* @__PURE__ */new Set([m,Math.max(g,m-.12),g])];for(const t of R){const e=await l(v,t,a);if((void 0===B||e.byteLength<B.byteLength)&&(B=e),e.byteLength<=h)return e}for(let t=0;t<3;t+=1){const t=Math.max(x.width,x.height);if(t<=E||void 0===B)break;const r=Math.sqrt(h/B.byteLength);x=c(e,i,Math.max(E,Math.floor(t*Math.min(.9,Math.max(.5,r))))),M(x);for(const t of[m,g]){const e=await l(v,t,a);if(e.byteLength<B.byteLength&&(B=e),e.byteLength<=h)return e}}if(void 0!==B&&B.byteLength<=f)return B;const j=Math.min(o<=320?160:240,Math.max(x.width,x.height)),D=r.minQuality??Math.min(m,.45);for(let t=0;t<2&&void 0!==B;t+=1){const r=Math.max(x.width,x.height),n=1===t?j:Math.max(j,Math.floor(r*Math.min(.9,.95*Math.sqrt(f/B.byteLength))));x=c(e,i,n),M(x);for(const t of/* @__PURE__ */new Set([g,D])){const e=await l(v,t,a);if(e.byteLength<B.byteLength&&(B=e),e.byteLength<=f)return e}if(n<=j)break}throw new w(`${n}生成失败:编码结果超过 ${f} 字节硬上限`)}finally{v.width=0,v.height=0}}function y(t,e,i,r){return s(i),new Promise((a,n)=>{let o,s,h,c;const d=()=>{void 0!==o&&clearTimeout(o),t.removeEventListener(e,s),t.removeEventListener("error",h),i?.removeEventListener("abort",c)};s=()=>{("seeked"===e?!t.seeking:t.readyState>=("loadedmetadata"===e?1:2))&&(d(),a())},h=()=>{d(),n(new Error(`视频预览准备失败:${e} 前解码错误`))},c=()=>{d(),n(new DOMException("媒体预览准备已取消","AbortError"))},o=setTimeout(()=>{d(),n(new Error(`视频预览准备失败:${e} 超时`))},15e3),t.addEventListener(e,s),t.addEventListener("error",h,{once:!0}),i?.addEventListener("abort",c,{once:!0});try{r?.(),i?.aborted?c():null!==t.error?h():s()}catch(t){d(),n(t)}})}function v(t={}){const e=t.maxConcurrency??function(){if("undefined"==typeof navigator)return 2;const t=navigator.userAgent;if(/iPad|iPhone|iPod/.test(t)||/Macintosh/.test(t)&&(navigator.maxTouchPoints??0)>1)return 1;const e=navigator.deviceMemory;return void 0!==e&&e<=2?1:2}();if(!Number.isInteger(e)||e<1||e>4)throw new RangeError("媒体预览并发数必须是 1-4 的整数");const r=o(e),a=o(1);let n=!1;return{async prepare(t,e){if(n)throw new Error("媒体预览执行器已释放");const o="video"===t.kind,h=await(o?a:r).acquire(e);try{const r=o?await async function(t,e){const i=URL.createObjectURL(t.file),r=document.createElement("video");r.muted=!0,r.preload="metadata",r.playsInline=!0;try{await y(r,"loadedmetadata",e,()=>{r.src=i,r.load()});const a=r.videoWidth,n=r.videoHeight;if(a<=0||n<=0)throw new Error("视频预览准备失败:视频尺寸无效");const o=Number.isFinite(r.duration)&&r.duration>0?r.duration:void 0,s=void 0===t.atTime?void 0===o?0:Math.min(1,o/2):Math.max(0,Math.min(t.atTime,o??t.atTime));s>0&&await y(r,"seeked",e,()=>{r.currentTime=s}),await y(r,"loadeddata",e,()=>{r.preload="auto"});const h=void 0===o?void 0:o;let c,d;try{c=await g(r,a,n,t,e)}catch(t){if(e?.aborted||t instanceof RangeError)throw t}if(t.includeDisplayPoster)try{d=await g(r,a,n,{...t,maxSize:960,targetBytes:163840,maxBytes:262144,quality:.9,minQuality:.8},e)}catch(t){if(e?.aborted||t instanceof RangeError)throw t}return{width:a,height:n,...void 0===h?{}:{duration:h},...void 0===c?{}:{posterData:c},...void 0===d?{}:{displayPosterData:d}}}finally{r.pause(),r.removeAttribute("src"),r.load(),URL.revokeObjectURL(i)}}(t,e):await async function(t,e){s(e);const{maxSize:r,targetBytes:a,maxBytes:n}=u(t),o=await i(t.file);function h(e,i){return"image/jpeg"===t.file.type&&t.file.size<=a&&Math.max(e,i)<=Math.min(r,480)}async function d(i,a){const o="image/jpeg"===t.file.type&&Math.max(a.width,a.height)<=r&&t.file.size<=n;try{const e=await i;if(!o||t.file.size>e.byteLength)return e}catch(t){if(!(o&&t instanceof w))throw t}return s(e),await t.file.arrayBuffer()}if(s(e),void 0!==o){if(!1===t.includePoster)return o;if(h(o.width,o.height))return{...o,posterData:await t.file.arrayBuffer()}}const l=void 0===o?void 0:c(o.width,o.height,r);let f;try{f=void 0===l?await createImageBitmap(t.file):await createImageBitmap(t.file,{resizeWidth:l.width,resizeHeight:l.height,resizeQuality:"high"})}catch(t){if(e?.aborted)throw t}if(void 0!==f)try{s(e);const i=o??{width:f.width,height:f.height};return!1===t.includePoster?i:void 0===o&&h(f.width,f.height)?{...i,posterData:await t.file.arrayBuffer()}:{...i,posterData:await d(g(f,f.width,f.height,t,e),i)}}finally{f.close()}const m=URL.createObjectURL(t.file),y=new Image;try{await new Promise((t,i)=>{let r,a;const n=()=>{void 0!==r&&clearTimeout(r),y.onload=null,y.onerror=null,e?.removeEventListener("abort",a)};a=()=>{n(),i(new DOMException("媒体预览准备已取消","AbortError"))},y.onload=()=>{n(),t()},y.onerror=()=>{n(),i(new Error("图片预览准备失败:Image 解码错误"))},r=setTimeout(()=>{n(),i(new Error("图片预览准备失败:Image 解码超时"))},15e3),e?.addEventListener("abort",a,{once:!0}),y.src=m});const i=o??{width:y.naturalWidth,height:y.naturalHeight};return!1===t.includePoster?i:h(y.naturalWidth,y.naturalHeight)?{...i,posterData:await t.file.arrayBuffer()}:{...i,posterData:await d(g(y,y.naturalWidth,y.naturalHeight,t,e),i)}}finally{y.removeAttribute("src"),URL.revokeObjectURL(m)}}(t,e);return s(e),r}finally{h()}},dispose(){n||(n=!0,r.dispose(),a.dispose())}}}export{v as createMediaPreviewPreparationExecutor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let e,t;const r={customerService:e=>e.customerService?.text??"",text:e=>e.text??"",file:e=>[e.file?.fileName,e.file?.extension].filter(e=>void 0!==e&&""!==e).join(" "),contact:e=>[e.contact?.displayName,e.contact?.username,e.contact?.targetId].filter(e=>void 0!==e&&""!==e).join(" "),image:()=>"",video:()=>"",voice:()=>"",sticker:()=>"",filesAlbum:e=>[e.filesAlbum?.caption,...e.filesAlbum?.items.map(e=>e.fileName)??[]].filter(Boolean).join(" "),mediaAlbum:e=>e.mediaAlbum?.caption?.trim()??"",miniProgram:e=>[e.miniProgram?.name,e.miniProgram?.description].filter(e=>void 0!==e&&""!==e).join(" "),robot:e=>e.robot?.modules.flatMap(e=>"section"===e.type?[e.content]:[]).filter(e=>""!==e.trim()).join(" ")??"",game:()=>"",transfer:e=>[e.transfer?.fromUserName,e.transfer?.toUserName,e.transfer?.remark,e.transfer?.coinName].filter(e=>void 0!==e&&""!==e).join(" "),gift:e=>[e.gift?.giftName,e.gift?.fromUserName,e.gift?.toUserName,e.gift?.explain].filter(e=>void 0!==e&&""!==e).join(" "),liveRoom:e=>[e.liveRoom?.liveRoomName,e.liveRoom?.broadcasterUserName].filter(e=>void 0!==e&&""!==e).join(" "),call:()=>"",redPacket:e=>e.redPacket?.coinName?.trim()??"",system:()=>"",unknown:()=>""};function n(e){return r[e.contentType](e.body)}async function i(e){const r=e.trim(),n=r.charAt(0);if(/^[A-Z]$/i.test(n))return n.toLocaleUpperCase();if(
|
|
1
|
+
let e,t;const r={customerService:e=>e.customerService?.text??"",text:e=>e.text??"",file:e=>[e.file?.fileName,e.file?.extension].filter(e=>void 0!==e&&""!==e).join(" "),contact:e=>[e.contact?.displayName,e.contact?.username,e.contact?.targetId].filter(e=>void 0!==e&&""!==e).join(" "),image:()=>"",video:()=>"",voice:()=>"",sticker:()=>"",filesAlbum:e=>[e.filesAlbum?.caption,...e.filesAlbum?.items.map(e=>e.fileName)??[]].filter(Boolean).join(" "),mediaAlbum:e=>e.mediaAlbum?.caption?.trim()??"",miniProgram:e=>[e.miniProgram?.name,e.miniProgram?.description].filter(e=>void 0!==e&&""!==e).join(" "),robot:e=>e.robot?.modules.flatMap(e=>"section"===e.type?[e.content]:[]).filter(e=>""!==e.trim()).join(" ")??"",game:()=>"",transfer:e=>[e.transfer?.fromUserName,e.transfer?.toUserName,e.transfer?.remark,e.transfer?.coinName].filter(e=>void 0!==e&&""!==e).join(" "),gift:e=>[e.gift?.giftName,e.gift?.fromUserName,e.gift?.toUserName,e.gift?.explain].filter(e=>void 0!==e&&""!==e).join(" "),liveRoom:e=>[e.liveRoom?.liveRoomName,e.liveRoom?.broadcasterUserName].filter(e=>void 0!==e&&""!==e).join(" "),call:()=>"",redPacket:e=>e.redPacket?.coinName?.trim()??"",system:()=>"",unknown:()=>""};function n(e){return r[e.contentType](e.body)}async function i(e){const r=e.trim(),n=r.charAt(0);if(/^[A-Z]$/i.test(n))return n.toLocaleUpperCase();if(!new RegExp("\\p{Script=Han}","u").test(n))return"#";const i=(await(t??(t=import("pinyin-pro").then(e=>e.pinyin)),t))(r,{type:"array"}),o=i[0]?.charAt(0).toLocaleUpperCase();return/^[A-Z]$/.test(o??"")?o:"#"}async function o(t){const r=t.trim().toLocaleLowerCase();if(""===r)throw new Error("IM 文本搜索关键词不能为空");const n=r.replace(/[\s'-]+/g,""),i=/^[a-z]+$/.test(n)?await(e??(e=import("pinyin-pro").then(e=>e.match)),e):void 0;return Object.freeze({keyword:r,match(e,t={}){const o=function(e,t){const r=[],n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");for(const t of e.matchAll(new RegExp(n,"giu"))){const e=t.index;r.push(Object.freeze({start:e,end:e+t[0].length}))}return Object.freeze(r)}(e,r);if(o.length>0)return Object.freeze({method:"direct",ranges:o});if(!1===t.pinyin||void 0===i||!new RegExp("\\p{Script=Han}","u").test(e))return null;const a=i(e,n);if(null===a)return null;const c=function(e,t){if(0===t.length)return Object.freeze([]);const r=[...new Set(t)].filter(t=>Number.isSafeInteger(t)&&t>=0&&t<e.length).sort((e,t)=>e-t);if(0===r.length)return Object.freeze([]);const n=[];let i=r[0],o=i;for(const e of r.slice(1))e!==o+1?(n.push(Object.freeze({start:i,end:o+1})),i=e,o=e):o=e;return n.push(Object.freeze({start:i,end:o+1})),Object.freeze(n)}(e,a);return 0===c.length?null:Object.freeze({method:"pinyin",ranges:c})}})}export{o as createImTextSearchMatcher,n as extractSearchText,i as getImTextSearchInitial};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MEDIA_ALBUM_MAX_ITEMS as
|
|
1
|
+
import{MEDIA_ALBUM_MAX_ITEMS as t,MEDIA_ALBUM_CONTENT_MAX_BYTES as o}from"./mapping/media-album-body.js";const r=Math.floor(3*(o-32768)/4);function a(o=1){if(!Number.isInteger(o)||o<1||o>t)throw new RangeError(`媒体缩略图项数必须是 1 到 ${t} 的整数`);const r=1===o?1:o+1;return{maxSize:o<=2?480:320,targetBytes:Math.min(8192,3*Math.floor(49152/r/3)),maxBytes:Math.min(o<=2?24576:16384,3*Math.floor(73728/r/3))}}export{r as MEDIA_THUMBNAIL_MAX_BYTES,a as resolveMediaThumbnailPolicy};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveMediaThumbnailPolicy as e,MEDIA_THUMBNAIL_MAX_BYTES as t}from"../../media-thumbnail-policy.js";import{MEDIA_ALBUM_CAPTION_MAX_LENGTH as a,MEDIA_ALBUM_MAX_ITEMS as i,resolveMediaAlbumSendContentType as n,measureMediaAlbumContentBytes as o,mediaAlbumBMessageFields as r,MEDIA_ALBUM_CONTENT_WARN_BYTES as d}from"../../mapping/media-album-body.js";import{computeSortKey as s}from"../../mapping/sort.js";import{SIMPLE_ENCRYPT_HEAD_BYTES as l}from"../../ports/crypto-port.js";import{mediaAssetResourceVersion as c}from"../../ports/media-asset-cache-port.js";import{LOCAL_MEDIA_ERROR_CODE as u}from"../../mapping/stored-message.js";function p(e){return Number.isFinite(e)&&e>0}function m(e,a){if(("video"===a||"image"===a)&&void 0!==e&&p(e.width)&&p(e.height)&&("video"!==a||void 0===e.duration||p(e.duration))&&("video"!==a||void 0===e.posterData||e.posterData instanceof Uint8Array&&0!==e.posterData.length&&!(e.posterData.length>t)))return{width:e.width,height:e.height,..."video"===a&&void 0!==e.duration?{duration:e.duration}:{},..."video"===a&&void 0!==e.posterData?{thumbData:new Uint8Array(e.posterData)}:{}}}function f(e,t){return void 0===t?e:{...e,width:t.width,height:t.height,...void 0===t.thumbData?{}:{thumbData:t.thumbData},...void 0===e.duration&&void 0!==t.duration?{duration:t.duration}:{}}}const v={contentType:"image",uploadKind:"image",encryptMode:"integral",streamUpload:!0,async buildPreview(t,a,i,n,o=1){const r=await i.imageDimensions(t,a,n),d=await i.imageThumbnail(t,{mimeType:a,...e(o)},n);return{width:r.width,height:r.height,...d.data.byteLength<=e(o).maxBytes?{thumbData:d.data}:{}}},buildBody:({url:e,meta:t,size:a,teaKey:i,fileEncryptType:n})=>({image:{url:e,width:t.width,height:t.height,...void 0!==t.thumbData?{thumbData:t.thumbData}:{},...void 0!==a?{size:a}:{},...void 0!==n?{fileEncryptType:n}:{},...void 0!==i?{teaKey:i}:{}}})},g={contentType:"video",uploadKind:"video",encryptMode:"integral",streamUpload:!0,async buildPreview(t,a,i,n,o=1){const r=await i.videoPoster(t,{mimeType:a,...e(o)},n);return{width:r.width,height:r.height,...r.data.byteLength<=e(o).maxBytes?{thumbData:r.data}:{},duration:r.duration}},buildBody:({url:e,meta:t,size:a,teaKey:i,fileEncryptType:n},o)=>({video:{url:e,width:t.width,height:t.height,...void 0!==t.duration?{duration:t.duration}:{},...void 0!==o.caption&&""!==o.caption?{describe:o.caption}:{},...void 0!==t.thumbData?{thumbData:t.thumbData}:{},...void 0!==a?{size:a,sizeUnit:"bytes"}:{},...void 0!==n?{fileEncryptType:n}:{},...void 0!==i?{teaKey:i}:{}}})},y={contentType:"voice",uploadKind:"voice",encryptMode:"integral",buildPreview:()=>Promise.resolve({width:0,height:0}),buildBody:({url:e,size:t,teaKey:a,fileEncryptType:i},n)=>({voice:{url:e,durationMs:n.durationMs??0,...void 0!==n.waveform&&n.waveform.length>0?{waveform:n.waveform}:{},...void 0!==t?{size:t}:{},...void 0!==i?{fileEncryptType:i}:{},...void 0!==a?{teaKey:a}:{}}})},h={contentType:"sticker",uploadKind:"sticker",encryptMode:"none",async buildPreview(e,t,a,i){const n=await a.imageDimensions(e,t,i);return{width:n.width,height:n.height}},buildBody:({url:e,meta:t,size:a})=>({sticker:{url:e,width:t.width,height:t.height,exprType:2,imageType:1,...void 0===a?{}:{size:a}}})};const w={contentType:"file",uploadKind:"file",encryptMode:"simple",streamUpload:!0,buildPreview:()=>Promise.resolve({width:0,height:0}),buildBody({url:e,size:t,teaKey:a,fileEncryptType:i},n){const o=n.filename??"",r=function(e){const t=e.lastIndexOf(".");return t>-1&&t<e.length-1?e.slice(t+1).toLowerCase():""}(o),d=function(e,t){const a=t??"";return a.startsWith("image/")||["jpg","jpeg","png","gif","webp","bmp","heic","svg"].includes(e)?1:a.startsWith("video/")||["mp4","mov","m4v","3gp","avi","mkv","webm","flv"].includes(e)?2:a.startsWith("audio/")||["mp3","m4a","wav","aac","flac","ogg"].includes(e)?3:["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","zip","rar","7z","apk","json"].includes(e)?4:0}(r,n.mimeType);return{file:{url:e,fileName:o,...void 0!==t?{size:t}:{},...""!==r?{extension:r}:{},...0!==d?{fileType:d}:{},...void 0!==n.mimeType&&""!==n.mimeType?{mimeType:n.mimeType}:{},...void 0!==i?{fileEncryptType:i}:{},...void 0!==a?{teaKey:a}:{}}}}},b={...w,contentType:"filesAlbum",buildBody(e,t){const a=w.buildBody(e,t).file;return{filesAlbum:{...t.caption?.trim()?{caption:t.caption}:{},items:[{...a,extension:a.extension??"",fileType:a.fileType??0,...["zip","rar","torrent"].includes(a.extension??"")?{fileType:5}:{},...void 0===e.md5?{}:{md5:e.md5}}]}}}};function T(e){switch(e){case"empty":return"media.empty";case"no-crypto":return"media.noCrypto";case"preview-failed":return"media.previewFailed";case"encrypt-failed":return"media.encryptFailed";case"upload-failed":case"offline":return"media.uploadFailed";case"cancelled":return"media.cancelled";case"paused":throw new Error("暂停不是失败状态,不应生成失败文案");case"invalid-duration":return"media.invalidDuration";case"content-too-large":return"media.contentTooLarge"}}function k(e,t){return"video"===e||void 0===t||t>16777216?"large":"small"}function M(){return new DOMException("媒体上传已取消","AbortError")}function I(e){return"album"===e.kind?e.items.flatMap(e=>void 0===e.resume||void 0!==e.uploaded?[]:[{resume:e.resume,kind:e.uploadKind}]):void 0===e.resume?[]:[{resume:e.resume,kind:e.spec.uploadKind}]}function A(e){if("album"===e.kind)return{code:u,reason:"unknown",displayCode:T(e.failureReason),retryable:!1};const t="video"===e.spec.contentType||"file"===e.spec.contentType||"filesAlbum"===e.spec.contentType;return{code:u,reason:"unknown",displayCode:t?"media.uploadInterrupted":T(e.failureReason),mediaKind:e.spec.uploadKind,retryable:!1}}function E(e,t){if(!Number.isInteger(e)||e<1||e>6)throw new RangeError(`媒体上传并发数必须是 1-6 的整数(${t})`)}function C(t){const p=function(e){let t=0,a=0;const i=[];function n(i){return t<e.total&&("large"!==i||a<e.largeFiles)}function o(e){t+=1,"large"===e&&(a+=1);let i=!1;return()=>{i||(i=!0,t-=1,"large"===e&&(a-=1),r())}}function r(){let e=0;for(;e<i.length;){const t=i[e];t.signal.aborted?(i.splice(e,1),t.signal.removeEventListener("abort",t.onAbort),t.reject(M())):n(t.tier)?(i.splice(e,1),t.signal.removeEventListener("abort",t.onAbort),t.resolve(o(t.tier))):e+=1}}return{acquire:(e,t)=>t.aborted?Promise.reject(M()):new Promise((a,n)=>{const o={tier:e,signal:t,resolve:a,reject:n,onAbort:()=>{const e=i.indexOf(o);e>=0&&i.splice(e,1),n(M())}};i.push(o),t.addEventListener("abort",o.onAbort,{once:!0}),r()})}}(function(e){if(void 0===e)return{total:5,largeFiles:3};if("number"==typeof e)return E(e,"总数"),{total:e,largeFiles:e};const t=e.total??5;E(t,"total");const a=e.largeFiles??Math.min(3,t);if(E(a,"largeFiles"),a>t)throw new RangeError(`媒体上传大文件档并发数 ${a} 不能超过总并发数 ${t}`);return{total:t,largeFiles:a}}(t.maxConcurrentUploads)),C=/* @__PURE__ */new Map,P=/* @__PURE__ */new Map,K=/* @__PURE__ */new Map,R=/* @__PURE__ */new Map;let D=!1;const z=/* @__PURE__ */new Map,U=/* @__PURE__ */new Map,x=/* @__PURE__ */new Set,S=/* @__PURE__ */new Map,_=/* @__PURE__ */new Map;function B(e,t){const a=S.get(e)??/* @__PURE__ */new Set;S.set(e,a),a.add(t),x.add(t),t.finally(()=>{a.delete(t),x.delete(t),0===a.size&&S.get(e)===a&&S.delete(e),ne(e)})}function O(e){return[...S.get(e)??[]]}const F=/* @__PURE__ */new Map,L=/* @__PURE__ */new Set,q=/* @__PURE__ */new Map,V=/* @__PURE__ */new Map,j=/* @__PURE__ */new Map,N=/* @__PURE__ */new Map,Y=/* @__PURE__ */new Map,$=/* @__PURE__ */new Map;let W=!0,G=0,H=0;function J(e){return{conversationType:e.conversationType,conversationId:e.conversationId}}function Q(e,a,i,n){t.mediaTransfer.abandonUpload(e).catch(e=>{t.onMediaTransferError?.({stage:"upload",kind:a,messageId:i,conversation:n,cause:e})})}function X(e,a,i,n,o,r){if(!W)return;const d=J(a);q.set(e,{input:J(a),state:i,percent:n,phase:r}),t.emitter.emit({type:"media-task:updated",conversation:d,task:{id:`upload:${e}`,messageId:e,ref:d,direction:"upload",state:i,percent:Math.max(0,Math.min(100,Math.round(n))),attempt:R.get(e)?.attempt??1,maxAttempts:3,...j.get(e),...V.has(e)?{items:Object.freeze(V.get(e).map(e=>Object.freeze({...e,state:"completed"===e.state?"completed":"canceled"===i||"failed"===i?i:e.state})))}:{},...U.get(e),...void 0===r?{}:{phase:r},...void 0===o?{}:{failure:o}}})}function Z(e,t){ie(),Y.delete(e),$.delete(e),Y.set(e,t),ae()}function ee(e){const t=R.get(e);if(C.has(e)||F.has(e)||O(e).length>0||void 0!==t&&(!0!==t.settled||void 0!==t.waiting))return!1;const a=q.get(e)?.state;return"failed"===a||"canceled"===a||"paused"===a&&"manual"===t?.pauseReason}function te(e,a){const i=J(a.input),n=I(a),o="media"===a.kind?a.spec.uploadKind:"image",r={...A(a),displayCode:"media.uploadInterrupted",retryable:!1};Y.delete(e),$.delete(e),R.delete(e),N.delete(e),j.delete(e),V.delete(e),U.delete(e),z.delete(e),q.delete(e),K.delete(e);for(const t of n)Q(t.resume,t.kind,e,i);if(function(e,a,i){const n=t.recoveryPort;if(void 0===n)return;const o=O(e),r=Promise.all(o).then(()=>n.remove(J(a),e)).catch(n=>{t.onMediaTransferError?.({stage:"upload",kind:i,messageId:e,conversation:J(a),cause:n})});B(e,r)}(e,i,o),!W)return;const d=t.domainState.getConversationMessage?.(i,e)??a.message;"sent"!==d.status&&(t.domainState.upsertMessages([{...d,status:"failed",failure:r}],"live"),X(e,i,"failed",0,r))}function ae(){if(W)for(const[e,t]of Y){if(Y.size<=3)break;ee(e)&&te(e,t)}}function ie(){if(!W)return;const e=Date.now();for(const[t,a]of Y){const i=$.get(t);void 0!==i&&e-i>=864e5&&ee(t)&&te(t,a)}}function ne(e){W&&(Y.has(e)&&ee(e)&&!$.has(e)&&$.set(e,Date.now()),ae())}async function oe(e,a,i,n,o,r,d=!1){const v=G,g=()=>W&&v===G;if(!g())return void 0!==r&&void 0!==i&&Q(r,e.uploadKind,i,J(a)),{ok:!1,reason:"cancelled"};const y=H;let h,w,b=o,I=r,A=Promise.resolve(void 0);const E=/* @__PURE__ */new Set,x="function"==typeof a.data;const S=function(e){return"undefined"!=typeof Blob&&e instanceof Blob}(a.data)?a.data:void 0,O=x||void 0!==S?void 0:a.data,F=x||void 0!==S,L=!0===e.streamUpload&&void 0!==S,V=e=>{if(void 0!==S)return S;if(void 0===e)throw new Error("媒体预览缺少内容:非 Blob 输入必须先读出字节");return new Blob([e],void 0===a.mimeType?void 0:{type:a.mimeType})};if(0===O?.length||0===S?.size)return{ok:!1,reason:"empty"};const $=a.encrypted??!0;if($&&void 0===t.crypto)return{ok:!1,reason:"no-crypto"};const ee=m(a.localPreviewMetadata,e.contentType);if(("video"===e.contentType||"image"===e.contentType)&&void 0!==a.localPreviewMetadata&&void 0===ee)return{ok:!1,reason:"preview-failed"};const te=void 0===i||void 0===n?t.outbox.allocateMessageIdentity({conversationId:a.conversationId,conversationType:a.conversationType}):{id:i,createdAt:n},{id:ae,createdAt:ie}=te,ne=t.getSelfId();let oe=ee??{width:0,height:0};if(!F)try{oe=f(await e.buildPreview(V(O),a.mimeType,t.mediaPreview),ee)}catch{}if(!g())return void 0!==I&&Q(I,e.uploadKind,ae,J(a)),{ok:!1,reason:"cancelled"};const re=S?.size??O?.byteLength,de={url:a.localPreviewUrl??"",...void 0===re?{}:{size:re}};let se={id:ae,conversationId:a.conversationId,conversationType:a.conversationType,senderId:ne,contentType:e.contentType,body:e.buildBody({...de,meta:oe},a),createdAt:ie,sortKey:s(ie,ae),status:"uploading",receipt:"unread",encryption:{encrypted:$},...void 0!==a.refMessageId?{refMessageId:a.refMessageId}:{}};t.domainState.upsertMessages([se],"live",{newOutgoing:!0});const ce=d?0:N.get(ae)??0;d&&j.delete(ae),N.set(ae,ce),X(ae,a,"queued",ce,void 0,"waiting-upload-slot");const ue=(i,n=!1)=>{const o={code:u,reason:"unknown",displayCode:"cleanup-unconfirmed"===h?"media.cleanupUnconfirmed":"resume-unavailable"===h?"media.resumeUnavailable":"timeout"===h?"media.uploadTimeout":T(i),mediaKind:e.uploadKind,retryable:n};if(!g())return{ok:!1,reason:i};const r=R.get(ae);return"paused"===r?.stopped?(X(ae,a,"paused",N.get(ae)??0),{ok:!1,reason:i}):void 0!==r&&void 0===r.stopped&&r.attempt<3&&("network"===r.failure||"timeout"===r.failure||"credentials-expired"===r.failure||"offline"===i&&void 0!==t.waitUntilOnline)?(X(ae,a,"queued",N.get(ae)??0,void 0,"waiting-retry"),{ok:!1,reason:i}):("cancelled"===r?.stopped||void 0!==r&&r.attempt>=3&&("network"===r.failure||"timeout"===r.failure||"credentials-expired"===r.failure)||(t.domainState.upsertMessages([{...se,status:"failed",failure:o}],"live"),X(ae,a,"cancelled"===i?"canceled":"failed",N.get(ae)??0,o)),{ok:!1,reason:i})},pe=async()=>{if(void 0!==I)try{await t.mediaTransfer.abandonUpload(I),I=void 0}catch(i){throw h="cleanup-unconfirmed",t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i}),i}},me=async i=>{if(await A,await Promise.all([...E]),"cancelled"===i&&"paused"!==R.get(ae)?.stopped&&!0!==R.get(ae)?.retainCheckpoint&&"cleanup-unconfirmed"!==h)try{await pe()}catch{}return"cancelled"===i&&"paused"!==R.get(ae)?.stopped&&!0!==R.get(ae)?.retainCheckpoint&&void 0!==t.recoveryPort&&(await Promise.all([...E]),await t.recoveryPort.remove(J(a),ae).catch(i=>t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i}))),g()?(Z(ae,{kind:"media",spec:e,input:a,createdAt:ie,message:se,failureReason:i,...!0===R.get(ae)?.retainCheckpoint?{retainCheckpoint:!0}:{},..."cleanup-unconfirmed"===h||"resume-unavailable"===h?{restartRequired:!0}:{},...void 0===b?{}:{teaKey:b},...void 0===I?{}:{resume:I}}),ue(i,!0)):{ok:!1,reason:"cancelled"}},fe=new AbortController;C.set(ae,fe),P.set(ae,J(a));const ve=R.get(ae)?.stopped;void 0!==ve&&fe.abort("cancelled"===ve&&R.get(ae)?.retainCheckpoint?"cancelled-preserve":ve),!1===t.isOnline?.()&&le(ae,"offline");try{if(d&&(await pe(),!g()))return{ok:!1,reason:"cancelled"};if(void 0!==S&&("video"!==e.contentType||void 0===ee?.thumbData)){try{oe=f(await e.buildPreview(S,a.mimeType,t.mediaPreview,fe.signal),ee)}catch{}if(!g())return{ok:!1,reason:"cancelled"};se={...se,body:e.buildBody({url:a.localPreviewUrl??"",meta:oe,size:S.size},a)},t.domainState.upsertMessages([se],"live")}const i=await p.acquire(k(e.contentType,S?.size??O?.byteLength),fe.signal);try{let i;X(ae,a,"running",N.get(ae)??0);try{L||(i=x?await a.data():void 0!==S?new Uint8Array(await S.arrayBuffer()):O)}catch{return ue("upload-failed",!0)}const n=L?S.size:i.length;if(0===n)return ue("empty");if(x&&("video"!==e.contentType||void 0===ee?.thumbData)){try{oe=f(await e.buildPreview(V(i),a.mimeType,t.mediaPreview,fe.signal),ee)}catch{}if(!g())return{ok:!1,reason:"cancelled"};se={...se,body:e.buildBody({url:a.localPreviewUrl??"",meta:oe,size:n},a)},t.domainState.upsertMessages([se],"live")}if(fe.signal.throwIfAborted(),("video"===e.contentType||"file"===e.contentType||"filesAlbum"===e.contentType)&&void 0!==t.recoveryPort&&!0===t.shouldPersistUpload?.(e.uploadKind,n)){w=new AbortController,_.set(ae,w);const n=w.signal;U.set(ae,{recovery:"session-only",recoveryReason:"fingerprint-pending"}),A=Promise.resolve().then(()=>t.recoveryPort.fingerprint(L?S:i,n)).catch(i=>{!n.aborted&&g()&&(U.set(ae,{recovery:"session-only",recoveryReason:"unavailable"}),t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i}))}),L||await A}if(fe.signal.aborted)throw M();let o,r,d=L?S:i,s=1;if($&&void 0!==t.crypto&&"none"!==e.encryptMode){const a=t.crypto;try{b??(b=a.randomTeaKey());const t=b;"simple"===e.encryptMode?(d=L?new Blob([new Uint8Array(a.encryptFileSimple({teaKey:t,plain:new Uint8Array(await S.slice(0,l).arrayBuffer())})),S.slice(l)]):a.encryptFileSimple({teaKey:t,plain:i}),s=2):L?(o=e=>a.encryptSymmetricChunked({teaKey:t,plain:e,signal:fe.signal}),s=3):(d=a.encryptSymmetric({teaKey:t,plain:i}),s=3)}catch{return ue("encrypt-failed")}}try{!1===t.isOnline?.()&&le(ae,"offline"),await(t.waitUntilOnline?.(fe.signal)),fe.signal.throwIfAborted();r=(await t.mediaTransfer.upload({recoveryManaged:!0,forceRefreshCredentials:!0===R.get(ae)?.refreshCredentials,data:d,...void 0===o?{}:{transformPart:o},kind:e.uploadKind,conversationType:a.conversationType,signal:fe.signal,...void 0===I?{}:{resume:I},onFailure:e=>{if(g()&&C.get(ae)===fe){h=e;const t=R.get(ae);void 0!==t&&(t.failure=e)}},onResumeInvalidated:()=>{g()&&C.get(ae)===fe&&(I=void 0)},onResumable:i=>{if(g()&&C.get(ae)===fe&&(I=i,!("cancelled"===R.get(ae)?.stopped&&!0!==R.get(ae)?.retainCheckpoint||void 0===w||void 0===t.recoveryPort||"video"!==e.contentType&&"file"!==e.contentType&&"filesAlbum"!==e.contentType))){const n=z.get(ae)??Date.now();z.set(ae,n);const o=A.then(async o=>{void 0===o||w?.signal.aborted||!g()&&!D||C.get(ae)!==fe||"cancelled"===R.get(ae)?.stopped&&!0!==R.get(ae)?.retainCheckpoint&&!D||(await t.recoveryPort.save({version:1,ref:J(a),messageId:ae,kind:"video"===e.contentType?"video":"file",createdAt:ie,savedAt:n,source:{...o,...void 0===a.filename?{}:{filename:a.filename},...void 0===a.mimeType?{}:{mimeType:a.mimeType}},encrypted:$,...void 0===b?{}:{teaKey:b},resume:i,...void 0===a.caption?{}:{caption:a.caption},...void 0===a.filesAlbum?{}:{filesAlbum:a.filesAlbum},...void 0===a.refMessageId?{}:{refMessageId:a.refMessageId},..."video"===e.contentType?{preview:oe}:{}}),C.get(ae)!==fe||w?.signal.aborted||U.set(ae,{recovery:"available"}))}).catch(i=>{const n="object"==typeof i&&null!==i&&"reason"in i?String(i.reason):"storage";(C.get(ae)===fe||Y.has(ae))&&U.set(ae,{recovery:"session-only",recoveryReason:n}),t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i})});E.add(o),B(ae,o),o.finally(()=>{E.delete(o);const e=q.get(ae);!W||void 0===e||"running"!==e.state&&"paused"!==e.state&&"queued"!==e.state||X(ae,e.input,e.state,e.percent,void 0,e.phase)})}},...void 0!==a.filename?{filename:a.filename}:{},...void 0!==a.mimeType?{mimeType:a.mimeType}:{},onProgress:e=>{if(!g()||fe.signal.aborted||C.get(ae)!==fe)return;const i=Number.isFinite(e.percent)?Math.max(0,Math.min(100,Math.round(e.percent))):0,n=Math.max(N.get(ae)??0,i);j.set(ae,{bytesTransferred:e.bytesTransferred,bytesTotal:e.bytesTotal}),N.set(ae,n),t.emitter.emit({type:"media:progress",conversation:J(a),messageId:ae,percent:n}),fe.signal.aborted||C.get(ae)!==fe||X(ae,a,"running",n,void 0,e.phase)}})).url}catch(i){if(fe.signal.aborted&&i instanceof Error&&"AbortError"===i.name||t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i}),!g())return{ok:!1,reason:"cancelled"};const n=fe.signal.aborted?K.get(ae)??"cancelled":"upload-failed";return await me(n)}if(!g())return{ok:!1,reason:"cancelled"};if(fe.signal.aborted){const e=K.get(ae)??"cancelled";return await me(e)}if(y===H&&("image"===e.contentType||"video"===e.contentType)&&void 0!==t.mediaAssetCache){const n=e.contentType,o=S??new Blob([i],void 0===a.mimeType?void 0:{type:a.mimeType}),d=o.size;t.mediaAssetCache.put({kind:n,messageId:ae,resourceVersion:c(r,{conversation:J(a)}),blob:o,...void 0===a.mimeType?{}:{mimeType:a.mimeType}}).catch(e=>{t.onMediaAssetCacheError?.({operation:"put",kind:n,messageId:ae,byteLength:d,cause:e})})}const u="filesAlbum"===e.contentType?await(t.mediaPreview.fileMd5?.(V(i),fe.signal)):void 0;if(!g())return{ok:!1,reason:"cancelled"};if(fe.signal.throwIfAborted(),"filesAlbum"===e.contentType&&void 0===u)throw new Error("FILES_ALBUM requires fileMd5");return await A,await Promise.all([...E]),g()?(fe.signal.throwIfAborted(),t.outbox.enqueueMedia({optimisticAlreadyCreated:!0,id:ae,conversationId:a.conversationId,conversationType:a.conversationType,contentType:e.contentType,body:e.buildBody({url:r,meta:oe,size:n,...void 0===u?{}:{md5:u},..."none"===e.encryptMode?{}:{teaKey:b,fileEncryptType:s}},a),encryption:{encrypted:$},createdAt:ie,...void 0!==a.refMessageId?{refMessageId:a.refMessageId}:{}}),await Promise.all([...E]),void 0!==t.recoveryPort&&await t.recoveryPort.remove(J(a),ae).catch(i=>t.onMediaTransferError?.({stage:"upload",kind:e.uploadKind,messageId:ae,conversation:J(a),cause:i})),X(ae,a,"completed",100),{ok:!0,messageId:ae}):{ok:!1,reason:"cancelled"}}finally{i()}}catch{if(!g())return{ok:!1,reason:"cancelled"};const e=fe.signal.aborted?K.get(ae)??"cancelled":"upload-failed";return await me(e)}finally{await A,await Promise.all([...E]),_.get(ae)===w&&_.delete(ae),!g()&&D&&await Promise.all([...E]),g()||void 0===I||D&&"available"===U.get(ae)?.recovery||Q(I,e.uploadKind,ae,J(a)),C.get(ae)===fe&&(C.delete(ae),P.delete(ae),Y.has(ae)||N.delete(ae),K.delete(ae))}}async function re(l,y,h,w,b=!1){const M=G,I=()=>W&&M===G,A=J(l),E=(e,t)=>{for(const a of t)void 0!==a.resume&&Q(a.resume,a.uploadKind,e,A)};if(!I())return void 0!==y&&void 0!==w&&E(y,w),{ok:!1,reason:"cancelled"};if(0===l.items.length)return{ok:!1,reason:"empty"};if(l.items.length>i)throw new RangeError(`媒体合集最多 ${i} 项,收到 ${l.items.length} 项`);const D=void 0!==l.caption&&""!==l.caption.trim()?l.caption:void 0;if(void 0!==D&&Array.from(D).length>a)throw new RangeError(`媒体合集配文最长 ${a} 字符,收到 ${Array.from(D).length}`);if(l.items.some(e=>0===e.data.size))return{ok:!1,reason:"empty"};if(void 0===w&&"mediaAlbum"!==n(l)){const e=l.items[0];return oe("video"===e.kind?g:v,{conversationId:l.conversationId,conversationType:l.conversationType,data:e.data,...void 0!==e.mimeType?{mimeType:e.mimeType}:{},...void 0!==e.filename?{filename:e.filename}:{},...void 0!==e.localPreviewUrl?{localPreviewUrl:e.localPreviewUrl}:{},...void 0!==e.localPreviewMetadata?{localPreviewMetadata:e.localPreviewMetadata}:{},...void 0!==l.encrypted?{encrypted:l.encrypted}:{},...void 0!==l.refMessageId?{refMessageId:l.refMessageId}:{}},y,h)}const z=l.encrypted??!0;if(z&&void 0===t.crypto)return{ok:!1,reason:"no-crypto"};const U=z?t.crypto:void 0,x=H,S=void 0===y||void 0===h?t.outbox.allocateMessageIdentity(A):{id:y,createdAt:h},{id:_,createdAt:B}=S,O=l.items.map((e,t)=>{const a=w?.[t];return{uploadKind:e.kind,...void 0===a?.uploaded?{}:{uploaded:a.uploaded},...void 0===a?.preview?{}:{preview:a.preview},...void 0===a?.teaKey?{}:{teaKey:a.teaKey},...void 0===a?.resume?{}:{resume:a.resume}}}),F=O.map((e,t)=>{const a=l.items[t].data.size,i=void 0!==e.uploaded?a:b?0:e.resume?.bytesUploaded??0;return{itemIndex:t,bytesTransferred:i,bytesTotal:a,percent:void 0!==e.uploaded?100:Math.min(99,Math.floor(i/a*100)),state:void 0!==e.uploaded?"completed":"queued"}});V.set(_,F);const L=()=>({...void 0===D?{}:{caption:D},items:l.items.map((e,t)=>function(e,t,a){const i=t.uploaded,n=i?.meta??t.preview??m(e.localPreviewMetadata,e.kind)??{width:0,height:0};return{kind:e.kind,url:i?.url??e.localPreviewUrl??"",width:n.width,height:n.height,..."video"===e.kind&&void 0!==n.duration&&n.duration>0?{durationMs:Math.max(1,Math.round(1e3*n.duration))}:{},...void 0===n.thumbData?{}:{thumbData:n.thumbData},size:i?.size??e.data.size,...void 0===i?.teaKey?{}:{teaKey:i.teaKey},...void 0===i?{}:{fileEncryptType:i.fileEncryptType},...void 0===a?{}:{hd:a}}}(e,O[t],l.hd))});let q={id:_,conversationId:l.conversationId,conversationType:l.conversationType,senderId:t.getSelfId(),contentType:"mediaAlbum",body:{mediaAlbum:L()},createdAt:B,sortKey:s(B,_),status:"uploading",receipt:"unread",encryption:{encrypted:z},...void 0!==l.refMessageId?{refMessageId:l.refMessageId}:{}};t.domainState.upsertMessages([q],"live",{newOutgoing:!0});const $=b?0:N.get(_)??0;let ee;b&&j.delete(_),N.set(_,$),X(_,l,"queued",$,void 0,"waiting-upload-slot");const te=(e,a)=>{const i={code:u,reason:"unknown",displayCode:"cleanup-unconfirmed"===ee?"media.cleanupUnconfirmed":"resume-unavailable"===ee?"media.resumeUnavailable":"timeout"===ee?"media.uploadTimeout":T(e),retryable:a};if(!I())return{ok:!1,reason:e};const n=R.get(_);return"paused"===n?.stopped?(X(_,l,"paused",N.get(_)??0),{ok:!1,reason:e}):void 0!==n&&void 0===n.stopped&&n.attempt<3&&("network"===n.failure||"timeout"===n.failure||"credentials-expired"===n.failure||"offline"===e&&void 0!==t.waitUntilOnline)?(X(_,l,"queued",N.get(_)??0,void 0,"waiting-retry"),{ok:!1,reason:e}):("cancelled"===n?.stopped||void 0!==n&&n.attempt>=3&&("network"===n.failure||"timeout"===n.failure||"credentials-expired"===n.failure)||(t.domainState.upsertMessages([{...q,status:"failed",failure:i}],"live"),X(_,l,"cancelled"===e?"canceled":"failed",N.get(_)??0,i)),{ok:!1,reason:e})},ae=new AbortController;C.set(_,ae),P.set(_,A);const ie=R.get(_)?.stopped;void 0!==ie&&ae.abort("cancelled"===ie&&R.get(_)?.retainCheckpoint?"cancelled-preserve":ie),!1===t.isOnline?.()&&le(_,"offline");const ne=()=>I()&&C.get(_)===ae,re=()=>{I()&&ne()&&(q={...q,body:{mediaAlbum:L()}},t.domainState.upsertMessages([q],"live"))},de=l.items.reduce((e,t)=>e+t.data.size,0),se=O.map((e,t)=>void 0!==e.uploaded?l.items[t].data.size:e.resume?.bytesUploaded??0),ce=()=>{if(!I()||!ne()||ae.signal.aborted)return;const e=se.reduce((e,t)=>e+t,0),a=Math.min(99,Math.max(N.get(_)??0,Math.floor(e/de*100)));j.set(_,{bytesTransferred:e,bytesTotal:de}),N.set(_,a),t.emitter.emit({type:"media:progress",conversation:A,messageId:_,percent:a}),!ae.signal.aborted&&ne()&&X(_,l,"running",a,void 0,"transferring")};let ue;const pe=async()=>{let e=!0;return await Promise.all(O.map(async a=>{if(void 0!==a.resume)try{await t.mediaTransfer.abandonUpload(a.resume),delete a.resume}catch(i){e=!1,ee="cleanup-unconfirmed",t.onMediaTransferError?.({stage:"upload",kind:a.uploadKind,messageId:_,conversation:A,cause:i})}})),e},me=e=>(Z(_,{kind:"album",input:l,createdAt:B,message:q,failureReason:e,items:O,...!0===R.get(_)?.retainCheckpoint?{retainCheckpoint:!0}:{},..."cleanup-unconfirmed"===ee||"resume-unavailable"===ee?{restartRequired:!0}:{}}),te(e,!0));try{if(b){const e=await pe();if(!I())return{ok:!1,reason:"cancelled"};if(!e)return me("cancelled"===K.get(_)?"cancelled":"upload-failed");for(let e=0;e<O.length;e+=1)void 0===O[e].uploaded&&(se[e]=0)}if(await Promise.all(l.items.map(async(a,i)=>{const n=O[i];if(void 0===n.uploaded)try{!1===t.isOnline?.()&&le(_,"offline"),await(t.waitUntilOnline?.(ae.signal)),ae.signal.throwIfAborted();const o=await async function(a){const{conversation:i,encryptWith:n,isCurrentAttempt:o,item:r,onBytesUploaded:d,onPreviewReady:s,onSlotAcquired:l,signal:c,state:u}=a,y="video"===r.kind?g:v,h=e(a.itemCount),w=m(r.localPreviewMetadata,r.kind),b=void 0!==w?.thumbData&&w.thumbData.byteLength>h.maxBytes?{width:w.width,height:w.height,...void 0===w.duration?{}:{duration:w.duration}}:w;let T=b??{width:0,height:0};if("video"!==r.kind||void 0===b?.thumbData)try{T=f(await y.buildPreview(r.data,r.mimeType,t.mediaPreview,c,a.itemCount),b)}catch{}void 0===T.thumbData&&void 0!==u.preview?.thumbData&&u.preview.thumbData.byteLength<=h.maxBytes&&(T=u.preview),u.preview=T,s();const M=await p.acquire(k(r.kind,r.data.size),c);try{let e;l();let s=1;if(void 0!==n){u.teaKey??(u.teaKey=n.randomTeaKey());const t=u.teaKey;e=e=>n.encryptSymmetricChunked({teaKey:t,plain:e,signal:c}),s=3}return{url:(await t.mediaTransfer.upload({recoveryManaged:!0,forceRefreshCredentials:a.forceRefreshCredentials,data:r.data,...void 0===e?{}:{transformPart:e},kind:y.uploadKind,conversationType:i.conversationType,signal:c,...void 0===u.resume?{}:{resume:u.resume},onFailure:e=>{o()&&a.onFailure(e)},onResumeInvalidated:()=>{o()&&delete u.resume},onResumable:e=>{W&&o()&&(u.resume=e)},...void 0!==r.filename?{filename:r.filename}:{},...void 0!==r.mimeType?{mimeType:r.mimeType}:{},onProgress:e=>{W&&!c.aborted&&o()&&d(e.bytesTransferred)}})).url,meta:T,size:r.data.size,...void 0===u.teaKey?{}:{teaKey:u.teaKey},fileEncryptType:s}}finally{M()}}({item:a,itemCount:l.items.length,state:n,conversation:A,encryptWith:U,signal:ae.signal,isCurrentAttempt:ne,onPreviewReady:re,onSlotAcquired:()=>{I()&&ne()&&!ae.signal.aborted&&(F[i]={...F[i],state:"running"},X(_,l,"running",N.get(_)??0))},forceRefreshCredentials:!0===R.get(_)?.refreshCredentials,onFailure:e=>{const t="cleanup-unconfirmed"===e||"resume-unavailable"===e;if(ae.signal.aborted&&!t)return;"cleanup-unconfirmed"!==e&&("cleanup-unconfirmed"===ee||"resume-unavailable"!==e&&"resume-unavailable"===ee)||(ee=e);const a=R.get(_);void 0!==a&&(a.failure=ee)},onBytesUploaded:e=>{se[i]=e,F[i]={...F[i],bytesTransferred:e,percent:Math.min(99,Math.floor(e/a.data.size*100)),state:"running"},ce()}});if(!ne())return;n.uploaded=o,F[i]={...F[i],bytesTransferred:a.data.size,percent:100,state:"completed"},se[i]=a.data.size,ce()}catch(e){ne()&&!ae.signal.aborted&&(F[i]={...F[i],state:"failed"}),((e,a)=>{void 0===ue&&(ue=ae.signal.aborted?K.get(_)??"cancelled":"upload-failed","upload-failed"===ue&&t.onMediaTransferError?.({stage:"upload",kind:e,messageId:_,conversation:A,cause:a}),ae.abort("offline"))})(a.kind,e)}})),!I())return{ok:!1,reason:"cancelled"};if(!ne())return{ok:!1,reason:"cancelled"};if("cancelled"===K.get(_))return"cleanup-unconfirmed"!==ee&&!0!==R.get(_)?.retainCheckpoint&&await pe(),I()?me("cancelled"):{ok:!1,reason:"cancelled"};if(void 0!==ue)return me(ue);if(ae.signal.aborted){return me(K.get(_)??"cancelled")}const a=L();let i;try{i=o(r(a).content)}catch(e){return t.onMediaAlbumContentSize?.({messageId:_,conversation:A,itemCount:a.items.length,outcome:"rejected",cause:e}),te("content-too-large",!1)}if(i>=d&&t.onMediaAlbumContentSize?.({messageId:_,conversation:A,itemCount:a.items.length,contentBytes:i,outcome:"warn"}),x===H&&void 0!==t.mediaAssetCache){const e=t.mediaAssetCache;l.items.forEach((a,i)=>{const n=O[i].uploaded;void 0!==n&&e.put({kind:a.kind,messageId:_,resourceVersion:c(n.url,{conversation:A,itemIndex:i}),blob:a.data,...void 0===a.mimeType?{}:{mimeType:a.mimeType}}).catch(e=>{t.onMediaAssetCacheError?.({operation:"put",kind:a.kind,messageId:_,byteLength:a.data.size,cause:e})})})}return t.outbox.enqueueMedia({optimisticAlreadyCreated:!0,id:_,conversationId:l.conversationId,conversationType:l.conversationType,contentType:"mediaAlbum",body:{mediaAlbum:a},encryption:{encrypted:z},createdAt:B,...void 0!==l.refMessageId?{refMessageId:l.refMessageId}:{}}),X(_,l,"completed",100),{ok:!0,messageId:_}}finally{I()||E(_,O),C.get(_)===ae&&(C.delete(_),P.delete(_),Y.has(_)||N.delete(_),K.delete(_))}}function de(e,a,i,n=1){const{id:o,createdAt:r}=i??t.outbox.allocateMessageIdentity(J(e)),d={attempt:n};let s,l;$.delete(o),R.set(o,d);const c=new Promise((e,t)=>{s=e,l=t});return d.done=c,(async()=>{let e=await a(o,r);for(;R.get(o)===d&&void 0===d.stopped&&d.attempt<3;){const a=Y.get(o);if(!W||e.ok||void 0===a||a.restartRequired||"network"!==d.failure&&"timeout"!==d.failure&&"credentials-expired"!==d.failure&&(e.ok||"offline"!==e.reason||void 0===t.waitUntilOnline))break;const i=new AbortController;if(d.waiting=i,await(t.waitUntilOnline?.(i.signal).catch(()=>{})),await new Promise(e=>{const t=setTimeout(a,1===d.attempt?1e3:3e3);function a(){clearTimeout(t),i.signal.removeEventListener("abort",a),e()}i.signal.addEventListener("abort",a,{once:!0}),i.signal.aborted&&a()}),await(t.waitUntilOnline?.(i.signal).catch(()=>{})),delete d.waiting,!W||void 0!==d.stopped||R.get(o)!==d)break;d.attempt+=1,d.refreshCredentials="credentials-expired"===d.failure,delete d.failure,Y.delete(o),$.delete(o),e=await se(o,a,!1)}const i=Y.get(o),n="cancelled"!==d.stopped&&d.attempt>=3&&("network"===d.failure||"timeout"===d.failure||"credentials-expired"===d.failure);if(W&&R.get(o)===d&&void 0!==i&&n&&!0===t.retainFailedUploads){d.stopped="cancelled",d.retainCheckpoint=!0,i.retainCheckpoint=!0;const e={...A(i),displayCode:"timeout"===d.failure?"media.uploadTimeout":"media.uploadFailed",retryable:!0};t.domainState.upsertMessages([{...i.message,status:"failed",failure:e}],"live"),X(o,i.input,"failed",N.get(o)??0,e)}else if(W&&R.get(o)===d&&void 0!==i&&("cancelled"===d.stopped||n)){d.stopped="cancelled";const a={...A(i),displayCode:"timeout"===d.failure?"media.uploadTimeout":"media.cancelled",retryable:!0===d.retainCheckpoint&&!n};(!0!==d.retainCheckpoint||n)&&await pe(o,i),W&&R.get(o)===d&&(t.domainState.upsertMessages([{...i.message,status:"failed",failure:a}],"live"),X(o,i.input,"canceled",N.get(o)??0,a)),e={ok:!1,reason:"cancelled"}}return"paused"===d.stopped?{ok:!1,reason:"paused"}:e})().then(e=>{d.settled=!0,ne(o),s(e)},e=>{d.settled=!0,ne(o),l(e)}),c.then(()=>{R.get(o)===d&&"paused"!==d.stopped&&(R.delete(o),Y.has(o)||(N.delete(o),j.delete(o),V.delete(o),U.delete(o),z.delete(o),q.delete(o)))},()=>{R.get(o)===d&&R.delete(o)}),c}function se(e,t,a){return"album"===t.kind?re(t.input,e,t.createdAt,t.items,a):oe(t.spec,t.input,e,t.createdAt,t.teaKey,t.resume,a)}function le(e,t){const a=R.get(e);if(!W||void 0===a||"cancelled"===a.stopped)return;if("paused"===a.stopped)return void("pagehide"===t&&"offline"===a.pauseReason&&(a.pauseReason="pagehide"));a.stopped="paused",a.pauseReason=t;const i=C.get(e);a.waiting?.abort(),i?.abort("paused");const n=q.get(e);void 0!==n&&R.get(e)===a&&"paused"===a.stopped&&X(e,n.input,"paused",N.get(e)??n.percent)}async function ce(e,t="manual"){const a=R.get(e);if(!W||void 0===a||"cancelled"===a.stopped)return!1;if("paused"===a.stopped)return("manual"===t||"pagehide"===t&&"offline"===a.pauseReason)&&(a.pauseReason=t),await a.done,ne(e),W&&R.get(e)===a&&Y.has(e);le(e,t),await a.done,await Promise.all(O(e));const i=Y.get(e);return!(!W||R.get(e)!==a||"paused"!==a.stopped||void 0===i)&&(X(e,i.input,"paused",N.get(e)??0),!0)}function ue(e){ie();const a=R.get(e),i=Y.get(e);if(!W||"paused"!==a?.stopped||!0!==a.settled||void 0===i||C.has(e))return!1;Y.delete(e),$.delete(e);const n=G;return de(i.input,()=>se(e,i,!1),{id:e,createdAt:i.createdAt},a.attempt).catch(a=>{W&&n===G&&t.onMediaTransferError?.({stage:"upload",kind:"media"===i.kind?i.spec.uploadKind:"image",messageId:e,conversation:J(i.input),cause:a})}),!0}async function pe(e,a){Y.delete(e),$.delete(e),U.delete(e),z.delete(e),j.delete(e),V.delete(e),L.add(e);try{await Promise.all(O(e)),await(t.recoveryPort?.remove(J(a.input),e).catch(i=>{t.onMediaTransferError?.({stage:"upload",kind:"media"===a.kind?a.spec.uploadKind:"image",messageId:e,conversation:J(a.input),cause:i})})),await Promise.all(I(a).map(async i=>{try{await t.mediaTransfer.abandonUpload(i.resume)}catch(n){t.onMediaTransferError?.({stage:"upload",kind:i.kind,messageId:e,conversation:J(a.input),cause:n})}}))}catch(i){t.onMediaTransferError?.({stage:"upload",kind:"media"===a.kind?a.spec.uploadKind:"image",messageId:e,conversation:J(a.input),cause:i})}finally{L.delete(e),U.delete(e),z.delete(e),j.delete(e)}}function me(e,a){if(ie(),!W)return!1;const i=R.get(e),n=C.get(e);if(!0!==a?.retainCheckpoint&&_.get(e)?.abort(),void 0!==i&&(i.stopped="cancelled",i.retainCheckpoint=!0===a?.retainCheckpoint,i.waiting?.abort()),void 0!==n){const i=P.get(e);return void 0!==i&&!0!==a?.retainCheckpoint&&function(e,a){if(void 0===t.recoveryPort)return;const i=O(e),n="video"===t.domainState.getConversationMessage?.(a,e)?.contentType?"video":"file",o=Promise.all(i).then(()=>t.recoveryPort.remove(a,e)).catch(i=>{t.onMediaTransferError?.({stage:"upload",kind:n,messageId:e,conversation:a,cause:i})});B(e,o)}(e,i),K.set(e,"cancelled"),n.abort(!0===a?.retainCheckpoint?"cancelled-preserve":"cancelled"),!0}const o=Y.get(e);if(void 0===o||void 0===i)return void 0!==i&&"queued"===q.get(e)?.state;if(!0===a?.retainCheckpoint)o.retainCheckpoint=!0,o.failureReason="cancelled";else{B(e,pe(e,o))}const r={...A(o),displayCode:"media.cancelled",retryable:!0===a?.retainCheckpoint};return t.domainState.upsertMessages([{...o.message,status:"failed",failure:r}],"live"),X(e,o.input,"canceled",N.get(e)??0,r),R.get(e)===i&&R.delete(e),ne(e),!0!==a?.retainCheckpoint&&(N.delete(e),V.delete(e),q.delete(e)),!0}async function fe(e,t,a,i){ie();const n=G,o=O(t);return o.length>0&&await Promise.all(o),W&&n===G?(z.delete(t),de(i,()=>oe(e,i,t,a,void 0,void 0,!0),{id:t,createdAt:a})):{ok:!1,reason:"cancelled"}}return{sendImage:e=>de(e,(t,a)=>oe(v,e,t,a)),sendVideo:e=>de(e,(t,a)=>oe(g,e,t,a)),replaceVideo:(e,t,a)=>fe(g,e,t,a),sendVoice:e=>{const t=e.durationMs;return void 0===t||!Number.isFinite(t)||t<1e3?Promise.resolve({ok:!1,reason:"invalid-duration"}):de(e,(t,a)=>oe(y,e,t,a))},sendFile:e=>void 0!==e.caption&&Array.from(e.caption).length>a?Promise.resolve({ok:!1,reason:"content-too-large"}):de(e,(t,a)=>oe(e.filesAlbum||e.caption?.trim()?b:w,e,t,a)),sendGif:e=>de(e,(t,a)=>oe(h,{...e,encrypted:!1},t,a)),sendMediaAlbum:e=>de(e,(t,a)=>re(e,t,a)),replaceFile:(e,t,i)=>void 0!==i.caption&&Array.from(i.caption).length>a?Promise.resolve({ok:!1,reason:"content-too-large"}):fe(i.filesAlbum||i.caption?.trim()?b:w,e,t,i),cancel:me,pause:ce,async pauseAll(e="pagehide"){for(const{controller:e}of F.values())e.abort();await Promise.all([...R.keys()].map(t=>ce(t,e)))},async resumePaused(e,t){await Promise.all([...R.entries()].map(async([a,i])=>{if(t?.aborted||"paused"!==i.stopped||"manual"===i.pauseReason)return;if(void 0===e&&"offline"!==i.pauseReason)return;const n=q.get(a)?.input;if(void 0!==e&&(n?.conversationType!==e.conversationType||n.conversationId!==e.conversationId))return;await i.done;const o=Y.get(a);t?.aborted||R.get(a)!==i||void 0===o||void 0===e&&"offline"!==i.pauseReason||(void 0===e||o.input.conversationType===e.conversationType&&o.input.conversationId===e.conversationId)&&ue(a)}))},resume:ue,cancelConversation(e,a="offline"){for(const t of F.values())t.ref.conversationType===e.conversationType&&t.ref.conversationId===e.conversationId&&t.controller.abort();for(const[a,i]of Y)if(i.input.conversationType===e.conversationType&&i.input.conversationId===e.conversationId){if(R.has(a))me(a);else{for(const e of I(i))Q(e.resume,e.kind,a,J(i.input));t.recoveryPort?.remove(J(i.input),a).catch(n=>t.onMediaTransferError?.({stage:"upload",kind:"media"===i.kind?i.spec.uploadKind:"image",messageId:a,conversation:e,cause:n}))}Y.delete(a),$.delete(a),V.delete(a),j.delete(a),N.delete(a),q.delete(a)}if(W)for(const[t,i]of P){if(i.conversationType!==e.conversationType||i.conversationId!==e.conversationId)continue;const n=C.get(t);if(void 0===n)continue;const o=R.get(t);void 0!==o&&(o.stopped="cancelled"),K.set(t,a),_.get(t)?.abort(),n.abort(a)}},cancelAll(e="offline"){if(W){if("offline"===e){const e=G;for(const a of R.keys()){const i=q.get(a)?.input;ce(a,"offline").catch(n=>{W&&e===G&&void 0!==i&&t.onMediaTransferError?.({stage:"upload",kind:"video"===t.domainState.getConversationMessage?.(i,a)?.contentType?"video":"file",messageId:a,conversation:i,cause:n})})}return}if("session-ended"===e){for(const{controller:e}of F.values())e.abort();for(const e of R.values())e.stopped="cancelled",e.waiting?.abort();G+=1,H+=1}for(const t of _.values())t.abort(e);for(const t of C.values())t.abort(e)}},retry(e,t){if(ie(),L.has(e))return!1;if(!W)return!1;const a=Y.get(e);if(void 0===a)return!1;if(!0===R.get(e)?.retainCheckpoint&&!0!==R.get(e)?.settled)return!1;if(a.restartRequired&&!0!==t?.restartUpload)return!1;const i=!0===t?.restartUpload||"cancelled"===a.failureReason&&!0!==a.retainCheckpoint;return Y.delete(e),$.delete(e),de(a.input,()=>se(e,a,i),{id:e,createdAt:a.createdAt}),!0},expireRetainedUploads:ie,invalidateAssetCacheWrites(){H+=1},async dispose(e){if(!W)return;D=!0===e?.preserveRecovery;for(const{controller:e}of F.values())e.abort();const a=[...R.values()].flatMap(e=>void 0===e.done?[]:[e.done]);for(const e of R.values())e.stopped="cancelled",e.waiting?.abort();if(W=!1,H+=1,!D)for(const e of _.values())e.abort();for(const e of C.values())e.abort(D?"page-preserve":"cancelled");for(const[e,t]of Y)if(!D||"available"!==U.get(e)?.recovery)for(const a of I(t))Q(a.resume,a.kind,e,J(t.input));Y.clear(),$.clear(),await Promise.allSettled(a),await Promise.all([...x]),C.clear(),N.clear(),K.clear();for(const[e,t]of Y)if(!D||"available"!==U.get(e)?.recovery)for(const a of I(t))Q(a.resume,a.kind,e,J(t.input));Y.clear(),$.clear(),R.clear(),j.clear(),V.clear(),U.clear(),z.clear(),q.clear(),await(t.recoveryPort?.drain())},async recoverUpload(e,a,i){ie();const n=t.recoveryPort;if(!W||void 0===n)throw new Error("IM_MEDIA_RECOVERY_UNAVAILABLE");if(R.has(a)||F.has(a))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const o=new AbortController;F.set(a,{controller:o,ref:e});const r=()=>{if(!W||o.signal.aborted||F.get(a)?.controller!==o)throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE")},d=(e,a)=>{if(void 0===e||e.senderId!==t.getSelfId()||void 0!==e.recalled||void 0!==e.deletedForEveryone||"media.cancelled"===e.failure?.displayCode&&!0!==e.failure.retryable||"media.uploadTimeout"===e.failure?.displayCode&&!1===e.failure.retryable||"failed"!==e.status&&"uploading"!==e.status)return!1;const i="video"===e.contentType,n="file"===e.contentType||"filesAlbum"===e.contentType&&1===e.body.filesAlbum?.items.length;return(i||n)&&(void 0===a||e.contentType===a)};let s;try{s=await n.acquireLease(o.signal),r();const l=t.domainState.getConversationMessage?.(e,a);if(!d(l))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const c=await n.get(e,a);if(r(),void 0===c)throw new Error("IM_MEDIA_RECOVERY_NOT_FOUND");const u="video"===c.kind?"video":c.filesAlbum||c.caption?.trim()?"filesAlbum":"file";if(!d(l,u))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const p=await n.fingerprint(i,o.signal);if(r(),p.size!==c.source.size||p.sha256!==c.source.sha256)throw new Error("IM_MEDIA_RECOVERY_FILE_MISMATCH");const m=t.domainState.getConversationMessage?.(e,a);if(R.has(a)||!d(m,u))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const f={conversationId:e.conversationId,conversationType:e.conversationType,data:i,encrypted:c.encrypted,filename:c.source.filename,mimeType:c.source.mimeType,caption:c.caption,filesAlbum:c.filesAlbum,refMessageId:c.refMessageId,...void 0===c.preview?{}:{localPreviewMetadata:{width:c.preview.width,height:c.preview.height,duration:c.preview.duration,posterData:c.preview.thumbData}}};return z.set(a,c.savedAt),await de(f,()=>oe("video"===c.kind?g:c.filesAlbum||c.caption?.trim()?b:w,f,a,c.createdAt,c.teaKey,c.resume),{id:a,createdAt:c.createdAt})}finally{F.get(a)?.controller===o&&F.delete(a),ne(a),s?.release()}}}}export{C as createMediaSender};
|
|
1
|
+
import{throwIfAborted as e}from"../../abort.js";import{resolveMediaThumbnailPolicy as t,MEDIA_THUMBNAIL_MAX_BYTES as a}from"../../media-thumbnail-policy.js";import{MEDIA_ALBUM_CAPTION_MAX_LENGTH as i,MEDIA_ALBUM_MAX_ITEMS as n,resolveMediaAlbumSendContentType as o,measureMediaAlbumContentBytes as r,mediaAlbumBMessageFields as d,MEDIA_ALBUM_CONTENT_WARN_BYTES as s}from"../../mapping/media-album-body.js";import{computeSortKey as l}from"../../mapping/sort.js";import{SIMPLE_ENCRYPT_HEAD_BYTES as c}from"../../ports/crypto-port.js";import{mediaAssetResourceVersion as u}from"../../ports/media-asset-cache-port.js";import{LOCAL_MEDIA_ERROR_CODE as p}from"../../mapping/stored-message.js";function m(e){return Number.isFinite(e)&&e>0}function f(e,i,n=1){if(("video"===i||"image"===i)&&void 0!==e&&m(e.width)&&m(e.height)&&("video"!==i||void 0===e.duration||m(e.duration))&&("video"!==i||void 0===e.posterData||e.posterData instanceof Uint8Array&&0!==e.posterData.length&&!(e.posterData.length>a)))return{width:e.width,height:e.height,..."video"===i&&void 0!==e.duration?{duration:e.duration}:{},..."video"===i&&void 0!==e.posterData&&e.posterData.byteLength<=t(n).maxBytes?{thumbData:new Uint8Array(e.posterData)}:{}}}function v(e,t){return void 0===t?e:{...e,width:t.width,height:t.height,...void 0===t.thumbData?{}:{thumbData:t.thumbData},...void 0===e.duration&&void 0!==t.duration?{duration:t.duration}:{}}}const g={contentType:"image",uploadKind:"image",encryptMode:"integral",streamUpload:!0,async buildPreview(e,a,i,n,o=1){const r=await i.imageDimensions(e,a,n),d=await i.imageThumbnail(e,{mimeType:a,...t(o)},n);return{width:r.width,height:r.height,...d.data.byteLength<=t(o).maxBytes?{thumbData:d.data}:{}}},buildBody:({url:e,meta:t,size:a,teaKey:i,fileEncryptType:n})=>({image:{url:e,width:t.width,height:t.height,...void 0!==t.thumbData?{thumbData:t.thumbData}:{},...void 0!==a?{size:a}:{},...void 0!==n?{fileEncryptType:n}:{},...void 0!==i?{teaKey:i}:{}}})},y={contentType:"video",uploadKind:"video",encryptMode:"integral",streamUpload:!0,async buildPreview(e,a,i,n,o=1){const r=await i.videoPoster(e,{mimeType:a,...t(o)},n);return{width:r.width,height:r.height,...r.data.byteLength<=t(o).maxBytes?{thumbData:r.data}:{},duration:r.duration}},buildBody:({url:e,meta:t,size:a,teaKey:i,fileEncryptType:n},o)=>({video:{url:e,width:t.width,height:t.height,...void 0!==t.duration?{duration:t.duration}:{},...void 0!==o.caption&&""!==o.caption?{describe:o.caption}:{},...void 0!==t.thumbData?{thumbData:t.thumbData}:{},...void 0!==a?{size:a,sizeUnit:"bytes"}:{},...void 0!==n?{fileEncryptType:n}:{},...void 0!==i?{teaKey:i}:{}}})},h={contentType:"voice",uploadKind:"voice",encryptMode:"integral",buildPreview:()=>Promise.resolve({width:0,height:0}),buildBody:({url:e,size:t,teaKey:a,fileEncryptType:i},n)=>({voice:{url:e,durationMs:n.durationMs??0,...void 0!==n.waveform&&n.waveform.length>0?{waveform:n.waveform}:{},...void 0!==t?{size:t}:{},...void 0!==i?{fileEncryptType:i}:{},...void 0!==a?{teaKey:a}:{}}})},w={contentType:"sticker",uploadKind:"sticker",encryptMode:"none",async buildPreview(e,t,a,i){const n=await a.imageDimensions(e,t,i);return{width:n.width,height:n.height}},buildBody:({url:e,meta:t,size:a})=>({sticker:{url:e,width:t.width,height:t.height,exprType:2,imageType:1,...void 0===a?{}:{size:a}}})};const b={contentType:"file",uploadKind:"file",encryptMode:"simple",streamUpload:!0,buildPreview:()=>Promise.resolve({width:0,height:0}),buildBody({url:e,size:t,teaKey:a,fileEncryptType:i},n){const o=n.filename??"",r=function(e){const t=e.lastIndexOf(".");return t>-1&&t<e.length-1?e.slice(t+1).toLowerCase():""}(o),d=function(e,t){const a=t??"";return a.startsWith("image/")||["jpg","jpeg","png","gif","webp","bmp","heic","svg"].includes(e)?1:a.startsWith("video/")||["mp4","mov","m4v","3gp","avi","mkv","webm","flv"].includes(e)?2:a.startsWith("audio/")||["mp3","m4a","wav","aac","flac","ogg"].includes(e)?3:["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","zip","rar","7z","apk","json"].includes(e)?4:0}(r,n.mimeType);return{file:{url:e,fileName:o,...void 0!==t?{size:t}:{},...""!==r?{extension:r}:{},...0!==d?{fileType:d}:{},...void 0!==n.mimeType&&""!==n.mimeType?{mimeType:n.mimeType}:{},...void 0!==i?{fileEncryptType:i}:{},...void 0!==a?{teaKey:a}:{}}}}},T={...b,contentType:"filesAlbum",buildBody(e,t){const a=b.buildBody(e,t).file;return{filesAlbum:{...t.caption?.trim()?{caption:t.caption}:{},items:[{...a,extension:a.extension??"",fileType:a.fileType??0,...["zip","rar","torrent"].includes(a.extension??"")?{fileType:5}:{},...void 0===e.md5?{}:{md5:e.md5}}]}}}};function k(e){switch(e){case"empty":return"media.empty";case"no-crypto":return"media.noCrypto";case"preview-failed":return"media.previewFailed";case"encrypt-failed":return"media.encryptFailed";case"upload-failed":case"offline":return"media.uploadFailed";case"cancelled":return"media.cancelled";case"paused":throw new Error("暂停不是失败状态,不应生成失败文案");case"invalid-duration":return"media.invalidDuration";case"content-too-large":return"media.contentTooLarge"}}function M(e,t){return"video"===e||void 0===t||t>16777216?"large":"small"}function I(){return new DOMException("媒体上传已取消","AbortError")}function A(e){return"album"===e.kind?e.items.flatMap(e=>void 0===e.resume||void 0!==e.uploaded?[]:[{resume:e.resume,kind:e.uploadKind}]):void 0===e.resume?[]:[{resume:e.resume,kind:e.spec.uploadKind}]}function E(e){if("album"===e.kind)return{code:p,reason:"unknown",displayCode:k(e.failureReason),retryable:!1};const t="video"===e.spec.contentType||"file"===e.spec.contentType||"filesAlbum"===e.spec.contentType;return{code:p,reason:"unknown",displayCode:t?"media.uploadInterrupted":k(e.failureReason),mediaKind:e.spec.uploadKind,retryable:!1}}function C(e,t){if(!Number.isInteger(e)||e<1||e>6)throw new RangeError(`媒体上传并发数必须是 1-6 的整数(${t})`)}function P(a){const m=function(e){let t=0,a=0;const i=[];function n(i){return t<e.total&&("large"!==i||a<e.largeFiles)}function o(e){t+=1,"large"===e&&(a+=1);let i=!1;return()=>{i||(i=!0,t-=1,"large"===e&&(a-=1),r())}}function r(){let e=0;for(;e<i.length;){const t=i[e];t.signal.aborted?(i.splice(e,1),t.signal.removeEventListener("abort",t.onAbort),t.reject(I())):n(t.tier)?(i.splice(e,1),t.signal.removeEventListener("abort",t.onAbort),t.resolve(o(t.tier))):e+=1}}return{acquire:(e,t)=>t.aborted?Promise.reject(I()):new Promise((a,n)=>{const o={tier:e,signal:t,resolve:a,reject:n,onAbort:()=>{const e=i.indexOf(o);e>=0&&i.splice(e,1),n(I())}};i.push(o),t.addEventListener("abort",o.onAbort,{once:!0}),r()})}}(function(e){if(void 0===e)return{total:5,largeFiles:3};if("number"==typeof e)return C(e,"总数"),{total:e,largeFiles:e};const t=e.total??5;C(t,"total");const a=e.largeFiles??Math.min(3,t);if(C(a,"largeFiles"),a>t)throw new RangeError(`媒体上传大文件档并发数 ${a} 不能超过总并发数 ${t}`);return{total:t,largeFiles:a}}(a.maxConcurrentUploads)),P=/* @__PURE__ */new Map,K=/* @__PURE__ */new Map,R=/* @__PURE__ */new Map,D=/* @__PURE__ */new Map;let z=!1;const U=/* @__PURE__ */new Map,x=/* @__PURE__ */new Map,S=/* @__PURE__ */new Set,_=/* @__PURE__ */new Map,B=/* @__PURE__ */new Map;function O(e,t){const a=_.get(e)??/* @__PURE__ */new Set;_.set(e,a),a.add(t),S.add(t),t.finally(()=>{a.delete(t),S.delete(t),0===a.size&&_.get(e)===a&&_.delete(e),oe(e)})}function F(e){return[..._.get(e)??[]]}const L=/* @__PURE__ */new Map,q=/* @__PURE__ */new Set,V=/* @__PURE__ */new Map,j=/* @__PURE__ */new Map,N=/* @__PURE__ */new Map,Y=/* @__PURE__ */new Map,$=/* @__PURE__ */new Map,W=/* @__PURE__ */new Map;let G=!0,H=0,J=0;function Q(e){return{conversationType:e.conversationType,conversationId:e.conversationId}}function X(e,t,i,n){a.mediaTransfer.abandonUpload(e).catch(e=>{a.onMediaTransferError?.({stage:"upload",kind:t,messageId:i,conversation:n,cause:e})})}function Z(e,t,i,n,o,r){if(!G)return;const d=Q(t);V.set(e,{input:Q(t),state:i,percent:n,phase:r}),a.emitter.emit({type:"media-task:updated",conversation:d,task:{id:`upload:${e}`,messageId:e,ref:d,direction:"upload",state:i,percent:Math.max(0,Math.min(100,Math.round(n))),attempt:D.get(e)?.attempt??1,maxAttempts:3,...N.get(e),...j.has(e)?{items:Object.freeze(j.get(e).map(e=>Object.freeze({...e,state:"completed"===e.state?"completed":"canceled"===i||"failed"===i?i:e.state})))}:{},...x.get(e),...void 0===r?{}:{phase:r},...void 0===o?{}:{failure:o}}})}function ee(e,t){ne(),$.delete(e),W.delete(e),$.set(e,t),ie()}function te(e){const t=D.get(e);if(P.has(e)||L.has(e)||F(e).length>0||void 0!==t&&(!0!==t.settled||void 0!==t.waiting))return!1;const a=V.get(e)?.state;return"failed"===a||"canceled"===a||"paused"===a&&"manual"===t?.pauseReason}function ae(e,t){const i=Q(t.input),n=A(t),o="media"===t.kind?t.spec.uploadKind:"image",r={...E(t),displayCode:"media.uploadInterrupted",retryable:!1};$.delete(e),W.delete(e),D.delete(e),Y.delete(e),N.delete(e),j.delete(e),x.delete(e),U.delete(e),V.delete(e),R.delete(e);for(const t of n)X(t.resume,t.kind,e,i);if(function(e,t,i){const n=a.recoveryPort;if(void 0===n)return;const o=F(e),r=Promise.all(o).then(()=>n.remove(Q(t),e)).catch(n=>{a.onMediaTransferError?.({stage:"upload",kind:i,messageId:e,conversation:Q(t),cause:n})});O(e,r)}(e,i,o),!G)return;const d=a.domainState.getConversationMessage?.(i,e)??t.message;"sent"!==d.status&&(a.domainState.upsertMessages([{...d,status:"failed",failure:r}],"live"),Z(e,i,"failed",0,r))}function ie(){if(G)for(const[e,t]of $){if($.size<=3)break;te(e)&&ae(e,t)}}function ne(){if(!G)return;const e=Date.now();for(const[t,a]of $){const i=W.get(t);void 0!==i&&e-i>=864e5&&te(t)&&ae(t,a)}}function oe(e){G&&($.has(e)&&te(e)&&!W.has(e)&&W.set(e,Date.now()),ie())}async function re(t,i,n,o,r,d,s=!1){const g=H,y=()=>G&&g===H;if(!y())return void 0!==d&&void 0!==n&&X(d,t.uploadKind,n,Q(i)),{ok:!1,reason:"cancelled"};const h=J;let w,b,T=r,A=d,E=Promise.resolve(void 0);const C=/* @__PURE__ */new Set,S="function"==typeof i.data;const _=function(e){return"undefined"!=typeof Blob&&e instanceof Blob}(i.data)?i.data:void 0,F=S||void 0!==_?void 0:i.data,L=S||void 0!==_,q=!0===t.streamUpload&&void 0!==_,j=e=>{if(void 0!==_)return _;if(void 0===e)throw new Error("媒体预览缺少内容:非 Blob 输入必须先读出字节");return new Blob([e],void 0===i.mimeType?void 0:{type:i.mimeType})};if(0===F?.length||0===_?.size)return{ok:!1,reason:"empty"};const W=i.encrypted??!0;if(W&&void 0===a.crypto)return{ok:!1,reason:"no-crypto"};const te=f(i.localPreviewMetadata,t.contentType);if(("video"===t.contentType||"image"===t.contentType)&&void 0!==i.localPreviewMetadata&&void 0===te)return{ok:!1,reason:"preview-failed"};const ae=void 0===n||void 0===o?a.outbox.allocateMessageIdentity({conversationId:i.conversationId,conversationType:i.conversationType}):{id:n,createdAt:o},{id:ie,createdAt:ne}=ae,oe=a.getSelfId();let re=te??{width:0,height:0};if(!L)try{re=v(await t.buildPreview(j(F),i.mimeType,a.mediaPreview),te)}catch{}if(!y())return void 0!==A&&X(A,t.uploadKind,ie,Q(i)),{ok:!1,reason:"cancelled"};const de=_?.size??F?.byteLength,se={url:i.localPreviewUrl??"",...void 0===de?{}:{size:de}};let le={id:ie,conversationId:i.conversationId,conversationType:i.conversationType,senderId:oe,contentType:t.contentType,body:t.buildBody({...se,meta:re},i),createdAt:ne,sortKey:l(ne,ie),status:"uploading",receipt:"unread",encryption:{encrypted:W},...void 0!==i.refMessageId?{refMessageId:i.refMessageId}:{}};a.domainState.upsertMessages([le],"live",{newOutgoing:!0});const ue=s?0:Y.get(ie)??0;s&&N.delete(ie),Y.set(ie,ue),Z(ie,i,"queued",ue,void 0,"waiting-upload-slot");const pe=(e,n=!1)=>{const o={code:p,reason:"unknown",displayCode:"cleanup-unconfirmed"===w?"media.cleanupUnconfirmed":"resume-unavailable"===w?"media.resumeUnavailable":"timeout"===w?"media.uploadTimeout":k(e),mediaKind:t.uploadKind,retryable:n};if(!y())return{ok:!1,reason:e};const r=D.get(ie);return"paused"===r?.stopped?(Z(ie,i,"paused",Y.get(ie)??0),{ok:!1,reason:e}):void 0!==r&&void 0===r.stopped&&r.attempt<3&&("network"===r.failure||"timeout"===r.failure||"credentials-expired"===r.failure||"offline"===e&&void 0!==a.waitUntilOnline)?(Z(ie,i,"queued",Y.get(ie)??0,void 0,"waiting-retry"),{ok:!1,reason:e}):("cancelled"===r?.stopped||void 0!==r&&r.attempt>=3&&("network"===r.failure||"timeout"===r.failure||"credentials-expired"===r.failure)||(a.domainState.upsertMessages([{...le,status:"failed",failure:o}],"live"),Z(ie,i,"cancelled"===e?"canceled":"failed",Y.get(ie)??0,o)),{ok:!1,reason:e})},me=async()=>{if(void 0!==A)try{await a.mediaTransfer.abandonUpload(A),A=void 0}catch(e){throw w="cleanup-unconfirmed",a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:e}),e}},fe=async e=>{if(await E,await Promise.all([...C]),"cancelled"===e&&"paused"!==D.get(ie)?.stopped&&!0!==D.get(ie)?.retainCheckpoint&&"cleanup-unconfirmed"!==w)try{await me()}catch{}return"cancelled"===e&&"paused"!==D.get(ie)?.stopped&&!0!==D.get(ie)?.retainCheckpoint&&void 0!==a.recoveryPort&&(await Promise.all([...C]),await a.recoveryPort.remove(Q(i),ie).catch(e=>a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:e}))),y()?(ee(ie,{kind:"media",spec:t,input:i,createdAt:ne,message:le,failureReason:e,...!0===D.get(ie)?.retainCheckpoint?{retainCheckpoint:!0}:{},..."cleanup-unconfirmed"===w||"resume-unavailable"===w?{restartRequired:!0}:{},...void 0===T?{}:{teaKey:T},...void 0===A?{}:{resume:A}}),pe(e,!0)):{ok:!1,reason:"cancelled"}},ve=new AbortController;P.set(ie,ve),K.set(ie,Q(i));const ge=D.get(ie)?.stopped;void 0!==ge&&ve.abort("cancelled"===ge&&D.get(ie)?.retainCheckpoint?"cancelled-preserve":ge),!1===a.isOnline?.()&&ce(ie,"offline");try{if(s&&(await me(),!y()))return{ok:!1,reason:"cancelled"};if(void 0!==_&&("video"!==t.contentType||void 0===te?.thumbData)){try{re=v(await t.buildPreview(_,i.mimeType,a.mediaPreview,ve.signal),te)}catch{}if(!y())return{ok:!1,reason:"cancelled"};le={...le,body:t.buildBody({url:i.localPreviewUrl??"",meta:re,size:_.size},i)},a.domainState.upsertMessages([le],"live")}const n=await m.acquire(M(t.contentType,_?.size??F?.byteLength),ve.signal);try{let n;Z(ie,i,"running",Y.get(ie)??0);try{q||(n=S?await i.data():void 0!==_?new Uint8Array(await _.arrayBuffer()):F)}catch{return pe("upload-failed",!0)}const o=q?_.size:n.length;if(0===o)return pe("empty");if(S&&("video"!==t.contentType||void 0===te?.thumbData)){try{re=v(await t.buildPreview(j(n),i.mimeType,a.mediaPreview,ve.signal),te)}catch{}if(!y())return{ok:!1,reason:"cancelled"};le={...le,body:t.buildBody({url:i.localPreviewUrl??"",meta:re,size:o},i)},a.domainState.upsertMessages([le],"live")}if(e(ve.signal),("video"===t.contentType||"file"===t.contentType||"filesAlbum"===t.contentType)&&void 0!==a.recoveryPort&&!0===a.shouldPersistUpload?.(t.uploadKind,o)){b=new AbortController,B.set(ie,b);const e=b.signal;x.set(ie,{recovery:"session-only",recoveryReason:"fingerprint-pending"}),E=Promise.resolve().then(()=>a.recoveryPort.fingerprint(q?_:n,e)).catch(n=>{!e.aborted&&y()&&(x.set(ie,{recovery:"session-only",recoveryReason:"unavailable"}),a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:n}))}),q||await E}if(ve.signal.aborted)throw I();let r,d,s=q?_:n,l=1;if(W&&void 0!==a.crypto&&"none"!==t.encryptMode){const e=a.crypto;try{T??(T=e.randomTeaKey());const a=T;"simple"===t.encryptMode?(s=q?new Blob([new Uint8Array(e.encryptFileSimple({teaKey:a,plain:new Uint8Array(await _.slice(0,c).arrayBuffer())})),_.slice(c)]):e.encryptFileSimple({teaKey:a,plain:n}),l=2):q?(r=t=>e.encryptSymmetricChunked({teaKey:a,plain:t,signal:ve.signal}),l=3):(s=e.encryptSymmetric({teaKey:a,plain:n}),l=3)}catch{return pe("encrypt-failed")}}try{!1===a.isOnline?.()&&ce(ie,"offline"),await(a.waitUntilOnline?.(ve.signal)),e(ve.signal);d=(await a.mediaTransfer.upload({recoveryManaged:!0,forceRefreshCredentials:!0===D.get(ie)?.refreshCredentials,data:s,...void 0===r?{}:{transformPart:r},kind:t.uploadKind,conversationType:i.conversationType,signal:ve.signal,...void 0===A?{}:{resume:A},onFailure:e=>{if(y()&&P.get(ie)===ve){w=e;const t=D.get(ie);void 0!==t&&(t.failure=e)}},onResumeInvalidated:()=>{y()&&P.get(ie)===ve&&(A=void 0)},onResumable:e=>{if(y()&&P.get(ie)===ve&&(A=e,!("cancelled"===D.get(ie)?.stopped&&!0!==D.get(ie)?.retainCheckpoint||void 0===b||void 0===a.recoveryPort||"video"!==t.contentType&&"file"!==t.contentType&&"filesAlbum"!==t.contentType))){const n=U.get(ie)??Date.now();U.set(ie,n);const o=E.then(async o=>{void 0===o||b?.signal.aborted||!y()&&!z||P.get(ie)!==ve||"cancelled"===D.get(ie)?.stopped&&!0!==D.get(ie)?.retainCheckpoint&&!z||(await a.recoveryPort.save({version:1,ref:Q(i),messageId:ie,kind:"video"===t.contentType?"video":"file",createdAt:ne,savedAt:n,source:{...o,...void 0===i.filename?{}:{filename:i.filename},...void 0===i.mimeType?{}:{mimeType:i.mimeType}},encrypted:W,...void 0===T?{}:{teaKey:T},resume:e,...void 0===i.caption?{}:{caption:i.caption},...void 0===i.filesAlbum?{}:{filesAlbum:i.filesAlbum},...void 0===i.refMessageId?{}:{refMessageId:i.refMessageId},..."video"===t.contentType?{preview:re}:{}}),P.get(ie)!==ve||b?.signal.aborted||x.set(ie,{recovery:"available"}))}).catch(e=>{const n="object"==typeof e&&null!==e&&"reason"in e?String(e.reason):"storage";(P.get(ie)===ve||$.has(ie))&&x.set(ie,{recovery:"session-only",recoveryReason:n}),a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:e})});C.add(o),O(ie,o),o.finally(()=>{C.delete(o);const e=V.get(ie);!G||void 0===e||"running"!==e.state&&"paused"!==e.state&&"queued"!==e.state||Z(ie,e.input,e.state,e.percent,void 0,e.phase)})}},...void 0!==i.filename?{filename:i.filename}:{},...void 0!==i.mimeType?{mimeType:i.mimeType}:{},onProgress:e=>{if(!y()||ve.signal.aborted||P.get(ie)!==ve)return;const t=Number.isFinite(e.percent)?Math.max(0,Math.min(100,Math.round(e.percent))):0,n=Math.max(Y.get(ie)??0,t);N.set(ie,{bytesTransferred:e.bytesTransferred,bytesTotal:e.bytesTotal}),Y.set(ie,n),a.emitter.emit({type:"media:progress",conversation:Q(i),messageId:ie,percent:n}),ve.signal.aborted||P.get(ie)!==ve||Z(ie,i,"running",n,void 0,e.phase)}})).url}catch(e){if(ve.signal.aborted&&e instanceof Error&&"AbortError"===e.name||a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:e}),!y())return{ok:!1,reason:"cancelled"};const n=ve.signal.aborted?R.get(ie)??"cancelled":"upload-failed";return await fe(n)}if(!y())return{ok:!1,reason:"cancelled"};if(ve.signal.aborted){const e=R.get(ie)??"cancelled";return await fe(e)}if(h===J&&("image"===t.contentType||"video"===t.contentType)&&void 0!==a.mediaAssetCache){const e=t.contentType,o=_??new Blob([n],void 0===i.mimeType?void 0:{type:i.mimeType}),r=o.size;a.mediaAssetCache.put({kind:e,messageId:ie,resourceVersion:u(d,{conversation:Q(i)}),blob:o,...void 0===i.mimeType?{}:{mimeType:i.mimeType}}).catch(t=>{a.onMediaAssetCacheError?.({operation:"put",kind:e,messageId:ie,byteLength:r,cause:t})})}const p="filesAlbum"===t.contentType?await(a.mediaPreview.fileMd5?.(j(n),ve.signal)):void 0;if(!y())return{ok:!1,reason:"cancelled"};if(e(ve.signal),"filesAlbum"===t.contentType&&void 0===p)throw new Error("FILES_ALBUM requires fileMd5");return await E,await Promise.all([...C]),y()?(e(ve.signal),a.outbox.enqueueMedia({optimisticAlreadyCreated:!0,id:ie,conversationId:i.conversationId,conversationType:i.conversationType,contentType:t.contentType,body:t.buildBody({url:d,meta:re,size:o,...void 0===p?{}:{md5:p},..."none"===t.encryptMode?{}:{teaKey:T,fileEncryptType:l}},i),encryption:{encrypted:W},createdAt:ne,...void 0!==i.refMessageId?{refMessageId:i.refMessageId}:{}}),await Promise.all([...C]),void 0!==a.recoveryPort&&await a.recoveryPort.remove(Q(i),ie).catch(e=>a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:ie,conversation:Q(i),cause:e})),Z(ie,i,"completed",100),{ok:!0,messageId:ie}):{ok:!1,reason:"cancelled"}}finally{n()}}catch{if(!y())return{ok:!1,reason:"cancelled"};const e=ve.signal.aborted?R.get(ie)??"cancelled":"upload-failed";return await fe(e)}finally{await E,await Promise.all([...C]),B.get(ie)===b&&B.delete(ie),!y()&&z&&await Promise.all([...C]),y()||void 0===A||z&&"available"===x.get(ie)?.recovery||X(A,t.uploadKind,ie,Q(i)),P.get(ie)===ve&&(P.delete(ie),K.delete(ie),$.has(ie)||Y.delete(ie),R.delete(ie))}}async function de(c,h,w,b,T=!1){const I=H,A=()=>G&&I===H,E=Q(c),C=(e,t)=>{for(const a of t)void 0!==a.resume&&X(a.resume,a.uploadKind,e,E)};if(!A())return void 0!==h&&void 0!==b&&C(h,b),{ok:!1,reason:"cancelled"};if(0===c.items.length)return{ok:!1,reason:"empty"};if(c.items.length>n)throw new RangeError(`媒体合集最多 ${n} 项,收到 ${c.items.length} 项`);const z=void 0!==c.caption&&""!==c.caption.trim()?c.caption:void 0;if(void 0!==z&&Array.from(z).length>i)throw new RangeError(`媒体合集配文最长 ${i} 字符,收到 ${Array.from(z).length}`);if(c.items.some(e=>0===e.data.size))return{ok:!1,reason:"empty"};if(void 0===b&&"mediaAlbum"!==o(c)){const e=c.items[0];return re("video"===e.kind?y:g,{conversationId:c.conversationId,conversationType:c.conversationType,data:e.data,...void 0!==e.mimeType?{mimeType:e.mimeType}:{},...void 0!==e.filename?{filename:e.filename}:{},...void 0!==e.localPreviewUrl?{localPreviewUrl:e.localPreviewUrl}:{},...void 0!==e.localPreviewMetadata?{localPreviewMetadata:e.localPreviewMetadata}:{},...void 0!==c.encrypted?{encrypted:c.encrypted}:{},...void 0!==c.refMessageId?{refMessageId:c.refMessageId}:{}},h,w)}const U=c.encrypted??!0;if(U&&void 0===a.crypto)return{ok:!1,reason:"no-crypto"};const x=U?a.crypto:void 0,S=J,_=void 0===h||void 0===w?a.outbox.allocateMessageIdentity(E):{id:h,createdAt:w},{id:B,createdAt:O}=_,F=c.items.map((e,t)=>{const a=b?.[t];return{uploadKind:e.kind,...void 0===a?.uploaded?{}:{uploaded:a.uploaded},...void 0===a?.preview?{}:{preview:a.preview},...void 0===a?.teaKey?{}:{teaKey:a.teaKey},...void 0===a?.resume?{}:{resume:a.resume}}}),L=F.map((e,t)=>{const a=c.items[t].data.size,i=void 0!==e.uploaded?a:T?0:e.resume?.bytesUploaded??0;return{itemIndex:t,bytesTransferred:i,bytesTotal:a,percent:void 0!==e.uploaded?100:Math.min(99,Math.floor(i/a*100)),state:void 0!==e.uploaded?"completed":"queued"}});j.set(B,L);const q=()=>({...void 0===z?{}:{caption:z},items:c.items.map((e,t)=>function(e,t,a){const i=t.uploaded,n=i?.meta??t.preview??f(e.localPreviewMetadata,e.kind)??{width:0,height:0};return{kind:e.kind,url:i?.url??e.localPreviewUrl??"",width:n.width,height:n.height,..."video"===e.kind&&void 0!==n.duration&&n.duration>0?{durationMs:Math.max(1,Math.round(1e3*n.duration))}:{},...void 0===n.thumbData?{}:{thumbData:n.thumbData},size:i?.size??e.data.size,...void 0===i?.teaKey?{}:{teaKey:i.teaKey},...void 0===i?{}:{fileEncryptType:i.fileEncryptType},...void 0===a?{}:{hd:a}}}(e,F[t],c.hd))});let V={id:B,conversationId:c.conversationId,conversationType:c.conversationType,senderId:a.getSelfId(),contentType:"mediaAlbum",body:{mediaAlbum:q()},createdAt:O,sortKey:l(O,B),status:"uploading",receipt:"unread",encryption:{encrypted:U},...void 0!==c.refMessageId?{refMessageId:c.refMessageId}:{}};a.domainState.upsertMessages([V],"live",{newOutgoing:!0});const W=T?0:Y.get(B)??0;let te;T&&N.delete(B),Y.set(B,W),Z(B,c,"queued",W,void 0,"waiting-upload-slot");const ae=(e,t)=>{const i={code:p,reason:"unknown",displayCode:"cleanup-unconfirmed"===te?"media.cleanupUnconfirmed":"resume-unavailable"===te?"media.resumeUnavailable":"timeout"===te?"media.uploadTimeout":k(e),retryable:t};if(!A())return{ok:!1,reason:e};const n=D.get(B);return"paused"===n?.stopped?(Z(B,c,"paused",Y.get(B)??0),{ok:!1,reason:e}):void 0!==n&&void 0===n.stopped&&n.attempt<3&&("network"===n.failure||"timeout"===n.failure||"credentials-expired"===n.failure||"offline"===e&&void 0!==a.waitUntilOnline)?(Z(B,c,"queued",Y.get(B)??0,void 0,"waiting-retry"),{ok:!1,reason:e}):("cancelled"===n?.stopped||void 0!==n&&n.attempt>=3&&("network"===n.failure||"timeout"===n.failure||"credentials-expired"===n.failure)||(a.domainState.upsertMessages([{...V,status:"failed",failure:i}],"live"),Z(B,c,"cancelled"===e?"canceled":"failed",Y.get(B)??0,i)),{ok:!1,reason:e})},ie=new AbortController;P.set(B,ie),K.set(B,E);const ne=D.get(B)?.stopped;void 0!==ne&&ie.abort("cancelled"===ne&&D.get(B)?.retainCheckpoint?"cancelled-preserve":ne),!1===a.isOnline?.()&&ce(B,"offline");const oe=()=>A()&&P.get(B)===ie,de=()=>{A()&&oe()&&(V={...V,body:{mediaAlbum:q()}},a.domainState.upsertMessages([V],"live"))},se=c.items.reduce((e,t)=>e+t.data.size,0),le=F.map((e,t)=>void 0!==e.uploaded?c.items[t].data.size:e.resume?.bytesUploaded??0),ue=()=>{if(!A()||!oe()||ie.signal.aborted)return;const e=le.reduce((e,t)=>e+t,0),t=Math.min(99,Math.max(Y.get(B)??0,Math.floor(e/se*100)));N.set(B,{bytesTransferred:e,bytesTotal:se}),Y.set(B,t),a.emitter.emit({type:"media:progress",conversation:E,messageId:B,percent:t}),!ie.signal.aborted&&oe()&&Z(B,c,"running",t,void 0,"transferring")};let pe;const me=async()=>{let e=!0;return await Promise.all(F.map(async t=>{if(void 0!==t.resume)try{await a.mediaTransfer.abandonUpload(t.resume),delete t.resume}catch(i){e=!1,te="cleanup-unconfirmed",a.onMediaTransferError?.({stage:"upload",kind:t.uploadKind,messageId:B,conversation:E,cause:i})}})),e},fe=e=>(ee(B,{kind:"album",input:c,createdAt:O,message:V,failureReason:e,items:F,...!0===D.get(B)?.retainCheckpoint?{retainCheckpoint:!0}:{},..."cleanup-unconfirmed"===te||"resume-unavailable"===te?{restartRequired:!0}:{}}),ae(e,!0));try{if(T){const e=await me();if(!A())return{ok:!1,reason:"cancelled"};if(!e)return fe("cancelled"===R.get(B)?"cancelled":"upload-failed");for(let e=0;e<F.length;e+=1)void 0===F[e].uploaded&&(le[e]=0)}if(await Promise.all(c.items.map(async(i,n)=>{const o=F[n];if(void 0===o.uploaded)try{!1===a.isOnline?.()&&ce(B,"offline"),await(a.waitUntilOnline?.(ie.signal)),e(ie.signal);const r=await async function(e){const{conversation:i,encryptWith:n,isCurrentAttempt:o,item:r,onBytesUploaded:d,onPreviewReady:s,onSlotAcquired:l,signal:c,state:u}=e,p="video"===r.kind?y:g,h=t(e.itemCount),w=f(r.localPreviewMetadata,r.kind,e.itemCount);let b=w??{width:0,height:0};if("video"!==r.kind||void 0===w?.thumbData)try{b=v(await p.buildPreview(r.data,r.mimeType,a.mediaPreview,c,e.itemCount),w)}catch{}void 0===b.thumbData&&void 0!==u.preview?.thumbData&&u.preview.thumbData.byteLength<=h.maxBytes&&(b=u.preview),u.preview=b,s();const T=await m.acquire(M(r.kind,r.data.size),c);try{let t;l();let s=1;if(void 0!==n){u.teaKey??(u.teaKey=n.randomTeaKey());const e=u.teaKey;t=t=>n.encryptSymmetricChunked({teaKey:e,plain:t,signal:c}),s=3}return{url:(await a.mediaTransfer.upload({recoveryManaged:!0,forceRefreshCredentials:e.forceRefreshCredentials,data:r.data,...void 0===t?{}:{transformPart:t},kind:p.uploadKind,conversationType:i.conversationType,signal:c,...void 0===u.resume?{}:{resume:u.resume},onFailure:t=>{o()&&e.onFailure(t)},onResumeInvalidated:()=>{o()&&delete u.resume},onResumable:e=>{G&&o()&&(u.resume=e)},...void 0!==r.filename?{filename:r.filename}:{},...void 0!==r.mimeType?{mimeType:r.mimeType}:{},onProgress:e=>{G&&!c.aborted&&o()&&d(e.bytesTransferred)}})).url,meta:b,size:r.data.size,...void 0===u.teaKey?{}:{teaKey:u.teaKey},fileEncryptType:s}}finally{T()}}({item:i,itemCount:c.items.length,state:o,conversation:E,encryptWith:x,signal:ie.signal,isCurrentAttempt:oe,onPreviewReady:de,onSlotAcquired:()=>{A()&&oe()&&!ie.signal.aborted&&(L[n]={...L[n],state:"running"},Z(B,c,"running",Y.get(B)??0))},forceRefreshCredentials:!0===D.get(B)?.refreshCredentials,onFailure:e=>{const t="cleanup-unconfirmed"===e||"resume-unavailable"===e;if(ie.signal.aborted&&!t)return;"cleanup-unconfirmed"!==e&&("cleanup-unconfirmed"===te||"resume-unavailable"!==e&&"resume-unavailable"===te)||(te=e);const a=D.get(B);void 0!==a&&(a.failure=te)},onBytesUploaded:e=>{le[n]=e,L[n]={...L[n],bytesTransferred:e,percent:Math.min(99,Math.floor(e/i.data.size*100)),state:"running"},ue()}});if(!oe())return;o.uploaded=r,L[n]={...L[n],bytesTransferred:i.data.size,percent:100,state:"completed"},le[n]=i.data.size,ue()}catch(e){oe()&&!ie.signal.aborted&&(L[n]={...L[n],state:"failed"}),((e,t)=>{void 0===pe&&(pe=ie.signal.aborted?R.get(B)??"cancelled":"upload-failed","upload-failed"===pe&&a.onMediaTransferError?.({stage:"upload",kind:e,messageId:B,conversation:E,cause:t}),ie.abort("offline"))})(i.kind,e)}})),!A())return{ok:!1,reason:"cancelled"};if(!oe())return{ok:!1,reason:"cancelled"};if("cancelled"===R.get(B))return"cleanup-unconfirmed"!==te&&!0!==D.get(B)?.retainCheckpoint&&await me(),A()?fe("cancelled"):{ok:!1,reason:"cancelled"};if(void 0!==pe)return fe(pe);if(ie.signal.aborted){return fe(R.get(B)??"cancelled")}const i=q();let n;try{n=r(d(i).content)}catch(e){return a.onMediaAlbumContentSize?.({messageId:B,conversation:E,itemCount:i.items.length,outcome:"rejected",cause:e}),ae("content-too-large",!1)}if(n>=s&&a.onMediaAlbumContentSize?.({messageId:B,conversation:E,itemCount:i.items.length,contentBytes:n,outcome:"warn"}),S===J&&void 0!==a.mediaAssetCache){const e=a.mediaAssetCache;c.items.forEach((t,i)=>{const n=F[i].uploaded;void 0!==n&&e.put({kind:t.kind,messageId:B,resourceVersion:u(n.url,{conversation:E,itemIndex:i}),blob:t.data,...void 0===t.mimeType?{}:{mimeType:t.mimeType}}).catch(e=>{a.onMediaAssetCacheError?.({operation:"put",kind:t.kind,messageId:B,byteLength:t.data.size,cause:e})})})}return a.outbox.enqueueMedia({optimisticAlreadyCreated:!0,id:B,conversationId:c.conversationId,conversationType:c.conversationType,contentType:"mediaAlbum",body:{mediaAlbum:i},encryption:{encrypted:U},createdAt:O,...void 0!==c.refMessageId?{refMessageId:c.refMessageId}:{}}),Z(B,c,"completed",100),{ok:!0,messageId:B}}finally{A()||C(B,F),P.get(B)===ie&&(P.delete(B),K.delete(B),$.has(B)||Y.delete(B),R.delete(B))}}function se(e,t,i,n=1){const{id:o,createdAt:r}=i??a.outbox.allocateMessageIdentity(Q(e)),d={attempt:n};let s,l;W.delete(o),D.set(o,d);const c=new Promise((e,t)=>{s=e,l=t});return d.done=c,(async()=>{let e=await t(o,r);for(;D.get(o)===d&&void 0===d.stopped&&d.attempt<3;){const t=$.get(o);if(!G||e.ok||void 0===t||t.restartRequired||"network"!==d.failure&&"timeout"!==d.failure&&"credentials-expired"!==d.failure&&(e.ok||"offline"!==e.reason||void 0===a.waitUntilOnline))break;const i=new AbortController;if(d.waiting=i,await(a.waitUntilOnline?.(i.signal).catch(()=>{})),await new Promise(e=>{const t=setTimeout(a,1===d.attempt?1e3:3e3);function a(){clearTimeout(t),i.signal.removeEventListener("abort",a),e()}i.signal.addEventListener("abort",a,{once:!0}),i.signal.aborted&&a()}),await(a.waitUntilOnline?.(i.signal).catch(()=>{})),delete d.waiting,!G||void 0!==d.stopped||D.get(o)!==d)break;d.attempt+=1,d.refreshCredentials="credentials-expired"===d.failure,delete d.failure,$.delete(o),W.delete(o),e=await le(o,t,!1)}const i=$.get(o),n="cancelled"!==d.stopped&&d.attempt>=3&&("network"===d.failure||"timeout"===d.failure||"credentials-expired"===d.failure);if(G&&D.get(o)===d&&void 0!==i&&n&&!0===a.retainFailedUploads){d.stopped="cancelled",d.retainCheckpoint=!0,i.retainCheckpoint=!0;const e={...E(i),displayCode:"timeout"===d.failure?"media.uploadTimeout":"media.uploadFailed",retryable:!0};a.domainState.upsertMessages([{...i.message,status:"failed",failure:e}],"live"),Z(o,i.input,"failed",Y.get(o)??0,e)}else if(G&&D.get(o)===d&&void 0!==i&&("cancelled"===d.stopped||n)){d.stopped="cancelled";const t={...E(i),displayCode:"timeout"===d.failure?"media.uploadTimeout":"media.cancelled",retryable:!0===d.retainCheckpoint&&!n};(!0!==d.retainCheckpoint||n)&&await me(o,i),G&&D.get(o)===d&&(a.domainState.upsertMessages([{...i.message,status:"failed",failure:t}],"live"),Z(o,i.input,"canceled",Y.get(o)??0,t)),e={ok:!1,reason:"cancelled"}}return"paused"===d.stopped?{ok:!1,reason:"paused"}:e})().then(e=>{d.settled=!0,oe(o),s(e)},e=>{d.settled=!0,oe(o),l(e)}),c.then(()=>{D.get(o)===d&&"paused"!==d.stopped&&(D.delete(o),$.has(o)||(Y.delete(o),N.delete(o),j.delete(o),x.delete(o),U.delete(o),V.delete(o)))},()=>{D.get(o)===d&&D.delete(o)}),c}function le(e,t,a){return"album"===t.kind?de(t.input,e,t.createdAt,t.items,a):re(t.spec,t.input,e,t.createdAt,t.teaKey,t.resume,a)}function ce(e,t){const a=D.get(e);if(!G||void 0===a||"cancelled"===a.stopped)return;if("paused"===a.stopped)return void("pagehide"===t&&"offline"===a.pauseReason&&(a.pauseReason="pagehide"));a.stopped="paused",a.pauseReason=t;const i=P.get(e);a.waiting?.abort(),i?.abort("paused");const n=V.get(e);void 0!==n&&D.get(e)===a&&"paused"===a.stopped&&Z(e,n.input,"paused",Y.get(e)??n.percent)}async function ue(e,t="manual"){const a=D.get(e);if(!G||void 0===a||"cancelled"===a.stopped)return!1;if("paused"===a.stopped)return("manual"===t||"pagehide"===t&&"offline"===a.pauseReason)&&(a.pauseReason=t),await a.done,oe(e),G&&D.get(e)===a&&$.has(e);ce(e,t),await a.done,await Promise.all(F(e));const i=$.get(e);return!(!G||D.get(e)!==a||"paused"!==a.stopped||void 0===i)&&(Z(e,i.input,"paused",Y.get(e)??0),!0)}function pe(e){ne();const t=D.get(e),i=$.get(e);if(!G||"paused"!==t?.stopped||!0!==t.settled||void 0===i||P.has(e))return!1;$.delete(e),W.delete(e);const n=H;return se(i.input,()=>le(e,i,!1),{id:e,createdAt:i.createdAt},t.attempt).catch(t=>{G&&n===H&&a.onMediaTransferError?.({stage:"upload",kind:"media"===i.kind?i.spec.uploadKind:"image",messageId:e,conversation:Q(i.input),cause:t})}),!0}async function me(e,t){$.delete(e),W.delete(e),x.delete(e),U.delete(e),N.delete(e),j.delete(e),q.add(e);try{await Promise.all(F(e)),await(a.recoveryPort?.remove(Q(t.input),e).catch(i=>{a.onMediaTransferError?.({stage:"upload",kind:"media"===t.kind?t.spec.uploadKind:"image",messageId:e,conversation:Q(t.input),cause:i})})),await Promise.all(A(t).map(async i=>{try{await a.mediaTransfer.abandonUpload(i.resume)}catch(n){a.onMediaTransferError?.({stage:"upload",kind:i.kind,messageId:e,conversation:Q(t.input),cause:n})}}))}catch(i){a.onMediaTransferError?.({stage:"upload",kind:"media"===t.kind?t.spec.uploadKind:"image",messageId:e,conversation:Q(t.input),cause:i})}finally{q.delete(e),x.delete(e),U.delete(e),N.delete(e)}}function fe(e,t){if(ne(),!G)return!1;const i=D.get(e),n=P.get(e);if(!0!==t?.retainCheckpoint&&B.get(e)?.abort(),void 0!==i&&(i.stopped="cancelled",i.retainCheckpoint=!0===t?.retainCheckpoint,i.waiting?.abort()),void 0!==n){const i=K.get(e);return void 0!==i&&!0!==t?.retainCheckpoint&&function(e,t){if(void 0===a.recoveryPort)return;const i=F(e),n="video"===a.domainState.getConversationMessage?.(t,e)?.contentType?"video":"file",o=Promise.all(i).then(()=>a.recoveryPort.remove(t,e)).catch(i=>{a.onMediaTransferError?.({stage:"upload",kind:n,messageId:e,conversation:t,cause:i})});O(e,o)}(e,i),R.set(e,"cancelled"),n.abort(!0===t?.retainCheckpoint?"cancelled-preserve":"cancelled"),!0}const o=$.get(e);if(void 0===o||void 0===i)return void 0!==i&&"queued"===V.get(e)?.state;if(!0===t?.retainCheckpoint)o.retainCheckpoint=!0,o.failureReason="cancelled";else{O(e,me(e,o))}const r={...E(o),displayCode:"media.cancelled",retryable:!0===t?.retainCheckpoint};return a.domainState.upsertMessages([{...o.message,status:"failed",failure:r}],"live"),Z(e,o.input,"canceled",Y.get(e)??0,r),D.get(e)===i&&D.delete(e),oe(e),!0!==t?.retainCheckpoint&&(Y.delete(e),j.delete(e),V.delete(e)),!0}async function ve(e,t,a,i){ne();const n=H,o=F(t);return o.length>0&&await Promise.all(o),G&&n===H?(U.delete(t),se(i,()=>re(e,i,t,a,void 0,void 0,!0),{id:t,createdAt:a})):{ok:!1,reason:"cancelled"}}return{sendImage:e=>se(e,(t,a)=>re(g,e,t,a)),sendVideo:e=>se(e,(t,a)=>re(y,e,t,a)),replaceVideo:(e,t,a)=>ve(y,e,t,a),sendVoice:e=>{const t=e.durationMs;return void 0===t||!Number.isFinite(t)||t<1e3?Promise.resolve({ok:!1,reason:"invalid-duration"}):se(e,(t,a)=>re(h,e,t,a))},sendFile:e=>void 0!==e.caption&&Array.from(e.caption).length>i?Promise.resolve({ok:!1,reason:"content-too-large"}):se(e,(t,a)=>re(e.filesAlbum||e.caption?.trim()?T:b,e,t,a)),sendGif:e=>se(e,(t,a)=>re(w,{...e,encrypted:!1},t,a)),sendMediaAlbum:e=>se(e,(t,a)=>de(e,t,a)),replaceFile:(e,t,a)=>void 0!==a.caption&&Array.from(a.caption).length>i?Promise.resolve({ok:!1,reason:"content-too-large"}):ve(a.filesAlbum||a.caption?.trim()?T:b,e,t,a),cancel:fe,pause:ue,async pauseAll(e="pagehide"){for(const{controller:e}of L.values())e.abort();await Promise.all([...D.keys()].map(t=>ue(t,e)))},async resumePaused(e,t){await Promise.all([...D.entries()].map(async([a,i])=>{if(t?.aborted||"paused"!==i.stopped||"manual"===i.pauseReason)return;if(void 0===e&&"offline"!==i.pauseReason)return;const n=V.get(a)?.input;if(void 0!==e&&(n?.conversationType!==e.conversationType||n.conversationId!==e.conversationId))return;await i.done;const o=$.get(a);t?.aborted||D.get(a)!==i||void 0===o||void 0===e&&"offline"!==i.pauseReason||(void 0===e||o.input.conversationType===e.conversationType&&o.input.conversationId===e.conversationId)&&pe(a)}))},resume:pe,cancelConversation(e,t="offline"){for(const t of L.values())t.ref.conversationType===e.conversationType&&t.ref.conversationId===e.conversationId&&t.controller.abort();for(const[t,i]of $)if(i.input.conversationType===e.conversationType&&i.input.conversationId===e.conversationId){if(D.has(t))fe(t);else{for(const e of A(i))X(e.resume,e.kind,t,Q(i.input));a.recoveryPort?.remove(Q(i.input),t).catch(n=>a.onMediaTransferError?.({stage:"upload",kind:"media"===i.kind?i.spec.uploadKind:"image",messageId:t,conversation:e,cause:n}))}$.delete(t),W.delete(t),j.delete(t),N.delete(t),Y.delete(t),V.delete(t)}if(G)for(const[a,i]of K){if(i.conversationType!==e.conversationType||i.conversationId!==e.conversationId)continue;const n=P.get(a);if(void 0===n)continue;const o=D.get(a);void 0!==o&&(o.stopped="cancelled"),R.set(a,t),B.get(a)?.abort(),n.abort(t)}},cancelAll(e="offline"){if(G){if("offline"===e){const e=H;for(const t of D.keys()){const i=V.get(t)?.input;ue(t,"offline").catch(n=>{G&&e===H&&void 0!==i&&a.onMediaTransferError?.({stage:"upload",kind:"video"===a.domainState.getConversationMessage?.(i,t)?.contentType?"video":"file",messageId:t,conversation:i,cause:n})})}return}if("session-ended"===e){for(const{controller:e}of L.values())e.abort();for(const e of D.values())e.stopped="cancelled",e.waiting?.abort();H+=1,J+=1}for(const t of B.values())t.abort(e);for(const t of P.values())t.abort(e)}},retry(e,t){if(ne(),q.has(e))return!1;if(!G)return!1;const a=$.get(e);if(void 0===a)return!1;if(!0===D.get(e)?.retainCheckpoint&&!0!==D.get(e)?.settled)return!1;if(a.restartRequired&&!0!==t?.restartUpload)return!1;const i=!0===t?.restartUpload||"cancelled"===a.failureReason&&!0!==a.retainCheckpoint;return $.delete(e),W.delete(e),se(a.input,()=>le(e,a,i),{id:e,createdAt:a.createdAt}),!0},expireRetainedUploads:ne,invalidateAssetCacheWrites(){J+=1},async dispose(e){if(!G)return;z=!0===e?.preserveRecovery;for(const{controller:e}of L.values())e.abort();const t=[...D.values()].flatMap(e=>void 0===e.done?[]:[e.done]);for(const e of D.values())e.stopped="cancelled",e.waiting?.abort();if(G=!1,J+=1,!z)for(const e of B.values())e.abort();for(const e of P.values())e.abort(z?"page-preserve":"cancelled");for(const[e,t]of $)if(!z||"available"!==x.get(e)?.recovery)for(const a of A(t))X(a.resume,a.kind,e,Q(t.input));$.clear(),W.clear(),await Promise.allSettled(t),await Promise.all([...S]),P.clear(),Y.clear(),R.clear();for(const[e,t]of $)if(!z||"available"!==x.get(e)?.recovery)for(const a of A(t))X(a.resume,a.kind,e,Q(t.input));$.clear(),W.clear(),D.clear(),N.clear(),j.clear(),x.clear(),U.clear(),V.clear(),await(a.recoveryPort?.drain())},async recoverUpload(e,t,i){ne();const n=a.recoveryPort;if(!G||void 0===n)throw new Error("IM_MEDIA_RECOVERY_UNAVAILABLE");if(D.has(t)||L.has(t))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const o=new AbortController;L.set(t,{controller:o,ref:e});const r=()=>{if(!G||o.signal.aborted||L.get(t)?.controller!==o)throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE")},d=(e,t)=>{if(void 0===e||e.senderId!==a.getSelfId()||void 0!==e.recalled||void 0!==e.deletedForEveryone||"media.cancelled"===e.failure?.displayCode&&!0!==e.failure.retryable||"media.uploadTimeout"===e.failure?.displayCode&&!1===e.failure.retryable||"failed"!==e.status&&"uploading"!==e.status)return!1;const i="video"===e.contentType,n="file"===e.contentType||"filesAlbum"===e.contentType&&1===e.body.filesAlbum?.items.length;return(i||n)&&(void 0===t||e.contentType===t)};let s;try{s=await n.acquireLease(o.signal),r();const l=a.domainState.getConversationMessage?.(e,t);if(!d(l))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const c=await n.get(e,t);if(r(),void 0===c)throw new Error("IM_MEDIA_RECOVERY_NOT_FOUND");const u="video"===c.kind?"video":c.filesAlbum||c.caption?.trim()?"filesAlbum":"file";if(!d(l,u))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const p=await n.fingerprint(i,o.signal);if(r(),p.size!==c.source.size||p.sha256!==c.source.sha256)throw new Error("IM_MEDIA_RECOVERY_FILE_MISMATCH");const m=a.domainState.getConversationMessage?.(e,t);if(D.has(t)||!d(m,u))throw new Error("IM_MEDIA_RECOVERY_INVALID_STATE");const f={conversationId:e.conversationId,conversationType:e.conversationType,data:i,encrypted:c.encrypted,filename:c.source.filename,mimeType:c.source.mimeType,caption:c.caption,filesAlbum:c.filesAlbum,refMessageId:c.refMessageId,...void 0===c.preview?{}:{localPreviewMetadata:{width:c.preview.width,height:c.preview.height,duration:c.preview.duration,posterData:c.preview.thumbData}}};return U.set(t,c.savedAt),await se(f,()=>re("video"===c.kind?y:c.filesAlbum||c.caption?.trim()?T:b,f,t,c.createdAt,c.teaKey,c.resume),{id:t,createdAt:c.createdAt})}finally{L.get(t)?.controller===o&&L.delete(t),oe(t),s?.release()}}}}export{P as createMediaSender};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MediaUploadRecoveryError as e}from"../../../im-browser/src/media/media-upload-recovery-codec.js";import{createBrowserMediaUploadRecovery as a}from"../../../im-browser/src/media/media-upload-recovery-store.js";function
|
|
1
|
+
import{MediaUploadRecoveryError as e}from"../../../im-browser/src/media/media-upload-recovery-codec.js";import{createBrowserMediaUploadRecovery as a}from"../../../im-browser/src/media/media-upload-recovery-store.js";import{throwIfAborted as r}from"../../../im-core/src/abort.js";function n(n){let t,i,o=!1,c=!1;const s=new AbortController;function l(){if(!t||!c||o)throw new e("unavailable");return t}return{port:{get:async(...e)=>l().get(...e),list:async()=>l().list(),save:async e=>l().save(e),remove:async(...e)=>l().remove(...e),clear:async()=>l().clear(),drain:async()=>t?.drain(),fingerprint:async(...e)=>l().fingerprint(...e),acquireLease:async e=>l().acquireLease(e),close:async()=>t?.close()},prepare:l=>o?Promise.reject(new e("unavailable")):(i??(i=(async()=>{t=a({namespaceFactory:n,accountId:l}),await t.acquireLease(s.signal),await t.list(),r(s.signal),c=!0})()),i),async prune(){c&&!o&&await l().list()},async dispose(e){if(o=!0,s.abort(),await(i?.catch(()=>{})),t)try{e||await t.clear()}finally{await t.close()}}}}function t(e){let a=e;const n=/* @__PURE__ */new Set;return{setOnline(e){if(a=e,a)for(const e of[...n])e()},wait:e=>(r(e),a?Promise.resolve():new Promise((a,t)=>{function i(){n.delete(o),e.removeEventListener("abort",c)}function o(){i(),a()}function c(){i();try{r(e)}catch(e){t(e)}}n.add(o),e.addEventListener("abort",c,{once:!0})}))}}export{n as createAccountMediaUploadRecovery,t as createMediaOnlineWaiter};
|
package/dist/sdk.d.ts
CHANGED
|
@@ -5269,7 +5269,7 @@ interface ImMediaTasksApi {
|
|
|
5269
5269
|
*
|
|
5270
5270
|
* 返回的对象可以**原样**作为 `localPreviewMetadata` 交给 `sendImage` / `sendVideo` /
|
|
5271
5271
|
* `sendMediaAlbum`:发送链路会复用可用元信息;合集项超出其可用消息空间时重新生成封面。
|
|
5272
|
-
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多
|
|
5272
|
+
* posterData 使用共享自适应发送规格(视频 JPEG,长边最多 480px,目标 8 KiB、硬上限 24 KiB);includeDisplayPoster 可在同一次解码中额外生成
|
|
5273
5273
|
* 仅供页面显示的高清 displayPoster(长边最多 960),不得绕过发送校验直接用它替换 posterData。
|
|
5274
5274
|
*
|
|
5275
5275
|
* @param input.kind 按文件类型选解码路径;`'video'` 才会抽首帧与读时长。
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k2-im",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.14",
|
|
5
|
+
"browserslist": {
|
|
6
|
+
"js": [
|
|
7
|
+
"chrome >= 93",
|
|
8
|
+
"edge >= 93",
|
|
9
|
+
"firefox >= 91",
|
|
10
|
+
"safari >= 15",
|
|
11
|
+
"ios_saf >= 15"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
5
14
|
"private": false,
|
|
6
15
|
"license": "MIT",
|
|
7
16
|
"publishConfig": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t,a,e){if(a<2||e<2||t.length!==a*e*4)return!1;const r=Math.max(1,Math.ceil(Math.sqrt(a*e/4096)));let h=0,l=0,n=0;for(let o=0;o<e-1;o+=r)for(let e=0;e<a-1;e+=r){const r=4*(o*a+e);let M=0;for(let e=0;e<3;e+=1)M=Math.max(M,Math.abs(t[r+e]-t[r+4+e]),Math.abs(t[r+e]-t[r+4*a+e]));h+=1,M<=3&&(l+=1),M>=48&&(n+=1)}return h>=256&&l/h<.4&&n/h<.04}export{t as isPhotoThumbnailCandidate};
|