1import{a as e}from"./startup-diagnostics-bridge-BB8dzHvV.js";import{m as t}from"./startup-core-CGeUO7uJ.js";import{b as r}from"./image-utils-BFdDQ3hX.js";const o=3e5;function n(){return new Promise((e,t)=>{const r=indexedDB.open("echo-startup-thumbnails-v1",1);r.onupgradeneeded=()=>r.result.createObjectStore("images",{keyPath:"key"}),r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error)})}async function a(e,t){const r=await n();try{return await new Promise((n,a)=>{const s=r.transaction("images").objectStore("images").get(`${e}:${t}`);s.onsuccess=()=>{const t=s.result;n((null==t?void 0:t.owner)===e&&Date.now()-t.savedAt<6048e5&&t.bytes instanceof ArrayBuffer&&t.bytes.byteLength<=o&&"string"==typeof t.mimeType&&t.mimeType.startsWith("image/")?new Blob([t.bytes],{type:t.mimeType}):null)},s.onerror=()=>a(s.error)})}finally{r.close()}}async function s(s,i,c){const l=i.filter(e=>(e.owner_id||e.user_id)===s&&e.image_url).slice(0,6),u=[];for(let n=0;n<l.length&&!c.aborted;n+=2)await Promise.all(l.slice(n,n+2).map(async n=>{var i;const l=n.image_url;if(!/^https?:\/\//.test(l))return;const m=e(c),f=setTimeout(()=>m.abort(),3e3);try{if(await a(s,l))return;const e=r(l,"thumbnail");if(!e)return;if(new URL(e,window.location.href).origin!==window.location.origin)return;const t=await fetch(e,{signal:m.signal,cache:"force-cache",credentials:"omit",referrerPolicy:"no-referrer"});if(!t.ok||Number(t.headers.get("content-length"))>o)return;const n=null==(i=t.body)?void 0:i.getReader();if(!n)return;const f=[];let y=0;for(;;){const e=await n.read();if(e.done)break;if(y+=e.value.byteLength,y>o||c.aborted)return void(await n.cancel());f.push(e.value)}const d=new Blob(f,{type:t.headers.get("content-type")||""});if(!d.type.startsWith("image/")||d.size>o||c.aborted)return;u.push({key:`${s}:${l}`,owner:s,url:l,bytes:await d.arrayBuffer(),mimeType:d.type,savedAt:Date.now()})}catch(y){t("thumbnail-cache-unavailable",{reason:y instanceof Error?y.name:"unknown"})}finally{clearTimeout(f),m.release()}}));if(c.aborted||!u.length)return;const m=await n();try{await new Promise((e,t)=>{const r=m.transaction("images","readwrite"),o=r.objectStore("images"),n=o.getAll();n.onsuccess=()=>{const e=n.result.filter(e=>e.owner===s),t=new Set([...u,...e].sort((e,t)=>t.savedAt-e.savedAt).slice(0,6).map(e=>e.key));for(const r of n.result)t.has(r.key)||o.delete(r.key);for(const r of u)t.has(r.key)&&o.put(r)},r.oncomplete=()=>e(),r.onerror=()=>t(r.error),r.onabort=()=>t(r.error)})}finally{m.close()}}export{s as cacheStartupThumbnails,a as readStartupThumbnail};
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.