module.exports=[66232,a=>{"use strict";let b="images";async function c(){return new Promise((a,c)=>{let d=indexedDB.open("CharacterImagesDB",1);d.onerror=()=>{c(Error(`IndexedDB error: ${d.error}`))},d.onsuccess=()=>{a(d.result)},d.onupgradeneeded=a=>{let c=a.target.result;if(!c.objectStoreNames.contains(b)){let a=c.createObjectStore(b,{keyPath:"id"});a.createIndex("timestamp","timestamp",{unique:!1}),a.createIndex("type","metadata.type",{unique:!1})}}})}async function d(a,d,e,f){let g=await c();return new Promise((c,h)=>{let i=g.transaction([b],"readwrite").objectStore(b),j={id:a,blob:d,sourceUrl:e,timestamp:Date.now(),metadata:f},k=i.put(j);k.onsuccess=()=>{g.close(),c()},k.onerror=()=>{g.close(),h(Error(`Failed to save image: ${k.error}`))}})}async function e(a){let d=await c();return new Promise((c,e)=>{let f=d.transaction([b],"readonly").objectStore(b).get(a);f.onsuccess=()=>{d.close();let a=f.result;c(a?a.blob:null)},f.onerror=()=>{d.close(),e(Error(`Failed to get image: ${f.error}`))}})}async function f(a){let d=await c();return new Promise((c,e)=>{let f=d.transaction([b],"readonly").objectStore(b).get(a);f.onsuccess=()=>{d.close(),c(f.result||null)},f.onerror=()=>{d.close(),e(Error(`Failed to get image record: ${f.error}`))}})}async function g(a){let d=await c();return new Promise((c,e)=>{let f=d.transaction([b],"readwrite").objectStore(b).delete(a);f.onsuccess=()=>{d.close(),c()},f.onerror=()=>{d.close(),e(Error(`Failed to delete image: ${f.error}`))}})}async function h(){let a=await c();return new Promise((c,d)=>{let e=a.transaction([b],"readonly").objectStore(b).getAll();e.onsuccess=()=>{a.close(),c(e.result||[])},e.onerror=()=>{a.close(),d(Error(`Failed to get all images: ${e.error}`))}})}async function i(a=2592e6){let d=await c(),e=Date.now()-a;return new Promise((a,c)=>{let f=d.transaction([b],"readwrite").objectStore(b).index("timestamp"),g=IDBKeyRange.upperBound(e),h=f.openCursor(g),i=0;h.onsuccess=b=>{let c=b.target.result;c?(c.delete(),i++,c.continue()):(d.close(),a(i))},h.onerror=()=>{d.close(),c(Error(`Failed to clear old images: ${h.error}`))}})}async function j(a){try{let b=await e(a);return null!==b}catch(a){return console.error("Error checking image existence:",a),!1}}async function k(){if("estimate"in navigator.storage){let a=await navigator.storage.estimate();return{usage:a.usage||0,quota:a.quota||0}}return null}async function l(a,b=3e4){let c=new AbortController,d=setTimeout(()=>c.abort(),b);try{let b=await fetch(a,{signal:c.signal});return clearTimeout(d),b}catch(a){throw clearTimeout(d),a}}async function m(a,b,c,e=3){let f;for(let g=1;g<=e;g++)try{let e=3e4+(g-1)*15e3,f=await l(b,e);if(!f.ok){if(524===f.status||f.status>=500)throw Error(`Server error (${f.status} ${f.statusText})`);throw Error(`Failed to fetch image (${f.status} ${f.statusText}): ${b}`)}let h=await f.blob();await d(a,h,b,c);return}catch(c){f=c;let b="AbortError"===c.name||c.message.includes("524")||c.message.includes("Server error")||c.message.includes("Network");if(g<e&&b){let b=1e3*Math.pow(2,g);console.warn(`Attempt ${g} failed for ${a}. Retrying image download in ${b}ms...`,c.message),await new Promise(a=>setTimeout(a,b))}else break}throw console.warn(`Final error downloading and saving image to IndexedDB for ${a}:`,f),f}function n(){return Math.floor(13*Math.random())+1}function o(){let a=n();return`/media/avatar${a}.png`}a.s(["clearOldImages",()=>i,"deleteImage",()=>g,"downloadAndSaveImage",()=>m,"getAllImages",()=>h,"getImage",()=>e,"getImageRecord",()=>f,"getRandomAvatarNumber",()=>n,"getRandomDefaultAvatar",()=>o,"getStorageInfo",()=>k,"imageExists",()=>j,"initDB",()=>c,"saveImage",()=>d])}];

//# sourceMappingURL=lib_storage_imageDB_ts_31e09dce._.js.map