PageSourceSearch

https://herohero.co/assets/BR_TLySk2.js

js herohero.co collected 2026-09-24 15:25:56 UTC 30,943 bytes, 1 lines download raw bytes

1(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`e2bba6101073785c6480ffad8979069e6f932abc`};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`a2006b2d-628e-4125-82ce-a543d2db5d63`,e._sentryDebugIdIdentifier=`sentry-dbid-a2006b2d-628e-4125-82ce-a543d2db5d63`)}catch{}})();import{I as e}from"./CphnXYkl.js";import{A as t,E as n,It as r,Kt as i,On as a,_r as o,h as s,jt as c,vr as l}from"./CvLieaVj.js";import{a as u,i as d,o as f,r as p}from"./DUYMFgW_.js";import{t as m}from"./DG7IBbBu.js";import{t as h}from"./DJQG3LFj2.js";import{t as g}from"./Dq84OlDj.js";import{t as _}from"./dVBb10RD2.js";function v(e){return e==null?0:e.size}async function y(e,t,n,r){let i=(t-1)*n,a=Math.min(i+n,r);return e.slice(i,a)}var b=1024*1024,x=4*1024*1024,S=3*b,C=`v2`;async function w(e,t){let n=await _();if(n.init(),n.update(`${C}:${t??``}:${e.size}:`),e.size<=S)await T(n,e,0,e.size);else{let t=Math.floor((e.size-b)/2);await T(n,e,0,b),await T(n,e,t,t+b),await T(n,e,e.size-b,e.size)}return n.digest()}async function T(e,t,n,r){for(let i=n;i<r;i+=x){let n=await t.slice(i,Math.min(r,i+x)).arrayBuffer();e.update(new Uint8Array(n))}}function E({defaultQueueSize:t}){let n=t,r=navigator.connection;if(r&&!r.saveData&&!e()&&r.effectiveType===`4g`){let e=Number.isFinite(navigator.deviceMemory)?navigator.deviceMemory:void 0;(r.downlink??0)>5&&(e===8||e===void 0)&&(n=Math.max(n,5))}let i=navigator.hardwareConcurrency??4;return n=i<=2?Math.min(n,2):i===4?Math.min(Math.max(n,3),4):Math.min(Math.max(n,4),5),n}var UploadAbortError=class extends l{static make(e){return e instanceof Error||(e=Error(e)),new this(`Upload aborted`,{cause:e})}},TooManyPartsError=class extends l{maxParts=-1;uploadedPartsCount=-1;static make(e){let t=new this(`Too many parts uploaded`);return t.maxParts=e.maxParts,t.uploadedPartsCount=e.uploadedPartsCount,t}},NoPresignedUrlFoundError=class extends l{presignedUrlsForPartNumbers={};partNumber=-1;static make(e,t){let n=new this(`No presigned url found`);return n.presignedUrlsForPartNumbers=e,n.partNumber=t,n}},MissingETagError=class extends l{partNumber=-1;static make(e){let t=new this(`Missing ETag in UploadPart response`);return t.partNumber=e,t}},MultiPartCompleteError=class extends l{parts=[];key=``;static make(e=[],t,n){let r=new this(this.name,{cause:n});return r.parts=e,r.key=t,r}},PartUploadFailedError=class extends l{static make(e){let t=new this(this.name);for(let n in e)t[n]=e[n];return t}},MultipartUploadError=class extends l{failedParts=[];static make(e,t,n){let r=new this(e,{cause:t});return r.failedParts=n,r}},PresignedUrlExpiredError=class extends l{response;static make(e,t){let n=new this(`Presigned url expired: ${e}`);return n.response=t,n}static wrap(e){return new this(`Presigned URL expired`,{cause:e})}},ChunkUploadNetworkError=class extends l{partNumber;status;static make(e,t,n){let r=new this(e);return r.partNumber=t,r.status=n,r}},ChunkUploadTimeoutError=class extends l{partNumber;timeout;static make(e,t,n){let r=new this(e);return r.partNumber=t,r.timeout=n,r}},RateLimitError=class extends l{static make(e){return new this(`Upload rate limit exceeded`,{cause:e})}},UploadTimeEstimator=class{startTime=Date.now();#e=[];estimateTimeLeft(e,t){let n=(Date.now()-this.startTime)/1e3,r=t-e,i=e/n;if(this.#e.push(i),this.#e.length<10)return 0;this.#e.length>10&&this.#e.shift();let a=this.#e.reduce((e,t,n)=>e+(n+1),0);return r/(this.#e.reduce((e,t,n)=>e+t*(n+1),0)/a)}},D=50*1024*1024,O=5*1024*1024*1024,k=1800*1e3,A=new Set([400,401,403,404]),j=500,M=5e3,N=3e4,P=2e3,F=3e4,GjirafaUpload=class{#e=1e4;#t=D;#n;#r;#i=4;#a;#o;#s=[];#c;#l;#u;#d;#f=[];#p;#m;#h=!0;#g;#_=!1;#v=!1;#y=null;#b=null;#x;#S;#C=new UploadTimeEstimator;#w;#T=null;#E=100;#D=`IDLE`;get state(){return this.#D}#O=f();#k(e,t){this.#O.emit(e,t)}on(e,t){this.#O.on(e,t)}off(e,t){this.#O.off(e,t)}#A(e){this.#D!==e&&(this.#w.info(`Multipart upload: state change from ${this.#D} to ${e}`),this.#D=e,this.#k(`statechange`,{state:e}))}constructor(e){this.#w=e.logger,this.#x=new Map,this.#S=new Map,this.#r=e.params,this.#n=e.client,this.#t=e.partSize??D,this.#p=e.requestKey,this.#y=e.uploadFileDetailsId,this.#b=e.userId??null,this.#f=Array.isArray(e.uploadedParts)?m(e.uploadedParts):[],this.#m=e.presignedUrls?m(e.presignedUrls):{},this.#c=e.bytesUploadedSoFar??0,this.#a=v(this.#r.body),this.#o=Math.max(1,Math.ceil((this.#a??this.#t)/this.#t)),this.#h=this.#o>
11,this.#M(),this.#l=e.abortController??new AbortController,this.#De(),this.#Oe()}#j(){let e=this.#c;for(let t of this.#f)e+=t.size;for(let t of this.#x.values())e+=t;return e}#M(){this.#i=E({defaultQueueSize:this.#i}),this.#w.info(`Using config { queueSize: ${this.#i}, partSize: ${this.#t}, totalBytes: ${this.#a}, bytesUploadedSoFar: ${this.#c}, totalParts: ${this.#o}, requestKey: ${this.#p} }`)}async#N(e,n=N){this.#w.log(`${e}: start waiting for connectivity`,{requestKey:this.#p,timeoutMs:n});let r=Date.now(),i=await t({timeout:n}),a=Date.now()-r;return this.#w.log(`${e}: stopped waiting for connectivity after ${a}ms`,{requestKey:this.#p,timeoutMs:n,elapsedMs:a}),i||this.#w.warn(`${e}: still no connectivity after waiting ${a}ms`),i}async#P(e,t,{timeoutMs:n=N}={}){let r=0;for(;;){r++,await this.#N(e,n);try{return await t()}catch(t){if(this.#l.signal.aborted)throw UploadAbortError.make(this.#l.signal.reason);if(!this.#F(t))throw t;let n=Math.min(F,P*2**(r-1));this.#w.warn(`${e}: network error on attempt ${r}, retrying in ${n}ms`,{attempt:r,backoff:n,requestKey:this.#p,error:t}),await a(n)}}}#F(e){if(!e)return!1;if(e instanceof ChunkUploadNetworkError||e instanceof ChunkUploadTimeoutError)return!0;if(e instanceof o)return e.status===0||e.allowRetry;if(e instanceof TypeError){let t=String(e.message||``).toLowerCase();return t.includes(`network`)||t.includes(`fetch`)}let t=e?.cause;return t?this.#F(t):!1}async#I(){return this.#d||=w(this.#r.body,this.#b),this.#d}async done(){return new Promise((e,t)=>{let n=()=>{this.#Me().finally(()=>{t(UploadAbortError.make(this.#l.signal.reason))})};if(this.#l.signal.aborted){n();return}this.#l.signal.addEventListener(`abort`,n,{once:!0}),this.#R().then(e).catch(t).finally(()=>{this.#l.signal.removeEventListener(`abort`,n)})})}#L(){this.#A(`IDLE`),this.#p=null,this.#m={},this.#s=[],this.#f=[],this.#c=0,this.#y=null,this.#T&&=(clearTimeout(this.#T),null),this.#u=void 0,this.#d=void 0,this.#_=!1,this.#v=!1,this.#C=new UploadTimeEstimator}async#R(e=0){try{if(this.#A(`RECONCILING`),this.#w.info(`Multipart upload cycle started`,{tryCount:e,requestKey:this.#p}),await this.#H(),this.#A(`UPLOADING`),await this.#q(),this.#_)return this.#w.info(`Skipping finalize - file already in encode queue`),{url:this.#p,isMultiPart:!0,uploadedParts:[]};this.#A(`VERIFYING`),this.#w.info(`Multipart upload chunks completed, proceeding to finalize`,{tryCount:e,uploadedPartsCount:this.#f.length});let t=await this.#J();return this.#w.info(`Finalize upload completed`,{tryCount:e,uploadedPartsCount:this.#f.length,isMultiPart:this.#h}),t}catch(t){if(this.#z(t)&&e<3)return await this.#V(e,t);if(t instanceof UploadAbortError||t instanceof MultiPartCompleteError)throw this.#w.error(t,{failedParts:this.#s}),t;let n=MultipartUploadError.make(t?.message??`Multipart upload failed`,t,this.#s);throw this.#w.fatal(n,{error:t,failedParts:this.#s}),n}}#z(e){return e instanceof PresignedUrlExpiredError||e instanceof NoPresignedUrlFoundError||e instanceof o&&(e.status===404||e.status===0)}#B(e){if(!(e instanceof o)||e.status!==400)return!1;let t=e.json?.errors?.[0]??e.message??``;return t.toLowerCase().includes(`all parts of multipart upload`)&&t.toLowerCase().includes(`already uploaded`)}async#V(e,t){return this.#w.warn(`Resettable multipart error, resetting upload state and retrying...`,{tryCount:e,error:t}),await this.#Me(),this.#L(),await this.#R(e+1)}async#H(){if(!this.#p||!this.#h)return;let e=m(this.#f),t=await this.#Se(this.#p);if(Array.isArray(t)){let n=this.#de(t);n.length>0&&this.#w.info(`Reconcile: found differences with server parts`,{requestKey:this.#p,totalParts:this.#o,localPartNumbers:e.map(e=>e.partNumber),serverPartNumbers:t.map(e=>e.partNumber),missingOrDifferentParts:n.map(e=>e.partNumber)})}Array.isArray(t)&&t.length>0&&(this.#f=t.map(e=>({eTag:e.eTag,partNumber:e.partNumber,size:e.size,url:this.#m[e.partNumber]??``}))),this.#c=0;let n=new Set(this.#f.map(e=>e.partNumber)),r=[];for(let e=1;e<=this.#o;e++)!n.has(e)&&!this.#m[e]&&r.push(e);if(r.length>0)throw this.#w.warn(`Missing presigned URLs for ${r.length} parts, restarting upload`,{missingUrlForPart:r,requestKey:this.#p}),PresignedUrlExpiredError.make(`Missing presigned URLs during resume`);this.#f.length===this.#o&&(this.#v=!0,this.#w.info(`All parts reconciled from server, will skip verification`,{uploadedPartsCount:this.#f.length,requestKey:this.#p}))}async*#U(){let e=this.#a??0,t=this.#t,n=this.#o,r=this.#r.body;for(let i=0,a=0;a<e;i++,a+=t){let o=Math.min(e,a+t);yield{getData:()=>{let e=a;return r.slice(e,o)},partNumber:i+1,lastPart:i===n-1}}}async#W(){let e=await this.#U().next();if(e.done)throw this.#w.error(`Chunk provider yielded no data — file appears to be 0 bytes`),MultipartUploadError.make(`Cannot upload: file has no content (0 bytes)`,void 0,[]);await this.#we(e.value)}#G(e){switch(e){case`already_uploaded`:return this.#_=!0,this.#w.info(`Skipping upload - file already in encode queue`),!0;case`skip_to_complete`:return!0;case`resume`:case`fresh`:return!1}}async#K(e){let t={fatalError:null};
1for await(let n of this.#U()){if(this.#l.signal.aborted||t.fatalError)break;if(this.#f.length>this.#e)throw TooManyPartsError.make({maxParts:this.#e,uploadedPartsCount:this.#f.length});if(this.#f.find(e=>e.eTag&&e.partNumber===n.partNumber)){this.#w.info(`Part ${n.partNumber} already uploaded`);continue}if(!this.#m[n.partNumber]){this.#w.info(`Part ${n.partNumber} already uploaded (no presigned URL)`);continue}e.add(async()=>{try{let e=this.#_e(n.partNumber);await this.#ue({partNumber:n.partNumber,getData:n.getData,uploadUrl:e})}catch(n){throw n instanceof PresignedUrlExpiredError&&(t.fatalError=n,e.clear()),n}})}return t}async#q(){this.#C.startTime=Date.now();let e=Date.now(),t=await this.#I();if(this.#w.addProperties({fileHash:t}),!this.#h){await this.#W();return}let n=await this.#ve();if(this.#l.signal.aborted)throw UploadAbortError.make(this.#l.signal.reason);if(this.#G(n.status))return;let r=new u({concurrency:this.#i}),i=await this.#K(r);if(await r.onIdle(),this.#l.signal.aborted)throw UploadAbortError.make(this.#l.signal.reason);if(i.fatalError)throw i.fatalError;this.#s.length>0&&await this.#ge();let a=(Date.now()-e)/1e3;this.#w.info(`uploadAllChunks completed. Took: ${a}s`,{totalParts:this.#o,failedParts:this.#s,uploadedParts:this.#f})}async#J(){if(await this.#N(`finalize upload pre-check`),this.#l.signal.aborted)throw UploadAbortError.make(this.#l.signal.reason);if(this.#h)return await this.#Y();{let e=this.#f[0]?.url;if(!e)throw this.#w.error(`Single part upload finished but URL is missing.`),Error(`Internal upload error: Final URL missing after successful single part upload.`);return{url:e,isMultiPart:!1,uploadedParts:m(this.#f)}}}async#Y(){let e=Date.now();if(this.#w.info(`Initiating multipart complete`,{requestKey:this.#p,uploadedPartsCount:this.#f.length}),await this.#Z(),this.#s.length>0)throw MultipartUploadError.make(`Some parts failed to upload`,void 0,this.#s);this.#f=this.#f.filter((e,t,n)=>t===n.findIndex(t=>t.partNumber===e.partNumber));let t=await this.#te({parts:this.#f,requestKey:this.#p}),n=(Date.now()-e)/1e3;if(this.#w.info(`Multipart complete finished`,{durationSeconds:n,result:t}),!this.#p)throw this.#w.error(`requestKey missing after successful multipart completion`),Error(`Internal upload error: requestKey missing after successful multipart completion.`);let r=this.#p;return this.#ne({loaded:this.#a??0,total:this.#a??0,partNumber:this.#o,uploadId:this.#p}),this.#X({url:r,result:t}),{url:r,isMultiPart:!0,uploadedParts:m(this.#f)}}#X({url:e,result:t}){this.#T&&=(clearTimeout(this.#T),null),this.#k(`complete`,{url:e,result:t,isMultiPart:this.#h})}#Z(){return this.#v?(this.#w.info(`Skipping verification - parts already reconciled from server`,{uploadedPartsCount:this.#f.length,requestKey:this.#p}),Promise.resolve()):i(async()=>{let e=await this.#Se(this.#p);if(this.#f.length===0){if(e.length===0)throw Error(`Server returned no parts for skip_to_complete flow - upload may have expired`);this.#w.info(`No local parts found, populating from server for complete call`,{uploadedPartsOnServerCount:e.length,requestKey:this.#p}),this.#f=e.map(e=>({eTag:e.eTag,partNumber:e.partNumber,size:e.size,url:``}));return}await this.#Q(e)},{onError:e=>{this.#w.error(new l(`Failed to verify uploaded parts against server`,{cause:e}),{requestKey:this.#p,totalParts:this.#o,fileSize:this.#a,error:e})}})}async#Q(e){let t=this.#de(e);t.length>0&&(this.#w.error(`Found ${t.length} missing or different parts on the server`,{missingOrDifferentParts:t.map(e=>e.partNumber),requestKey:this.#p,totalParts:this.#o,fileSize:this.#a,failedParts:this.#s}),this.#$(t),await this.#ge())}#$(e){for(let t of e){let e=this.#s.findIndex(e=>e.partNumber===t.partNumber);e===-1?this.#s.push(t):this.#s[e]?Object.assign(this.#s[e],t):(this.#w.error(`Inconsistent state in #failedParts for partNumber ${t.partNumber}`),this.#s.push(t))}}#ee(e){let t=this.#s.findIndex(t=>t.partNumber===e);t!==-1&&this.#s.splice(t,1)}async#te(e){try{for(let t of e.parts)t.eTag||this.#$([t]);if(this.#s.length>0)throw this.#w.error(`We still have invalid parts after retrying`,{parts:this.#s,requestKey:e.requestKey,totalParts:this.#o,fileSize:this.#a}),MultiPartCompleteError.make(this.#s,e.requestKey);let t=e.parts.slice().sort((e,t)=>
1e.partNumber-t.partNumber);return!!await this.#P(`multipart complete`,async()=>{let n=await r.gjirafaMultipartAssetsComplete(this.#l.signal,{parts:t,requestKey:e.requestKey});if(!n)throw o.withData({status:0,allowRetry:!0,message:`Multipart complete request returned no response`});return n})}catch(t){throw this.#w.error(t),t instanceof MultiPartCompleteError?t:MultiPartCompleteError.make(e.parts,e.requestKey,t instanceof Error?t:Error(String(t)))}}#ne(e){let t=e.loaded,n=this.#a??0,r=0;n>0?r=Math.round(t/n*100):t===0&&n===0&&(r=100),r>=100&&n>0&&this.#f.reduce((e,t)=>e+t.size,0)<n&&(r=99),r=Math.max(0,Math.min(r,100));let i={progress:r,timeLeft:this.#C.estimateTimeLeft(t,n),isMultiPart:this.#h,uploadId:e.uploadId??this.#p,bytesLoaded:t,bytesTotal:n,partsUploaded:this.#f.length,partsInProgress:this.#x.size,totalParts:this.#o,triggeringPartNumber:e.partNumber};this.#T&&clearTimeout(this.#T),r===100||r===0?(this.#k(`progress`,i),this.#T=null):this.#T=setTimeout(()=>{this.#k(`progress`,i),this.#T=null},this.#E)}async#re(e,t=3){for(;;)try{return await d(async()=>{if(this.#l.signal.aborted)throw new p(UploadAbortError.make(this.#l.signal.reason));return await this.#ie(e)},{retries:t,randomize:!0,minTimeout:j,maxTimeout:M,shouldRetry:({error:e})=>!(e instanceof PresignedUrlExpiredError||e instanceof UploadAbortError),onFailedAttempt:({error:t,attemptNumber:n,retriesLeft:r})=>{this.#w.error(`${t.constructor.name}: Failed to upload chunk ${e.partNumber}`)}})}catch(n){if(n instanceof PresignedUrlExpiredError||n instanceof UploadAbortError)throw n;if(n instanceof ChunkUploadNetworkError||n instanceof ChunkUploadTimeoutError||n instanceof o&&(n.status===0||n.status===void 0)){this.#w.warn(`SendChunk: network/timeout error for part ${e.partNumber}, waiting to come back online`,{error:n.message,...n instanceof o?{status:n.status,msg:n.message,res:n.response}:{}}),await this.#N(`SendChunk: network/timeout error for part ${e.partNumber}`,M),await a(j),this.#w.log(`SendChunk: network/timeout retry for part ${e.partNumber}`);continue}throw this.#he(e,n,t),n}}async#ie(e){let t=`Attempt chunk upload: for part ${e.partNumber}`;await this.#N(t);let n=this.#n();n.open(`PUT`,e.url,!0),this.#ae(n,e);let r=!1;return new Promise((i,a)=>{n.timeout=k,this.#S.set(e.partNumber,n);let o=()=>{this.#S.delete(e.partNumber),this.#x.delete(e.partNumber)};n.onload=()=>{if(r=!0,A.has(n.status))a(PresignedUrlExpiredError.make(`HTTP ${n.status} ${n.statusText}`,String(n.response)));else if(n.status>=200&&n.status<300)i(n);else{let r=`${t} - failed with status ${n.status} ${n.statusText}`;this.#w.warn(r,{res:n.response,resText:n.responseText,status:n.status}),a(ChunkUploadNetworkError.make(r,e.partNumber,n.status))}o()},n.onerror=()=>{if(!r){if(A.has(n.status))a(PresignedUrlExpiredError.make(`HTTP ${n.status} ${n.statusText}`,String(n.response)));else{let r=`${t} - failed due to a network error with status ${n.status}`;this.#w.warn(r,{res:n.response,resType:n.responseType,status:n.status}),a(ChunkUploadNetworkError.make(r,e.partNumber,n.status))}o()}},n.ontimeout=()=>{let t=n.timeout??k,r=this.#x.get(e.partNumber)??0;this.#w.error(`Chunk upload for part ${e.partNumber} timed out after ~${Math.round(t/6e4)} minutes`,{partNumber:e.partNumber,requestKey:this.#p,timeoutMs:t,bytesLoadedBeforeTimeout:r,partSize:e.partSize,uploadUrl:e.url}),o(),a(ChunkUploadTimeoutError.make(`Chunk upload for part ${e.partNumber} timed out after ${t}ms`,e.partNumber,t))},n.onabort=()=>{o(),a(UploadAbortError.make(this.#l.signal.reason))},n.upload.onprogress=this.#pe(n,e,()=>r),this.#me(n),n.send(e.getData())})}#ae(e,t){let n={...t.headers,"Content-Type":this.#r.contentType};Object.entries(n).forEach(([t,n])=>e.setRequestHeader(t,n))}#oe(e){this.#x.set(e,0),this.#ne({loaded:this.#j(),total:this.#a??0,partNumber:e,uploadId:this.#p})}#se(e){this.#x.delete(e),this.#ne({loaded:this.#j(),total:this.#a??0,partNumber:e,uploadId:this.#p})}#ce(e,t,n,r){return{url:r,partNumber:e,partSize:t,getData:n,headers:{PartNumber:String(e),PartSize:String(t)}}}#le(e,t,n,r){let i=t.replace(/"/g,``),a=this.#f.findIndex(t=>t.partNumber===e),o={partNumber:e,eTag:i,url:n,size:r};a===-1?this.#f.push(o):this.#f[a]=o;let s=this.#j();this.#k(`chunk.uploadComplete`,{uploadedParts:m(this.#f),requestKey:this.#p,presignedUrls:m(this.#m),bytesUploadedSoFar:s,isMultiPart:this.#h}),this.#w.info(`Part ${e} uploaded`,{partSize:r,bytesUploadedSoFar:s,totalBytes:this.#a,uploadedPartsCount:this.#f.length}),this.#ne({loaded:s,total:this.#a??0,partNumber:e,uploadId:this.#p})}async#ue({partNumber:e,getData:t,uploadUrl:n}){let r=v(t())||0;this.#oe(e);let i=this.#ce(e,r,t,n),a=await this.#re(i);if(!a)throw PartUploadFailedError.make({...i});
1if(this.#l.signal.aborted)throw UploadAbortError.make(this.#l.signal.reason);let o=this.#Te(a);if(!o)throw MissingETagError.make(e);this.#se(e),this.#le(e,o,n,r)}#de(e){let t=new Map(e.map(e=>[e.partNumber,e])),n=[];for(let e=1;e<=this.#o;e++)t.has(e)||n.push({partNumber:e});for(let e of this.#f){let r=t.get(e.partNumber),i=r?.eTag?.replace(/"/g,``);(!r||i!==e.eTag||r.size!==e.size)&&n.push(e)}return n}#fe(e){let t=0;for(let n=1;n<=this.#o;n++)if(!e.has(n)){let e=n===this.#o;t+=e&&this.#a%this.#t||this.#t}return t}#pe(e,t,n){return r=>{if(n()||this.#me(e)){this.#x.delete(t.partNumber),this.#ne({loaded:this.#j(),total:this.#a??0,partNumber:t.partNumber,uploadId:this.#p});return}this.#x.set(t.partNumber,r.loaded),this.#k(`chunk.uploadProgress`,{progressEvent:r,partNumber:t.partNumber}),this.#ne({loaded:this.#j(),total:this.#a??0,partNumber:t.partNumber,uploadId:this.#p})}}#me(e){return this.#l.signal.aborted?(e.abort(),!0):!1}#he(e,t,n){this.#$([{partNumber:e.partNumber,url:e.url,size:e.partSize}]),this.#k(`partUploadFailed`,{partNumber:e.partNumber,url:e.url,partSize:e.partSize,retries:n,error:t}),this.#x.delete(e.partNumber),this.#ne({loaded:this.#j(),total:this.#a??0,partNumber:e.partNumber,uploadId:this.#p})}async#ge(){let e=0;await this.#N(`retry failed parts`);let t=new u({concurrency:this.#i});for(;this.#s.length>0&&e<3;){e++,this.#w.info(`Retry attempt ${e} for failed parts`);let n=[...this.#s];if(this.#s=[],e>1){let t=Math.min(1e3*2**(e-1),1e4)+Math.floor(Math.random()*250);this.#w.info(`Retrying in ${t}ms`),await new Promise(e=>setTimeout(e,t))}let r=[];for(let e of n)t.add(async()=>{try{await this.#N(`retry failed part ${e.partNumber}`);let t=e.partNumber,n;try{n=this.#_e(t)}catch(e){throw e instanceof NoPresignedUrlFoundError?PresignedUrlExpiredError.wrap(e):e}let i=await y(this.#r.body,t,this.#t,this.#a);await this.#ue({partNumber:t,getData:()=>i,uploadUrl:n}),this.#w.info(`Successfully retried part ${t}`),this.#ee(t),r.push(null)}catch(t){this.#w.error(new l(`Failed to retry part ${e.partNumber}:`,{cause:t}),t),this.#x.delete(e.partNumber),r.push(e)}});await t.onIdle(),this.#s=r.filter(g)}this.#s.length>0&&(this.#k(`uploadRetryFailed`,{failedParts:this.#s,retryCount:e}),this.#w.error(`${this.#s.length} parts still failed after 3 retries`))}#_e(e){if(!this.#m[e])throw NoPresignedUrlFoundError.make(Object.values(this.#m),e);return this.#m[e]}async#ve(){if(this.#p)return{status:`resume`};await this.#N(`initialize multipart upload`);let e=await this.#I(),t=await this.#ye({contentLength:this.#a??0,mimeType:this.#r.contentType,partsNumbers:this.#o,fileName:this.#r.fileName,fileHash:e});if(this.#p=t.requestKey,this.#y=t.uploadFileDetailsId,!this.#y)throw c.make({requestKey:t.requestKey,totalBytes:this.#a??null,totalParts:this.#o,fileName:this.#r.fileName,contentType:this.#r.contentType});if(t.isAlreadyUploaded)return this.#w.info(`File fully uploaded (409), skipping to encode`,{requestKey:this.#p}),this.#k(`created`,{requestKey:this.#p,presignedUrls:{},isMultiPart:!0,uploadFileDetailsId:this.#y}),{status:`already_uploaded`};if(t.skipToComplete)return this.#w.info(`All parts uploaded but complete was not called, skipping to finalize`,{requestKey:this.#p}),this.#k(`created`,{requestKey:this.#p,presignedUrls:{},isMultiPart:!0,uploadFileDetailsId:this.#y}),{status:`skip_to_complete`};let n=t.presignedUrl??[];if(this.#m=n.reduce((e,t)=>(e[t.partNumber]=t.presignedUrl,e),{}),n.length<this.#o){let e=new Set(n.map(e=>e.partNumber));this.#c=this.#fe(e),this.#w.info(`Resume: calculated bytes already uploaded`,{uploadedBytes:this.#c,totalBytes:this.#a,uploadedParts:this.#o-n.length,totalParts:this.#o})}if(this.#k(`created`,{requestKey:this.#p,presignedUrls:m(this.#m),isMultiPart:!0,uploadFileDetailsId:this.#y}),n.length===0)throw o.withData({status:0,allowRetry:!0,message:`Server returned no presigned URLs for non-uploaded file`});return{status:n.length===this.#o?`fresh`:`resume`}}async#ye(e){return this.#u||=this.#P(`create multipart upload`,async()=>{try{let t=await r.getGjirafaMultipartUpload(this.#l.signal,e);return!t.presignedUrl?.length&&t.requestKey?await this.#xe({requestKey:t.requestKey,uploadFileDetailsId:t.uploadFileDetailsId}):t}catch(e){if(e instanceof o&&e.status===409){let t=e.json;return this.#be(t)}throw e}}),this.#u}#be(e){return this.#w.info(`File fully uploaded (409), skipping to encode`,e),{requestKey:e.requestKey,presignedUrl:[],uploadFileDetailsId:e.uploadFileDetailsId,isAlreadyUploaded:!0}}async#xe(e){this.#w.info(`Partial upload detected (202), fetching resume URLs`,e);try{let t=await this.#P(`fetch resume URLs`,async()=>
1{let t=await r.gjirafaMultipartUploadResume(this.#l.signal,e.requestKey);if(!t)throw o.withData({status:0,allowRetry:!0,message:`Resume request returned no response`});return t});return{requestKey:t.requestKey,presignedUrl:t.presignedUrl??[],uploadFileDetailsId:t.uploadFileDetailsId??e.uploadFileDetailsId,isAlreadyUploaded:!1}}catch(t){if(this.#B(t))return this.#w.info(`All parts uploaded but complete was not called (400 from resume), skipping to complete`,{requestKey:e.requestKey}),{requestKey:e.requestKey,presignedUrl:[],uploadFileDetailsId:e.uploadFileDetailsId,isAlreadyUploaded:!1,skipToComplete:!0};throw t instanceof o&&t.status===400&&this.#w.warn(`Unhandled 400 error from resume endpoint`,{requestKey:e.requestKey,errorMessage:t.message,errorJson:t.json}),t}}async#Se(e){return((await this.#P(`fetch uploaded multipart parts`,async()=>{let t=await r.getGjirafaMultipartParts(this.#l.signal,e);if(!t)throw o.withData({status:0,allowRetry:!0,message:`Failed to fetch multipart upload parts`});return t}))?.result??[]).map(e=>({partNumber:e.partNumber,eTag:(e.eTag??``).replace(/"/g,``),size:e.size}))}#Ce(e){return/uploads\/(?<requestKey>[a-f0-9]{32})/.exec(e)?.groups?.requestKey}async#we(e){this.#h=!1;let t=e.getData(),n=e=>{e.lengthComputable&&(this.#c=e.loaded,this.#a=e.total,this.#ne({loaded:this.#c,total:this.#a,partNumber:1,uploadId:this.#p}))};return i(async()=>{this.#w.info(`Single part upload`),await this.#N(`single part upload init`);let{url:i,uploadFileDetailsId:a}=await this.#P(`single part upload init request`,async()=>{let e=await r.getGjirafaUpload(this.#l.signal,{mimeType:this.#r.contentType,fileName:this.#r.fileName,contentLength:this.#a??0});if(!e)throw o.withData({status:0,allowRetry:!0,message:`Failed to get single part upload URL`});return e});if(this.#p=this.#Ce(i),this.#y=a,!this.#y)throw c.make({url:i,fileName:this.#r.fileName,contentType:this.#r.contentType});this.#k(`created`,{requestKey:this.#p,presignedUrls:{},isMultiPart:!1,uploadFileDetailsId:this.#y});let s=v(t)||0;await this.#N(`single part upload put request`),this.#g=await new Promise((r,a)=>{let o=this.#n();o.open(`PUT`,i,!0),this.#ae(o,{url:i,partNumber:1,partSize:s,getData:e.getData,headers:{}}),o.timeout=k,this.#S.set(1,o);let c=()=>{o.onload=null,o.onerror=null,o.upload.onprogress=null,o.onabort=null,o.ontimeout=null,this.#S.delete(1),this.#x.delete(1)};o.onload=()=>{try{A.has(o.status)?a(PresignedUrlExpiredError.make(`HTTP ${o.status} ${o.statusText}`,String(o.response))):o.status<200||o.status>=300?a(o):r(o)}finally{c()}},o.upload.onprogress=e=>{this.#me(o)||(this.#x.set(1,e.loaded),n(e))},o.onerror=()=>{c(),A.has(o.status)?a(PresignedUrlExpiredError.make(`HTTP ${o.status} ${o.statusText}`,String(o.response))):a(o)},o.onabort=()=>{c(),a(UploadAbortError.make(`Aborted single-part upload`))},o.ontimeout=()=>{let e=o.timeout??k,t=this.#x.get(1)??0;this.#w.error(`Single part upload timed out after ~${Math.round(e/6e4)} minutes`,{partNumber:1,requestKey:this.#p,timeoutMs:e,bytesLoadedBeforeTimeout:t,partSize:s}),c(),a(ChunkUploadTimeoutError.make(`Single part upload timed out after ${e}ms`,1,e))},this.#me(o),o.send(t)}),this.#ne({loaded:s,partNumber:1,total:s,uploadId:this.#p}),this.#f.push({eTag:this.#Te(this.#g)??``,partNumber:1,url:i,size:s}),this.#ne({loaded:s,partNumber:1,total:s,uploadId:this.#p}),this.#X({url:i,result:this.#g})},{onError:e=>{if(this.#l.signal.aborted){this.#w.warn(`Upload aborted, ignoring error`);return}this.#w.error(new l(`Failed to upload single part`,{cause:e}),{fileType:this.#r.contentType,fileSize:v(t),error:e})}})}#Te(e){return e.getResponseHeader(`ETag`)?.replace(/"/g,``)}#Ee=()=>{this.#w.info(`Page unloading, attempting to abort upload (request key: ${this.#p}).`),this.#Me()};#De(){window.addEventListener(`beforeunload`,this.#Ee,{signal:this.#l.signal});let e=()=>{this.#A(`DONE`),window.removeEventListener(`beforeunload`,this.#Ee),window.removeEventListener(`offline`,this.#ke),window.removeEventListener(`online`,this.#Ae),this.off(`complete`,e)};this.on(`complete`,e)}#Oe(){window.addEventListener(`offline`,this.#ke,{signal:this.#l.
1signal}),window.addEventListener(`online`,this.#Ae,{signal:this.#l.signal})}#ke=()=>{this.#w.warn(`Went offline: aborting in-flight chunk requests`),this.#je(`Went offline`)};#Ae=()=>{this.#w.info(`Back online: uploads will resume`)};#je(e){for(let[e,t]of this.#S.entries())try{this.#w.info(`Aborting in-flight part ${e} due to network change`),t.abort()}catch(t){this.#w.error(new l(`Failed to abort in-flight XHR during offline`,{cause:t}),{partNumber:e})}}async#Me(){if(this.#T&&=(clearTimeout(this.#T),null),this.#p)try{await r.gjirafaMultipartUploadAbort(null,this.#p),this.#w.info(`Multipart upload aborted for ${this.#p}`)}catch(e){this.#w.error(new l(`Failed to abort multipart upload`,{cause:e}),{requestKey:this.#p})}}};function I(e,{width:t,time:n,start:r,end:i,fps:a}={}){let o=new URLSearchParams;if(n&&r)throw Error("Cannot set `time` and `start` simultaneously; use `time` for static thumbnails.");t&&o.append(`width`,String(t)),typeof n==`number`&&o.append(`time`,String(Math.floor(n))),typeof r==`number`&&o.append(`start`,String(Math.floor(r))),typeof i==`number`&&o.append(`end`,String(Math.floor(i))),typeof a==`number`&&o.append(`fps`,String(a));let s=o.toString();return s?`${e}?${s}`:e}function L(e){return!e||Number.isNaN(e)?0:Math.floor(e/2)}var R=`https://assets.herohero.co/static/og/default-thumbnail.png`,z=16/9;function B(e){if(e?.width&&e.height)return e.width/e.height}async function V(e){if(!e)return z;let t=await h(e);return t===0?z:Math.min(t,z)}var H=640;function U(e){let t=e.size,r=t>O;return new Promise((i,a)=>{if(r)return a(new l(`File is too large to create preview.`));let o=document.createElement(`video`),c=URL.createObjectURL(e);o.setAttribute(`src`,c),o.load();let u,d=()=>{URL.revokeObjectURL(c),o.remove()};o.addEventListener(`loadedmetadata`,()=>{setTimeout(()=>{o.currentTime=L(o.duration)},200),o.addEventListener(`seeked`,()=>{let e=o.videoWidth,a=o.videoHeight;if(Math.max(e,a)>H){let t=H/Math.max(e,a);e=Math.floor(e*t),a=Math.floor(a*t),n.log(`Scaling preview dimensions: ${e}x${a}`)}typeof OffscreenCanvas<`u`?(u=new OffscreenCanvas(e,a),n.log(`Using OffscreenCanvas for preview`)):(u=document.createElement(`canvas`),u.width=e,u.height=a,n.log(`Using HTMLCanvasElement for preview`));let s=u.getContext(`2d`);if(!s){n.error(`Failed to get 2D context from canvas for video preview.`),d(),i({duration:o.duration,width:o.videoWidth,height:o.videoHeight,aspectRatio:o.videoWidth/o.videoHeight,fileSize:t});return}s.drawImage(o,0,0,e,a);let c={duration:o.duration,width:o.videoWidth,height:o.videoHeight,aspectRatio:o.videoWidth/o.videoHeight,fileSize:t},l=r?.6:.8,f=e=>{d(),i(e?{...c,previewBlob:e}:c)};window.OffscreenCanvas!==void 0&&u instanceof OffscreenCanvas?u.convertToBlob({type:`image/jpeg`,quality:l}).then(f).catch(e=>{n.error(`OffscreenCanvas.convertToBlob failed:`,e),d(),i(c)}):u instanceof HTMLCanvasElement?u.toBlob(f,`image/jpeg`,l):(n.warn(`Canvas is of unexpected type for blob conversion.`),d(),i(c))},{once:!0,passive:!0})},{once:!0,passive:!0}),o.addEventListener(`error`,e=>{let t=new l(`Failed to load video for preview.`,{cause:e});d(),s.error(t),a(t)})})}function W(e){let t=document.createElement(`audio`),n=URL.createObjectURL(e);return t.setAttribute(`src`,n),new Promise((r,i)=>{t.addEventListener(`loadedmetadata`,()=>{let i=t.duration;r({duration:i,fileSize:e.size}),URL.revokeObjectURL(n),t.remove()},{once:!0,passive:!0}),t.addEventListener(`error`,e=>{URL.revokeObjectURL(n),t.remove(),i(e)}),t.load()})}export{U as a,L as c,RateLimitError as d,V as i,GjirafaUpload as l,R as n,B as o,W as r,I as s,z as t,MultiPartCompleteError as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.