import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{x as t}from"./vendor-markdown-0Mxgxy0L.js";import{i as n,r}from"./api-client-bbJLzRVE.js";var i=e(t(),1);function a(e,t,a,o=0){let[s,c]=(0,i.useState)(null),[l,u]=(0,i.useState)(!1),d=(0,i.useRef)(null);return(0,i.useEffect)(()=>{let i=!1,o=/^(\/|[A-Za-z]:[/\\])/.test(e)?`/api/fs/raw?path=${encodeURIComponent(e)}`:`${n(t)}/files/raw?path=${encodeURIComponent(e)}`,s=r();return fetch(o,{headers:s?{Authorization:`Bearer ${s}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{if(i)return;let t=a?new Blob([e],{type:a}):e,n=URL.createObjectURL(t);d.current&&URL.revokeObjectURL(d.current),d.current=n,c(n)}).catch(()=>{i||u(!0)}),()=>{i=!0}},[e,t,a,o]),(0,i.useEffect)(()=>()=>{d.current&&URL.revokeObjectURL(d.current)},[]),{blobUrl:s,error:l}}export{a as t};