;/*FB_PKG_DELIM*/

__d("WAFindMostRecentMediaEntry",["WAMediaUtils","WAResultOrError"],(function(a,b,c,d,e,f,g){"use strict";function a(a){var b=null;for(var a=a,c=Array.isArray(a),e=0,a=c?a:a[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var f,g;if(c){if(e>=a.length)break;g=a[e++]}else{e=a.next();if(e.done)break;g=e.value}g=g;var h=g[0];g=g[1];g=d("WAMediaUtils").decodeMediaEntryData(g);(((f=b)==null?void 0:f[1].mediaKeyTimestamp)==null||g.mediaKeyTimestamp!=null&&g.mediaKeyTimestamp>((f=b)==null?void 0:f[1].mediaKeyTimestamp))&&(b=[h,g])}return b!=null?d("WAResultOrError").makeResult(b):d("WAResultOrError").makeError("no-media-entry")}g.findMostRecentMediaEntry=a}),98);
__d("MAWGetMostRescentDecodedMediaEntry",["MAWDbMediaTxns","MAWIndexedDb","MAWTransactionMode","WAFindMostRecentMediaEntry","WAHashUtils","WAResultOrError","WATagsLogger","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["No existing media entry found for plaintextHash ",". Returning new MsgMap."]);h=function(){return a};return a}var i=d("WATagsLogger").TAGS(["getMostRecentDecodedMediaEntry"]),j=d("MAWIndexedDb").makeMsgrTransactor({media:d("MAWTransactionMode").READONLY},"getMediaEntries",function(a){return function(b){return d("MAWDbMediaTxns").maybeGetMediaFromPlaintextHash(a,b).then(function(a){if(!a){i.LOG(h(),d("WAHashUtils").sanitisePlaintextHash(b));return d("WAResultOrError").makeError("no-media-by-plaintext-hash")}return d("WAResultOrError").makeResult(a.mediaEntries)})}});function a(a){return k.apply(this,arguments)}function k(){k=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){a=(yield j(a));if(a.success===!1)return a;a=d("WAFindMostRecentMediaEntry").findMostRecentMediaEntry(a.value);return a.success===!1?a:d("WAResultOrError").makeResult(a.value[1])});return k.apply(this,arguments)}g.getMediaEntries=j;g.getMostRecentDecodedMediaEntry=a}),98);
__d("MAWGetProtocolMsgIdAndSortOrderMsApi",["MAWIndexedDb","MAWTransactionMode","WAJids"],(function(a,b,c,d,e,f,g){"use strict";a=d("MAWIndexedDb").makeMsgrTransactor({messages:d("MAWTransactionMode").READONLY},"getProtocolMsgIdAndSortOrderMs",function(a){return function(b){return a.messages.get({msgId:b}).then(function(a){if(a==null)return null;var b=a.sortOrderMs;if(b==null)return null;if(d("WAJids").isAuthorSystem(a.author))return null;a={author:a.author,chat:a.threadJid,externalId:a.externalId};return{protocolMsgId:a,sortOrderMs:b}})}});g.getProtocolMsgIdAndSortOrderMs=a}),98);
__d("WAMediaUtilsWasmUrl",["bx"],(function(a,b,c,d,e,f,g){"use strict";a=c("bx").getURL(c("bx")("237"));g.WAMediaUtilsWasmUrl=a}),98);
__d("WAPreloadWamediaUtilsWasm",["WAMediaUtilsWasmUrl","WAWasmModuleCache"],(function(a,b,c,d,e,f,g){"use strict";a=function(){void d("WAWasmModuleCache").loadWasmModule(d("WAMediaUtilsWasmUrl").WAMediaUtilsWasmUrl)};g.preloadWamediaUtilsWasm=a}),98);
__d("WAPreloadWebpCheckWasm",["WAWasmModuleCache","bx"],(function(a,b,c,d,e,f,g){"use strict";var h=c("bx").getURL(c("bx")("6946"));a=function(){void d("WAWasmModuleCache").loadWasmModule(h)};g.preloadWebpCheckWasm=a}),98);
__d("WAPrewarmMediaValidate",["WALogger","WAPreloadWamediaUtilsWasm","WAPreloadWebpCheckWasm"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["prewarmMediaValidate: serverMediaType is null"]);h=function(){return a};return a}function a(a){if(a==null){d("WALogger").WARN(h());return}(a==="sticker"||a==="image")&&d("WAPreloadWebpCheckWasm").preloadWebpCheckWasm();(a==="video"||a==="audio")&&d("WAPreloadWamediaUtilsWasm").preloadWamediaUtilsWasm()}g.prewarmMediaValidate=a}),98);
__d("WAPrepareMediaDownloadV2",["Promise","WAErrorMessage","WAGetAgeBucketForMediaKeyTimestamp","WAHashUtils","WAMediaQplHelper","WAPrewarmMediaValidate","WAProgressiveJpegGetPJpegDetails","WAResultOrError"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media due to runtime-error: ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["start download ",". entry: "," mediaKeyTimestampAgeBucket: ",", size: ",", serverMediaType: ",""]);j=function(){return a};return a}var k=0;function a(a){var c=a.hash,e=a.logger,f=a.mediaDownloadFlow;a=a.mediaEntry;var g=a.directPath,l=a.downloadableThumbnail,m=a.mediaKeyTimestamp,n=a.serverMediaType,o=a.size;d("WAPrewarmMediaValidate").prewarmMediaValidate(n);m=d("WAGetAgeBucketForMediaKeyTimestamp").getAgeBucketForMediaKeyTimestamp(m);e.LOG(j(),d("WAHashUtils").sanitisePlaintextHash(c),f.downloadEntry,m,o,n);o=(c=d("WAProgressiveJpegGetPJpegDetails").maybeGetProgressiveJpegDetailsUsingMediaEntry(a).value)!=null?c:null;f.addPoint("wa_protocol_media_download_start",{bool:{duplicateDirectPath:(l==null?void 0:l.directPath)===g,hasDownloadableThumbnail:(l==null?void 0:l.directPath)!=null,isProgressiveJpeg:o!=null},string:{mediaKeyTimestampAgeBucket:m,mediaType:n}});return{logDownloadResult:function(a){k++;f.addAnnotations({"int":{concurrentDownloadCount:k}});return a.then(function(a){if(a.success){var b=a.value.validatedResult.validatedPlaintext.byteLength;f.addPoint("wa_protocol_media_download_end",{string:{media_size:d("WAMediaQplHelper").convertIntegerSizeToStringBucket(b)}})}else f.addPoint("wa_protocol_media_download_fail",{string:{wa_protocol_media_download_fail_reason:a.error}});return a})["catch"](function(a){f.addPoint("wa_protocol_media_download_fail",{string:{wa_protocol_media_download_fail_reason:"runtime-error"}});var c=d("WAErrorMessage").maybeGetMessageFromError(a);e.ERROR(i(),c);return(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("runtime-error",a))})["finally"](function(){k--})}}}g.prepareMediaDownloadV2=a}),98);
__d("WAIsMp4",[],(function(a,b,c,d,e,f){"use strict";function a(a){return a.length<8?!1:a[4]===102&&a[5]===116&&a[6]===121&&a[7]===112}f.isMp4=a}),66);
__d("WAIsOgg",[],(function(a,b,c,d,e,f){"use strict";function a(a){if(a.length<4)return!1;return a[0]!==79||a[1]!==103||a[2]!==103||a[3]!==83?!1:!0}f.isOgg=a}),66);
__d("WAIsWebP",[],(function(a,b,c,d,e,f){"use strict";function a(a){if(a.length<12)return!1;if(a[0]!==82||a[1]!==73||a[2]!==70||a[3]!==70)return!1;return a[8]!==87||a[9]!==69||a[10]!==66||a[11]!==80?!1:!0}f.isWebP=a}),66);
__d("WASIContext",[],(function(a,b,c,d,e,f){"use strict";a=function(a){var b;this.fs=(b=a==null?void 0:a.fs)!=null?b:{};this.args=(b=a==null?void 0:a.args)!=null?b:[];this.env=(b=a==null?void 0:a.env)!=null?b:{};this.stdin=(b=a==null?void 0:a.stdin)!=null?b:function(){return null};this.stdout=(b=a==null?void 0:a.stdout)!=null?b:function(){};this.stderr=(b=a==null?void 0:a.stderr)!=null?b:function(){};this.debug=a==null?void 0:a.debug;this.isTTY=!!(a==null?void 0:a.isTTY)};f.WASIContext=a}),66);
__d("WASISnapshotPreview1",["$InternalEnum"],(function(a,b,c,d,e,f){"use strict";a=Object.freeze({SUCCESS:0,E2BIG:1,EACCESS:2,EADDRINUSE:3,EADDRNOTAVAIL:4,EAFNOSUPPORT:5,EAGAIN:6,EALREADY:7,EBADF:8,EBADMSG:9,EBUSY:10,ECANCELED:11,ECHILD:12,ECONNABORTED:13,ECONNREFUSED:14,ECONNRESET:15,EDEADLK:16,EDESTADDRREQ:17,EDOM:18,EDQUOT:19,EEXIST:20,EFAULT:21,EFBIG:22,EHOSTUNREACH:23,EIDRM:24,EILSEQ:25,EINPROGRESS:26,EINTR:27,EINVAL:28,EIO:29,EISCONN:30,EISDIR:31,ELOOP:32,EMFILE:33,EMLINK:34,EMSGSIZE:35,EMULTIHOP:36,ENAMETOOLONG:37,ENETDOWN:38,ENETRESET:39,ENETUNREACH:40,ENFILE:41,ENOBUFS:42,ENODEV:43,ENOENT:44,ENOEXEC:45,ENOLCK:46,ENOLINK:47,ENOMEM:48,ENOMSG:49,ENOPROTOOPT:50,ENOSPC:51,ENOSYS:52,ENOTCONN:53,ENOTDIR:54,ENOTEMPTY:55,ENOTRECOVERABLE:56,ENOTSOCK:57,ENOTSUP:58,ENOTTY:59,ENXIO:60,EOVERFLOW:61,EOWNERDEAD:62,EPERM:63,EPIPE:64,EPROTO:65,EPROTONOSUPPORT:66,EPROTOTYPE:67,ERANGE:68,EROFS:69,ESPIPE:70,ESRCH:71,ESTALE:72,ETIMEDOUT:73,ETXTBSY:74,EXDEV:75,ENOTCAPABLE:76});d=(c=b("$InternalEnum"))({REALTIME:0,MONOTONIC:1,PROCESS_CPUTIME_ID:2,THREAD_CPUTIME_ID:3});e=c({SET:0,CUR:1,END:2});b=c({UNKNOWN:0,BLOCK_DEVICE:1,CHARACTER_DEVICE:2,DIRECTORY:3,REGULAR_FILE:4,SOCKET_DGRAM:5,SOCKET_STREAM:6,SYMBOLIC_LINK:7});var g=c({DIR:0});c=c({CLOCK:0,FD_READ:1,FD_WRITE:2});var h={SYMLINK_FOLLOW:1<<0},i={CREAT:1<<0,DIRECTORY:1<<1,EXCL:1<<2,TRUNC:1<<3},j={APPEND:1<<0,DSYNC:1<<1,NONBLOCK:1<<2,RSYNC:1<<3,SYNC:1<<4},k={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)},l={ATIM:1<<0,ATIM_NOW:1<<1,MTIM:1<<2,MTIM_NOW:1<<3},m={SUBSCRIPTION_CLOCK_ABSTIME:1<<0},n={FD_READWRITE_HANGUP:1<<0},o=64,p=48,q=32;f.RESULT=a;f.Clock=d;f.Whence=e;f.FileType=b;f.PreopenType=g;f.EventType=c;f.LookupFlags=h;f.OpenFlags=i;f.FileDescriptorFlags=j;f.RightsFlags=k;f.FileStatTimestampFlags=l;f.SubscriptionClockFlags=m;f.EventReadWriteFlags=n;f.FILESTAT_SIZE=o;f.SUBSCRIPTION_SIZE=p;f.EVENT_SIZE=q}),66);
__d("WASIDrive",["WASISnapshotPreview1","WATextEncoding"],(function(a,b,c,d,e,f,g){"use strict";a=function(){function a(a){this.nextFD=10,this.openMap=new Map(),this.fs=babelHelpers["extends"]({},a),this.openMap.set(3,new j(this.fs,"/"))}var b=a.prototype;b.$1=function(a,b,c){a=new h(a,c);b&&(a.buffer=new Uint8Array(new ArrayBuffer(1024),0,0));c=this.nextFD;this.openMap.set(c,a);this.nextFD++;return[d("WASISnapshotPreview1").RESULT.SUCCESS,c]};b.$2=function(a,b){a=new j(a,b);b=this.nextFD;this.openMap.set(b,a);this.nextFD++;return[d("WASISnapshotPreview1").RESULT.SUCCESS,b]};b.$3=function(a,b){return b==="."?!0:a.containsDirectory(b)};b.open=function(a,b,c,e){var f,g=!!(c&(f=d("WASISnapshotPreview1")).OpenFlags.CREAT),h=!!(c&f.OpenFlags.DIRECTORY),i=!!(c&f.OpenFlags.EXCL);c=!!(c&f.OpenFlags.TRUNC);f=this.openMap.get(a);if(!(f instanceof j))return[d("WASISnapshotPreview1").RESULT.EBADF];if(f.containsFile(b)){if(h)return[d("WASISnapshotPreview1").RESULT.ENOTDIR];if(i)return[d("WASISnapshotPreview1").RESULT.EEXIST];a=f.get(b);return this.$1(a,c,e)}else if(this.$3(f,b)){if(b===".")return this.$2(this.fs,"/");var k="/"+b+"/";h=Object.entries(this.fs).filter(function(a){a=a[0];return a.startsWith(k)});return this.$2(Object.fromEntries(h),k)}else{if(g){i=f.fullPath(b);this.fs[i]={path:i,mode:"binary",content:new Uint8Array(0),timestamps:{access:new Date(),modification:new Date(),change:new Date()}};return this.$1(this.fs[i],c,e)}return[d("WASISnapshotPreview1").RESULT.ENOTCAPABLE]}};b.close=function(a){if(!this.openMap.has(a))return d("WASISnapshotPreview1").RESULT.EBADF;var b=this.openMap.get(a);b instanceof h&&b.sync();this.openMap["delete"](a);return d("WASISnapshotPreview1").RESULT.SUCCESS};b.read=function(a,b){a=this.openMap.get(a);return!a||a instanceof j?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.read(b)]};b.pread=function(a,b,c){a=this.openMap.get(a);return!a||a instanceof j?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.pread(b,c)]};b.write=function(a,b){a=this.openMap.get(a);if(!a||a instanceof j)return d("WASISnapshotPreview1").RESULT.EBADF;a.write(b);return d("WASISnapshotPreview1").RESULT.SUCCESS};b.pwrite=function(a,b,c){a=this.openMap.get(a);if(!a||a instanceof j)return d("WASISnapshotPreview1").RESULT.EBADF;a.pwrite(b,c);return d("WASISnapshotPreview1").RESULT.SUCCESS};b.sync=function(a){a=this.openMap.get(a);if(!a||a instanceof j)return d("WASISnapshotPreview1").RESULT.EBADF;a.sync();return d("WASISnapshotPreview1").RESULT.SUCCESS};b.seek=function(a,b,c){a=this.openMap.get(a);return!a||a instanceof j?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.seek(b,c)]};b.tell=function(a){a=this.openMap.get(a);return!a||a instanceof j?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.tell()]};b.renumber=function(a,b){if(!this.exists(a)||!this.exists(b))return d("WASISnapshotPreview1").RESULT.EBADF;if(a===b)return d("WASISnapshotPreview1").RESULT.SUCCESS;this.close(b);a=this.openMap.get(a);this.openMap.set(b,a);return d("WASISnapshotPreview1").RESULT.SUCCESS};b.unlink=function(a,b){a=this.openMap.get(a);if(!(a instanceof j))return d("WASISnapshotPreview1").RESULT.EBADF;if(!a.contains(b))return d("WASISnapshotPreview1").RESULT.ENOENT;var c=Object.keys(this.fs);for(var e=0;e<c.length;e++){var f=c[e];(f===a.fullPath(b)||f.startsWith(a.fullPath(b)+"/"))&&delete this.fs[f]}return d("WASISnapshotPreview1").RESULT.SUCCESS};b.rename=function(a,b,c,e){a=this.openMap.get(a);c=this.openMap.get(c);if(!(a instanceof j)||!(c instanceof j))return d("WASISnapshotPreview1").RESULT.EBADF;if(!a.contains(b))return d("WASISnapshotPreview1").RESULT.ENOENT;if(c.contains(e))return d("WASISnapshotPreview1").RESULT.EEXIST;a=a.fullPath(b);b=c.fullPath(e);c=Object.keys(this.fs);for(e=0;e<c.length;e++){var f=c[e];if(f.startsWith(a)){var g=f.replace(a,b);this.fs[g]=this.fs[f];this.fs[g].path=g;delete this.fs[f]}}return d("WASISnapshotPreview1").RESULT.SUCCESS};b.list=function(a){a=this.openMap.get(a);return!(a instanceof j)?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.list()]};b.stat=function(a){a=this.openMap.get(a);return!(a instanceof h)?[d("WASISnapshotPreview1").RESULT.EBADF]:[d("WASISnapshotPreview1").RESULT.SUCCESS,a.stat()]};b.pathStat=function(a,b){a=this.openMap.get(a);if(!(a instanceof j))return[d("WASISnapshotPreview1").RESULT.EBADF];if(a.containsFile(b)){var c=a.fullPath(b);c=new h(this.fs[c],0).stat();return[d("WASISnapshotPreview1").RESULT.SUCCESS,c]}else if(this.$3(a,b)){if(b===".")return[d("WASISnapshotPreview1").RESULT.SUCCESS,new j(this.fs,"/").stat()];var e="/"+b+"/";c=Object.entries(this.fs).filter(function(a){a=a[0];return a.startsWith(e)});a=new j(Object.fromEntries(c),e).stat();return[d("WASISnapshotPreview1").RESULT.SUCCESS,a]}else return[d("WASISnapshotPreview1").RESULT.ENOTCAPABLE]};b.setFlags=function(a,b){a=this.openMap.get(a);if(a instanceof h){a.setFlags(b);return d("WASISnapshotPreview1").RESULT.SUCCESS}else return d("WASISnapshotPreview1").RESULT.EBADF};b.setSize=function(a,b){a=this.openMap.get(a);if(a instanceof h){a.setSize(Number(b));return d("WASISnapshotPreview1").RESULT.SUCCESS}else return d("WASISnapshotPreview1").RESULT.EBADF};b.setAccessTime=function(a,b){a=this.openMap.get(a);if(a instanceof h){a.setAccessTime(b);return d("WASISnapshotPreview1").RESULT.SUCCESS}else return d("WASISnapshotPreview1").RESULT.EBADF};b.setModificationTime=function(a,b){a=this.openMap.get(a);if(a instanceof h){a.setModificationTime(b);return d("WASISnapshotPreview1").RESULT.SUCCESS}else return d("WASISnapshotPreview1").RESULT.EBADF};b.pathSetAccessTime=function(a,b,c){a=this.openMap.get(a);if(!(a instanceof j))return d("WASISnapshotPreview1").RESULT.EBADF;a=a.get(b);if(a==null)return d("WASISnapshotPreview1").RESULT.ENOTCAPABLE;b=new h(a,0);b.setAccessTime(c);b.sync();return d("WASISnapshotPreview1").RESULT.SUCCESS};b.pathSetModificationTime=function(a,b,c){a=this.openMap.get(a);if(!(a instanceof j))return d("WASISnapshotPreview1").RESULT.EBADF;a=a.get(b);if(a==null)return d("WASISnapshotPreview1").RESULT.ENOTCAPABLE;b=new h(a,0);b.setModificationTime(c);b.sync();return d("WASISnapshotPreview1").RESULT.SUCCESS};b.pathCreateDir=function(a,b){a=this.openMap.get(a);if(!(a instanceof j))return d("WASISnapshotPreview1").RESULT.EBADF;if(a.contains(b))return d("WASISnapshotPreview1").RESULT.ENOTCAPABLE;a=a.fullPath(b)+"/.runno";this.fs[a]={path:a,timestamps:{access:new Date(),modification:new Date(),change:new Date()},mode:"string",content:""};return d("WASISnapshotPreview1").RESULT.SUCCESS};b.exists=function(a){return this.openMap.has(a)};b.fileType=function(a){a=this.openMap.get(a);if(!a)return d("WASISnapshotPreview1").FileType.UNKNOWN;else if(a instanceof h)return d("WASISnapshotPreview1").FileType.REGULAR_FILE;else return d("WASISnapshotPreview1").FileType.DIRECTORY};b.fileFdflags=function(a){a=this.openMap.get(a);if(a instanceof h)return a.fdflags;else return 0};return a}();var h=function(){var b=a.prototype;b.getOffset=function(){return Number(this.$1)};function a(a,b){this.$1=BigInt(0);this.isDirty=!1;this.file=a;if(this.file.mode==="string"){a=this.file.content;var c=d("WATextEncoding").newTextEncoder();this.buffer=c.encode(a)}else this.buffer=this.file.content;this.fdflags=b;this.flagAppend=!!(b&d("WASISnapshotPreview1").FileDescriptorFlags.APPEND);this.flagDSync=!!(b&d("WASISnapshotPreview1").FileDescriptorFlags.DSYNC);this.flagNonBlock=!!(b&d("WASISnapshotPreview1").FileDescriptorFlags.NONBLOCK);this.flagRSync=!!(b&d("WASISnapshotPreview1").FileDescriptorFlags.RSYNC);this.flagSync=!!(b&d("WASISnapshotPreview1").FileDescriptorFlags.SYNC)}b.read=function(a){a=this.buffer.subarray(this.getOffset(),this.getOffset()+a);this.$1+=BigInt(a.length);return a};b.pread=function(a,b){return this.buffer.subarray(b,b+a)};b.write=function(a){this.isDirty=!0;if(this.flagAppend){var b=this.buffer.length;this.$2(b+a.byteLength);this.buffer.set(a,b)}else{b=Math.max(this.getOffset()+a.byteLength,this.buffer.byteLength);this.$2(b);this.buffer.set(a,this.getOffset());this.$1+=BigInt(a.byteLength)}(this.flagDSync||this.flagSync)&&this.sync()};b.pwrite=function(a,b){this.isDirty=!0;if(this.flagAppend){var c=this.buffer.length;this.$2(c+a.byteLength);this.buffer.set(a,c)}else{c=Math.max(b+a.byteLength,this.buffer.byteLength);this.$2(c);this.buffer.set(a,b)}(this.flagDSync||this.flagSync)&&this.sync()};b.sync=function(){if(!this.isDirty)return;this.isDirty=!1;if(this.file.mode==="binary"){this.file.content=new Uint8Array(this.buffer);return}var a=d("WATextEncoding").newTextDecoder();this.file.content=a.decode(this.buffer);return};b.seek=function(a,b){switch(b){case d("WASISnapshotPreview1").Whence.SET:this.$1=a;break;case d("WASISnapshotPreview1").Whence.CUR:this.$1+=a;break;case d("WASISnapshotPreview1").Whence.END:this.$1=BigInt(this.buffer.length)+a;break}return this.$1};b.tell=function(){return this.$1};b.stat=function(){return{path:this.file.path,timestamps:this.file.timestamps,type:d("WASISnapshotPreview1").FileType.REGULAR_FILE,byteLength:this.buffer.length}};b.setFlags=function(a){this.fdflags=a};b.setSize=function(a){this.$2(a)};b.setAccessTime=function(a){this.file.timestamps.access=a};b.setModificationTime=function(a){this.file.timestamps.modification=a};b.$2=function(a){if(a<=this.buffer.buffer.byteLength){this.buffer=new Uint8Array(this.buffer.buffer,0,a);return}var b;this.buffer.buffer.byteLength===0?b=new ArrayBuffer(a<1024?1024:a*2):a>this.buffer.buffer.byteLength*2?b=new ArrayBuffer(a*2):b=new ArrayBuffer(this.buffer.buffer.byteLength*2);b=new Uint8Array(b,0,a);b.set(this.buffer);this.buffer=b};return a}();function i(a,b){b=b.replace(/[/\-\\^$*+?.()|[\]{}]/g,"\\$&");b=new RegExp("^"+b);return a.replace(b,"")}var j=function(){function a(a,b){this.dir=a,this.prefix=b}var b=a.prototype;b.containsFile=function(a){var b=Object.keys(this.dir);for(var c=0;c<b.length;c++){var d=b[c];d=i(d,this.prefix);if(d===a)return!0}return!1};b.containsDirectory=function(a){var b=Object.keys(this.dir);for(var c=0;c<b.length;c++){var d=b[c];d=i(d,this.prefix);if(d.startsWith(a+"/"))return!0}return!1};b.contains=function(a){var b=Object.keys(this.dir);for(var c=0;c<b.length;c++){var d=b[c];d=i(d,this.prefix);if(d===a||d.startsWith(a+"/"))return!0}return!1};b.get=function(a){return this.dir[this.fullPath(a)]};b.fullPath=function(a){return""+this.prefix+a};b.list=function(){var a=[],b=new Set(),c=Object.keys(this.dir);for(var e=0;e<c.length;e++){var f=c[e];f=i(f,this.prefix);if(f.includes("/")){var g=f.split("/")[0];if(b.has(g))continue;b.add(g);a.push({name:g,type:d("WASISnapshotPreview1").FileType.DIRECTORY})}else a.push({name:f,type:d("WASISnapshotPreview1").FileType.REGULAR_FILE})}return a};b.stat=function(){return{path:this.prefix,timestamps:{access:new Date(),modification:new Date(),change:new Date()},type:d("WASISnapshotPreview1").FileType.DIRECTORY,byteLength:0}};return a}();g.WASIDrive=a}),98);
__d("WASI",["WACryptoDependencies","WASIContext","WASIDrive","WASISnapshotPreview1","WATextEncoding","err"],(function(a,b,c,d,e,f,g){"use strict";function a(a){var b,e=new(d("WASIContext").WASIContext)(a),f=new(d("WASIDrive").WASIDrive)(e.fs);function g(){return Object.entries(e.env).map(function(a){var b=a[0];a=a[1];return b+"="+a})}var o={args_get:function(a,c){a=a;c=c;var f=new DataView(b.buffer);for(var g=e.args,h=Array.isArray(g),i=0,g=h?g:g[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var j;if(h){if(i>=g.length)break;j=g[i++]}else{i=g.next();if(i.done)break;j=i.value}j=j;f.setUint32(a,c,!0);a+=4;j=d("WATextEncoding").newTextEncoder().encode(j+"\0");var k=new Uint8Array(b.buffer,c,j.byteLength);k.set(j);c+=j.byteLength}return d("WASISnapshotPreview1").RESULT.SUCCESS},args_sizes_get:function(a,c){var f=e.args,g=f.reduce(function(a,b){return a+d("WATextEncoding").newTextEncoder().encode(b+"\0").byteLength},0),h=new DataView(b.buffer);h.setUint32(a,f.length,!0);h.setUint32(c,g,!0);return d("WASISnapshotPreview1").RESULT.SUCCESS},clock_res_get:function(){throw c("err")("clock_res_get is not implemented")},clock_time_get:function(a,c,e){c=d("WASISnapshotPreview1").Clock.cast(a);if(c==null)return d("WASISnapshotPreview1").RESULT.EINVAL;switch(c){case d("WASISnapshotPreview1").Clock.REALTIME:case d("WASISnapshotPreview1").Clock.MONOTONIC:case d("WASISnapshotPreview1").Clock.PROCESS_CPUTIME_ID:case d("WASISnapshotPreview1").Clock.THREAD_CPUTIME_ID:a=new DataView(b.buffer);a.setBigUint64(e,n(new Date()),!0);return d("WASISnapshotPreview1").RESULT.SUCCESS}},environ_get:function(a,c){a=a;c=c;var e=new DataView(b.buffer),f=g();for(var h=0;h<f.length;h++){var i=f[h];e.setUint32(a,c,!0);a+=4;i=d("WATextEncoding").newTextEncoder().encode(i+"\0");var j=new Uint8Array(b.buffer,c,i.byteLength);j.set(i);c+=i.byteLength}return d("WASISnapshotPreview1").RESULT.SUCCESS},environ_sizes_get:function(a,c){var e=g().reduce(function(a,b){return a+d("WATextEncoding").newTextEncoder().encode(b+"\0").byteLength},0),f=new DataView(b.buffer);f.setUint32(a,g().length,!0);f.setUint32(c,e,!0);return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_advise:function(){throw c("err")("fd_advise is not implemented")},fd_allocate:function(){throw c("err")("fd_allocate is not implemented")},fd_close:function(a){return f.close(a)},fd_datasync:function(){throw c("err")("fd_datasync is not implemented")},fd_fdstat_get:function(a,c){if(a<3){if(e.isTTY){var g=i^d("WASISnapshotPreview1").RightsFlags.FD_SEEK^d("WASISnapshotPreview1").RightsFlags.FD_TELL;g=l(d("WASISnapshotPreview1").FileType.CHARACTER_DEVICE,0,g)}else g=l(d("WASISnapshotPreview1").FileType.CHARACTER_DEVICE,0);var h=new Uint8Array(b.buffer,c,g.byteLength);h.set(g);return d("WASISnapshotPreview1").RESULT.SUCCESS}if(!f.exists(a))return d("WASISnapshotPreview1").RESULT.EBADF;h=f.fileType(a);g=f.fileFdflags(a);a=l(h,g);h=new Uint8Array(b.buffer,c,a.byteLength);h.set(a);return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_fdstat_set_flags:function(a,b){return f.setFlags(a,b)},fd_fdstat_set_rights:function(){return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_filestat_get:function(a,c){if(a<3){var e;switch(a){case 0:e="/dev/stdin";break;case 1:e="/dev/stdout";break;case 2:e="/dev/stderr";break;default:e="/dev/undefined";break}var g=k({path:e,byteLength:0,timestamps:{access:new Date(),modification:new Date(),change:new Date()},type:d("WASISnapshotPreview1").FileType.CHARACTER_DEVICE}),h=new Uint8Array(b.buffer,c,g.byteLength);h.set(g);return d("WASISnapshotPreview1").RESULT.SUCCESS}h=f.stat(a);if(h.length===1)return h[0];g=h[1];a=k(g);h=new Uint8Array(b.buffer,c,a.byteLength);h.set(a);return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_filestat_set_size:function(){throw c("err")("fd_filestat_set_size is not implemented")},fd_filestat_set_times:function(){throw c("err")("fd_filestat_set_times is not implemented")},fd_pread:function(){throw c("err")("fd_pread is not implemented")},fd_prestat_dir_name:function(a,c,e){if(a!==3)return d("WASISnapshotPreview1").RESULT.EBADF;a=d("WATextEncoding").newTextEncoder().encode("/");c=new Uint8Array(b.buffer,c,e);c.set(a.subarray(0,e));return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_prestat_get:function(a,c){if(a!==3)return d("WASISnapshotPreview1").RESULT.EBADF;a=d("WATextEncoding").newTextEncoder().encode(".");c=new DataView(b.buffer,c);c.setUint8(0,d("WASISnapshotPreview1").PreopenType.DIR);c.setUint32(4,a.byteLength,!0);return d("WASISnapshotPreview1").RESULT.SUCCESS},fd_pwrite:function(){throw c("err")("fd_pwrite is not implemented")},fd_read:function(a,c,g,h){if(a===1||a===2)return d("WASISnapshotPreview1").RESULT.ENOTSUP;var i=new DataView(b.buffer);c=j(i,c,g);g=d("WATextEncoding").newTextEncoder();var k=0,l=d("WASISnapshotPreview1").RESULT.SUCCESS;for(var m=0;m<c.length;m++){var n=c[m],o=void 0;if(a===0){var p=e.stdin(n.byteLength);if(p==null)break;o=g.encode(p)}else{p=f.read(a,n.byteLength);if(p.length===1){l=p[0];break}else o=p[1]}p=Math.min(n.byteLength,o.byteLength);n.set(o.subarray(0,p));k+=p}i.setUint32(h,k,!0);return l},fd_readdir:function(){throw c("err")("fd_readdir is not implemented")},fd_renumber:function(){throw c("err")("fd_renumber is not implemented")},fd_seek:function(a,e,g,h){g=d("WASISnapshotPreview1").Whence.cast(g);if(g==null)throw c("err")("fd_seek: invalid whence");a=f.seek(a,e,g);if(a.length===1)return a[0];e=a[0];g=a[1];a=new DataView(b.buffer);a.setBigUint64(h,g,!0);return e},fd_sync:function(){throw c("err")("fd_sync is not implemented")},fd_tell:function(){throw c("err")("fd_tell is not implemented")},fd_write:function(a,c,g,h){if(a===0)return d("WASISnapshotPreview1").RESULT.ENOTSUP;var i=new DataView(b.buffer);c=j(i,c,g);g=d("WATextEncoding").newTextDecoder();var k=0,l=d("WASISnapshotPreview1").RESULT.SUCCESS;for(var m=0;m<c.length;m++){var n=c[m];if(n.byteLength===0)continue;if(a===1||a===2){var o=a===1?e.stdout:e.stderr,p=g.decode(n);o(p)}else{l=f.write(a,n);if(l!==d("WASISnapshotPreview1").RESULT.SUCCESS)break}k+=n.byteLength}i.setUint32(h,k,!0);return l},path_create_directory:function(){throw c("err")("path_create_directory is not implemented")},path_filestat_get:function(){throw c("err")("path_filestat_get is not implemented")},path_filestat_set_times:function(){throw c("err")("path_filestat_set_times is not implemented")},path_link:function(){throw c("err")("path_link is not implemented")},path_open:function(a,c,d,e,g,h,i,j,k){c=new DataView(b.buffer);h=m(b,d,e);i=f.open(a,h,g,j);if(i.length===1)return i[0];d=i[0];e=i[1];c.setUint32(k,e,!0);return d},path_readlink:function(){throw c("err")("path_readlink is not implemented")},path_remove_directory:function(){throw c("err")("path_remove_directory is not implemented")},path_rename:function(){throw c("err")("path_rename is not implemented")},path_symlink:function(){throw c("err")("path_symlink is not implemented")},path_unlink_file:function(){throw c("err")("path_unlink_file is not implemented")},poll_oneoff:function(){throw c("err")("poll_oneoff is not implemented")},proc_exit:function(a){throw new h(a)},proc_raise:function(){throw c("err")("proc_raise is not implemented")},random_get:function(a,c){a=new Uint8Array(b.buffer,a,c);d("WACryptoDependencies").getCrypto().getRandomValues(a);return d("WASISnapshotPreview1").RESULT.SUCCESS},sched_yield:function(){throw c("err")("sched_yield is not implemented")},sock_accept:function(){throw c("err")("sock_accept is not implemented")},sock_recv:function(){throw c("err")("sock_recv is not implemented")},sock_send:function(){throw c("err")("sock_send is not implemented")},sock_shutdown:function(){throw c("err")("sock_shutdown is not implemented")}};return{getImportObject:function(){return{wasi_snapshot_preview1:o}},start:function(a){var d=a.exports.memory;if(d instanceof WebAssembly.Memory)b=d;else throw c("err")("Expected memory object");d=a.exports._start;try{d()}catch(a){if(a instanceof h)return{exitCode:a.code,fs:f.fs};else if(a instanceof WebAssembly.RuntimeError)return{exitCode:134,fs:f.fs};else throw a}return{exitCode:0,fs:f.fs}}}}var h=function(b){babelHelpers.inheritsLoose(a,b);function a(a){var c;c=b.call(this)||this;c.code=a;return c}return a}(babelHelpers.wrapNativeSuper(Error)),i=(b=d("WASISnapshotPreview1")).RightsFlags.FD_DATASYNC|b.RightsFlags.FD_READ|b.RightsFlags.FD_SEEK|b.RightsFlags.FD_FDSTAT_SET_FLAGS|b.RightsFlags.FD_SYNC|b.RightsFlags.FD_TELL|b.RightsFlags.FD_WRITE|b.RightsFlags.FD_ADVISE|b.RightsFlags.FD_ALLOCATE|b.RightsFlags.PATH_CREATE_DIRECTORY|b.RightsFlags.PATH_CREATE_FILE|b.RightsFlags.PATH_LINK_SOURCE|b.RightsFlags.PATH_LINK_TARGET|b.RightsFlags.PATH_OPEN|b.RightsFlags.FD_READDIR|b.RightsFlags.PATH_READLINK|b.RightsFlags.PATH_RENAME_SOURCE|b.RightsFlags.PATH_RENAME_TARGET|b.RightsFlags.PATH_FILESTAT_GET|b.RightsFlags.PATH_FILESTAT_SET_SIZE|b.RightsFlags.PATH_FILESTAT_SET_TIMES|b.RightsFlags.FD_FILESTAT_GET|b.RightsFlags.FD_FILESTAT_SET_SIZE|b.RightsFlags.FD_FILESTAT_SET_TIMES|b.RightsFlags.PATH_SYMLINK|b.RightsFlags.PATH_REMOVE_DIRECTORY|b.RightsFlags.PATH_UNLINK_FILE|b.RightsFlags.POLL_FD_READWRITE|b.RightsFlags.SOCK_SHUTDOWN|b.RightsFlags.SOCK_ACCEPT;function j(a,b,c){var d=new Array(c);b=b;for(var e=0;e<c;e++){var f=a.getUint32(b,!0);b+=4;var g=a.getUint32(b,!0);b+=4;d[e]=new Uint8Array(a.buffer,f,g)}return d}function k(a){var b=new Uint8Array(d("WASISnapshotPreview1").FILESTAT_SIZE),c=new DataView(b.buffer);c.setBigUint64(0,BigInt(0),!0);c.setBigUint64(8,BigInt(o(a.path)),!0);c.setUint8(16,a.type);c.setBigUint64(24,BigInt(1),!0);c.setBigUint64(32,BigInt(a.byteLength),!0);c.setBigUint64(40,n(a.timestamps.access),!0);c.setBigUint64(48,n(a.timestamps.modification),!0);c.setBigUint64(56,n(a.timestamps.change),!0);return b}function l(a,b,c){var d;d=(d=c)!=null?d:i;c=(c=c)!=null?c:i;var e=new Uint8Array(24),f=new DataView(e.buffer,0,24);f.setUint8(0,a);f.setUint32(2,b,!0);f.setBigUint64(8,d,!0);f.setBigUint64(16,c,!0);return e}function m(a,b,c){return d("WATextEncoding").newTextDecoder().decode(new Uint8Array(a.buffer,b,c))}function n(a){return BigInt(a.getTime())*BigInt(1e6)}function o(a,b){b===void 0&&(b=0);var c=3735928559^b;b=1103547991^b;for(var d=0,e;d<a.length;d++)e=a.charCodeAt(d),c=Math.imul(c^e,2654435761),b=Math.imul(b^e,1597334677);c=Math.imul(c^c>>>16,2246822507)^Math.imul(b^b>>>13,3266489909);b=Math.imul(b^b>>>16,2246822507)^Math.imul(c^c>>>13,3266489909);return 4294967296*(2097151&b)+(c>>>0)}g.createWasi=a}),98);
__d("WAMp4Check",["WAMediaUtilsWasmUrl","WAResultOrError","WASI","WAWasmModuleCache","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h="input",i="output",j="/"+h,k="/"+i;function l(a){var b,c=a.input,d=a.stdout;a=a.stderr;return{args:["wamediautil","mp4check","--error-tolerance=2","--json-report="+i,h],fs:(b={},b[j]={path:j,timestamps:{access:new Date(),change:new Date(),modification:new Date()},mode:"binary",content:new Uint8Array(c)},b[k]={path:k,timestamps:{access:new Date(),change:new Date(),modification:new Date()},mode:"string",content:""},b),stdout:d,stderr:a}}function a(a){var c=a.getWasmModule,e=a.logError,f=a.logMessage;return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){a=a.input;a=d("WASI").createWasi(l({input:a,stderr:e,stdout:f}));var b=a.getImportObject;a=a.start;var g=(yield c());g=(yield WebAssembly.instantiate(g,b()));b=a(g);a=b.exitCode;g=b.fs;if(a!==0){e("mp4Check failed with exit code "+a);return d("WAResultOrError").makeError("invalid-media")}a=(b=g[k])==null?void 0:b.content;if(typeof a!=="string"){e("mp4check failed invalid result type");return d("WAResultOrError").makeError("runtime-error")}b=(g=JSON.parse(a))!=null?g:{};return d("WAResultOrError").makeResult({videoStreamReport:(b==null?void 0:b.video_stream_report)==null?null:{streamType:(a=b.video_stream_report)==null?void 0:a.stream_type,calculatedFps:(g=b.video_stream_report)==null?void 0:g.calculated_fps,nominalFps:(a=b.video_stream_report)==null?void 0:a.nominal_fps,videoWidth:(g=b.video_stream_report)==null?void 0:g.video_width,videoHeight:(a=b.video_stream_report)==null?void 0:a.video_height,duration:(g=b.video_stream_report)==null?void 0:g.duration,avgBitsPerSecond:(a=b.video_stream_report)==null?void 0:a.avg_bits_per_second},audioStreamReport:(b==null?void 0:b.audio_stream_report)==null?null:{streamType:(g=b.audio_stream_report)==null?void 0:g.stream_type,samplingRate:(a=b.audio_stream_report)==null?void 0:a.sampling_rate,numberOfChannels:(g=b.audio_stream_report)==null?void 0:g.number_of_channels,avgBitsPerSecond:(a=b.audio_stream_report)==null?void 0:a.avg_bits_per_second}})});function g(b){return a.apply(this,arguments)}return g}()}c=function(){return d("WAWasmModuleCache").loadWasmModule(d("WAMediaUtilsWasmUrl").WAMediaUtilsWasmUrl)};g.createMp4Check=a;g.getMp4CheckWasm=c}),98);
__d("WAParseWav",[],(function(a,b,c,d,e,f){"use strict";function a(a){var b=new DataView(a);if(a.byteLength<44)return null;return b.getUint32(0)!==1380533830||b.getUint32(8)!==1463899717?null:a}function b(a){a=new DataView(a);var b=a.getUint16(22,!0);a=a.getUint32(24,!0);return{numChannels:b,sampleRate:a}}f.validateWav=a;f.parseWav=b}),66);
__d("WAWebPCheck",["WAResultOrError","WASI","WAWasmModuleCache","asyncToGeneratorRuntime","bx"],(function(a,b,c,d,e,f,g){"use strict";var h="input",i="/"+h;function j(a){var b,c=a.input,d=a.stdout;a=a.stderr;return{args:["webpcheck",h],fs:(b={},b[i]={path:i,timestamps:{access:new Date(),change:new Date(),modification:new Date()},mode:"binary",content:new Uint8Array(c)},b),stdout:d,stderr:a}}function a(a){var c=a.getWasmModule,e=a.logError,f=a.logMessage;return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){a=a.input;a=d("WASI").createWasi(j({input:a,stderr:e,stdout:f}));var b=a.getImportObject;a=a.start;var g=(yield c());g=(yield WebAssembly.instantiate(g,b()));b=a(g);a=b.exitCode;if(a!==0){e("WebPCheck failed with exit code "+a);return d("WAResultOrError").makeError("invalid-media")}return d("WAResultOrError").makeResult()});function g(b){return a.apply(this,arguments)}return g}()}var k=c("bx").getURL(c("bx")("6946"));e=function(){return d("WAWasmModuleCache").loadWasmModule(k)};g.createWebPCheck=a;g.getWebpCheckWasm=e}),98);
__d("WAValidateMedia",["Promise","WAIsMp4","WAIsOgg","WAIsWebP","WAMp4Check","WAParseWav","WAResultOrError","WATagsLogger","WAWebPCheck","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["validateMedia threw an exception: ",""]);k=function(){return a};return a}var l=d("WATagsLogger").TAGS(["WAValidateMedia"]);function a(a,b){b==null?void 0:b.addPoint("media_validation_start");return m(a).then(function(a){a.success?b==null?void 0:b.addPoint("media_validation_end",{bool:{is_validation_setup_failed:a.value.validationSetupFailed,is_validation_skipped:a.value.skipValidation},string:{validated_mime_type:a.value.mimeType}}):b==null?void 0:b.addPoint("media_validation_fail",{string:{validationError:a.error}});return a})["catch"](function(c){l.ERROR(k(),c);b==null?void 0:b.addPoint("media_validation_fail",{string:{validationError:c.toString()}});return d("WAResultOrError").makeResult({skipValidation:!0,mimeType:null,validatedPlaintext:a,validationSetupFailed:!0})})}function m(a){var c=new Uint8Array(a);if(d("WAIsWebP").isWebP(c))return p(a);if(d("WAIsMp4").isMp4(c))return r(a);if(d("WAIsOgg").isOgg(c))return(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeResult({skipValidation:!1,mimeType:"audio/ogg",validatedPlaintext:a,validationSetupFailed:!1,audioStreamReport:null}));c=d("WAParseWav").validateWav(a);return c!=null?(h||(h=b("Promise"))).resolve(t(c)):(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeResult({mimeType:null,skipValidation:!0,validatedPlaintext:a,validationSetupFailed:!1}))}var n=function(a){l.WARN(j(),a)},o=function(a){l.LOG(i(),a)};function p(a){return q.apply(this,arguments)}function q(){q=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=d("WAWebPCheck").createWebPCheck({getWasmModule:d("WAWebPCheck").getWebpCheckWasm,logError:n,logMessage:o});b=(yield b({input:a}));return!b.success?d("WAResultOrError").makeError(b.error==="invalid-media"?"invalid-webp":b.error):d("WAResultOrError").makeResult({skipValidation:!1,mimeType:"image/webp",validatedPlaintext:a,validationSetupFailed:!1})});return q.apply(this,arguments)}function r(a){return s.apply(this,arguments)}function s(){s=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=d("WAMp4Check").createMp4Check({getWasmModule:d("WAMp4Check").getMp4CheckWasm,logError:n,logMessage:o});b=(yield b({input:a}));if(!b.success)return d("WAResultOrError").makeError(b.error==="invalid-media"?"invalid-mp4":b.error);b=b.value;var c=b.videoStreamReport;b=b.audioStreamReport;return c==null?b==null?d("WAResultOrError").makeError("invalid-mp4"):d("WAResultOrError").makeResult({skipValidation:!1,mimeType:"audio/mp4",validatedPlaintext:a,validationSetupFailed:!1,audioStreamReport:b}):d("WAResultOrError").makeResult({skipValidation:!1,mimeType:"video/mp4",validatedPlaintext:a,validationSetupFailed:!1,videoStreamReport:c,audioStreamReport:b})});return s.apply(this,arguments)}function t(a){var b=d("WAParseWav").parseWav(a),c=b.numChannels;b=b.sampleRate;return d("WAResultOrError").makeResult({skipValidation:!1,mimeType:"audio/wav",validatedPlaintext:a,validationSetupFailed:!1,audioStreamReport:{streamType:"LPCM",samplingRate:b,numberOfChannels:c}})}g.validateMedia=a}),98);
__d("WADownloadFullSizeOnlyTask",["EncryptedBackupsResignCdnUrl","MAWCastToMsgrServerMediaType","MAWEBSwitch","Promise","WADownloadMedia","WAFindMostRecentMediaEntry","WAIsMediaExpiredError","WAMediaUtils","WAPrepareMediaDownloadV2","WAResultOrError","WAValidateMedia","asyncToGeneratorRuntime","gkx"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media after restore CDN URL: ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media and restore failed: ",""]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media and can not restore: ",""]);k=function(){return a};return a}function a(a){return l.apply(this,arguments)}function l(){l=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var c=a.abortSignal,e=a.dbCallbacks,f=a.fullSizePlaintextHash,g=a.logger,i=a.mediaDownloadFlow;i.addPoint("get_media_entries_start");a=(yield e.getMediaEntries(f));if(!a.success){i.addPoint("get_media_entries_fail");return{fullsizePromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry"))}}a=a.value;i.addPoint("get_media_entries_end");var j=(yield d("WAFindMostRecentMediaEntry").findMostRecentMediaEntry(a));if(!j.success)return{fullsizePromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry"))};j=j.value;var k=j[0];j=j[1];j=d("WAMediaUtils").validateDecodedMediaEntryForDownload(j);if(!j.success)return{fullsizePromise:(h||(h=b("Promise"))).resolve(j)};j=j.value;f=d("WAPrepareMediaDownloadV2").prepareMediaDownloadV2({hash:f,logger:g,mediaDownloadFlow:i,mediaEntry:j});f=f.logDownloadResult;c=m({abortSignal:c,dbCallbacks:e,logger:g,mediaDownloadFlow:i,mediaEntries:a,msgIdOfRecentMediaEntry:k,recentMediaEntry:j}).then(function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){if(!a.success)return a;var b=(yield d("WAValidateMedia").validateMedia(a.value.plaintext,i));return!b.success?b:d("WAResultOrError").makeResult({serverMediaType:a.value.serverMediaType,unvalidatedMimeType:a.value.mimeType,validatedResult:b.value})});return function(b){return a.apply(this,arguments)}}());return{fullsizePromise:f(c)}});return l.apply(this,arguments)}function m(a){return n.apply(this,arguments)}function n(){n=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.abortSignal,e=a.dbCallbacks,f=a.logger,g=a.mediaDownloadFlow;a.mediaEntries;var h=a.msgIdOfRecentMediaEntry;a=a.recentMediaEntry;var l=c("MAWEBSwitch").isEnabled()&&c("gkx")("23960");l&&g.addPoint("forcing_eb_download");l=l?d("WAResultOrError").makeError("signature-expired"):yield d("WADownloadMedia").downloadFullMediaOnly({abortSignal:b,downloadMediaMetric:g,mediaEntry:babelHelpers["extends"]({},a,{fbid:void 0,objectId:null}),protocolMsgId:null,updateMediaEntryForMsg:e.updateMediaEntryForMsg});if(l.success)return l;if(!d("WAIsMediaExpiredError").isMediaExpiredError(l.error)||!c("MAWEBSwitch").isEnabled())return l;var m=(yield e.getProtocolMsgIdAndSortOrderMs(h));if(m==null)return d("WAResultOrError").makeError("missing-sort-order-ms-for-restore");var n=m.protocolMsgId;m=m.sortOrderMs;a=a;h=h;var o=d("MAWCastToMsgrServerMediaType").castToMsgrServerMediaType(a.serverMediaType);if(o==null||a.objectId==null){f.ERROR(k(),l.error);return l}l=(yield d("EncryptedBackupsResignCdnUrl").resignCdnUrl({deliveryObjectId:a.objectId,logger:f,mediaDownloadFlow:g,mediaType:o,msgId:h,protocolMsgId:n,sortOrderMs:m}));if(!l.success){f.ERROR(j(),l.error);return l}o=(yield d("WADownloadMedia").downloadFullMediaOnly({abortSignal:b,downloadMediaMetric:g,mediaEntry:babelHelpers["extends"]({},a,{directPath:l.value,fbid:void 0,objectId:null}),protocolMsgId:null,updateMediaEntryForMsg:e.updateMediaEntryForMsg}));if(!o.success){f.ERROR(i(),o.error);return o}return d("WAResultOrError").makeResult(o.value)});return n.apply(this,arguments)}g.startDownloadFullSizeTask=a;g.downloadOrRestoreFullSize=m}),98);
__d("WADownloadMediaPreviewV2",["WADownloadMedia","WADownloadProgressiveJpegPreview","WAMediaCrypto","WAMediaUtils","WAResultOrError","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["preview mediaEntry is incomplete: ",""]);h=function(){return a};return a}function a(a){return i.apply(this,arguments)}function i(){i=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.abortSignal,c=a.hash,e=a.mediaEntry,f=a.progressiveJpegDetails,g=a.mediaDownloadFlow,i=a.updateMediaEntryForMsg;a=a.logger;var j=e.serverMediaType,k=d("WAMediaUtils").getMimeTypeFromServerMediaType(j);c=f==null?d("WAResultOrError").makeError("jpeg-stream-not-supported"):yield d("WADownloadProgressiveJpegPreview").maybeDownloadProgressiveJpegPreviewV2({abortSignal:b,hash:c,serverMediaType:j,mediaEntry:e,progressiveJpegDetails:f});if(c.success===!0)return d("WAResultOrError").makeResult({plaintext:c.value,mimeType:k,serverMediaType:j});f=e.downloadableThumbnail;if((f==null?void 0:f.directPath)==null)return d("WAResultOrError").makeError("media-not-found");c=d("WAMediaUtils").validateDownloadableThumbnailForDownload(f);if(c.success===!1){a.ERROR(h(),c.error);return d("WAResultOrError").makeError(c.error[0])}f=c.value;a=f.directPath;c=f.fileEncSha256;var l=f.fileSha256;f=f.mediaKey;var m=d("WAMediaCrypto").convertServerMediaTypeToPreviewMediaType(j);if(m==null)return d("WAResultOrError").makeError("request-error");b=(yield d("WADownloadMedia").downloadMediaImpl({abortSignal:b,protocolMsgId:null,downloadFlow:g,mediaTypeDetails:{messageType:m,type:"preview"},directPath:a,fileEncSha256:c,fileSha256:l,mediaKey:f,objectId:null,fbid:null,mediaEntry:e,dbCallbacks:{updateMediaEntryForMsg:i}}));return b.success===!1?b:d("WAResultOrError").makeResult({plaintext:b.value,mimeType:k,serverMediaType:j})});return i.apply(this,arguments)}g.downloadMediaPreview=a}),98);
__d("WAIsPreviewSupported",["$InternalEnum","WAProgressiveJpegGetPJpegDetails"],(function(a,b,c,d,e,f,g){"use strict";var h=b("$InternalEnum").Mirrored(["NO","YES"]),i=b("$InternalEnum").Mirrored(["NO","YES","DuplicatedWithFullSize"]);function a(a){var b=a.serverMediaType;switch(b){case"image":var c,e;c=(c=d("WAProgressiveJpegGetPJpegDetails").maybeGetProgressiveJpegDetailsUsingMediaEntry(a).value)!=null?c:null;c=c!=null?h.YES:h.NO;if(((e=a.downloadableThumbnail)==null?void 0:e.directPath)==null)return[c,i.NO];a.downloadableThumbnail.directPath;e=a.downloadableThumbnail.directPath===a.directPath?i.DuplicatedWithFullSize:i.YES;return[c,e];case"video":if(((c=a.downloadableThumbnail)==null?void 0:c.directPath)==null)return[h.NO,i.NO];a.downloadableThumbnail.directPath;e=a.downloadableThumbnail.directPath===a.directPath?i.NO:i.YES;return[h.NO,e];case"sticker":case"ptt":case"audio":case"document":case"gif":case"ppic":case"md-app-state":case"md-msg-hist":case"kyc-id":case"template":case"thumbnail-image":case"thumbnail-video":case"thumbnail-gif":case"thumbnail-document":case"thumbnail-link":case"novi-video":case"novi-image":case"payment-bg-image":case"product":case"product-catalog-image":case"xma-image":case"biz-cover-photo":case"preview":case"newsletter-audio":case"newsletter-document":case"newsletter-image":case"newsletter-gif":case"newsletter-ptt":case"newsletter-sticker":case"newsletter-thumbnail-link":case"newsletter-video":case"sticker-pack":case"thumbnail-sticker-pack":case"music-artwork":return[h.NO,i.NO];default:b;return[h.NO,i.NO]}}g.PjpegPreviewSupport=h;g.DownloadablePreviewSupport=i;g.checkPreviewSupport=a}),98);
__d("WADownloadPreviewOnlyTask",["EncryptedBackupsResignCdnUrl","MAWCastToMsgrServerMediaType","MAWEBSwitch","Promise","WADownloadMediaPreviewV2","WAFindMostRecentMediaEntry","WAIsMediaExpiredError","WAIsPreviewSupported","WAMediaUtils","WAPrepareMediaDownloadV2","WAProgressiveJpegGetPJpegDetails","WAResultOrError","WAValidateMedia","asyncToGeneratorRuntime","gkx"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media after restore CDN URL: ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media and restore failed: ",""]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media and can not restore: ",""]);k=function(){return a};return a}function a(a){return l.apply(this,arguments)}function l(){l=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var c=a.abortSignal,e=a.dbCallbacks,f=a.fullSizePlaintextHash,g=a.logger,i=a.mediaDownloadFlow;i.addPoint("get_media_entries_start");a=(yield e.getMediaEntries(f));if(!a.success){i.addPoint("get_media_entries_fail");return{previewPromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry"))}}i.addPoint("get_media_entries_end");var j=a.value;j=(yield d("WAFindMostRecentMediaEntry").findMostRecentMediaEntry(j));if(!j.success)return{previewPromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry"))};j=j.value;var k=j[0];j=j[1];j=d("WAMediaUtils").validateDecodedMediaEntryForDownload(j);if(!j.success)return{previewPromise:(h||(h=b("Promise"))).resolve(j)};j=j.value;var l=d("WAPrepareMediaDownloadV2").prepareMediaDownloadV2({hash:f,logger:g,mediaDownloadFlow:i,mediaEntry:j});l=l.logDownloadResult;var n=d("WAIsPreviewSupported").checkPreviewSupport(j),o=n[0];n=n[1];if(o===d("WAIsPreviewSupported").PjpegPreviewSupport.NO&&n===d("WAIsPreviewSupported").DownloadablePreviewSupport.NO)return{previewPromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("preview-not-supported"))};o=m({abortSignal:c,dbCallbacks:e,fullSizePlaintextHash:f,logger:g,mediaDownloadFlow:i,mediaEntries:a.value,msgIdOfRecentMediaEntry:k,recentMediaEntry:j}).then(function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){if(!a.success)return a;var b=(yield d("WAValidateMedia").validateMedia(a.value.plaintext,i));return!b.success?b:d("WAResultOrError").makeResult({serverMediaType:a.value.serverMediaType,unvalidatedMimeType:a.value.mimeType,validatedResult:b.value})});return function(b){return a.apply(this,arguments)}}());return{previewPromise:l(o)}});return l.apply(this,arguments)}function m(a){return n.apply(this,arguments)}function n(){n=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.abortSignal,e=a.dbCallbacks,f=a.fullSizePlaintextHash,g=a.logger,h=a.mediaDownloadFlow;a.mediaEntries;var l=a.msgIdOfRecentMediaEntry;a=a.recentMediaEntry;var m=c("MAWEBSwitch").isEnabled()&&c("gkx")("23960");m&&h.addPoint("forcing_eb_download");var n=d("WAProgressiveJpegGetPJpegDetails").maybeGetProgressiveJpegDetailsUsingMediaEntry(a);n=n.success===!0?n.value:null;b={abortSignal:b,hash:f,logger:g,mediaDownloadFlow:h,progressiveJpegDetails:n,updateMediaEntryForMsg:e.updateMediaEntryForMsg};f=m?d("WAResultOrError").makeError("signature-expired"):yield d("WADownloadMediaPreviewV2").downloadMediaPreview(babelHelpers["extends"]({},b,{mediaEntry:babelHelpers["extends"]({},a,{fbid:void 0,objectId:null})}));if(f.success)return d("WAResultOrError").makeResult({mimeType:f.value.mimeType,plaintext:f.value.plaintext,serverMediaType:f.value.serverMediaType});if(!d("WAIsMediaExpiredError").isMediaExpiredError(f.error)||!c("MAWEBSwitch").isEnabled()||c("gkx")("1327")!==!0)return f;n=(yield e.getProtocolMsgIdAndSortOrderMs(l));if(n==null)return d("WAResultOrError").makeError("missing-sort-order-ms-for-restore");m=n.protocolMsgId;e=n.sortOrderMs;n=a;a=l;l=d("MAWCastToMsgrServerMediaType").castToMsgrServerMediaType(n.serverMediaType);if(l==null||((l=n.downloadableThumbnail)==null?void 0:l.objectId)==null){g.ERROR(k(),f.error);return f}l=(yield d("EncryptedBackupsResignCdnUrl").resignCdnUrl({deliveryObjectId:n.downloadableThumbnail.objectId,logger:g,mediaDownloadFlow:h,mediaType:"preview",msgId:a,protocolMsgId:m,sortOrderMs:e}));if(!l.success){g.ERROR(j(),l.error);return l}f=(yield d("WADownloadMediaPreviewV2").downloadMediaPreview(babelHelpers["extends"]({},b,{mediaEntry:babelHelpers["extends"]({},n,{directPath:l.value,fbid:void 0,objectId:null})})));if(!f.success){g.ERROR(i(),f.error);return f}return d("WAResultOrError").makeResult({mimeType:f.value.mimeType,plaintext:f.value.plaintext,serverMediaType:f.value.serverMediaType})});return n.apply(this,arguments)}g.startDownloadPreviewTask=a;g.downloadOrRestorePreviewOnly=m}),98);
__d("WADownloadProgressiveJpegUsingMediaStreaming",["WAByteArray","WACryptoSha256","WACryptoUtils","WADownloadProgressiveJpegPlaintextStreamer","WADownloadProgressiveJpegPreview","WAErrorMessage","WAMediaUtils","WAProgressiveJpegAddJPEGTrailingTag","WAResolvable","WAResultOrError","WAStreamAsyncIterator","WATypedArraysConcat","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["Exception occurred during Media Streaming: Reason: ",""]);h=function(){return a};return a}function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Media streaming for ProgressiveJpeg download failed due to plaintext hash mismatch."]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["pjpeg stream ended before reaching previewTargetScanIndex"]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["fullsizeResolvable is settled before previewResolvable"]);k=function(){return a};return a}function l(){var a=babelHelpers.taggedTemplateLiteralLoose(["handleProgressiveJpegDownloadStream unexpected runtime-error: ",""]);l=function(){return a};return a}function m(){var a=babelHelpers.taggedTemplateLiteralLoose(["handleProgressiveJpegDownloadStream completed"]);m=function(){return a};return a}function n(){var a=babelHelpers.taggedTemplateLiteralLoose(["create DownloadAndDecryptPJpegStream unexpected runtime-error: ",""]);n=function(){return a};return a}function o(){var a=babelHelpers.taggedTemplateLiteralLoose(["Using Media Streaming to download ProgressiveJpeg."]);o=function(){return a};return a}function a(a){return p.apply(this,arguments)}function p(){p=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.abortSignal,c=a.directPath,e=a.downloadFlow,f=a.fileEncSha256,g=a.fileSha256,h=a.logger,i=a.mediaKey,j=a.progressiveJpegDetails,p=a.serverMediaType,r=h.TAGS(["MediaStreaming"]);r.LOG(o());e.addPoint("create_pjpeg_stream_start");a=(yield d("WADownloadProgressiveJpegPlaintextStreamer").downloadProgressiveJpegPlaintextUsingStreams({abortSignal:b,directPath:c,eventFlow:e,fileEncSha256:f,mediaKey:i,progressiveJpegDetails:j,serverMediaType:p})["catch"](function(a){r.ERROR(n(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)}));if(a.success===!1){e.addPoint("create_pjpeg_stream_fail");return a}e.addPoint("create_pjpeg_stream_end");var s=new(d("WAResolvable").Resolvable)();h=!1;b=q({downloadFlow:e,fileSha256:g,mediaStreamingLogger:r,previewResolvable:s,progressiveJpegDetails:j,progressiveJpegDownloadStream:a.value,serverMediaType:p}).then(function(a){h=!0;r.DEV(m());return a})["catch"](function(a){h=!0;r.ERROR(l(),d("WAErrorMessage").maybeGetMessageFromError(a));s.reject(a);return d("WAResultOrError").makeError("runtime-error",a)});var t=d("WAMediaUtils").getMimeTypeFromServerMediaType(p);function u(a){return a.success===!1?a:d("WAResultOrError").makeResult({mimeType:t,plaintext:a.value,serverMediaType:p})}c=b.then(u);f=s.promise.then(u);i=(yield s.promise);i.success===!0&&h===!0&&r.ERROR(k());if(i.success===!0)return d("WAResultOrError").makeResult({fullsizePromise:c,previewPromise:f});e=(yield b);i.success;if(e.success===!0)return d("WAResultOrError").makeResult({fullsizePromise:c,previewPromise:f});e.success;return e});return p.apply(this,arguments)}function q(a){return r.apply(this,arguments)}function r(){r=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.downloadFlow,c=a.fileSha256,e=a.mediaStreamingLogger,f=a.previewResolvable,g=a.progressiveJpegDetails;a=a.progressiveJpegDownloadStream;b.addPoint("download_pjpeg_preview_start");var k=0;g=d("WADownloadProgressiveJpegPreview").getPreviewTargetScan(g.scanLengths)-1;try{var l=[],m=!0,n=!1,o;try{for(var p=babelHelpers.asyncIterator(d("WAStreamAsyncIterator").streamAsyncIterator(a)),a,a;a=(yield p.next()),m=a.done,a=(yield a.value),!m;m=!0){a=a;if(a==null)continue;l.push(a);if(k===g){b.addPoint("media_streaming_preview_processed");a=d("WAByteArray").uint8ArrayToBuffer(d("WATypedArraysConcat").concatTypedArrays(Uint8Array,[].concat(l,[d("WAProgressiveJpegAddJPEGTrailingTag").JPEG_TRAILING_TAG])));f.resolve(d("WAResultOrError").makeResult(a));b.addPoint("download_pjpeg_preview_end")}k++}}catch(a){n=!0,o=a}finally{try{!m&&p["return"]!=null&&(yield p["return"]())}finally{if(n)throw o}}f.isSettled===!1&&(e.ERROR(j()),f.resolve(d("WAResultOrError").makeError("runtime-error")),b.addPoint("download_pjpeg_preview_fail"));a=d("WAByteArray").uint8ArrayToBuffer(d("WATypedArraysConcat").concatTypedArrays(Uint8Array,[].concat(l)));k=(yield d("WACryptoSha256").sha256(a));if(!d("WACryptoUtils").arrayBuffersEqual(c,k)){e.WARN(i());return d("WAResultOrError").makeError("hash-mismatch")}return d("WAResultOrError").makeResult(a)}catch(a){e.ERROR(h(),a);f.isSettled===!1&&(f.resolve(d("WAResultOrError").makeError("runtime-error",a)),b.addPoint("download_pjpeg_preview_fail"));return d("WAResultOrError").makeError("runtime-error",a)}});return r.apply(this,arguments)}g.downloadProgresiveJpegUsingMediaStreaming=a}),98);
__d("WADownloadFullSizeAndPreviewTask",["EncryptedBackupsResignCdnUrl","MAWCastToMsgrServerMediaType","MAWEBSwitch","Promise","UserAgent","WADownloadFullSizeOnlyTask","WADownloadPreviewOnlyTask","WADownloadProgressiveJpegUsingMediaStreaming","WAErrorMessage","WAFindMostRecentMediaEntry","WAHashUtils","WAIsMediaExpiredError","WAIsPreviewSupported","WAMediaUtils","WAPrepareMediaDownloadV2","WAProgressiveJpegGetPJpegDetails","WAResultOrError","WAStartMediaDownloadQplFlow","WAValidateMedia","asyncToGeneratorRuntime","gkx"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["downloadProgresiveJpegUsingMediaStreaming unexpected runtime-error: ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to download media and can not restore: ",""]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["downloadProgresiveJpegUsingMediaStreaming unexpected runtime-error: ",""]);k=function(){return a};return a}function l(){var a=babelHelpers.taggedTemplateLiteralLoose(["media entry: ",""]);l=function(){return a};return a}function m(){var a=babelHelpers.taggedTemplateLiteralLoose(["skip pjpeg streaming because pjpeg metadata is null"]);m=function(){return a};return a}function n(){var a=babelHelpers.taggedTemplateLiteralLoose(["fallback to non-streaming download"]);n=function(){return a};return a}function o(){var a=babelHelpers.taggedTemplateLiteralLoose(["outter promise failed: ",""]);o=function(){return a};return a}function p(){var a=babelHelpers.taggedTemplateLiteralLoose(["outter promise: ",""]);p=function(){return a};return a}function q(){var a=babelHelpers.taggedTemplateLiteralLoose(["invalid mediaEntry for download: ",""]);q=function(){return a};return a}function r(){var a=babelHelpers.taggedTemplateLiteralLoose(["preview duplicated with fullsize"]);r=function(){return a};return a}function s(){var a=babelHelpers.taggedTemplateLiteralLoose(["preview not supported"]);s=function(){return a};return a}function a(a){return t.apply(this,arguments)}function t(){t=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var c=a.abortSignal,e=a.dbCallbacks,f=a.fullSizePlaintextHash,g=a.logger;a=a.mediaDownloadFlow;a.addPoint("get_media_entries_start");var i=(yield e.getMediaEntries(f));if(!i.success){a.addPoint("get_media_entries_fail");return{fullsizePromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry")),previewPromise:h.resolve(d("WAResultOrError").makeError("missing-media-entry"))}}a.addPoint("get_media_entries_end");i=i.value;var j=(yield d("WAFindMostRecentMediaEntry").findMostRecentMediaEntry(i));if(!j.success)return{fullsizePromise:(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("missing-media-entry")),previewPromise:h.resolve(d("WAResultOrError").makeError("missing-media-entry"))};j=j.value;var k=j[0];j=j[1];j=d("WAMediaUtils").validateDecodedMediaEntryForDownload(j);if(!j.success){g.ERROR(q(),j.error);return{fullsizePromise:(h||(h=b("Promise"))).resolve(j),previewPromise:h.resolve(j)}}return w({abortSignal:c,dbCallbacks:e,fullSizePlaintextHash:f,logger:g,mediaDownloadFlow:a,mediaEntries:i,msgIdOfRecentMediaEntry:k,recentMediaEntry:j.value}).then(function(a){g.DEV(p(),a.success===!0?"success":a.error);if(!a.success){g.ERROR(o(),a.error);return{fullsizePromise:(h||(h=b("Promise"))).resolve(a),previewPromise:h.resolve(a)}}return a.value})});return t.apply(this,arguments)}function u(a,b){return v.apply(this,arguments)}function v(){v=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a,c){a=(yield a);if(!a.success)return(h||(h=b("Promise"))).resolve(a);c=(yield d("WAValidateMedia").validateMedia(a.value.plaintext,c));return!c.success?c:d("WAResultOrError").makeResult({serverMediaType:a.value.serverMediaType,unvalidatedMimeType:a.value.mimeType,validatedResult:c.value})});return v.apply(this,arguments)}function w(a){return x.apply(this,arguments)}function x(){x=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.abortSignal,c=a.dbCallbacks,e=a.fullSizePlaintextHash,f=a.logger,g=a.mediaDownloadFlow,h=a.mediaEntries,i=a.msgIdOfRecentMediaEntry;a=a.recentMediaEntry;var j=d("WAPrepareMediaDownloadV2").prepareMediaDownloadV2({hash:e,logger:f,mediaDownloadFlow:g,mediaEntry:a});j=j.logDownloadResult;var k={abortSignal:b,dbCallbacks:c,logger:f,mediaDownloadFlow:g,mediaEntries:h,msgIdOfRecentMediaEntry:i,recentMediaEntry:a};b=(yield y(babelHelpers["extends"]({},k,{fullSizePlaintextHash:e})));if(b.success){c=b.value;h=c.fullsizePromise;i=c.previewPromise;a=h.then(function(a){if(a.success)return a;g.addPoint("fallback_to_non_streaming_download",{string:{streaming_fallback_reason:a.error}});return d("WADownloadFullSizeOnlyTask").downloadOrRestoreFullSize(k)});return d("WAResultOrError").makeResult({fullsizePromise:j(u(a,g)),previewPromise:u(i,g)})}c=C(b.error);if(!c.shouldFallback)return d("WAResultOrError").makeError(c.error);g.addPoint("fallback_to_non_streaming_download",{string:{streaming_fallback_reason:c.error}});f.LOG(n());h=u(d("WADownloadFullSizeOnlyTask").downloadOrRestoreFullSize(k),g);a=A(babelHelpers["extends"]({},k,{fullSizePlaintextHash:e,fullsizePromise:h}));return d("WAResultOrError").makeResult({fullsizePromise:j(h),previewPromise:a})});return x.apply(this,arguments)}function y(a){return z.apply(this,arguments)}function z(){z=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b,e=a.abortSignal,f=a.dbCallbacks,g=a.logger,h=a.mediaDownloadFlow;a.mediaEntries;var n=a.msgIdOfRecentMediaEntry;a=a.recentMediaEntry;var o=c("MAWEBSwitch").isEnabled()&&c("gkx")("23960");o&&h.addPoint("forcing_eb_download");var p=a.directPath,q=a.fileEncSha256,r=a.fileSha256,s=a.mediaKey,t=a.serverMediaType;b=(b=d("WAProgressiveJpegGetPJpegDetails").maybeGetProgressiveJpegDetailsUsingMediaEntry(a).value)!=null?b:null;if(b==null||a.serverMediaType!=="image"||!d("WAMediaUtils").isTransformStreamSupported()||c("UserAgent").isBrowser("Safari < 18")||c("UserAgent").isBrowser("Mobile Safari < 18")){a.serverMediaType==="image"&&b==null&&(g.LOG(m()),g.DEV(l(),a));return d("WAResultOrError").makeError("jpeg-stream-not-supported")}h.addPoint("media_streaming_start");o=o?d("WAResultOrError").makeError("signature-expired"):yield d("WADownloadProgressiveJpegUsingMediaStreaming").downloadProgresiveJpegUsingMediaStreaming({abortSignal:e,directPath:p,downloadFlow:h,fileEncSha256:q,fileSha256:r,logger:g,mediaKey:s,progressiveJpegDetails:b,serverMediaType:t})["catch"](function(a){g.ERROR(k(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)});if(o.success){h.addPoint("media_streaming_end");return o}if(!d("WAIsMediaExpiredError").isMediaExpiredError(o.error)||!c("MAWEBSwitch").isEnabled()){B(h,o);return o}p=(yield f.getProtocolMsgIdAndSortOrderMs(n));if(p==null)return d("WAResultOrError").makeError("missing-sort-order-ms-for-restore");q=p.protocolMsgId;r=p.sortOrderMs;s=a;t=n;f=s.fileEncSha256;p=s.fileSha256;a=s.mediaKey;n=s.serverMediaType;var u=d("MAWCastToMsgrServerMediaType").castToMsgrServerMediaType(n);if(u==null||s.objectId==null){g.ERROR(j(),o.error);return o}o=(yield d("EncryptedBackupsResignCdnUrl").resignCdnUrl({deliveryObjectId:s.objectId,logger:g,mediaDownloadFlow:h,mediaType:u,msgId:t,protocolMsgId:q,sortOrderMs:r}));if(!o.success)return o;s=(yield d("WADownloadProgressiveJpegUsingMediaStreaming").downloadProgresiveJpegUsingMediaStreaming({abortSignal:e,directPath:o.value,downloadFlow:h,fileEncSha256:f,fileSha256:p,logger:g,mediaKey:a,progressiveJpegDetails:b,serverMediaType:n})["catch"](function(a){g.ERROR(i(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)}));if(s.success){h.addPoint("media_streaming_end");return s}else{B(h,s);return s}});return z.apply(this,arguments)}function A(a){var c=a.abortSignal,e=a.dbCallbacks,f=a.fullSizePlaintextHash,g=a.fullsizePromise,i=a.logger,j=a.mediaDownloadFlow,k=a.mediaEntries,l=a.msgIdOfRecentMediaEntry;a=a.recentMediaEntry;var m=a.serverMediaType,n=d("WAIsPreviewSupported").checkPreviewSupport(a),o=n[0];n=n[1];if(o===d("WAIsPreviewSupported").PjpegPreviewSupport.NO&&n===d("WAIsPreviewSupported").DownloadablePreviewSupport.NO){i.LOG(s());return(h||(h=b("Promise"))).resolve(d("WAResultOrError").makeError("preview-not-supported"))}if(n===d("WAIsPreviewSupported").DownloadablePreviewSupport.DuplicatedWithFullSize){i.LOG(r());return g}var p=d("WAStartMediaDownloadQplFlow").startMediaDownloadQplFlow({downloadEntry:j.downloadEntry,isPreview:!0,msgType:null,protocolMsgId:null,triggerUIView:null});o=d("WAPrepareMediaDownloadV2").prepareMediaDownloadV2({hash:f,logger:i,mediaDownloadFlow:p,mediaEntry:a});n=o.logDownloadResult;p.addAnnotations({bool:{isMediaManager:!0},string:{downloadKind:"fullsizeAndPreview",fullSizeMediaType:m,mediaType:"preview",sanitisedMediaHash:d("WAHashUtils").sanitisePlaintextHash(f)}});g=d("WADownloadPreviewOnlyTask").downloadOrRestorePreviewOnly({abortSignal:c,dbCallbacks:e,fullSizePlaintextHash:f,logger:i,mediaDownloadFlow:p,mediaEntries:k,msgIdOfRecentMediaEntry:l,recentMediaEntry:a});return n(u(g,p)).then(function(a){a.success?p.endSuccess():p.endFail(a.error,{string:{failReason:a.error}});return a})["catch"](function(a){p.endFail("runtime-error",{string:{failReason:d("WAErrorMessage").maybeGetMessageFromError(a)}});return d("WAResultOrError").makeError("runtime-error",a)})}function B(a,b){a.addPoint("media_streaming_fail",{string:{wa_media_download_streaming_fail_reason:b.payload!=null?d("WAErrorMessage").maybeGetMessageFromError(b.payload):b.error}})}function C(a){switch(a){case"runtime-error":case"jpeg-stream-not-supported":return{error:a,shouldFallback:!0};case"missing-expected-hmacs":case"hmac-chiphertext-array-mismatch":return{error:a,shouldFallback:!0};case"missing-media-entry":case"missing-media-entry-for-restore":case"missing-sort-order-ms-for-restore":case"preview-not-supported":return{error:a,shouldFallback:!1};case"direct-path-undefined":case"direct-path-corrupted":case"direct-path-empty":case"create-payload-failed":case"resign-cdn-url-request-error":case"resign-cdn-url-runtime-error":return{error:a,shouldFallback:!1};case"invalid-webp":case"invalid-mp4":return{error:a,shouldFallback:!1};case"decryption-error":case"enc-hash-mismatch":case"hash-mismatch":case"ciphertext-hash-mismatch":return{error:a,shouldFallback:!0};case"access-expired":case"disconnected":case"backoff":case"body-network-error":case"http-fetch-exception":case"no-host":case"server-timeout":case"unspecified-http-error":case"media-not-found":case"download-throttled":case"request-error":case"max-attempts-exceeded":case"signature-expired":case"media-entry-invalid":return{error:a,shouldFallback:!1};case"media-entry-invalid-direct-path":case"media-entry-invalid-file-enc-sha256":case"media-entry-invalid-file-sha256":case"media-entry-invalid-media-key":case"media-entry-invalid-server-media-type":return{error:a,shouldFallback:!1}}}g.startDownloadFullSizeAndPreviewTask=a}),98);
__d("WAMediaManagerWorkerScheduler",["WorkerScheduler"],(function(a,b,c,d,e,f,g){"use strict";var h;function a(){h==null&&(h=d("WorkerScheduler").makeScheduler("MediaManager",{concurrency:16,maxConcurrency:32,maxThrottleMs:30*1e3,timeToStuckMs:60*1e3}));return h}g.mediaManagerWorkerScheduler=a}),98);
__d("mapWorkerSchedulerTask",[],(function(a,b,c,d,e,f){"use strict";function a(a,b){return babelHelpers["extends"]({},a,{run:function(){return a.run().then(b)},promise:a.promise.then(b)})}f.mapWorkerSchedulerTask=a}),66);
__d("WAMediaManager",["$InternalEnum","WADownloadFullSizeAndPreviewTask","WADownloadFullSizeOnlyTask","WADownloadPreviewOnlyTask","WAErrorMessage","WAHashUtils","WAMediaManagerCache","WAMediaManagerWorkerScheduler","WAResultOrError","WATagsLogger","WorkerScheduler","mapWorkerSchedulerTask"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["preview end"]);h=function(){return a};return a}function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["previewPromise runtime-error: ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["fullsize end"]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["fullsizePromise runtime-error: ",""]);k=function(){return a};return a}function l(){var a=babelHelpers.taggedTemplateLiteralLoose(["fullsize: ",", preview: ",""]);l=function(){return a};return a}function m(){var a=babelHelpers.taggedTemplateLiteralLoose(["end"]);m=function(){return a};return a}function n(){var a=babelHelpers.taggedTemplateLiteralLoose(["runtime-error: ",""]);n=function(){return a};return a}function o(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);o=function(){return a};return a}function p(){var a=babelHelpers.taggedTemplateLiteralLoose(["end"]);p=function(){return a};return a}function q(){var a=babelHelpers.taggedTemplateLiteralLoose(["runtime-error: ",""]);q=function(){return a};return a}function r(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);r=function(){return a};return a}var s=b("$InternalEnum").Mirrored(["HIGH","MEDIUM","LOW"]),t=d("WATagsLogger").TAGS(["MediaManager"]);function a(a){var b=a.dbCallbacks,c=d("WAMediaManagerWorkerScheduler").mediaManagerWorkerScheduler(),e=d("WAMediaManagerCache").createMediaDownloadCache(),f=function(a){var f=y({downloadKind:"fullsize",fullSizePlaintextHash:a.fullSizePlaintextHash}),g=e.getFullsize(a);f.DEV(r(),g.type);if(g.type==="cache-hit")return g.cache;var h=new AbortController(),i=c.task({fn:function(){return d("WADownloadFullSizeOnlyTask").startDownloadFullSizeTask({abortSignal:h.signal,dbCallbacks:b,fullSizePlaintextHash:a.fullSizePlaintextHash,logger:f,mediaDownloadFlow:a.mediaDownloadFlow})},name:"media-manager-download-fullsize-only",priority:u(a.priority)}),j=i.run();g.setCache(a.fullSizePlaintextHash,h,a.mediaDownloadFlow,d("mapWorkerSchedulerTask").mapWorkerSchedulerTask(i,function(a){return a.fullsizePromise}));return j.then(function(a){return a.fullsizePromise})["catch"](function(a){f.ERROR(q(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)})["finally"](function(){f.DEV(p())})},g=function(a){var f=y({downloadKind:"preview",fullSizePlaintextHash:a.fullSizePlaintextHash}),g=e.getPreview(a);f.DEV(o(),g.type);if(g.type==="cache-hit")return g.cache;var h=new AbortController(),i=c.task({fn:function(){return d("WADownloadPreviewOnlyTask").startDownloadPreviewTask({abortSignal:h.signal,dbCallbacks:b,fullSizePlaintextHash:a.fullSizePlaintextHash,logger:f,mediaDownloadFlow:a.mediaDownloadFlow})},name:"media-manager-download-preview-only",priority:u(a.priority)});g.setCache(a.fullSizePlaintextHash,h,a.mediaDownloadFlow,d("mapWorkerSchedulerTask").mapWorkerSchedulerTask(i,function(a){return a.previewPromise}));g=i.run();return g.then(function(a){return a.previewPromise})["catch"](function(a){f.ERROR(n(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)})["finally"](function(){f.DEV(m())})};a=function(a){var m=y({downloadKind:"fullsizeAndPreview",fullSizePlaintextHash:a.fullSizePlaintextHash}),n=e.getFullsizeAndPreview(a),o=n.fullsizeCacheResult;n=n.previewCacheResult;m.DEV(l(),o.type,n.type);if(o.type==="cache-hit"&&n.type==="cache-hit")return{fullsizePromise:o.cache,previewPromise:n.cache};if(n.type==="cache-hit"){var p=f(a);return{fullsizePromise:p,previewPromise:n.cache}}if(o.type==="cache-hit"){p=g(a);return{fullsizePromise:o.cache,previewPromise:p}}o.type;n.type;var q=new AbortController();p=c.task({fn:function(){return d("WADownloadFullSizeAndPreviewTask").startDownloadFullSizeAndPreviewTask({abortSignal:q.signal,dbCallbacks:b,fullSizePlaintextHash:a.fullSizePlaintextHash,logger:m,mediaDownloadFlow:a.mediaDownloadFlow})},name:"media-manager-download-fullsize-and-preview",priority:u(a.priority)});o.setCache(a.fullSizePlaintextHash,q,a.mediaDownloadFlow,d("mapWorkerSchedulerTask").mapWorkerSchedulerTask(p,function(a){return a.fullsizePromise}));n.setCache(a.fullSizePlaintextHash,q,a.mediaDownloadFlow,d("mapWorkerSchedulerTask").mapWorkerSchedulerTask(p,function(a){return a.previewPromise}));o=p.run();return{fullsizePromise:o.then(function(a){return a.fullsizePromise})["catch"](function(a){m.ERROR(k(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)})["finally"](function(){m.DEV(j())}),previewPromise:o.then(function(a){return a.previewPromise})["catch"](function(a){m.ERROR(i(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("runtime-error",a)})["finally"](function(){m.DEV(h())})}};return{clearCache:e.clearCache,dequeueDownload:e.cancelTask,enqueueDownloadFullSize:x("fullsize",f),enqueueDownloadFullSizeAndPreview:x("fullsizeAndPreview",a),enqueueDownloadPreview:x("preview",g)}}function u(a){switch(a){case s.HIGH:return d("WorkerScheduler").BLOCKING_PRIORITY;case s.MEDIUM:return d("WorkerScheduler").REGULAR_PRIORITY;case s.LOW:return d("WorkerScheduler").BACKGROUND_PRIORITY}}var v=typeof ((c=navigator.storage)==null?void 0:c.getDirectory)==="function",w=typeof self.caches==="object";function x(a,b){return function(c){var e=c.fullSizePlaintextHash,f=c.mediaDownloadFlow;try{f.addPoint("enqueue_start",{bool:{isMediaManager:!0,isOPFSSupported:v,isWebCacheSupported:w},string:{downloadKind:a,sanitisedMediaHash:d("WAHashUtils").sanitisePlaintextHash(e)}});e=b(c);f.addPoint("enqueue_end");return e}catch(a){f.addPoint("enqueue_fail");throw a}}}function y(a){var b=a.downloadKind;a=a.fullSizePlaintextHash;a=t.TAGS(["hash:"+d("WAHashUtils").sanitisePlaintextHash(a),b]);return a}g.MediaTaskPriority=s;g.baseLogger=t;g.createMediaManager=a;g.toWorkerSchedulerPriority=u}),98);
__d("WAMediaManagerCache",["WAHashUtils","WAMediaManager","WAPromiseDelays"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["worker task cancel"]);h=function(){return a};return a}function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["http abort cancel"]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["start"]);j=function(){return a};return a}var k=1e3*30;function a(){var a=new Map(),b=new Map(),c=function(a,c,e,f){b.set(a,{abortController:c,mediaDownloadFlow:e,task:f}),f.promise.then(function(a){a=a.success;return a?d("WAPromiseDelays").delayMs(k):void 0})["finally"](function(){b["delete"](a)})},e=function(b,c,e,f){a.set(b,{abortController:c,mediaDownloadFlow:e,task:f}),f.promise.then(function(a){a=a.success;return a?d("WAPromiseDelays").delayMs(k):void 0})["finally"](function(){a["delete"](b)})};return{cancelTask:function(c){var e=d("WAMediaManager").baseLogger.TAGS(["hash:"+d("WAHashUtils").sanitisePlaintextHash(c),"cancelTask"]);e.LOG(j());var f=[b,a];for(var g=0;g<f.length;g++){var k=f[g],l=k.get(c);if(l!=null){var m=l.task.cancel();l.mediaDownloadFlow.addPoint("cancel_download_triggered");m===!1?(l.abortController.abort(),l.mediaDownloadFlow.addPoint("http_abort_cancel"),e.LOG(i())):(l.mediaDownloadFlow.addPoint("worker_task_cancel_cancel"),e.LOG(h()));k["delete"](c)}}},clearCache:function(){a.clear(),b.clear()},getFullsize:function(a){var e=b.get(a.fullSizePlaintextHash);if(e!=null){l(a.mediaDownloadFlow,"hit","fullsize");e.task.promote(d("WAMediaManager").toWorkerSchedulerPriority(a.priority));return{cache:e.task.promise,type:"cache-hit"}}l(a.mediaDownloadFlow,"miss","fullsize");return{setCache:c,type:"cache-miss"}},getFullsizeAndPreview:function(f){var g=d("WAMediaManager").toWorkerSchedulerPriority(f.priority),h=b.get(f.fullSizePlaintextHash),i=a.get(f.fullSizePlaintextHash);if(h!=null&&i!=null){l(f.mediaDownloadFlow,"hit","fullsize-and-preview");h.task.promote(g);i.task.promote(g);return{fullsizeCacheResult:{cache:h.task.promise,type:"cache-hit"},previewCacheResult:{cache:i.task.promise,type:"cache-hit"}}}if(h!=null){l(f.mediaDownloadFlow,"hit","fullsize");h.task.promote(g);return{fullsizeCacheResult:{cache:h.task.promise,type:"cache-hit"},previewCacheResult:{setCache:e,type:"cache-miss"}}}if(i!=null){l(f.mediaDownloadFlow,"hit","preview");i.task.promote(g);return{fullsizeCacheResult:{setCache:c,type:"cache-miss"},previewCacheResult:{cache:i.task.promise,type:"cache-hit"}}}l(f.mediaDownloadFlow,"miss","fullsize-and-preview");return{fullsizeCacheResult:{setCache:c,type:"cache-miss"},previewCacheResult:{setCache:e,type:"cache-miss"}}},getPreview:function(b){var c=a.get(b.fullSizePlaintextHash);if(c!=null){l(b.mediaDownloadFlow,"hit","preview");c.task.promote(d("WAMediaManager").toWorkerSchedulerPriority(b.priority));return{cache:c.task.promise,type:"cache-hit"}}l(b.mediaDownloadFlow,"miss","preview");return{setCache:e,type:"cache-miss"}}}}function l(a,b,c){a.addAnnotations({string:{media_manager_cache_result:b,media_manager_cache_type:c}})}g.DOWNLOAD_TASK_CACHE_TTL_MS=k;g.createMediaDownloadCache=a}),98);
__d("MAWMediaManager",["MAWGetMostRescentDecodedMediaEntry","MAWGetProtocolMsgIdAndSortOrderMsApi","MAWUpdateMediaEntryForMsgApi","WAMediaManager"],(function(a,b,c,d,e,f,g){"use strict";a=d("WAMediaManager").createMediaManager({dbCallbacks:{getMediaEntries:d("MAWGetMostRescentDecodedMediaEntry").getMediaEntries,getProtocolMsgIdAndSortOrderMs:d("MAWGetProtocolMsgIdAndSortOrderMsApi").getProtocolMsgIdAndSortOrderMs,updateMediaEntryForMsg:d("MAWUpdateMediaEntryForMsgApi").updateMediaEntryForMsg}});g.mawMediaManager=a}),98);/*FB_PKG_DELIM*/
__d("EBCreateMinosWasmFunction",["WAErrorMessage","WAResultOrError","WASI","asyncToGeneratorRuntime","decodeProtobuf","encodeProtobuf"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["Unexpected runtime error: ",""]);h=function(){return a};return a}function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["invalid result type"]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["non-zero-exit-code: ",""]);j=function(){return a};return a}function k(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);k=function(){return a};return a}function l(){var a=babelHelpers.taggedTemplateLiteralLoose(["",""]);l=function(){return a};return a}var m="input",n="output",o="/"+m,p="/"+n;function q(a){var b=a.command,c=a.input,d=a.stderr;a=a.stdout;var e=new Date();return{args:["minos_cli",b,"-i="+m,"-o="+n],fs:(b={},b[o]={content:new Uint8Array(c),mode:"binary",path:o,timestamps:{access:e,change:e,modification:e}},b),stderr:d,stdout:a}}function a(a){var c=a.InputSpec,e=a.ResultSpec,f=a.command,g=a.getWasmModule,m=a.logger,n=a.validateResult,o=m.TAGS(["WasmFunc"]),r=function(a){o.ERROR(l(),a)},s=function(a){o.LOG(k(),a)};return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){try{a=d("encodeProtobuf").encodeProtobuf(c,a).readBuffer();a=d("WASI").createWasi(q({command:f,input:a,stderr:r,stdout:s}));var b=a.getImportObject;a=a.start;var k=(yield g());k=(yield WebAssembly.instantiate(k,b()));b=a(k);a=b.exitCode;k=b.fs;k=(b=k[p])==null?void 0:b.content;if(a!==0){o.ERROR(j(),a);return d("WAResultOrError").makeError("wasm-internal-non-zero-exit-code")}if(!(k instanceof Uint8Array)){o.ERROR(i());return d("WAResultOrError").makeError("wasm-internal-invalid-result-type")}b=d("decodeProtobuf").decodeProtobuf(e,k);return n(b)}catch(a){o.ERROR(h(),d("WAErrorMessage").maybeGetMessageFromError(a));return d("WAResultOrError").makeError("wasm-internal-runtime-error",a)}});function k(b){return a.apply(this,arguments)}return k}()}g.createMinosWasmFunction=a}),98);
__d("EBMinosLogger",["WATagsLogger"],(function(a,b,c,d,e,f,g){"use strict";a=d("WATagsLogger").TAGS(["minos"]);g.minosLogger=a}),98);
__d("EBMinosTypes",["WAJids"],(function(a,b,c,d,e,f,g){"use strict";function a(a){return a}function b(a){return a.endsWith(d("WAJids").MSGR_USER_DOMAIN)?a.slice(0,-d("WAJids").MSGR_USER_DOMAIN.length):null}function c(a){return a}function e(a){return a}function f(a){return a}function h(a){return a}function i(a){return a}function j(a){return a}function k(a){return a}function l(a){return a}function m(a){return a}function n(a){return a}function o(a){return a}function p(a){return a}function q(a){return a}function r(a){return a}function s(a){return a}function t(a){return a}g.unsafeCastToUserFbId=a;g.userJidToUserFbId=b;g.unsafeCastToEpochHead=c;g.unsafeCastToEpochSignature=e;g.unsafeCastToEpochNumber=f;g.unsafeCastToExportRootKey=h;g.unsafeCastToMekId=i;g.unsafeCastMekKey=j;g.unsafeCastMekRosterHash=k;g.unsafeCastToMekFbId=l;g.unsafeCastToMekMiThreadId=m;g.unsafeCastToMailboxFbId=n;g.unsafeCastToMailboxSigningPK=o;g.unsafeCastToMailboxSigningSK=p;g.unsafeCastToMailboxEncryptionPK=q;g.unsafeCastToMailboxEncryptionSK=r;g.unsafeCastToMailboxAuthPK=s;g.unsafeCastToMailboxAuthSK=t}),98);
__d("EBGetMinosWasm",["WAWasmModuleCache","bx"],(function(a,b,c,d,e,f,g){"use strict";var h=c("bx").getURL(c("bx")("31853"));a=function(){return d("WAWasmModuleCache").loadWasmModule(h)};g.getMinosWasm=a}),98);
__d("EBMinosWasm.pb",["WAProtoConst"],(function(a,b,c,d,e,f,g){a={};b={};c={};e={};f={};var h={},i={},j={},k={},l={},m={},n={},o={},p={},q={},r={},s={},t={},u={},v={};a.internalSpec={transportSigningSk:[1,(d=d("WAProtoConst")).FLAGS.REQUIRED|d.TYPES.BYTES],mek:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES],plaintext:[3,d.FLAGS.REQUIRED|d.TYPES.BYTES],metadata:[4,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,b]};b.internalSpec={mekId:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],timestamp:[2,d.FLAGS.REQUIRED|d.TYPES.UINT64],messageId:[3,d.FLAGS.REQUIRED|d.TYPES.STRING],threadId:[4,d.FLAGS.REQUIRED|d.TYPES.STRING],senderFbid:[5,d.FLAGS.REQUIRED|d.TYPES.STRING]};c.internalSpec={ciphertext:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],signature:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES]};e.internalSpec={key:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],mekId:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES],rosterHash:[3,d.FLAGS.REQUIRED|d.TYPES.BYTES]};f.internalSpec={epochHeads:[1,d.FLAGS.REPEATED|d.TYPES.BYTES]};h.internalSpec={mek:[1,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,e]};i.internalSpec={theirEpochId:[1,d.FLAGS.REQUIRED|d.TYPES.UINT64],toMailboxPk:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES],fromKeypair:[3,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,j],mek:[4,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,e]};j.internalSpec={sk:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],pk:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES]};k.internalSpec={ciphertext:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES]};l.internalSpec={exportRootKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],epochNumber:[2,d.FLAGS.REQUIRED|d.TYPES.UINT64]};m.internalSpec={mailboxSigningPublicKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],mailboxSigningPrivateKey:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES]};n.internalSpec={exportRootKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],epochNumber:[2,d.FLAGS.REQUIRED|d.TYPES.UINT64]};o.internalSpec={mailboxEncryptionPublicKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],mailboxEncryptionPrivateKey:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES]};p.internalSpec={exportRootKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],epochNumber:[2,d.FLAGS.REQUIRED|d.TYPES.UINT64]};q.internalSpec={mailboxAuthPublicKey:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],mailboxAuthPrivateKey:[2,d.FLAGS.REQUIRED|d.TYPES.BYTES]};r.internalSpec={publicData:[1,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,t],signingSecretKeys:[2,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,s]};s.internalSpec={mailboxSigningSk:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],previousMailboxSigningSk:[2,d.TYPES.BYTES]};t.internalSpec={epochNumber:[1,d.FLAGS.REQUIRED|d.TYPES.UINT64],userFbid:[2,d.FLAGS.REQUIRED|d.TYPES.UINT64],mailboxSigningPk:[3,d.FLAGS.REQUIRED|d.TYPES.BYTES],mailboxEncryptionPk:[4,d.FLAGS.REQUIRED|d.TYPES.BYTES],mailboxAuthPk:[5,d.FLAGS.REQUIRED|d.TYPES.BYTES],previousEpochHead:[6,d.TYPES.BYTES]};u.internalSpec={epochSignatures:[1,d.FLAGS.REQUIRED|d.TYPES.MESSAGE,v]};v.internalSpec={selfSignature:[1,d.FLAGS.REQUIRED|d.TYPES.BYTES],prevSignature:[2,d.TYPES.BYTES]};g.MinosEncryptAndSignMessageInputSpec=a;g.MinosEncryptAndSignMessageInput$MinosMessageMetadataSpec=b;g.MinosEncryptAndSignMessageResultSpec=c;g.MekSpec=e;g.GenerateMekInputSpec=f;g.GenerateMekResultSpec=h;g.EncryptMekForDistributionInputSpec=i;g.EncryptMekForDistributionInput$MailboxAuthKPSpec=j;g.EncryptMekForDistributionResultSpec=k;g.DeriveMailboxSigningKeypairInputSpec=l;g.DeriveMailboxSigningKeypairResultSpec=m;g.DeriveMailboxEncryptionKeypairInputSpec=n;g.DeriveMailboxEncryptionKeypairResultSpec=o;g.DeriveMailboxAuthKeypairInputSpec=p;g.DeriveMailboxAuthKeypairResultSpec=q;g.MinosOpenEpochInputSpec=r;g.MinosOpenEpochInput$EpochSigningSecretKeysSpec=s;g.MinosOpenEpochInput$EpochPublicDataSpec=t;g.MinosOpenEpochResultSpec=u;g.MinosOpenEpochResult$EpochSignaturesSpec=v}),98);
__d("EBMinosWasmDeriveMailboxAuthKeypair",["EBCreateMinosWasmFunction","EBGetMinosWasm","EBMinosLogger","EBMinosTypes","EBMinosWasm.pb","WAResultOrError","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function a(a){var c=a.getWasmModule;a=a.logger;var e=a.TAGS(["derive-mailbox-auth-key-pair"]);function f(a){var b=a.mailboxAuthPrivateKey;a=a.mailboxAuthPublicKey;return d("WAResultOrError").makeResult({pk:d("EBMinosTypes").unsafeCastToMailboxAuthPK(a),sk:d("EBMinosTypes").unsafeCastToMailboxAuthSK(b)})}return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.epochNumber;a=a.exportRootKey;var g=d("EBCreateMinosWasmFunction").createMinosWasmFunction({InputSpec:d("EBMinosWasm.pb").DeriveMailboxAuthKeypairInputSpec,ResultSpec:d("EBMinosWasm.pb").DeriveMailboxAuthKeypairResultSpec,command:"derive-mailbox-auth-key-pair",getWasmModule:c,logger:e,validateResult:f});g=(yield g({epochNumber:b,exportRootKey:a}));return g});function g(b){return a.apply(this,arguments)}return g}()}c=a({getWasmModule:d("EBGetMinosWasm").getMinosWasm,logger:d("EBMinosLogger").minosLogger});g.createMinosWasmDeriveMailboxAuthKeypair=a;g.deriveMailboxAuthKeypair=c}),98);
__d("EBMinosWasmDeriveMailboxEncryptionKeypair",["EBCreateMinosWasmFunction","EBGetMinosWasm","EBMinosLogger","EBMinosTypes","EBMinosWasm.pb","WAResultOrError","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function a(a){var c=a.getWasmModule;a=a.logger;var e=a.TAGS(["derive-mailbox-encryption-key-pair"]);function f(a){var b=a.mailboxEncryptionPrivateKey;a=a.mailboxEncryptionPublicKey;return d("WAResultOrError").makeResult({pk:d("EBMinosTypes").unsafeCastToMailboxEncryptionPK(a),sk:d("EBMinosTypes").unsafeCastToMailboxEncryptionSK(b)})}return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.epochNumber;a=a.exportRootKey;var g=d("EBCreateMinosWasmFunction").createMinosWasmFunction({InputSpec:d("EBMinosWasm.pb").DeriveMailboxEncryptionKeypairInputSpec,ResultSpec:d("EBMinosWasm.pb").DeriveMailboxEncryptionKeypairResultSpec,command:"derive-mailbox-encryption-key-pair",getWasmModule:c,logger:e,validateResult:f});g=(yield g({epochNumber:b,exportRootKey:a}));return g});function g(b){return a.apply(this,arguments)}return g}()}c=a({getWasmModule:d("EBGetMinosWasm").getMinosWasm,logger:d("EBMinosLogger").minosLogger});g.createMinosWasmDeriveMailboxEncryptionKeypair=a;g.deriveMailboxEncryptionKeypair=c}),98);
__d("EBMinosWasmDeriveMailboxSigningKeypair",["EBCreateMinosWasmFunction","EBGetMinosWasm","EBMinosLogger","EBMinosTypes","EBMinosWasm.pb","WAResultOrError","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";function a(a){var c=a.getWasmModule;a=a.logger;var e=a.TAGS(["derive-mailbox-signing-key-pair"]);function f(a){var b=a.mailboxSigningPrivateKey;a=a.mailboxSigningPublicKey;return d("WAResultOrError").makeResult({pk:d("EBMinosTypes").unsafeCastToMailboxSigningPK(a),sk:d("EBMinosTypes").unsafeCastToMailboxSigningSK(b)})}return function(){var a=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){var b=a.epochNumber;a=a.exportRootKey;var g=d("EBCreateMinosWasmFunction").createMinosWasmFunction({InputSpec:d("EBMinosWasm.pb").DeriveMailboxSigningKeypairInputSpec,ResultSpec:d("EBMinosWasm.pb").DeriveMailboxSigningKeypairResultSpec,command:"derive-mailbox-signing-key-pair",getWasmModule:c,logger:e,validateResult:f});g=(yield g({epochNumber:b,exportRootKey:a}));return g});function g(b){return a.apply(this,arguments)}return g}()}c=a({getWasmModule:d("EBGetMinosWasm").getMinosWasm,logger:d("EBMinosLogger").minosLogger});g.createMinosWasmDeriveMailboxSigningKeypair=a;g.deriveMailboxSigningKeypair=c}),98);
__d("EBSenderUploadQueue",["EBMinosLogger","PersistedQueueApi","Promise","WAPersistedQueue","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h;function i(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to write to ebSenderUploadQueue ",""]);i=function(){return a};return a}function j(){var a=babelHelpers.taggedTemplateLiteralLoose(["EB Upload Queue is already initialized"]);j=function(){return a};return a}c=function(a){return a};e=5;var k=null;function l(){return k==null?m():k}function m(){k!=null&&d("EBMinosLogger").minosLogger.ERROR(j());var a=d("WAPersistedQueue").initPersistedQueue("ebSenderUploadQueue",d("PersistedQueueApi").persistedQueueApi());k=a;return a}function a(a){return n.apply(this,arguments)}function n(){n=b("asyncToGeneratorRuntime").asyncToGenerator(function*(a){if(a.length===0)return(h||(h=b("Promise"))).resolve();try{var c=l();yield c.addAndCommit(a)}catch(a){d("EBMinosLogger").minosLogger.ERROR(i(),a);return(h||(h=b("Promise"))).reject(a)}});return n.apply(this,arguments)}g.toSendersQueueId=c;g.MAX_RETRY_COUNT=e;g.ebSenderUploadQueue=l;g.initEbSenderUploadQueue=m;g.enqueueMessages=a}),98);
__d("EBUploadSentMessageFakeData",["EBMinosLogger","EBMinosTypes","EBMinosWasmDeriveMailboxAuthKeypair","EBMinosWasmDeriveMailboxEncryptionKeypair","EBMinosWasmDeriveMailboxSigningKeypair","EBSenderUploadQueue","MpsTypes","WAStanzaUtils","asyncToGeneratorRuntime","err"],(function(a,b,c,d,e,f,g){"use strict";function h(){var a=babelHelpers.taggedTemplateLiteralLoose(["Failed to generate fake minos data: ",""]);h=function(){return a};return a}f=[new Uint8Array([1,2,3]).buffer,new Uint8Array([4,5,6]).buffer].map((e=d("EBMinosTypes")).unsafeCastToEpochHead);var i={actionType:1,originalMsgProtocolId:{externalId:d("WAStanzaUtils").toStanzaId("123")},supplementalKey:"456"},j=new TextEncoder().encode("This is a test message"),k=e.unsafeCastToExportRootKey(new TextEncoder().encode("fake_epoch_root_with_32_bytes_01").buffer),l=e.unsafeCastToExportRootKey(new TextEncoder().encode("fake_epoch_root_with_32_bytes_02").buffer),m=e.unsafeCastToEpochNumber(1),n=e.unsafeCastToEpochNumber(1),o=e.unsafeCastToEpochHead(new TextEncoder().encode("fake_epoch_head_with_32_bytes_01").buffer),p;function a(){if(p==null){var a=q()["catch"](function(a){d("EBMinosLogger").minosLogger.ERROR(h(),a);throw a});p=a;return p}return p}function q(){return r.apply(this,arguments)}function r(){r=b("asyncToGeneratorRuntime").asyncToGenerator(function*(){var a=(yield d("EBMinosWasmDeriveMailboxAuthKeypair").deriveMailboxAuthKeypair({epochNumber:m,exportRootKey:k}));if(!a.success)throw c("err")("Failed to generate mailbox signing key pair");var b=(yield d("EBMinosWasmDeriveMailboxSigningKeypair").deriveMailboxSigningKeypair({epochNumber:m,exportRootKey:k}));if(!b.success)throw c("err")("Failed to generate mailbox signing key pair");var e=(yield d("EBMinosWasmDeriveMailboxEncryptionKeypair").deriveMailboxEncryptionKeypair({epochNumber:m,exportRootKey:k}));if(!e.success)throw c("err")("Failed to generate mailbox signing key pair");e=(yield d("EBMinosWasmDeriveMailboxEncryptionKeypair").deriveMailboxEncryptionKeypair({epochNumber:n,exportRootKey:l}));if(!e.success)throw c("err")("Failed to generate mailbox signing key pair");return{fakeMessage:j,recipientEncryptionKeyPair:e.value,recipientEpochHead:o,recipientEpochNumber:n,recipientMailboxKeyFbId:d("EBMinosTypes").unsafeCastToMailboxFbId(123),recipientUserFbId:d("EBMinosTypes").unsafeCastToUserFbId("123456"),senderAuthKeypair:a.value,senderEpochNumber:m,senderSigningKeypair:b.value}});return r.apply(this,arguments)}e={directive:i,epochHeads:[o],messageId:d("MpsTypes").toMessageId("143222"),payload:new Uint8Array(0).buffer,queueId:d("EBSenderUploadQueue").toSendersQueueId(123),retryCount:0,senderId:"59668010114073@msgr",tags:[],threadId:d("MpsTypes").toThreadId("59668010114073@msgr"),timestampMs:41};g.FAKE_EPOCH_HEADS=f;g.getFakeMinosData=a;g.FAKE_UPLOAD_ENTITY=e}),98);
__d("EBGetContactMailboxPublicKeys",["EBUploadSentMessageFakeData","Promise","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h;function a(){return i.apply(this,arguments)}function i(){i=b("asyncToGeneratorRuntime").asyncToGenerator(function*(){var a=(yield d("EBUploadSentMessageFakeData").getFakeMinosData());return(h||(h=b("Promise"))).resolve([a.recipientEpochHead])});return i.apply(this,arguments)}g.getContactMailboxPublicKeys=a}),98);
__d("EBGetCurrentMailboxPublicKeys",["EBUploadSentMessageFakeData","Promise","asyncToGeneratorRuntime"],(function(a,b,c,d,e,f,g){"use strict";var h;function a(){return i.apply(this,arguments)}function i(){i=b("asyncToGeneratorRuntime").asyncToGenerator(function*(){var a=(yield d("EBUploadSentMessageFakeData").getFakeMinosData());return(h||(h=b("Promise"))).resolve([a.recipientEpochHead])});return i.apply(this,arguments)}g.getCurrentMailboxPublicKeys=a}),98);
__d("LSOptOutOfBackup",["LSAppendDataTraceAddon","LSIsMobileClient","LSIssueNewEbTaskAndGetTaskIDV2","LSLogMebClientEvent.nop","gkx","justknobx"],(function(a,b,c,d,e,f,g){function a(){var a=arguments,d=a[a.length-1],e=[],f=[];return d.sequence([function(g){return d.sequence([function(f){return e[0]=d.i64.of_float(Date.now()),function(a){d.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsOptOutOfBackupStoredProcedure] Beginning execution."),(c("gkx")("23657")||c("gkx")("26375"))&&c("justknobx")._("1099")?d.sequence([function(a){return d.sequence([function(a){return void 0!==void 0?d.storedProcedure(b("LSAppendDataTraceAddon"),void 0,d.i64.cast([0,1469]),d.i64.cast([0,2]),void 0,void 0):d.resolve()},function(a){return d.storedProcedure(b("LSIsMobileClient")).then(function(a){return a=a,e[11]=a[0],a})},function(a){return e[11]?e[12]=!0:e[12]=!1,e[12]&&!0?(function(a){d.logger(a).mustfix(a)}("[EncryptedBackups][MEBTraceUtils] LSDataTraceMciTraceLog native op not supported"),e[14]="LSDataTraceMciTraceLog native op not supported",function(a){d.logger(a).mustfix(a)}(["[EncryptedBackups][MEBTraceUtils] ","",e[14]].join("")),e[13]=d.createArray(),void 0!==void 0?e[15]=(e[13].push(void 0),e[13]):0,d.nativeOperation(b("LSLogMebClientEvent.nop"),"MEBTraceUtils",e[14],e[13],d.i64.cast([0,3]))):d.resolve()}])},function(c){return e[8]=new d.Map(),e[8].set("backup_id",a[0]),e[8].set("trace_id",void 0),e[9]=d.toJSON(e[8]),d.storedProcedure(b("LSIssueNewEbTaskAndGetTaskIDV2"),"encrypted_backups_opt_out",d.i64.cast([0,50019]),e[9],d.i64.cast([0,0]),d.i64.cast([0,93]),d.i64.cast([0,0]),void 0,d.i64.cast([0,0])).then(function(a){return a=a,e[10]=a[0],a})},function(a){return e[1]=d.i64.cast([0,0])}]):d.resolve((function(a){d.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsOptOutOfBackupStoredProcedure] backup opt out flow is not enabled"),e[1]=d.i64.cast([0,1])))},function(a){return e[2]=d.i64.of_float(Date.now()),e[3]=d.i64.random(),e[5]="Finishing execution. Execution time: ",e[6]=d.i64.to_string(d.i64.sub(e[2],e[0])),e[7]=" ms",e[4]="",function(a){d.logger(a).info(a)}(["[EncryptedBackups][LSEncryptedBackupsOptOutOfBackupStoredProcedure] ",e[4],e[5],e[4],e[6],e[4],e[7]].join("")),d.i64.eq(d.i64.mod_(e[3],d.i64.cast([0,1e3])),d.i64.cast([0,0]))?(e[8]=",",e[9]=d.createArray(),void 0!==void 0?e[10]=(e[9].push(void 0),e[9]):0,d.nativeOperation(b("LSLogMebClientEvent.nop"),"LSEncryptedBackupsOptOutOfBackupStoredProcedure",[e[5],e[8],e[6],e[8],e[7]].join(""),e[9],d.i64.cast([0,4]))):d.resolve()},function(a){return f[0]=e[1]}])},function(a){return d.resolve(f)}])}a.__sproc_name__="LSEncryptedBackupsOptOutOfBackupStoredProcedure";a.__tables__=[];d=a;g["default"]=d}),98);
__d("LSOptOutOfBackupStoredProcedure",["LSOptOutOfBackup","LSSynchronousPromise","Promise","cr:8709"],(function(a,b,c,d,e,f,g){var h;function a(a,e){a=a.storedProcedure(c("LSOptOutOfBackup"),e.backupId);return(h||(h=b("Promise"))).resolve(d("LSSynchronousPromise").maybeExtractValueIfSynchronousPromise(a))}g["default"]=a}),98);
__d("encryptedBackupsOptOutOfBackup",["LSEncryptedBackupsOpStatus","LSFactory","LSIntEnum","LSOptOutOfBackupStoredProcedure","LSResult","ReQL"],(function(a,b,c,d,e,f,g){"use strict";var h;function a(a){return d("ReQL").firstAsync(d("ReQL").fromTableAscending(a.tables.encrypted_backups)).then(function(b){if(b==null)return c("LSResult")((h||(h=d("LSIntEnum"))).ofNumber(c("LSEncryptedBackupsOpStatus").FAILURE));var e=b.backupId;return e!=null?a.runInTransaction(function(a){return c("LSOptOutOfBackupStoredProcedure")(c("LSFactory")(a),{backupId:e})},"readwrite",void 0,void 0,f.id+":31"):c("LSResult")((h||(h=d("LSIntEnum"))).ofNumber(c("LSEncryptedBackupsOpStatus").FAILURE))}).then(function(){return d("ReQL").toArrayAsync(d("ReQL").fromTableAscending(a.tables.secure_encrypted_backups_client_state).take(1))})}g.optOutOfBackupStoredProcedure=a}),98);/*FB_PKG_DELIM*/
__d("LSRecordEpochSyncStatus",["LSArrayGetObjectAt","LSBase64Encode.nop","LSIssueNewEbTaskAndGetTaskIDV2"],(function(a,b,c,d,e,f){function a(){var a=arguments,c=a[a.length-1],d=[],e=[];return c.sequence([function(e){return a[7]?c.sequence([function(e){return function(a){c.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsRecordEpochSyncStatusStoredProcedure] Issue record epoch sync task"),d[0]=c.createArray(),d[1]=c.i64.of_int32(a[6].length),c.i64.gt(d[1],c.i64.cast([0,0]))?c.loopAsync(d[1],function(e){return d[5]=e,c.sequence([function(e){return c.nativeTypeOperation("Array",b("LSArrayGetObjectAt"),a[6],d[5]).then(function(a){return a=a,d[6]=a[0],d[7]=a[1],a})},function(a){return d[8]=d[6].get("from"),d[9]=d[6].get("to"),d[10]=d[8].get("epoch_anon_id"),c.nativeOperation(b("LSBase64Encode.nop"),d[10]).then(function(a){return a=a,d[11]=a[0],a})},function(a){return d[11]!==void 0?d[12]=d[11]:d[12]="",d[13]=d[8].get("epoch_id"),d[14]=new c.Map(),d[14].set("anon_id",d[12]),d[14].set("epoch_id",d[13]),d[15]=d[9].get("epoch_anon_id"),c.nativeOperation(b("LSBase64Encode.nop"),d[15]).then(function(a){return a=a,d[16]=a[0],a})},function(a){return d[16]!==void 0?d[17]=d[16]:d[17]="",d[18]=d[9].get("epoch_id"),d[19]=new c.Map(),d[19].set("anon_id",d[17]),d[19].set("epoch_id",d[18]),d[20]=d[6].get("has_forward_edge"),d[21]=d[6].get("has_backward_edge"),d[22]=d[6].get("result_code"),d[23]=d[6].get("error_message"),d[24]=new c.Map(),d[24].set("from",d[14]),d[24].set("to",d[19]),d[24].set("has_forward_edge",d[20]),d[24].set("has_backward_edge",d[21]),d[24].set("result_code",d[22]),d[24].set("error_message",d[23]),d[25]=(d[0].push(d[24]),d[0])}])}):c.resolve()},function(e){return d[2]=new c.Map(),d[2].set("local_device_id",a[0]),d[2].set("decryption_device_id",a[1]),d[2].set("target_device_id",a[2]),d[2].set("epoch_sync_reason",a[3]),d[2].set("start_ms",a[4]),d[2].set("end_ms",a[5]),d[2].set("results",d[0]),d[3]=c.toJSON(d[2]),c.storedProcedure(b("LSIssueNewEbTaskAndGetTaskIDV2"),"meb_record_epoch_sync",c.i64.cast([0,50039]),d[3],c.i64.cast([0,0]),c.i64.cast([0,93]),c.i64.cast([0,0]),void 0,c.i64.cast([0,0])).then(function(a){return a=a,d[4]=a[0],a})}]):c.sequence([function(e){return function(a){c.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsRecordEpochSyncStatusStoredProcedure] Issue record epoch sync task"),d[0]=c.createArray(),d[1]=c.i64.of_int32(a[6].length),c.i64.gt(d[1],c.i64.cast([0,0]))?c.loopAsync(d[1],function(e){return d[5]=e,c.sequence([function(e){return c.nativeTypeOperation("Array",b("LSArrayGetObjectAt"),a[6],d[5]).then(function(a){return a=a,d[6]=a[0],d[7]=a[1],a})},function(a){return d[8]=d[6].get("from"),d[9]=d[6].get("to"),d[10]=d[8].get("epoch_anon_id"),c.nativeOperation(b("LSBase64Encode.nop"),d[10]).then(function(a){return a=a,d[11]=a[0],a})},function(a){return d[11]!==void 0?d[12]=d[11]:d[12]="",d[13]=d[8].get("epoch_id"),d[14]=new c.Map(),d[14].set("anon_id",d[12]),d[14].set("epoch_id",d[13]),d[15]=d[9].get("epoch_anon_id"),c.nativeOperation(b("LSBase64Encode.nop"),d[15]).then(function(a){return a=a,d[16]=a[0],a})},function(a){return d[16]!==void 0?d[17]=d[16]:d[17]="",d[18]=d[9].get("epoch_id"),d[19]=new c.Map(),d[19].set("anon_id",d[17]),d[19].set("epoch_id",d[18]),d[20]=d[6].get("has_forward_edge"),d[21]=d[6].get("has_backward_edge"),d[22]=d[6].get("result_code"),d[23]=d[6].get("error_message"),d[24]=new c.Map(),d[24].set("from",d[14]),d[24].set("to",d[19]),d[24].set("has_forward_edge",d[20]),d[24].set("has_backward_edge",d[21]),d[24].set("result_code",d[22]),d[24].set("error_message",d[23]),d[25]=(d[0].push(d[24]),d[0])}])}):c.resolve()},function(e){return d[2]=new c.Map(),d[2].set("local_device_id",a[0]),d[2].set("decryption_device_id",a[1]),d[2].set("target_device_id",a[2]),d[2].set("epoch_sync_reason",a[3]),d[2].set("start_ms",a[4]),d[2].set("end_ms",a[5]),d[2].set("results",d[0]),d[3]=c.toJSON(d[2]),c.storedProcedure(b("LSIssueNewEbTaskAndGetTaskIDV2"),"meb_record_epoch_sync",c.i64.cast([0,50039]),d[3],c.i64.cast([0,0]),c.i64.cast([0,93]),c.i64.cast([0,0]),void 0,c.i64.cast([0,0])).then(function(a){return a=a,d[4]=a[0],a})}])},function(a){return c.resolve(e)}])}a.__sproc_name__="LSEncryptedBackupsRecordEpochSyncStatusStoredProcedure";a.__tables__=[];e.exports=a}),null);
__d("LSStoreEpoch",["LSLogMebClientEvent.nop"],(function(a,b,c,d,e,f){function a(){var a=arguments,b=a[a.length-1],c=[],d=[];return b.sequence([function(d){return b.sequence([function(d){return c[1]="Storing newly derived epoch ",c[2]=b.blobs.to_string(a[2]),c[3]=" authority_level:",c[4]=b.i64.to_string(a[5]),c[5]=" status:",c[6]=b.i64.to_string(a[4]),c[0]="",function(a){b.logger(a).info(a)}(["[EncryptedBackups][LSEncryptedBackupsStoreEpochStoredProcedure] ",c[0],c[1],c[0],c[2],c[0],c[3],c[0],c[4],c[0],c[5],c[0],c[6]].join("")),b.resolve()},function(c){return a[6]?(function(a){b.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsStoreEpochStoredProcedure] Storing epoch in epochs table (regular execution)"),b.filter(b.db.table(169).fetch([[[a[0]]]]),function(c){return b.i64.eq(c.epochId,a[0])&&b.i64.gt(c.authorityLevel,a[5])}).next().then(function(c){var d=c.done;c.value;return d?b.db.table(169).put({epochId:a[0],backupId:a[1],epochAnonIdBlob:a[2],epochRootKeyBlob:a[3],epochStatus:a[4],authorityLevel:a[5]}):0})):(function(a){b.logger(a).info(a)}("[EncryptedBackups][LSEncryptedBackupsStoreEpochStoredProcedure] Storing epoch in epochs table (regular execution)"),b.filter(b.db.table(169).fetch([[[a[0]]]]),function(c){return b.i64.eq(c.epochId,a[0])&&b.i64.gt(c.authorityLevel,a[5])}).next().then(function(c){var d=c.done;c.value;return d?b.db.table(169).put({epochId:a[0],backupId:a[1],epochAnonIdBlob:a[2],epochRootKeyBlob:a[3],epochStatus:a[4],authorityLevel:a[5]}):0}))}])},function(a){return b.resolve(d)}])}a.__sproc_name__="LSEncryptedBackupsStoreEpochStoredProcedure";a.__tables__=["secure_encrypted_backups_epochs"];e.exports=a}),null);