@helia/verified-fetch 2.6.10 → 2.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js
CHANGED
|
@@ -83,7 +83,7 @@ ${[...t.errors.entries()].map(([o,s])=>`
|
|
|
83
83
|
`,"\r"," "," ","\0"].some(t=>this.checkString(t,{offset:6})))return{ext:"vtt",mime:"text/vtt"};if(this.check([137,80,78,71,13,10,26,10])){await e.ignore(8);async function t(){return{length:await e.readToken(SU),type:await e.readToken(new Yn(4,"latin1"))}}do{let n=await t();if(n.length<0)return;switch(n.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(n.length+4)}}while(e.position+8<e.fileInfo.size);return{ext:"png",mime:"image/png"}}if(this.check([65,82,82,79,87,49,0,0]))return{ext:"arrow",mime:"application/x-apache-arrow"};if(this.check([103,108,84,70,2,0,0,0]))return{ext:"glb",mime:"model/gltf-binary"};if(this.check([102,114,101,101],{offset:4})||this.check([109,100,97,116],{offset:4})||this.check([109,111,111,118],{offset:4})||this.check([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(this.check([73,73,82,79,8,0,0,0,24]))return{ext:"orf",mime:"image/x-olympus-orf"};if(this.checkString("gimp xcf "))return{ext:"xcf",mime:"image/x-xcf"};if(this.checkString("ftyp",{offset:4})&&(this.buffer[8]&96)!==0){let t=new Yn(4,"latin1").get(this.buffer,8).replace("\0"," ").trim();switch(t){case"avif":case"avis":return{ext:"avif",mime:"image/avif"};case"mif1":return{ext:"heic",mime:"image/heif"};case"msf1":return{ext:"heic",mime:"image/heif-sequence"};case"heic":case"heix":return{ext:"heic",mime:"image/heic"};case"hevc":case"hevx":return{ext:"heic",mime:"image/heic-sequence"};case"qt":return{ext:"mov",mime:"video/quicktime"};case"M4V":case"M4VH":case"M4VP":return{ext:"m4v",mime:"video/x-m4v"};case"M4P":return{ext:"m4p",mime:"video/mp4"};case"M4B":return{ext:"m4b",mime:"audio/mp4"};case"M4A":return{ext:"m4a",mime:"audio/x-m4a"};case"F4V":return{ext:"f4v",mime:"video/mp4"};case"F4P":return{ext:"f4p",mime:"video/mp4"};case"F4A":return{ext:"f4a",mime:"audio/mp4"};case"F4B":return{ext:"f4b",mime:"audio/mp4"};case"crx":return{ext:"cr3",mime:"image/x-canon-cr3"};default:return t.startsWith("3g")?t.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.check([82,73,70,70])){if(this.checkString("WEBP",{offset:8}))return{ext:"webp",mime:"image/webp"};if(this.check([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(this.check([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/wav"};if(this.check([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(this.check([73,73,85,0,24,0,0,0,136,231,116,216]))return{ext:"rw2",mime:"image/x-panasonic-rw2"};if(this.check([48,38,178,117,142,102,207,17,166,217])){async function t(){let n=new Uint8Array(16);return await e.readBuffer(n),{id:n,size:Number(await e.readToken(AU))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await t(),i=n.size-24;if(fs(n.id,[145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101])){let o=new Uint8Array(16);if(i-=await e.readBuffer(o),fs(o,[64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"audio/x-ms-asf"};if(fs(o,[192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"video/x-ms-asf"};break}await e.ignore(i)}return{ext:"asf",mime:"application/vnd.ms-asf"}}if(this.check([171,75,84,88,32,49,49,187,13,10,26,10]))return{ext:"ktx",mime:"image/ktx"};if((this.check([126,16,4])||this.check([126,24,4]))&&this.check([48,77,73,69],{offset:4}))return{ext:"mie",mime:"application/x-mie"};if(this.check([39,10,0,0,0,0,0,0,0,0,0,0],{offset:2}))return{ext:"shp",mime:"application/x-esri-shape"};if(this.check([255,79,255,81]))return{ext:"j2c",mime:"image/j2c"};if(this.check([0,0,0,12,106,80,32,32,13,10,135,10]))switch(await e.ignore(20),await e.readToken(new Yn(4,"ascii"))){case"jp2 ":return{ext:"jp2",mime:"image/jp2"};case"jpx ":return{ext:"jpx",mime:"image/jpx"};case"jpm ":return{ext:"jpm",mime:"image/jpm"};case"mjp2":return{ext:"mj2",mime:"image/mj2"};default:return}if(this.check([255,10])||this.check([0,0,0,12,74,88,76,32,13,10,135,10]))return{ext:"jxl",mime:"image/jxl"};if(this.check([254,255]))return this.check([0,60,0,63,0,120,0,109,0,108],{offset:2})?{ext:"xml",mime:"application/xml"}:void 0;if(this.check([208,207,17,224,161,177,26,225]))return{ext:"cfb",mime:"application/x-cfb"};if(await e.peekBuffer(this.buffer,{length:Math.min(256,e.fileInfo.size),mayBeLess:!0}),this.check([97,99,115,112],{offset:36}))return{ext:"icc",mime:"application/vnd.iccprofile"};if(this.checkString("**ACE",{offset:7})&&this.checkString("**",{offset:12}))return{ext:"ace",mime:"application/x-ace-compressed"};if(this.checkString("BEGIN:")){if(this.checkString("VCARD",{offset:6}))return{ext:"vcf",mime:"text/vcard"};if(this.checkString("VCALENDAR",{offset:6}))return{ext:"ics",mime:"text/calendar"}}if(this.checkString("FUJIFILMCCD-RAW"))return{ext:"raf",mime:"image/x-fujifilm-raf"};if(this.checkString("Extended Module:"))return{ext:"xm",mime:"audio/x-xm"};if(this.checkString("Creative Voice File"))return{ext:"voc",mime:"audio/x-voc"};if(this.check([4,0,0,0])&&this.buffer.length>=16){let t=new DataView(this.buffer.buffer).getUint32(12,!0);if(t>12&&this.buffer.length>=t+16)try{let n=new TextDecoder().decode(this.buffer.slice(16,t+16));if(JSON.parse(n).files)return{ext:"asar",mime:"application/x-asar"}}catch{}}if(this.check([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(this.checkString("SCRM",{offset:44}))return{ext:"s3m",mime:"audio/x-s3m"};if(this.check([71])&&this.check([71],{offset:188}))return{ext:"mts",mime:"video/mp2t"};if(this.check([71],{offset:4})&&this.check([71],{offset:196}))return{ext:"mts",mime:"video/mp2t"};if(this.check([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(this.check([68,73,67,77],{offset:128}))return{ext:"dcm",mime:"application/dicom"};if(this.check([76,0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70]))return{ext:"lnk",mime:"application/x.ms.shortcut"};if(this.check([98,111,111,107,0,0,0,0,109,97,114,107,0,0,0,0]))return{ext:"alias",mime:"application/x.apple.alias"};if(this.checkString("Kaydara FBX Binary \0"))return{ext:"fbx",mime:"application/x.autodesk.fbx"};if(this.check([76,80],{offset:34})&&(this.check([0,0,1],{offset:8})||this.check([1,0,2],{offset:8})||this.check([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(this.check([6,6,237,245,216,29,70,229,189,49,239,231,254,116,183,29]))return{ext:"indd",mime:"application/x-indesign"};if(await e.peekBuffer(this.buffer,{length:Math.min(512,e.fileInfo.size),mayBeLess:!0}),WU(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254]))return this.check([60,0,63,0,120,0,109,0,108,0],{offset:2})?{ext:"xml",mime:"application/xml"}:this.check([255,14,83,0,107,0,101,0,116,0,99,0,104,0,85,0,112,0,32,0,77,0,111,0,100,0,101,0,108,0],{offset:2})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:void 0;if(this.checkString("-----BEGIN PGP MESSAGE-----"))return{ext:"pgp",mime:"application/pgp-encrypted"}};detectImprecise=async e=>{if(this.buffer=new Uint8Array(cS),await e.peekBuffer(this.buffer,{length:Math.min(8,e.fileInfo.size),mayBeLess:!0}),this.check([0,0,1,186])||this.check([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(this.check([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(this.check([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(this.check([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(this.buffer.length>=2&&this.check([255,224],{offset:0,mask:[255,224]})){if(this.check([16],{offset:1,mask:[22]}))return this.check([8],{offset:1,mask:[8]})?{ext:"aac",mime:"audio/aac"}:{ext:"aac",mime:"audio/aac"};if(this.check([2],{offset:1,mask:[6]}))return{ext:"mp3",mime:"audio/mpeg"};if(this.check([4],{offset:1,mask:[6]}))return{ext:"mp2",mime:"audio/mpeg"};if(this.check([6],{offset:1,mask:[6]}))return{ext:"mp1",mime:"audio/mpeg"}}};async readTiffTag(e){let t=await this.tokenizer.readToken(e?lh:Ut);switch(this.tokenizer.ignore(10),t){case 50341:return{ext:"arw",mime:"image/x-sony-arw"};case 50706:return{ext:"dng",mime:"image/x-adobe-dng"};default:}}async readTiffIFD(e){let t=await this.tokenizer.readToken(e?lh:Ut);for(let n=0;n<t;++n){let i=await this.readTiffTag(e);if(i)return i}}async readTiffHeader(e){let t=(e?lh:Ut).get(this.buffer,2),n=(e?EU:sr).get(this.buffer,4);if(t===42){if(n>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(n>=8){let o=(e?lh:Ut).get(this.buffer,8),s=(e?lh:Ut).get(this.buffer,10);if(o===28&&s===254||o===31&&s===11)return{ext:"nef",mime:"image/x-nikon-nef"}}}return await this.tokenizer.ignore(n),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(t===43)return{ext:"tif",mime:"image/tiff"}}},bit=new Set(XU),vit=new Set(YU);var Ac=ze("helia:verified-fetch:content-type-parser"),e8="application/octet-stream";function Eee(r){return Ac("checking for svg"),/^(<\?xml[^>]+>)?[^<^\w]+<svg/ig.test(r)}async function See(r){Ac("checking for json");try{return JSON.parse(r),!0}catch(e){return Ac("failed to parse as json",e),!1}}function Aee(r){Ac("checking for text");let e=new TextDecoder("utf-8",{fatal:!0});try{return e.decode(r)}catch{return null}}async function _ee(r){return Ac("checking for html"),/^\s*<(?:!doctype\s+html|html|head|body)\b/i.test(r)}async function ZU(r,e){Ac("contentTypeParser called for fileName: %s, byte size=%s",e,r.length);let t=(await QU(r))?.mime;if(t!=null)return Ac("detectedType: %s",t),t;if(Ac("no detectedType"),e==null){let n=Aee(r);return n!=null?Eee(n)?"image/svg+xml":await See(n)?"application/json":await _ee(n)?"text/html; charset=utf-8":"text/plain; charset=utf-8":e8}switch(e.split(".").pop()){case"css":return"text/css";case"html":return"text/html; charset=utf-8";case"js":return"application/javascript";case"json":return"application/json";case"txt":return"text/plain";case"woff2":return"font/woff2";case"svg":return"image/svg+xml";case"csv":return"text/csv";case"doc":return"application/msword";case"xls":return"application/vnd.ms-excel";case"ppt":return"application/vnd.ms-powerpoint";case"msi":return"application/x-msdownload";default:return e8}}function JU(r){return r?.then!=null}async function t8({bytes:r,path:e,response:t,contentTypeParser:n,log:i,defaultContentType:o="application/octet-stream"}){let s;if(n!=null)try{let a=e.split("/").pop()?.trim();a=a===""?void 0:a;let c=n(r,a);if(JU(c)){let l=await c;l!=null&&(s=l)}else c!=null&&(s=c);i.trace("contentTypeParser returned %s",s)}catch(a){i.error("error parsing content type",a)}s===e8&&(s=o),i.trace('setting content type to "%s"',s??o),t.headers.set("content-type",s??o)}var r8=class extends Mt{codes=[ct];canHandle({cid:e,accept:t,pathDetails:n,byteRangeContext:i}){return this.log("checking if we can handle %c with accept %s",e,t),n==null||i==null?!1:e.code===ct}getRedirectUrl(e){let{resource:t,path:n}=e;if(n===""?!t.toString().endsWith("/"):!n.endsWith("/"))try{let o=new URL(t.toString());return o.pathname.endsWith("/")?null:(o.pathname=`${o.pathname}/`,o.toString())}catch{return`${t.toString()}/`}return null}async handle(e){let{cid:t,options:n,withServerTiming:i=!1,pathDetails:o}=e,{handleServerTiming:s,contentTypeParser:a,helia:c,getBlockstore:l}=this.pluginOptions,u=this.log,f=e.resource,h=e.path,d=!1,m=e.byteRangeContext,g=o.ipfsRoots,w=o.terminalElement,x=w.cid;if(w?.type==="directory"){let S=w.cid,T=this.getRedirectUrl(e);if(T!=null){if(u.trace("directory url normalization spec requires redirect..."),n?.redirect==="error")throw u('could not redirect to %s as redirect option was set to "error"',T),new TypeError("Failed to fetch");if(n?.redirect==="manual")return u("returning 301 permanent redirect to %s",T),km(f,T);u("following redirect to %s",T),f=T,d=!0}let D="index.html";try{u.trace("found directory at %c/%s, looking for index.html",t,h);let A=await s("exporter-dir","",async()=>pr(`/ipfs/${S}/${D}`,c.blockstore,{signal:n?.signal,onProgress:n?.onProgress}),i);u.trace("found root file at %c/%s with cid %c",S,D,A.cid),h=D,x=A.cid}catch(A){this.log.error("error loading path %c/%s",S,D,A),n?.signal?.throwIfAborted(),e.isDirectory=!0,e.directoryEntries=[],e.modified++,this.log.trace("attempting to get directory entries because index.html was not found");let I=yU({...c,blockstore:l(e.cid,e.resource,n?.session??!0,n)});try{for await(let k of I.ls(S,{signal:n?.signal,onProgress:n?.onProgress}))e.directoryEntries.push(k);return null}catch(k){return u.error("error listing directory %c",S,k),m5("Unable to get directory contents")}}finally{n?.onProgress?.(new G("verified-fetch:request:end",{cid:S,path:D}))}}m.isRangeRequest&&m.isValidRangeRequest&&w.type==="file"&&(m.setFileSize(w.unixfs.fileSize()),u.trace("fileSize for rangeRequest %d",m.getFileSize()));let v=m.offset,b=m.length;u.trace("calling exporter for %c/%s with offset=%o & length=%o",x,h,v,b);try{let T=(await s("exporter-file","",async()=>pr(x,c.blockstore,{signal:n?.signal,onProgress:n?.onProgress}),i)).content({signal:n?.signal,onProgress:n?.onProgress,offset:v,length:b});u("got async iterator for %c/%s",t,h);let{stream:D,firstChunk:A}=await s("stream-and-chunk","",async()=>wU(T,h??"",this.pluginOptions.logger,{onProgress:n?.onProgress,signal:n?.signal}),i);m.setBody(D);let I=cn(f,m.getBody(),{byteRangeContext:m,log:u},{redirected:d});return await s("set-content-type","",async()=>t8({bytes:A,path:h,response:I,contentTypeParser:a,log:u}),i),c5(I,g),I}catch(S){return n?.signal?.throwIfAborted(),u.error("error streaming %c/%s",t,h,S),m.isRangeRequest&&S.code==="ERR_INVALID_PARAMS"?p5(f):Qd(f.toString(),"Unable to stream content")}}};var n8=class extends Mt{canHandle(e){this.log("checking if we can handle %c with accept %s",e.cid,e.accept);let{pathDetails:t,cid:n}=e;return t!=null?!1:n.code===ct||n.code===Pn}async handle(e){let{cid:t,resource:n,options:i,withServerTiming:o=!1}=e,{getBlockstore:s,handleServerTiming:a}=this.pluginOptions,c=s(t,n,i?.session??!0,i),l=await a("path-walking","",async()=>NM({...e,blockstore:c,log:this.log}),o);return e.modified++,l instanceof Response?(this.log.trace("path walking failed"),l.status===404?l:null):(e.pathDetails=l,null)}};var eF;(function(r){r[r.SEND_QUERY=0]="SEND_QUERY",r[r.PEER_RESPONSE=1]="PEER_RESPONSE",r[r.FINAL_PEER=2]="FINAL_PEER",r[r.QUERY_ERROR=3]="QUERY_ERROR",r[r.PROVIDER=4]="PROVIDER",r[r.VALUE=5]="VALUE",r[r.ADD_PEER=6]="ADD_PEER",r[r.DIAL_PEER=7]="DIAL_PEER"})(eF||(eF={}));function i8(r){return r.charAt(0)==="1"||r.charAt(0)==="Q"?at(r):gn(W.parse(r))}var Km=class extends Error{name="PluginError";code;fatal;details;response;constructor(e,t,n){super(t),this.code=e,this.fatal=n?.fatal??!1,this.details=n?.details,this.response=n?.response}},na=class extends Km{name="PluginFatalError";constructor(e,t,n){super(e,t,{...n,fatal:!0}),this.name="PluginFatalError"}};var o8=class extends Mt{codes=[];canHandle({cid:e,accept:t,query:n,byteRangeContext:i}){return this.log("checking if we can handle %c with accept %s",e,t),i==null?!1:t==="application/vnd.ipfs.ipns-record"||n.format==="ipns-record"}async handle(e){let{resource:t,path:n,options:i}=e,{helia:o}=this.pluginOptions;if(e.reqFormat="ipns-record",n!==""||!(t.startsWith("ipns://")||t.includes(".ipns.")||t.includes("/ipns/")))throw this.log.error('invalid request for IPNS name "%s" and path "%s"',t,n),new na("ERR_INVALID_IPNS_NAME","Invalid IPNS name",{response:Cm(t,new Error("Invalid IPNS name"))});let s;try{let h;t.startsWith("ipns://")?h=t.replace("ipns://",""):t.includes("/ipns/")?h=t.split("/ipns/")[1].split("/")[0].split("?")[0]:h=t.split(".ipns.")[0].split("://")[1],this.log.trace('trying to parse peer id from "%s"',h),s=i8(h)}catch(h){throw this.log.error("could not parse peer id from IPNS url %s",t,h),new na("ERR_NO_PEER_ID_FOUND","could not parse peer id from url",{response:Cm(t,h)})}let a=Ve([O("/ipns/"),s.toMultihash().bytes]),c=new nt("/dht/record/"+H(a,"base32"),!1),l=await o.datastore.get(c,i),u=kt.deserialize(l);e.byteRangeContext.setBody(u.value);let f=cn(t,e.byteRangeContext.getBody(),{byteRangeContext:e.byteRangeContext,log:this.log});return f.headers.set("content-type","application/vnd.ipfs.ipns-record"),f}};var s8=class extends Mt{codes=[qo,Lo];canHandle({cid:e,accept:t,byteRangeContext:n}){return this.log("checking if we can handle %c with accept %s",e,t),n==null?!1:t==="application/vnd.ipld.dag-json"&&e.code!==Pn?!0:qo===e.code||Lo===e.code}async handle(e){let{path:t,resource:n,cid:i,accept:o,options:s}=e,{getBlockstore:a}=this.pluginOptions,c=s?.session??!0;this.log.trace("fetching %c/%s",i,t);let l=e.pathDetails?.terminalElement.cid??e.cid,f=await a(l,n,c,s).get(l,s),h;if(o==="application/vnd.ipld.dag-cbor"||o==="application/cbor")try{let m=If(f);h=Af(m)}catch(m){return this.log.error("could not transform %c to application/vnd.ipld.dag-cbor",m),ta(n)}else h=f;e.byteRangeContext.setBody(h);let d=cn(n,e.byteRangeContext.getBody(),{byteRangeContext:e.byteRangeContext,log:this.log});return d.headers.set("content-type",o??"application/json"),d}};var Iee=["application/vnd.ipld.dag-json","application/vnd.ipld.raw","application/octet-stream"];function Tee({headers:r,accept:e}){let n=(e??new Headers(r).get("accept")??"").split(",").map(i=>i.split(";")[0]).map(i=>i.trim());for(let i of n){if(i==="*/*")return;if(Iee.includes(i??""))return i}}var a8=class extends Mt{codes=[vt,cr.code];canHandle({cid:e,accept:t,query:n,byteRangeContext:i}){return this.log("checking if we can handle %c with accept %s",e,t),i==null?!1:t==="application/vnd.ipld.raw"||n.format==="raw"}async handle(e){let{path:t,resource:n,cid:i,accept:o,query:s,options:a}=e,{getBlockstore:c,contentTypeParser:l}=this.pluginOptions,u=a?.session??!0,f=this.log;if(o==="application/vnd.ipld.raw"||s.format==="raw"?(e.reqFormat="raw",e.query.download=!0,e.query.filename=e.query.filename??`${i.toString()}.bin`,f.trace("Set content disposition...")):f.trace("Did NOT set content disposition..."),t!==""&&i.code===vt)throw f.trace("404-ing raw codec request for %c/%s",i,t),new na("ERR_RAW_PATHS_NOT_SUPPORTED","Raw codec does not support paths",{response:g5(n,"Raw codec does not support paths")});let h=e.pathDetails?.terminalElement.cid??e.cid,m=await c(h,n,u,a).get(h,a);e.byteRangeContext.setBody(m);let g=cn(n,e.byteRangeContext.getBody(),{byteRangeContext:e.byteRangeContext,log:f},{redirected:!1});return await t8({bytes:m,path:t,response:g,defaultContentType:Tee({headers:a?.headers,accept:o}),contentTypeParser:l,log:f}),g}};var Cee=({weak:r,reqFormat:e})=>e==="tar"||e==="car"||e==="ipns-record"||r===!0?"W/":"",kee=({reqFormat:r})=>r==null?"":r==="tar"?".x-tar":`.${r}`;function mh({cid:r,reqFormat:e,weak:t,rangeStart:n,rangeEnd:i,contentPrefix:o}){let s=Cee({weak:t,reqFormat:e}),a=kee({reqFormat:e});return(n!=null||i!=null)&&(a+=`.${n??"0"}-${i??"N"}`),`${s}"${o??""}${r.toString()}${a}"`}var Sot=O("ustar\0","binary"),Aot=O("ustar ","binary"),_ot=O(" \0","binary");var oF=it(rF(),1);function Ree(r){return r[Symbol.asyncIterator]!=null}function Dee(r){if(Ree(r))return(async()=>{let n=new Uint8Array(0);for await(let i of r)n=Ve([n,i],n.length+i.length);return n})();let e=[],t=0;for(let n of r)e.push(n),t+=n.byteLength;return Ve(e,t)}var nF=Dee;var Nee="0000000000000000000",Oee="7777777777777777777",Lee=48,Bee=O("ustar\0","binary"),Mee=O("00","binary"),Uee=parseInt("7777",8),Fee=257,$ee=263,Hee=function(r){switch(r){case"file":return 0;case"link":return 1;case"symlink":return 2;case"character-device":return 3;case"block-device":return 4;case"directory":return 5;case"fifo":return 6;case"contiguous-file":return 7;case"pax-header":return 72;default:return 0}},Vee=function(r){let e=256;for(let t=0;t<148;t++)e+=r[t];for(let t=156;t<512;t++)e+=r[t];return e},_c=function(r,e){let t=r.toString(8);return t.length>e?O(Oee.slice(0,e)+" "):O(Nee.slice(0,e-t.length)+t+" ")},fS=function(r){let e=O(r).byteLength,t=Math.floor(Math.log(e)/Math.log(10))+1;return e+t>=Math.pow(10,t)&&t++,`${e+t}${r}`};function iF(r){let e="";r.name!=null&&(e+=fS(" path="+r.name+`
|
|
84
84
|
`)),r.linkname!=null&&(e+=fS(" linkpath="+r.linkname+`
|
|
85
85
|
`));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=fS(" "+n+"="+t[n]+`
|
|
86
|
-
`));return O(e)}function c8(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),O(t).byteLength!==t.length)return null;for(;O(t).byteLength>100;){let i=t.indexOf("/");if(i===-1)return null;n+=n!==""?"/"+t.slice(0,i):t.slice(0,i),t=t.slice(i+1)}return O(t).byteLength>100||O(n).byteLength>155||r.linkname!=null&&O(r.linkname).byteLength>100?null:(e.set(O(t),0),e.set(_c(r.mode&Uee,6),100),e.set(_c(r.uid,6),108),e.set(_c(r.gid,6),116),e.set(_c(r.size,11),124),e.set(_c(r.mtime.getTime()/1e3|0,11),136),e[156]=Lee+Hee(r.type),r.linkname!=null&&e.set(O(r.linkname),157),e.set(Bee,Fee),e.set(Mee,$ee),r.uname!=null&&e.set(O(r.uname),265),r.gname!=null&&e.set(O(r.gname),297),e.set(_c(r.devmajor??0,6),329),e.set(_c(r.devminor??0,6),337),n!=null&&e.set(O(n),345),e.set(_c(Vee(e),6),148),e)}var{S_IFMT:Kee,S_IFBLK:qee,S_IFCHR:jee,S_IFDIR:Wee,S_IFIFO:Gee,S_IFLNK:Xee}=oF.default,Yee=parseInt("755",8),Qee=parseInt("644",8),sF=new Uint8Array(1024);function Zee(r=0){switch(r&Kee){case qee:return"block-device";case jee:return"character-device";case Wee:return"directory";case Gee:return"fifo";case Xee:return"symlink";default:return"file"}}function hS(r){return r&=511,r!==0?sF.subarray(0,512-r):new Uint8Array(0)}function dS(r){if(r.pax==null){let e=c8(r);if(e!=null)return e}return Jee(r)}function Jee(r){let e=iF(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new oe(c8(t)??new Uint8Array(0),e,hS(e.length),c8({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function l8(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??Zee(e.mode),mode:e.mode??(e.type==="directory"?Yee:Qee),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=O(t)),t instanceof Uint8Array||vi(t)){n.size=t.length,yield dS(n),yield vi(t)?t.subarray():t,yield hS(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=H(await nF(t)),yield dS(n);continue}if(yield dS(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let i=0;for await(let o of t??[])i+=o.length,yield vi(o)?o.subarray():o;if(i!==n.size)throw new Error(`size mismatch, wrote ${i} of ${n.size} bytes`);yield hS(n.size)}yield sF}}var ete=["file","raw","directory"];function tte(r){let e,t;return(r.type==="file"||r.type==="directory")&&(e=r.unixfs.mode,t=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:r.path,mode:e,mtime:t,size:Number(r.size),type:r.type==="directory"?"directory":"file"}}function aF(r){if(!ete.includes(r.type))throw new gi(`${r.type} is not a UnixFS node`);let e={header:tte(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*cF(r,e,t){let n=await pr(r,e,t);if(n.type==="file"||n.type==="raw"){yield*ot([aF(n)],l8());return}if(n.type==="directory"){yield*ot(ih(r,e,t),i=>Nt(i,o=>aF(o)),l8());return}throw new gi("Not a UnixFS node")}var u8=class extends Mt{codes=[];canHandle({cid:e,accept:t,query:n,byteRangeContext:i}){return this.log("checking if we can handle %c with accept %s",e,t),i==null?!1:t==="application/x-tar"||n.format==="tar"}async handle(e){let{cid:t,path:n,resource:i,options:o,pathDetails:s}=e,{getBlockstore:a}=this.pluginOptions,c=s?.terminalElement.cid??t;if(c.code!==ct&&c.code!==vt)return ta("only UnixFS data can be returned in a TAR file");e.reqFormat="tar",e.query.download=!0,e.query.filename=e.query.filename??`${c.toString()}.tar`;let l=a(c,i,o?.session,o),u=Tm(cF(`/ipfs/${t}/${n}`,l,o));e.byteRangeContext.setBody(u);let f=cn(i,e.byteRangeContext.getBody(),{byteRangeContext:e.byteRangeContext,log:this.log});return f.headers.set("content-type","application/x-tar"),f.headers.set("etag",mh({cid:c,reqFormat:e.reqFormat,weak:!0})),f}};function lF(r){let e=rte(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function rte(r){return r.replace(/[^\x00-\x7F]/g,"_")}var nte={[Pn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[qo]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[Lo]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[ct]:["application/octet-stream","application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"],[vt]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.dag-json","application/vnd.ipld.car","application/x-tar"]};function uF(r,e){let t=nte[r.code];if(e!=null)return ite(e,t)}function ite(r,e){let t=r.split(",").map(n=>{let i=n.trim().split(";");return{mimeType:`${i[0]}`.trim(),weight:ote(i[1])}}).sort((n,i)=>n.weight===i.weight?0:n.weight>i.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let i of e)if(n.includes(i)||n==="*/*"||n.startsWith("*/")&&i.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&i.split("/")[0]===n.split("/")[0])return i}function ote(r){if(r!=null&&(r=r.trim()),r?.startsWith("q=")!==!0)return 1;let e=parseFloat(r.replace("q=",""));return isNaN(e)?0:e}var f8={raw:"application/vnd.ipld.raw",car:"application/vnd.ipld.car","dag-json":"application/vnd.ipld.dag-json","dag-cbor":"application/vnd.ipld.dag-cbor",json:"application/json",cbor:"application/cbor","ipns-record":"application/vnd.ipfs.ipns-record",tar:"application/x-tar"};function fF(r){if(r!=null)return f8[r]}function pS(r){let e=r.get("accept");return!!(e!=null&&Object.values(f8).includes(e))}function mS(r){let e=r?.format;return!!(e!=null&&Object.keys(f8).includes(e))}function dF({query:r,headers:e}){return pS(e)||mS(r)}function hF({query:r,headers:e,logger:t}){let n=t.forComponent("helia:verified-fetch:get-resolved-accept-header"),i=new Headers(e),o=i.get("accept")??void 0;if(o!=null&&n('incoming accept header "%s"',o),!dF({query:r,headers:i}))return n("no explicit IPLD content-type requested, returning incoming accept header %s",o),o;let s=fF(r?.format);r?.format!=null&&n('incoming query format "%s", mapped to %s',r.format,s);let a=o;return!pS(i)&&mS(r)&&(n("accept header not recognized, but query format provided, setting accept header to %s",s),a=s),n('resolved accept header to "%s"',a),a}async function qm(r,e,t){let n=performance.now();try{let i=await t(),s=(performance.now()-n).toFixed(1),a=`${r};dur=${s};desc="${e}"`;return{result:i,header:a,error:null}}catch(i){let s=(performance.now()-n).toFixed(1),a=`${r};dur=${s};desc="${e}"`;return{result:null,error:i,header:a}}}var pF=it(y7(),1),d8=class{lru;constructor(e){this.lru=(0,pF.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var mF=new d8(1e3),ste=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,ate=/^\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,cte=/^https?:\/\/(.*[^/])\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,lte=/^https?:\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\.(?<protocol>ip[fn]s)\.([^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/;function ute(r){let e=r?.protocol;if(e==null)return!1;let t=r?.cidOrPeerIdOrDnsLink;if(t==null)return!1;let n=r?.path,i=r?.queryString;return["ipns","ipfs"].includes(e)&&typeof t=="string"&&(n==null||typeof n=="string")&&(i==null||typeof i=="string")}function jm(r){for(let e of[lte,ste,cte,ate]){let t=r.match(e);if(ute(t?.groups))return t.groups}throw new TypeError(`Invalid URL: ${r}, please use ipfs://, ipns://, or gateway URLs only`)}function fte(r){if(r==null)return;let e=r.answer?.TTL,t=r.record?.ttl,n=t!=null?Number(t/BigInt(1e9)):void 0;return e??n}var dte=/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;function hte(r){return dte.test(r)&&r.includes("-")&&!r.includes(".")}function pte(r){return r.replace(/--/g,"%").replace(/-/g,".").replace(/%/g,"-")}async function gF({urlString:r,ipns:e,logger:t,withServerTiming:n=!1},i){let o=t.forComponent("helia:verified-fetch:parse-url-string"),{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:l}=jm(r),u,f,h=[],d,m=[];if(s==="ipfs")try{u=W.parse(a)}catch(x){o.error(x),h.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else if(d=mF.get(a),d!=null)u=d.cid,f=d.path,o.trace("resolved %s to %c from cache",a,u);else{o.trace("Attempting to resolve PeerId for %s",a);let x;try{x=i8(a);let v=x?.publicKey;if(v==null)throw new TypeError("cidOrPeerIdOrDnsLink contains no public key");if(n){let b=async()=>e.resolve(v,i),S=await qm("ipns.resolve",`Resolve IPNS name ${a}`,b);if(m.push(S),S.error!=null)throw S.error;d=S.result}else d=await e.resolve(v,i);u=d?.cid,f=d?.path,o.trace("resolved %s to %c",a,u)}catch(v){i?.signal?.throwIfAborted(),x==null?(o.error('could not parse PeerId string "%s"',a,v),h.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${v.message}`))):(o.error("could not resolve PeerId %c",x,v),h.push(new TypeError(`Could not resolve PeerId "${a}": ${v.message}`)))}if(u==null){let v=a;hte(a)&&(v=pte(a),o.trace('decoded dnslink from "%s" to "%s"',a,v)),o.trace("Attempting to resolve DNSLink for %s",v);try{if(n){let b=await qm("ipns.resolveDNSLink",`Resolve DNSLink ${v}`,e.resolveDNSLink.bind(e,v,i));if(m.push(b),b.error!=null)throw b.error;d=b.result}else d=await e.resolveDNSLink(v,i);u=d?.cid,f=d?.path,o.trace("resolved %s to %c",v,u)}catch(b){i?.signal?.throwIfAborted(),o.error('could not resolve DnsLink for "%s"',a,b),h.push(b)}}}if(u==null)throw h.length===1?h[0]:(h.push(new Error(`Invalid resource. Cannot determine CID from URL "${r}".`)),h);let g=fte(d);d!=null&&(g=g??60*2,o.trace("caching %s resolved to %s with TTL: %s",a,u,g),mF.set(a,d,g*1e3));let w={};if(l!=null&&l.length>0){let x=l.split("&");for(let v of x){let[b,S]=v.split("=");w[b]=decodeURIComponent(S)}w.download!=null&&(w.download=w.download==="true"),w.filename!=null&&(w.filename=w.filename.toString())}return{protocol:s,cid:u,path:mte(f,c??""),query:w,ttl:g,ipfsPath:`/${s}/${a}${c!=null&&c!==""?`/${c}`:""}`,serverTimings:m}}function mte(r,e){let t="";return r!=null&&(t+=r),e.length>0&&(t=`${t.length>0?`${t}/`:t}${e}`),t=t.replace(/\/(\/)+/g,"/"),t.startsWith("/")&&(t=t.substring(1)),t.split("/").map(decodeURIComponent).join("/")}function yF(r){return r.match(/\.[a-zA-Z0-9]{1,4}$/)!=null||r.endsWith("/")?r:`${r}/`}async function wF({resource:r,options:e,logger:t,cid:n,fetch:i=globalThis.fetch}){let o=t.forComponent("helia:verified-fetch:get-redirect-response");if(typeof r!="string"||e==null||["ipfs://","ipns://"].some(u=>r.startsWith(u)))return null;let s=new Headers(e?.headers),a=s.get("x-forwarded-host"),c=s.get("host");if(s.get("x-forwarded-for")==null&&a==null&&c==null)return o.trace("no redirect info found in headers"),null;o.trace("checking for redirect info");try{let u=jm(r),f=new URL(r),h=a??f.host,d=new URL(f);if(u.protocol==="ipfs"&&n.version===0?d.host=`${n.toV1()}.ipfs.${h}`:d.host=`${u.cidOrPeerIdOrDnsLink}.${u.protocol}.${h}`,c?.includes(u.protocol)===!0&&d.host.includes(c))return o.trace("request was for a subdomain already, not setting location header"),null;if(c!=null&&!d.host.includes(c))return o.trace("host header is not the same as the subdomain url host, not setting location header"),null;if(f.host===d.host)return o.trace("req url is the same as the subdomain url, not setting location header"),null;d.pathname=yF(f.pathname.replace(`/${u.cidOrPeerIdOrDnsLink}`,"").replace(`/${u.protocol}`,"")),o.trace("subdomain url %s",d.href);let m=new URL(f,`${f.protocol}//${h}`);m.pathname=yF(f.pathname),o.trace("path url %s",m.href);try{let g=await i(d,{method:"HEAD"});if(g.ok)return o("subdomain supported, redirecting to subdomain"),km(r.toString(),d.href);throw o("subdomain not supported, subdomain failed with status %s %s",g.status,g.statusText),new a5("subdomain not supported")}catch(g){return o("subdomain not supported",g),m.href===f.href?(o("path url is the same as the request url, not setting location header"),null):km(r.toString(),m.href)}}catch(u){o.error("error setting location header for x-forwarded-host",u)}return null}async function xF(r,{ipns:e,logger:t},{withServerTiming:n=!1,...i}={withServerTiming:!1}){if(typeof r=="string")return gF({urlString:r,ipns:e,logger:t,withServerTiming:n},i);let o=W.asCID(r);if(o!=null)return{cid:o,protocol:"ipfs",path:"",query:{},ipfsPath:`/ipfs/${o.toString()}`,ttl:29030400,serverTimings:[]};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function bF(r){let e=W.asCID(r);if(e!=null)return`ipfs://${e}`;try{return`ipfs://${W.parse(r.toString())}`}catch{}let{protocol:t,cidOrPeerIdOrDnsLink:n}=jm(r.toString());return`${t}://${n}`}var gte=100,yte=60*1e3;function wte(r){if(r==null)return;let e;return r?.signal===null?e=void 0:e=r?.signal,{...r,signal:e}}var h8=class{helia;ipns;log;contentTypeParser;blockstoreSessions;serverTimingHeaders=[];withServerTiming;plugins=[];constructor({helia:e,ipns:t},n){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??LC(e),this.contentTypeParser=n?.contentTypeParser??ZU,this.blockstoreSessions=new o5({max:n?.sessionCacheSize??gte,ttl:n?.sessionTTLms??yte,dispose:a=>{a.close()}}),this.withServerTiming=n?.withServerTiming??!1;let i={...n,logger:H_("helia:verified-fetch"),getBlockstore:(a,c,l,u)=>this.getBlockstore(a,c,l,u),handleServerTiming:async(a,c,l)=>this.handleServerTiming(a,c,l,this.withServerTiming),helia:e,contentTypeParser:this.contentTypeParser},o=[new n8(i),new u5(i),new o8(i),new y5(i),new a8(i),new u8(i),new s8(i),new P5(i),new r8(i)],s=n?.plugins?.map(a=>a(i))??[];if(s.length>0){let a=new Map(o.map(l=>[l.constructor.name,l])),c=new Map(s.map(l=>[l.constructor.name,l]));this.plugins=o.map(l=>c.get(l.constructor.name)??l),this.plugins.push(...s.filter(l=>!a.has(l.constructor.name)))}else this.plugins=o;this.log.trace("created VerifiedFetch instance")}getBlockstore(e,t,n=!0,i={}){let o=bF(t);if(!n)return this.helia.blockstore;let s=this.blockstoreSessions.get(o);return s==null&&(s=this.helia.blockstore.createSession(e,i),this.blockstoreSessions.set(o,s)),s}async handleServerTiming(e,t,n,i){if(!i)return n();let{error:o,result:s,header:a}=await qm(e,t,n);if(this.serverTimingHeaders.push(a),o!=null)throw o;return s}handleFinalResponse(e,{query:t,cid:n,reqFormat:i,ttl:o,protocol:s,ipfsPath:a,pathDetails:c,byteRangeContext:l}={}){if(this.serverTimingHeaders.length>0){let f=this.serverTimingHeaders.join(", ");e.headers.set("Server-Timing",f),this.serverTimingHeaders=[]}if(e.headers.get("Transfer-Encoding")!=="chunked"&&l!=null){let f=l.length;f!=null&&(this.log.trace("Setting Content-Length from byteRangeContext: %d",f),e.headers.set("Content-Length",f.toString()))}let u;return this.log.trace("checking for content disposition"),t?.download===!0?u="attachment":this.log.trace("download not requested"),t?.filename!=null?(u==null&&(u="inline"),u=`${u}; ${lF(t.filename)}`):this.log.trace("no filename specified in query"),u!=null?e.headers.set("Content-Disposition",u):this.log.trace("no content disposition specified"),n!=null&&e.headers.get("etag")==null&&e.headers.set("etag",mh({cid:c?.terminalElement.cid??n,reqFormat:i,weak:!1})),s!=null&&FB({response:e,ttl:o,protocol:s}),a!=null&&e.headers.set("X-Ipfs-Path",a),e.headers.set("Access-Control-Allow-Origin","*"),e.headers.set("Access-Control-Allow-Methods","GET, HEAD, OPTIONS"),e.headers.set("Access-Control-Allow-Headers","Range, X-Requested-With"),e.headers.set("Access-Control-Expose-Headers","Content-Range, Content-Length, X-Ipfs-Path, X-Stream-Output"),i!=="car"?e.headers.set("Accept-Ranges","bytes"):e.headers.set("Accept-Ranges","none"),e}async runPluginPipeline(e,t=3){let n,i=0,o=new Set,s=e.modified;for(;i<t;){this.log(`Starting pipeline pass #${i+1}`),i++;let a=this.plugins.filter(u=>!o.has(u.constructor.name)).filter(u=>u.canHandle(e));if(a.length===0){this.log.trace("No plugins can handle the current context.. checking by CID code");let u=this.plugins.filter(f=>f.codes.includes(e.cid.code));if(u.length>0)a.push(...u);else{this.log.trace("No plugins found that can handle request by CID code; exiting pipeline.");break}}this.log.trace("Plugins ready to handle request: ",a.map(u=>u.constructor.name).join(", "));let c=!1,l=!1;for(let u of a){try{this.log.trace("Invoking plugin:",u.constructor.name),o.add(u.constructor.name);let f=await u.handle(e);if(f!=null){n=f,l=!0;break}}catch(f){if(e.options?.signal?.throwIfAborted(),this.log.error("Error in plugin:",u.constructor.name,f),f.name==="PluginFatalError")return f.response??Qd(e.resource,"Failed to fetch")}finally{let f=e.modified;c=f!==s,c&&(s=f)}if(n!=null){this.log.trace("Plugin produced final response:",u.constructor.name);break}}if(l&&n!=null)break;if(!c){this.log.trace("No context changes and no final response; exiting pipeline.");break}}return n}async fetch(e,t){this.log("fetch %s",e);let n=wte(t),i=n?.withServerTiming??this.withServerTiming;n?.onProgress?.(new G("verified-fetch:request:start",{resource:e}));let o;try{o=await this.handleServerTiming("parse-resource","",async()=>xF(e,{ipns:this.ipns,logger:this.helia.logger},{withServerTiming:i,...n}),i),this.serverTimingHeaders.push(...o.serverTimings.map(({header:h})=>h))}catch(h){return n?.signal?.throwIfAborted(),this.log.error("error parsing resource %s",e,h),this.handleFinalResponse(Cm(e.toString(),h))}n?.onProgress?.(new G("verified-fetch:request:resolve",{cid:o.cid,path:o.path}));let s=hF({query:o.query,headers:n?.headers,logger:this.helia.logger}),a=uF(o.cid,s);if(this.log("output type %s",a),s!=null&&a==null)return this.handleFinalResponse(ta(e.toString()));let c=a?.split(";")[0]??"application/octet-stream",l=await wF({resource:e,options:n,logger:this.helia.logger,cid:o.cid});if(l!=null)return this.handleFinalResponse(l);let u={...o,resource:e.toString(),accept:a,options:n,withServerTiming:i,onProgress:n?.onProgress,modified:0};this.log.trace('finding handler for cid code "%s" and response content type "%s"',o.cid.code,c);let f=await this.runPluginPipeline(u);return n?.onProgress?.(new G("verified-fetch:request:end",{cid:o.cid,path:o.path})),this.handleFinalResponse(f??m5(e.toString()),u)}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};var Wm,p8=async function(e,t){return Wm==null&&(Wm=await gS()),Wm(e,t)};p8.start=async function(){await Wm?.start()};p8.stop=async function(){await Wm?.stop()};function xte(r){return"ipfs-_blank"}function bte(r,e){let t=e.globalData.gatewayURLWithoutSubdomain.host;return`<a class="ipfs-hash" translate="no" href="${e.globalData.gatewayURLWithoutSubdomain.protocol}//${t}/ipfs/${r.hash}?filename=${r.name}">${r.shortHash}</a>`}function vte(r){let e=r.split("."),t=[];for(let n=e.length-1;n>=0;n--){let i=e[n];if(i==="ipfs"||i==="ipns")break;t.push(i)}return t.reverse(),t.join(".")}function Ete(r){let e;try{e=new URL(r)}catch{e=new URL("https://inbrowser.link")}return e.host=vte(e.host),e}function Ste(r){return r.path!=null?`Index of <a href="${`${r.globalData.gatewayURL}/${r.path}`}">${r.name}</a>`:`Index of ${r.name} ${r.path}`}function Ate(r){return r.listing.map(e=>`<div class="type-icon">
|
|
86
|
+
`));return O(e)}function c8(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),O(t).byteLength!==t.length)return null;for(;O(t).byteLength>100;){let i=t.indexOf("/");if(i===-1)return null;n+=n!==""?"/"+t.slice(0,i):t.slice(0,i),t=t.slice(i+1)}return O(t).byteLength>100||O(n).byteLength>155||r.linkname!=null&&O(r.linkname).byteLength>100?null:(e.set(O(t),0),e.set(_c(r.mode&Uee,6),100),e.set(_c(r.uid,6),108),e.set(_c(r.gid,6),116),e.set(_c(r.size,11),124),e.set(_c(r.mtime.getTime()/1e3|0,11),136),e[156]=Lee+Hee(r.type),r.linkname!=null&&e.set(O(r.linkname),157),e.set(Bee,Fee),e.set(Mee,$ee),r.uname!=null&&e.set(O(r.uname),265),r.gname!=null&&e.set(O(r.gname),297),e.set(_c(r.devmajor??0,6),329),e.set(_c(r.devminor??0,6),337),n!=null&&e.set(O(n),345),e.set(_c(Vee(e),6),148),e)}var{S_IFMT:Kee,S_IFBLK:qee,S_IFCHR:jee,S_IFDIR:Wee,S_IFIFO:Gee,S_IFLNK:Xee}=oF.default,Yee=parseInt("755",8),Qee=parseInt("644",8),sF=new Uint8Array(1024);function Zee(r=0){switch(r&Kee){case qee:return"block-device";case jee:return"character-device";case Wee:return"directory";case Gee:return"fifo";case Xee:return"symlink";default:return"file"}}function hS(r){return r&=511,r!==0?sF.subarray(0,512-r):new Uint8Array(0)}function dS(r){if(r.pax==null){let e=c8(r);if(e!=null)return e}return Jee(r)}function Jee(r){let e=iF(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new oe(c8(t)??new Uint8Array(0),e,hS(e.length),c8({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function l8(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??Zee(e.mode),mode:e.mode??(e.type==="directory"?Yee:Qee),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=O(t)),t instanceof Uint8Array||vi(t)){n.size=t.length,yield dS(n),yield vi(t)?t.subarray():t,yield hS(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=H(await nF(t)),yield dS(n);continue}if(yield dS(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let i=0;for await(let o of t??[])i+=o.length,yield vi(o)?o.subarray():o;if(i!==n.size)throw new Error(`size mismatch, wrote ${i} of ${n.size} bytes`);yield hS(n.size)}yield sF}}var ete=["file","raw","directory"];function tte(r){let e,t;return(r.type==="file"||r.type==="directory")&&(e=r.unixfs.mode,t=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:r.path,mode:e,mtime:t,size:Number(r.size),type:r.type==="directory"?"directory":"file"}}function aF(r){if(!ete.includes(r.type))throw new gi(`${r.type} is not a UnixFS node`);let e={header:tte(r)};return(r.type==="file"||r.type==="raw")&&(e.body=r.content()),e}async function*cF(r,e,t){let n=await pr(r,e,t);if(n.type==="file"||n.type==="raw"){yield*ot([aF(n)],l8());return}if(n.type==="directory"){yield*ot(ih(r,e,t),i=>Nt(i,o=>aF(o)),l8());return}throw new gi("Not a UnixFS node")}var u8=class extends Mt{codes=[];canHandle({cid:e,accept:t,query:n,byteRangeContext:i}){return this.log("checking if we can handle %c with accept %s",e,t),i==null?!1:t==="application/x-tar"||n.format==="tar"}async handle(e){let{cid:t,path:n,resource:i,options:o,pathDetails:s}=e,{getBlockstore:a}=this.pluginOptions,c=s?.terminalElement.cid??t;if(c.code!==ct&&c.code!==vt)return ta("only UnixFS data can be returned in a TAR file");e.reqFormat="tar",e.query.download=!0,e.query.filename=e.query.filename??`${c.toString()}.tar`;let l=a(c,i,o?.session,o),u=Tm(cF(`/ipfs/${t}/${n}`,l,o));e.byteRangeContext.setBody(u);let f=cn(i,e.byteRangeContext.getBody(),{byteRangeContext:e.byteRangeContext,log:this.log});return f.headers.set("content-type","application/x-tar"),f.headers.set("etag",mh({cid:c,reqFormat:e.reqFormat,weak:!0})),f}};function lF(r){let e=rte(r);return e===r?`filename="${r}"`:`filename="${e}"; filename*=UTF-8''${encodeURIComponent(r)}`}function rte(r){return r.replace(/[^\x00-\x7F]/g,"_")}var nte={[Pn]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[qo]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[Lo]:["application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car"],[ct]:["application/octet-stream","application/json","application/vnd.ipld.dag-cbor","application/cbor","application/vnd.ipld.dag-json","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.car","application/x-tar"],[vt]:["application/octet-stream","application/vnd.ipld.raw","application/vnd.ipfs.ipns-record","application/vnd.ipld.dag-json","application/vnd.ipld.car","application/x-tar"]};function uF(r,e){let t=nte[r.code];if(e!=null)return ite(e,t)}function ite(r,e){let t=r.split(",").map(n=>{let i=n.trim().split(";");return{mimeType:`${i[0]}`.trim(),weight:ote(i[1])}}).sort((n,i)=>n.weight===i.weight?0:n.weight>i.weight?-1:1).map(n=>n.mimeType);for(let n of t)for(let i of e)if(n.includes(i)||n==="*/*"||n.startsWith("*/")&&i.split("/")[1]===n.split("/")[1]||n.endsWith("/*")&&i.split("/")[0]===n.split("/")[0])return i}function ote(r){if(r!=null&&(r=r.trim()),r?.startsWith("q=")!==!0)return 1;let e=parseFloat(r.replace("q=",""));return isNaN(e)?0:e}var f8={raw:"application/vnd.ipld.raw",car:"application/vnd.ipld.car","dag-json":"application/vnd.ipld.dag-json","dag-cbor":"application/vnd.ipld.dag-cbor",json:"application/json",cbor:"application/cbor","ipns-record":"application/vnd.ipfs.ipns-record",tar:"application/x-tar"};function fF(r){if(r!=null)return f8[r]}function pS(r){let e=r.get("accept");return!!(e!=null&&Object.values(f8).includes(e))}function mS(r){let e=r?.format;return!!(e!=null&&Object.keys(f8).includes(e))}function dF({query:r,headers:e}){return pS(e)||mS(r)}function hF({query:r,headers:e,logger:t}){let n=t.forComponent("helia:verified-fetch:get-resolved-accept-header"),i=new Headers(e),o=i.get("accept")??void 0;if(o!=null&&n('incoming accept header "%s"',o),!dF({query:r,headers:i}))return n("no explicit IPLD content-type requested, returning incoming accept header %s",o),o;let s=fF(r?.format);r?.format!=null&&n('incoming query format "%s", mapped to %s',r.format,s);let a=o;return!pS(i)&&mS(r)&&(n("accept header not recognized, but query format provided, setting accept header to %s",s),a=s),n('resolved accept header to "%s"',a),a}async function qm(r,e,t){let n=performance.now();try{let i=await t(),s=(performance.now()-n).toFixed(1),a=`${r};dur=${s};desc="${e}"`;return{result:i,header:a,error:null}}catch(i){let s=(performance.now()-n).toFixed(1),a=`${r};dur=${s};desc="${e}"`;return{result:null,error:i,header:a}}}var pF=it(y7(),1),d8=class{lru;constructor(e){this.lru=(0,pF.default)(e)}get(e){let t=this.lru.get(e);if(t!=null){if(t.expire!=null&&t.expire<Date.now()){this.lru.remove(e);return}return t.value}}set(e,t,n){this.lru.set(e,{value:t,expire:Date.now()+n})}has(e){return this.get(e)!=null}remove(e){this.lru.remove(e)}clear(){this.lru.clear()}};var mF=new d8(1e3),ste=/^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,ate=/^\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,cte=/^https?:\/\/(.*[^/])\/(?<protocol>ip[fn]s)\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/,lte=/^https?:\/\/(?<cidOrPeerIdOrDnsLink>[^/?]+)\.(?<protocol>ip[fn]s)\.([^/?]+)\/?(?<path>[^?]*)\??(?<queryString>.*)$/;function ute(r){let e=r?.protocol;if(e==null)return!1;let t=r?.cidOrPeerIdOrDnsLink;if(t==null)return!1;let n=r?.path,i=r?.queryString;return["ipns","ipfs"].includes(e)&&typeof t=="string"&&(n==null||typeof n=="string")&&(i==null||typeof i=="string")}function jm(r){for(let e of[lte,ste,cte,ate]){let t=r.match(e);if(ute(t?.groups))return t.groups}throw new TypeError(`Invalid URL: ${r}, please use ipfs://, ipns://, or gateway URLs only`)}function fte(r){if(r==null)return;let e=r.answer?.TTL,t=r.record?.ttl,n=t!=null?Number(t/BigInt(1e9)):void 0;return e??n}var dte=/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;function hte(r){return dte.test(r)&&r.includes("-")&&!r.includes(".")}function pte(r){return r.replace(/--/g,"%").replace(/-/g,".").replace(/%/g,"-")}async function gF({urlString:r,ipns:e,logger:t,withServerTiming:n=!1},i){let o=t.forComponent("helia:verified-fetch:parse-url-string"),{protocol:s,cidOrPeerIdOrDnsLink:a,path:c,queryString:l}=jm(r),u,f,h=[],d,m=[];if(s==="ipfs")try{u=W.parse(a)}catch(x){o.error(x),h.push(new TypeError("Invalid CID for ipfs://<cid> URL"))}else if(d=mF.get(a),d!=null)u=d.cid,f=d.path,o.trace("resolved %s to %c from cache",a,u);else{o.trace("Attempting to resolve PeerId for %s",a);let x;try{x=i8(a);let v=x?.publicKey;if(v==null)throw new TypeError("cidOrPeerIdOrDnsLink contains no public key");if(n){let b=async()=>e.resolve(v,i),S=await qm("ipns.resolve",`Resolve IPNS name ${a}`,b);if(m.push(S),S.error!=null)throw S.error;d=S.result}else d=await e.resolve(v,i);u=d?.cid,f=d?.path,o.trace("resolved %s to %c",a,u)}catch(v){i?.signal?.throwIfAborted(),x==null?(o.error('could not parse PeerId string "%s"',a,v),h.push(new TypeError(`Could not parse PeerId in ipns url "${a}", ${v.message}`))):(o.error("could not resolve PeerId %c",x,v),h.push(new TypeError(`Could not resolve PeerId "${a}": ${v.message}`)))}if(u==null){let v=a;hte(a)&&(v=pte(a),o.trace('decoded dnslink from "%s" to "%s"',a,v)),o.trace("Attempting to resolve DNSLink for %s",v);try{if(n){let b=await qm("ipns.resolveDNSLink",`Resolve DNSLink ${v}`,e.resolveDNSLink.bind(e,v,i));if(m.push(b),b.error!=null)throw b.error;d=b.result}else d=await e.resolveDNSLink(v,i);u=d?.cid,f=d?.path,o.trace("resolved %s to %c",v,u)}catch(b){i?.signal?.throwIfAborted(),o.error('could not resolve DnsLink for "%s"',a,b),h.push(b)}}}if(u==null)throw h.length===1?h[0]:(h.push(new Error(`Invalid resource. Cannot determine CID from URL "${r}".`)),h);let g=fte(d);d!=null&&(g=g??60*2,o.trace("caching %s resolved to %s with TTL: %s",a,u,g),mF.set(a,d,g*1e3));let w={};if(l!=null&&l.length>0){let x=l.split("&");for(let v of x){let[b,S]=v.split("=");w[b]=decodeURIComponent(S)}w.download!=null&&(w.download=w.download==="true"),w.filename!=null&&(w.filename=w.filename.toString())}return{protocol:s,cid:u,path:mte(f,c??""),query:w,ttl:g,ipfsPath:`/${s}/${a}${c!=null&&c!==""?`/${c}`:""}`,serverTimings:m}}function mte(r,e){let t="";return r!=null&&(t+=r),e.length>0&&(t=`${t.length>0?`${t}/`:t}${e}`),t=t.replace(/\/(\/)+/g,"/"),t.startsWith("/")&&(t=t.substring(1)),t.split("/").map(decodeURIComponent).join("/")}function yF(r){return r.match(/\.[a-zA-Z0-9]{1,4}$/)!=null||r.endsWith("/")?r:`${r}/`}async function wF({resource:r,options:e,logger:t,cid:n,fetch:i=globalThis.fetch}){let o=t.forComponent("helia:verified-fetch:get-redirect-response");if(typeof r!="string"||e==null||["ipfs://","ipns://"].some(u=>r.startsWith(u)))return null;let s=new Headers(e?.headers),a=s.get("x-forwarded-host"),c=s.get("host");if(s.get("x-forwarded-for")==null&&a==null&&c==null)return o.trace("no redirect info found in headers"),null;o.trace("checking for redirect info");try{let u=jm(r),f=new URL(r),h=a??f.host,d=new URL(f);if(u.protocol==="ipfs"&&n.version===0?d.host=`${n.toV1()}.ipfs.${h}`:d.host=`${u.cidOrPeerIdOrDnsLink}.${u.protocol}.${h}`,c?.includes(u.protocol)===!0&&d.host.includes(c))return o.trace("request was for a subdomain already, not setting location header"),null;if(c!=null&&!d.host.includes(c))return o.trace("host header is not the same as the subdomain url host, not setting location header"),null;if(f.host===d.host)return o.trace("req url is the same as the subdomain url, not setting location header"),null;d.pathname=yF(f.pathname.replace(`/${u.cidOrPeerIdOrDnsLink}`,"").replace(`/${u.protocol}`,"")),o.trace("subdomain url %s",d.href);let m=new URL(f,`${f.protocol}//${h}`);m.pathname=yF(f.pathname),o.trace("path url %s",m.href);try{let g=await i(d,{method:"HEAD"});if(g.ok)return o("subdomain supported, redirecting to subdomain"),km(r.toString(),d.href);throw o("subdomain not supported, subdomain failed with status %s %s",g.status,g.statusText),new a5("subdomain not supported")}catch(g){return o("subdomain not supported",g),m.href===f.href?(o("path url is the same as the request url, not setting location header"),null):km(r.toString(),m.href)}}catch(u){o.error("error setting location header for x-forwarded-host",u)}return null}async function xF(r,{ipns:e,logger:t},{withServerTiming:n=!1,...i}={withServerTiming:!1}){if(typeof r=="string")return gF({urlString:r,ipns:e,logger:t,withServerTiming:n},i);let o=W.asCID(r);if(o!=null)return{cid:o,protocol:"ipfs",path:"",query:{},ipfsPath:`/ipfs/${o.toString()}`,ttl:29030400,serverTimings:[]};throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${r}`)}function bF(r){let e=W.asCID(r);if(e!=null)return`ipfs://${e}`;try{return`ipfs://${W.parse(r.toString())}`}catch{}let{protocol:t,cidOrPeerIdOrDnsLink:n}=jm(r.toString());return`${t}://${n}`}var gte=100,yte=60*1e3;function wte(r){if(r==null)return;let e;return r?.signal===null?e=void 0:e=r?.signal,{...r,signal:e}}var h8=class{helia;ipns;log;contentTypeParser;blockstoreSessions;serverTimingHeaders=[];withServerTiming;plugins=[];constructor({helia:e,ipns:t},n){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipns=t??LC(e),this.contentTypeParser=n?.contentTypeParser??ZU,this.blockstoreSessions=new o5({max:n?.sessionCacheSize??gte,ttl:n?.sessionTTLms??yte,dispose:a=>{a.close()}}),this.withServerTiming=n?.withServerTiming??!1;let i={...n,logger:H_("helia:verified-fetch"),getBlockstore:(a,c,l,u)=>this.getBlockstore(a,c,l,u),handleServerTiming:async(a,c,l)=>this.handleServerTiming(a,c,l,this.withServerTiming),helia:e,contentTypeParser:this.contentTypeParser},o=[new n8(i),new u5(i),new o8(i),new y5(i),new a8(i),new u8(i),new s8(i),new P5(i),new r8(i)],s=n?.plugins?.map(a=>a(i))??[];if(s.length>0){let a=new Map(o.map(l=>[l.constructor.name,l])),c=new Map(s.map(l=>[l.constructor.name,l]));this.plugins=o.map(l=>c.get(l.constructor.name)??l),this.plugins.push(...s.filter(l=>!a.has(l.constructor.name)))}else this.plugins=o;this.log.trace("created VerifiedFetch instance")}getBlockstore(e,t,n=!0,i={}){let o=bF(t);if(!n)return this.helia.blockstore;let s=this.blockstoreSessions.get(o);return s==null&&(s=this.helia.blockstore.createSession(e,i),this.blockstoreSessions.set(o,s)),s}async handleServerTiming(e,t,n,i){if(!i)return n();let{error:o,result:s,header:a}=await qm(e,t,n);if(this.serverTimingHeaders.push(a),o!=null)throw o;return s}handleFinalResponse(e,{query:t,cid:n,reqFormat:i,ttl:o,protocol:s,ipfsPath:a,pathDetails:c,byteRangeContext:l}={}){if(this.serverTimingHeaders.length>0){let f=this.serverTimingHeaders.join(", ");e.headers.set("Server-Timing",f),this.serverTimingHeaders=[]}if(e.headers.get("Transfer-Encoding")!=="chunked"&&l!=null){let f=l.length;f!=null&&(this.log.trace("Setting Content-Length from byteRangeContext: %d",f),e.headers.set("Content-Length",f.toString()))}let u;return this.log.trace("checking for content disposition"),t?.download===!0?u="attachment":this.log.trace("download not requested"),t?.filename!=null?(u==null&&(u="inline"),u=`${u}; ${lF(t.filename)}`):this.log.trace("no filename specified in query"),u!=null?e.headers.set("Content-Disposition",u):this.log.trace("no content disposition specified"),n!=null&&e.headers.get("etag")==null&&e.headers.set("etag",mh({cid:c?.terminalElement.cid??n,reqFormat:i,weak:!1})),s!=null&&FB({response:e,ttl:o,protocol:s}),a!=null&&e.headers.set("X-Ipfs-Path",a),e.headers.set("Access-Control-Allow-Origin","*"),e.headers.set("Access-Control-Allow-Methods","GET, HEAD, OPTIONS"),e.headers.set("Access-Control-Allow-Headers","Range, X-Requested-With"),e.headers.set("Access-Control-Expose-Headers","Content-Range, Content-Length, X-Ipfs-Path, X-Stream-Output"),i!=="car"?e.headers.set("Accept-Ranges","bytes"):e.headers.set("Accept-Ranges","none"),e}async runPluginPipeline(e,t=3){let n,i=0,o=new Set,s=e.modified;for(;i<t;){this.log(`Starting pipeline pass #${i+1}`),i++;let a=this.plugins.filter(u=>!o.has(u.constructor.name)).filter(u=>u.canHandle(e));if(a.length===0){this.log.trace("No plugins can handle the current context.. checking by CID code");let u=this.plugins.filter(f=>f.codes.includes(e.cid.code));if(u.length>0)a.push(...u);else{this.log.trace("No plugins found that can handle request by CID code; exiting pipeline.");break}}this.log.trace("Plugins ready to handle request: ",a.map(u=>u.constructor.name).join(", "));let c=!1,l=!1;for(let u of a){try{this.log.trace("Invoking plugin:",u.constructor.name),o.add(u.constructor.name);let f=await u.handle(e);if(f!=null){n=f,l=!0;break}}catch(f){if(e.options?.signal?.throwIfAborted(),this.log.error("Error in plugin:",u.constructor.name,f),f.name==="PluginFatalError")return f.response??Qd(e.resource,"Failed to fetch")}finally{let f=e.modified;c=f!==s,c&&(s=f)}if(n!=null){this.log.trace("Plugin produced final response:",u.constructor.name);break}}if(l&&n!=null)break;if(!c){this.log.trace("No context changes and no final response; exiting pipeline.");break}}return n}async fetch(e,t){if(this.log("fetch %s",e),t?.method==="OPTIONS")return this.handleFinalResponse(new Response(null,{status:200}));let n=wte(t),i=n?.withServerTiming??this.withServerTiming;n?.onProgress?.(new G("verified-fetch:request:start",{resource:e}));let o;try{o=await this.handleServerTiming("parse-resource","",async()=>xF(e,{ipns:this.ipns,logger:this.helia.logger},{withServerTiming:i,...n}),i),this.serverTimingHeaders.push(...o.serverTimings.map(({header:h})=>h))}catch(h){return n?.signal?.throwIfAborted(),this.log.error("error parsing resource %s",e,h),this.handleFinalResponse(Cm(e.toString(),h))}n?.onProgress?.(new G("verified-fetch:request:resolve",{cid:o.cid,path:o.path}));let s=hF({query:o.query,headers:n?.headers,logger:this.helia.logger}),a=uF(o.cid,s);if(this.log("output type %s",a),s!=null&&a==null)return this.handleFinalResponse(ta(e.toString()));let c=a?.split(";")[0]??"application/octet-stream",l=await wF({resource:e,options:n,logger:this.helia.logger,cid:o.cid});if(l!=null)return this.handleFinalResponse(l);let u={...o,resource:e.toString(),accept:a,options:n,withServerTiming:i,onProgress:n?.onProgress,modified:0};this.log.trace('finding handler for cid code "%s" and response content type "%s"',o.cid.code,c);let f=await this.runPluginPipeline(u);return n?.onProgress?.(new G("verified-fetch:request:end",{cid:o.cid,path:o.path})),this.handleFinalResponse(f??m5(e.toString()),u)}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};var Wm,p8=async function(e,t){return Wm==null&&(Wm=await gS()),Wm(e,t)};p8.start=async function(){await Wm?.start()};p8.stop=async function(){await Wm?.stop()};function xte(r){return"ipfs-_blank"}function bte(r,e){let t=e.globalData.gatewayURLWithoutSubdomain.host;return`<a class="ipfs-hash" translate="no" href="${e.globalData.gatewayURLWithoutSubdomain.protocol}//${t}/ipfs/${r.hash}?filename=${r.name}">${r.shortHash}</a>`}function vte(r){let e=r.split("."),t=[];for(let n=e.length-1;n>=0;n--){let i=e[n];if(i==="ipfs"||i==="ipns")break;t.push(i)}return t.reverse(),t.join(".")}function Ete(r){let e;try{e=new URL(r)}catch{e=new URL("https://inbrowser.link")}return e.host=vte(e.host),e}function Ste(r){return r.path!=null?`Index of <a href="${`${r.globalData.gatewayURL}/${r.path}`}">${r.name}</a>`:`Index of ${r.name} ${r.path}`}function Ate(r){return r.listing.map(e=>`<div class="type-icon">
|
|
87
87
|
<div class="${xte(e.name)}"> </div>
|
|
88
88
|
</div>
|
|
89
89
|
<div>
|