1import{c as P,r as v,s as U}from"./index-DH6psoju.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const C=P("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]),B=["image/jpeg","image/png","image/webp","image/gif","image/heic","image/heif"],F=["video/mp4","video/quicktime","video/webm"],D="JPG, PNG, WEBP, GIF, HEIC",G="MP4, MOV, WEBM",N={jpg:"image/jpeg",jpeg:"image/jpeg",jfif:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",heic:"image/heic",heif:"image/heif",mp4:"video/mp4",m4v:"video/mp4",mov:"video/quicktime",webm:"video/webm"};function E(e){var a;if(e.type)return e.type;const n=((a=e.name.split(".").pop())==null?void 0:a.toLowerCase())||"";return N[n]||"application/octet-stream"}function H(e){return B.includes(E(e))}function J(e){return F.includes(E(e))}const O=10,A=1e3,R=8*1024*1024;function I(e){if(e.type)return e;const n=E(e);if(n==="application/octet-stream")return e;try{return new File([e],e.name,{type:n,lastModified:e.lastModified})}catch{return e}}async function x(e){return new Promise(n=>setTimeout(n,e))}function L(e,n,a,m){return new Promise((s,p)=>{const t=new XMLHttpRequest;t.open("PUT",e,!0),Object.entries(a).forEach(([r,w])=>t.setRequestHeader(r,w)),t.upload.onprogress=r=>{r.lengthComputable&&m(Math.round(r.loaded/r.total*100))},t.onload=()=>{t.status>=200&&t.status<300?s():p(new Error(`R2 PUT failed (${t.status}): ${t.responseText.slice(0,200)}`))},t.onerror=()=>p(new Error("R2 PUT network error")),t.onabort=()=>p(new Error("R2 PUT aborted")),t.send(n)})}async function V(e,n="general",a){var y;e=I(e);const m="jrsixrzqzuguxabfxzgj",{data:s}=await U.auth.getSession(),p=(y=s==null?void 0:s.session)==null?void 0:y.access_token;if(!p)throw new Error("Not authenticated");if(e.size>=R){const u=await fetch(`https://${m}.supabase.co/functions/v1/r2-presign`,{method:"POST",headers:{Authorization:`Bearer ${p}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e.name,content_type:E(e),size:e.size,context:n})});if(!u.ok){const l=await u.json().catch(()=>({error:`Presign failed (${u.status})`}));throw new Error(l.error||`Presign failed (${u.status})`)}const{upload_url:z,file_url:j,object_key:_,required_headers:h}=await u.json();await L(z,e,h,l=>a==null?void 0:a(Math.min(95,l)));const d=await fetch(`https://${m}.supabase.co/functions/v1/r2-finalize`,{method:"POST",headers:{Authorization:`Bearer ${p}`,"Content-Type":"application/json"},body:JSON.stringify({object_key:_,file_url:j,mime_type:E(e),file_size:e.size,context:n})});if(!d.ok){const l=await d.json().catch(()=>({error:"Finalize failed"}));throw new Error(l.error||"Finalize failed")}const T=await d.json();return a==null||a(100),T}const t=new FormData;t.append("file",e),t.append("context",n);const r=await fetch(`https://${m}.supabase.co/functions/v1/r2-upload`,{method:"POST",headers:{Authorization:`Bearer ${p}`},body:t});if(!r.ok){const u=await r.json().catch(()=>({error:`Upload failed (${r.status})`}));throw new Error(u.error||`Upload failed (${r.status})`)}const w=await r.json();return a==null||a(100),w}function W(e={}){const[n,a]=v.useState(!1),[m,s]=v.useState(0);return{upload:v.useCallback(async t=>{var y,u,z,j,_;t=I(t),a(!0),s(0);const r="jrsixrzqzuguxabfxzgj",w=e.context||"general";try{const{data:h}=await U.auth.getSession(),d=(y=h==null?void 0:h.session)==null?void 0:y.access_token;if(!d)throw new Error("Not authenticated");if(t.size>=R){const i=await fetch(`https://${r}.supabase.co/functions/v1/r2-presign`,{method:"POST",headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},body:JSON.stringify({filename:t.name,content_type:E(t),size:t.size,context:w})});if(!i.ok){const f=await i.json().catch(()=>({error:`Presign failed (${i.status})`}));throw new Error(f.error||`Presign failed (${i.status})`)}const{upload_url:o,file_url:c,object_key:b,required_headers:S}=await i.json();let g=null;for(let f=0;f<=3;f++)try{await L(o,t,S,k=>{s(Math.min(95,k))}),g=null;break}catch(k){g=k,f<3&&await x(A*2**f)}if(g)throw g;const $=await fetch(`https://${r}.supabase.co/functions/v1/r2-finalize`,{method:"POST",headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},body:JSON.stringify({object_key:b,file_url:c,mime_type:E(t),file_size:t.size,context:w})});if(!$.ok){const f=await $.json().catch(()=>({error:"Finalize failed"}));throw new Error(f.error||"Finalize failed")}const M=await $.json();return s(100),(u=e.onSuccess)==null||u.call(e,M),M}const T=`https://${r}.supabase.co/functions/v1/r2-upload`;s(10);let l=null;for(let i=0;i<=O;i++){try{const o=new FormData;o.append("file",t),o.append("context",w);const c=await fetch(T,{method:"POST",headers:{Authorization:`Bearer ${d}`},body:o});if(s(50+Math.min(i*5,40)),c.ok){const b=await c.json();return s(100),(z=e.onSuccess)==null||z.call(e,b),b}
6if(c.status===401||c.status===403||c.status===413){const S=(await c.json().catch(()=>({error:`Upload failed (${c.status})`}))).error||`Upload failed (${c.status})`,g=new Error(S);throw g.terminal=!0,g}l=new Error(`Upload failed (${c.status})`)}catch(o){if(o!=null&&o.terminal||(j=o.message)!=null&&j.includes("Not authenticated"))throw o;l=o}if(i<O){const o=Math.min(A*2**i,3e4);await x(o)}}throw l||new Error("Upload failed after retries")}catch(h){const d=h.message||"Upload failed";throw(_=e.onError)==null||_.call(e,d),h}finally{a(!1)}},[e.context,e.onSuccess,e.onError]),uploading:n,progress:m}}export{D as I,C as U,G as V,W as a,J as b,H as i,V 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.