@helia/verified-fetch 1.3.14 → 1.4.0
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/README.md +9 -6
- package/dist/index.min.js +15 -15
- package/dist/src/index.d.ts +84 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/parse-url-string.d.ts +7 -0
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +1 -1
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/resource-to-cache-key.d.ts +15 -0
- package/dist/src/utils/resource-to-cache-key.d.ts.map +1 -0
- package/dist/src/utils/resource-to-cache-key.js +27 -0
- package/dist/src/utils/resource-to-cache-key.js.map +1 -0
- package/dist/src/verified-fetch.d.ts +4 -10
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +44 -14
- package/dist/src/verified-fetch.js.map +1 -1
- package/package.json +14 -14
- package/src/index.ts +99 -9
- package/src/utils/parse-url-string.ts +1 -1
- package/src/utils/resource-to-cache-key.ts +30 -0
- package/src/verified-fetch.ts +66 -26
package/dist/src/index.d.ts
CHANGED
|
@@ -90,22 +90,25 @@
|
|
|
90
90
|
*
|
|
91
91
|
* The [helia](https://www.npmjs.com/package/helia) module is configured with a libp2p node that is suited for decentralized applications, alternatively [@helia/http](https://www.npmjs.com/package/@helia/http) is available which uses HTTP gateways for all network operations.
|
|
92
92
|
*
|
|
93
|
-
*
|
|
93
|
+
* You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
|
|
94
94
|
*
|
|
95
95
|
* ```typescript
|
|
96
96
|
* import { trustlessGateway } from '@helia/block-brokers'
|
|
97
97
|
* import { createHeliaHTTP } from '@helia/http'
|
|
98
|
-
* import { delegatedHTTPRouting } from '@helia/routers'
|
|
98
|
+
* import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
|
|
99
99
|
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
100
100
|
*
|
|
101
101
|
* const fetch = await createVerifiedFetch(
|
|
102
102
|
* await createHeliaHTTP({
|
|
103
103
|
* blockBrokers: [
|
|
104
|
-
* trustlessGateway(
|
|
104
|
+
* trustlessGateway()
|
|
105
|
+
* ],
|
|
106
|
+
* routers: [
|
|
107
|
+
* delegatedHTTPRouting('http://delegated-ipfs.dev'),
|
|
108
|
+
* httpGatewayRouting({
|
|
105
109
|
* gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
|
|
106
110
|
* })
|
|
107
|
-
* ]
|
|
108
|
-
* routers: ['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl))
|
|
111
|
+
* ]
|
|
109
112
|
* })
|
|
110
113
|
* )
|
|
111
114
|
*
|
|
@@ -588,7 +591,7 @@
|
|
|
588
591
|
* 1. `TypeError` - If the resource argument is not a string, CID, or CID string.
|
|
589
592
|
* 2. `TypeError` - If the options argument is passed and not an object.
|
|
590
593
|
* 3. `TypeError` - If the options argument is passed and is malformed.
|
|
591
|
-
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal.
|
|
594
|
+
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
|
|
592
595
|
*/
|
|
593
596
|
import type { GetBlockProgressEvents, Helia } from '@helia/interface';
|
|
594
597
|
import type { ResolveDNSLinkProgressEvents } from '@helia/ipns';
|
|
@@ -634,6 +637,29 @@ export interface CreateVerifiedFetchInit {
|
|
|
634
637
|
* @default [dnsJsonOverHttps('https://cloudflare-dns.com/dns-query'),dnsJsonOverHttps('https://dns.google/resolve')]
|
|
635
638
|
*/
|
|
636
639
|
dnsResolvers?: DNSResolver[] | DNSResolvers;
|
|
640
|
+
/**
|
|
641
|
+
* By default we will not connect to any HTTP Gateways providers over local or
|
|
642
|
+
* loopback addresses, this is because they are typically running on remote
|
|
643
|
+
* peers that have published private addresses by mistate.
|
|
644
|
+
*
|
|
645
|
+
* Pass `true` here to connect to local Gateways as well, this may be useful
|
|
646
|
+
* in testing environments.
|
|
647
|
+
*
|
|
648
|
+
* @default false
|
|
649
|
+
*/
|
|
650
|
+
allowLocal?: boolean;
|
|
651
|
+
/**
|
|
652
|
+
* By default we will not connect to any gateways over HTTP addresses,
|
|
653
|
+
* requring HTTPS connections instead. This is because it will cause
|
|
654
|
+
* "mixed-content" errors to appear in the console when running in secure
|
|
655
|
+
* browser contexts.
|
|
656
|
+
*
|
|
657
|
+
* Pass `true` here to connect to insecure Gateways as well, this may be
|
|
658
|
+
* useful in testing environments.
|
|
659
|
+
*
|
|
660
|
+
* @default false
|
|
661
|
+
*/
|
|
662
|
+
allowInsecure?: boolean;
|
|
637
663
|
}
|
|
638
664
|
export interface CreateVerifiedFetchOptions {
|
|
639
665
|
/**
|
|
@@ -645,6 +671,20 @@ export interface CreateVerifiedFetchOptions {
|
|
|
645
671
|
* @default undefined
|
|
646
672
|
*/
|
|
647
673
|
contentTypeParser?: ContentTypeParser;
|
|
674
|
+
/**
|
|
675
|
+
* Blockstore sessions are cached for reuse with requests with the same
|
|
676
|
+
* base URL or CID. This parameter controls how many to cache. Once this limit
|
|
677
|
+
* is reached older/less used sessions will be evicted from the cache.
|
|
678
|
+
*
|
|
679
|
+
* @default 100
|
|
680
|
+
*/
|
|
681
|
+
sessionCacheSize?: number;
|
|
682
|
+
/**
|
|
683
|
+
* How long each blockstore session should stay in the cache for.
|
|
684
|
+
*
|
|
685
|
+
* @default 60000
|
|
686
|
+
*/
|
|
687
|
+
sessionTTLms?: number;
|
|
648
688
|
}
|
|
649
689
|
/**
|
|
650
690
|
* A ContentTypeParser attempts to return the mime type of a given file. It
|
|
@@ -669,6 +709,44 @@ export type VerifiedFetchProgressEvents = ProgressEvent<'verified-fetch:request:
|
|
|
669
709
|
* progress events.
|
|
670
710
|
*/
|
|
671
711
|
export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledProgressEvents | VerifiedFetchProgressEvents> {
|
|
712
|
+
/**
|
|
713
|
+
* If true, try to create a blockstore session - this can reduce overall
|
|
714
|
+
* network traffic by first querying for a set of peers that have the data we
|
|
715
|
+
* wish to retrieve. Subsequent requests for data using the session will only
|
|
716
|
+
* be sent to those peers, unless they don't have the data, in which case
|
|
717
|
+
* further peers will be added to the session.
|
|
718
|
+
*
|
|
719
|
+
* Sessions are cached based on the CID/IPNS name they attempt to access. That
|
|
720
|
+
* is, requests for `https://qmfoo.ipfs.localhost/bar.txt` and
|
|
721
|
+
* `https://qmfoo.ipfs.localhost/baz.txt` would use the same session, if this
|
|
722
|
+
* argument is true for both fetch requests.
|
|
723
|
+
*
|
|
724
|
+
* @default true
|
|
725
|
+
*/
|
|
726
|
+
session?: boolean;
|
|
727
|
+
/**
|
|
728
|
+
* By default we will not connect to any HTTP Gateways providers over local or
|
|
729
|
+
* loopback addresses, this is because they are typically running on remote
|
|
730
|
+
* peers that have published private addresses by mistate.
|
|
731
|
+
*
|
|
732
|
+
* Pass `true` here to connect to local Gateways as well, this may be useful
|
|
733
|
+
* in testing environments.
|
|
734
|
+
*
|
|
735
|
+
* @default false
|
|
736
|
+
*/
|
|
737
|
+
allowLocal?: boolean;
|
|
738
|
+
/**
|
|
739
|
+
* By default we will not connect to any gateways over HTTP addresses,
|
|
740
|
+
* requring HTTPS connections instead. This is because it will cause
|
|
741
|
+
* "mixed-content" errors to appear in the console when running in secure
|
|
742
|
+
* browser contexts.
|
|
743
|
+
*
|
|
744
|
+
* Pass `true` here to connect to insecure Gateways as well, this may be
|
|
745
|
+
* useful in testing environments.
|
|
746
|
+
*
|
|
747
|
+
* @default false
|
|
748
|
+
*/
|
|
749
|
+
allowInsecure?: boolean;
|
|
672
750
|
}
|
|
673
751
|
/**
|
|
674
752
|
* Create and return a Helia node
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAklBG;AAOH,OAAO,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAO,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CA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AAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;CACzF;AAED,MAAM,MAAM,qBAAqB,GAE/B,sBAAsB,GAEtB,sBAAsB,GAEtB,4BAA4B,CAAA;AAE9B,MAAM,MAAM,2BAA2B,GACrC,aAAa,CAAC,8BAA8B,EAAE,SAAS,CAAC,GACxD,aAAa,CAAC,6BAA6B,EAAE,MAAM,CAAC,GACpD,aAAa,CAAC,uCAAuC,EAAE,SAAS,CAAC,GACjE,aAAa,CAAC,4BAA4B,EAAE,SAAS,CAAC,GACtD,aAAa,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW,EAAE,eAAe,CAAC,qBAAqB,GAAG,2BAA2B,CAAC;IAC1H;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,IAAI,CAAC,EAAE,KAAK,GAAG,uBAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CA2B/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -90,22 +90,25 @@
|
|
|
90
90
|
*
|
|
91
91
|
* The [helia](https://www.npmjs.com/package/helia) module is configured with a libp2p node that is suited for decentralized applications, alternatively [@helia/http](https://www.npmjs.com/package/@helia/http) is available which uses HTTP gateways for all network operations.
|
|
92
92
|
*
|
|
93
|
-
*
|
|
93
|
+
* You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
|
|
94
94
|
*
|
|
95
95
|
* ```typescript
|
|
96
96
|
* import { trustlessGateway } from '@helia/block-brokers'
|
|
97
97
|
* import { createHeliaHTTP } from '@helia/http'
|
|
98
|
-
* import { delegatedHTTPRouting } from '@helia/routers'
|
|
98
|
+
* import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
|
|
99
99
|
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
100
100
|
*
|
|
101
101
|
* const fetch = await createVerifiedFetch(
|
|
102
102
|
* await createHeliaHTTP({
|
|
103
103
|
* blockBrokers: [
|
|
104
|
-
* trustlessGateway(
|
|
104
|
+
* trustlessGateway()
|
|
105
|
+
* ],
|
|
106
|
+
* routers: [
|
|
107
|
+
* delegatedHTTPRouting('http://delegated-ipfs.dev'),
|
|
108
|
+
* httpGatewayRouting({
|
|
105
109
|
* gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
|
|
106
110
|
* })
|
|
107
|
-
* ]
|
|
108
|
-
* routers: ['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl))
|
|
111
|
+
* ]
|
|
109
112
|
* })
|
|
110
113
|
* )
|
|
111
114
|
*
|
|
@@ -588,11 +591,11 @@
|
|
|
588
591
|
* 1. `TypeError` - If the resource argument is not a string, CID, or CID string.
|
|
589
592
|
* 2. `TypeError` - If the options argument is passed and not an object.
|
|
590
593
|
* 3. `TypeError` - If the options argument is passed and is malformed.
|
|
591
|
-
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal.
|
|
594
|
+
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
|
|
592
595
|
*/
|
|
593
596
|
import { trustlessGateway } from '@helia/block-brokers';
|
|
594
597
|
import { createHeliaHTTP } from '@helia/http';
|
|
595
|
-
import { delegatedHTTPRouting } from '@helia/routers';
|
|
598
|
+
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers';
|
|
596
599
|
import { dns } from '@multiformats/dns';
|
|
597
600
|
import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js';
|
|
598
601
|
/**
|
|
@@ -603,10 +606,16 @@ export async function createVerifiedFetch(init, options) {
|
|
|
603
606
|
init = await createHeliaHTTP({
|
|
604
607
|
blockBrokers: [
|
|
605
608
|
trustlessGateway({
|
|
606
|
-
|
|
609
|
+
allowInsecure: init?.allowInsecure,
|
|
610
|
+
allowLocal: init?.allowLocal
|
|
611
|
+
})
|
|
612
|
+
],
|
|
613
|
+
routers: [
|
|
614
|
+
...(init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
|
|
615
|
+
httpGatewayRouting({
|
|
616
|
+
gateways: init?.gateways ?? []
|
|
607
617
|
})
|
|
608
618
|
],
|
|
609
|
-
routers: (init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
|
|
610
619
|
dns: createDns(init?.dnsResolvers)
|
|
611
620
|
});
|
|
612
621
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,qBAAqB,GAAG,IAAI,kBAAkB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAA;IAC9E,KAAK,UAAU,aAAa,CAAE,QAAkB,EAAE,OAA2B;QAC3E,OAAO,qBAAqB,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;IACD,aAAa,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IAC3E,aAAa,CAAC,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IAE7E,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,SAAS,OAAO,CAAE,GAAQ;IACxB,0EAA0E;IAC1E,OAAO,GAAG,EAAE,UAAU,IAAI,IAAI;QAC5B,GAAG,EAAE,SAAS,IAAI,IAAI;QACtB,GAAG,EAAE,EAAE,IAAI,IAAI;QACf,GAAG,EAAE,IAAI,IAAI,IAAI;QACjB,GAAG,EAAE,KAAK,IAAI,IAAI,CAAA;AACtB,CAAC;AAED,SAAS,SAAS,CAAE,SAAwC;IAC1D,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAM;IACR,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;YACT,SAAS,EAAE;gBACT,GAAG,EAAE,SAAS;aACf;SACF,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -32,6 +32,13 @@ interface ParsedUrlStringResultsBase extends ResolveResult {
|
|
|
32
32
|
ttl?: number;
|
|
33
33
|
}
|
|
34
34
|
export type ParsedUrlStringResults = ParsedUrlStringResultsBase;
|
|
35
|
+
interface MatchUrlGroups {
|
|
36
|
+
protocol: 'ipfs' | 'ipns';
|
|
37
|
+
cidOrPeerIdOrDnsLink: string;
|
|
38
|
+
path?: string;
|
|
39
|
+
queryString?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function matchURLString(urlString: string): MatchUrlGroups;
|
|
35
42
|
/**
|
|
36
43
|
* A function that parses ipfs:// and ipns:// URLs, returning an object with easily recognizable properties.
|
|
37
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-url-string.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-url-string.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAwB,IAAI,EAAqB,iBAAiB,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACvK,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAItD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,eAAe,CAAA;CACxB;AACD,MAAM,WAAW,qBAAsB,SAAQ,eAAe,CAAC,qBAAqB,GAAG,iBAAiB,GAAG,4BAA4B,CAAC,EAAE,YAAY;CAErJ;AAED,MAAM,WAAW,cAAe,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACtE,MAAM,CAAC,EAAE,sBAAsB,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,0BAA2B,SAAQ,aAAa;IACxD,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,KAAK,EAAE,cAAc,CAAA;IAErB;;;;;;;OAOG;IACH,QAAQ,E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G,MAAM,CAAA;IACzB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAgBD,wBAAgB,cAAc,CAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAUjE;AAsDD;;;;;;;;GAQG;AAEH,wBAAsB,cAAc,CAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAoHxJ"}
|
|
@@ -20,7 +20,7 @@ function matchUrlGroupsGuard(groups) {
|
|
|
20
20
|
(path == null || typeof path === 'string') &&
|
|
21
21
|
(queryString == null || typeof queryString === 'string');
|
|
22
22
|
}
|
|
23
|
-
function matchURLString(urlString) {
|
|
23
|
+
export function matchURLString(urlString) {
|
|
24
24
|
for (const pattern of [URL_REGEX, PATH_REGEX, PATH_GATEWAY_REGEX, SUBDOMAIN_GATEWAY_REGEX]) {
|
|
25
25
|
const match = urlString.match(pattern);
|
|
26
26
|
if (matchUrlGroupsGuard(match?.groups)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-url-string.js","sourceRoot":"","sources":["../../../src/utils/parse-url-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAMhC,MAAM,SAAS,GAAG,IAAI,IAAI,CAA2C,IAAI,CAAC,CAAA;AAuC1E,MAAM,SAAS,GAAG,kGAAkG,CAAA;AACpH,MAAM,UAAU,GAAG,iGAAiG,CAAA;AACpH,MAAM,kBAAkB,GAAG,oHAAoH,CAAA;AAC/I,MAAM,uBAAuB,GAAG,oHAAoH,CAAA;AASpJ,SAAS,mBAAmB,CAAE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OAAO,IAAI,EAAE,CAAC;QAC5C,KAAK;QACL,GAAG;QACH,QAAQ,EAAE,IAAI,QAAQ,IAAI,oBAAoB,GAAG,OAAO,IAAI,IAAI,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;KACzE,CAAA;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAE,YAAgC,EAAE,OAAe;IACnE,IAAI,IAAI,GAAG,EAAE,CAAA;IAEb,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,IAAI,YAAY,CAAA;IACtB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,OAAO,EAAE,CAAA;IAC3D,CAAC;IAED,oCAAoC;IACpC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAEpC,0CAA0C;IAC1C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
/**
|
|
3
|
+
* Takes a resource and returns a session cache key as an IPFS or IPNS path with
|
|
4
|
+
* any trailing segments removed.
|
|
5
|
+
*
|
|
6
|
+
* E.g.
|
|
7
|
+
*
|
|
8
|
+
* - Qmfoo -> /ipfs/Qmfoo
|
|
9
|
+
* - https://Qmfoo.ipfs.gateway.org -> /ipfs/Qmfoo
|
|
10
|
+
* - https://gateway.org/ipfs/Qmfoo -> /ipfs/Qmfoo
|
|
11
|
+
* - https://gateway.org/ipfs/Qmfoo/bar.txt -> /ipfs/Qmfoo
|
|
12
|
+
* - etc
|
|
13
|
+
*/
|
|
14
|
+
export declare function resourceToSessionCacheKey(url: string | CID): string;
|
|
15
|
+
//# sourceMappingURL=resource-to-cache-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-to-cache-key.d.ts","sourceRoot":"","sources":["../../../src/utils/resource-to-cache-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAE,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAcpE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import { matchURLString } from './parse-url-string.js';
|
|
3
|
+
/**
|
|
4
|
+
* Takes a resource and returns a session cache key as an IPFS or IPNS path with
|
|
5
|
+
* any trailing segments removed.
|
|
6
|
+
*
|
|
7
|
+
* E.g.
|
|
8
|
+
*
|
|
9
|
+
* - Qmfoo -> /ipfs/Qmfoo
|
|
10
|
+
* - https://Qmfoo.ipfs.gateway.org -> /ipfs/Qmfoo
|
|
11
|
+
* - https://gateway.org/ipfs/Qmfoo -> /ipfs/Qmfoo
|
|
12
|
+
* - https://gateway.org/ipfs/Qmfoo/bar.txt -> /ipfs/Qmfoo
|
|
13
|
+
* - etc
|
|
14
|
+
*/
|
|
15
|
+
export function resourceToSessionCacheKey(url) {
|
|
16
|
+
const cid = CID.asCID(url);
|
|
17
|
+
if (cid != null) {
|
|
18
|
+
return `ipfs://${cid}`;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return `ipfs://${CID.parse(url.toString())}`;
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
24
|
+
const { protocol, cidOrPeerIdOrDnsLink } = matchURLString(url.toString());
|
|
25
|
+
return `${protocol}://${cidOrPeerIdOrDnsLink}`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=resource-to-cache-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-to-cache-key.js","sourceRoot":"","sources":["../../../src/utils/resource-to-cache-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,yBAAyB,CAAE,GAAiB;IAC1D,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE1B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,UAAU,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAA;IAC9C,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEzE,OAAO,GAAG,QAAQ,MAAM,oBAAoB,EAAE,CAAA;AAChD,CAAC"}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { type IPNS } from '@helia/ipns';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CreateVerifiedFetchOptions, Resource, VerifiedFetchInit as VerifiedFetchOptions } from './index.js';
|
|
3
3
|
import type { Helia } from '@helia/interface';
|
|
4
|
-
import type { DNSResolver } from '@multiformats/dns/resolvers';
|
|
5
4
|
interface VerifiedFetchComponents {
|
|
6
5
|
helia: Helia;
|
|
7
6
|
ipns?: IPNS;
|
|
8
7
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Potential future options for the VerifiedFetch constructor.
|
|
11
|
-
*/
|
|
12
|
-
interface VerifiedFetchInit {
|
|
13
|
-
contentTypeParser?: ContentTypeParser;
|
|
14
|
-
dnsResolvers?: DNSResolver[];
|
|
15
|
-
}
|
|
16
8
|
export declare class VerifiedFetch {
|
|
17
9
|
private readonly helia;
|
|
18
10
|
private readonly ipns;
|
|
19
11
|
private readonly log;
|
|
20
12
|
private readonly contentTypeParser;
|
|
21
|
-
|
|
13
|
+
private readonly blockstoreSessions;
|
|
14
|
+
constructor({ helia, ipns }: VerifiedFetchComponents, init?: CreateVerifiedFetchOptions);
|
|
15
|
+
private getBlockstore;
|
|
22
16
|
/**
|
|
23
17
|
* Accepts an `ipns://...` URL as a string and returns a `Response` containing
|
|
24
18
|
* a raw IPNS record.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verified-fetch.d.ts","sourceRoot":"","sources":["../../src/verified-fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"verified-fetch.d.ts","sourceRoot":"","sources":["../../src/verified-fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAA;AA+B1D,OAAO,KAAK,EAAgC,0BAA0B,EAAE,QAAQ,EAAE,iBAAiB,IAAI,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAG/I,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,kBAAkB,CAAA;AAQhE,UAAU,uBAAuB;IAC/B,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;AA0FD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA+B;IACjE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqC;gBAE3D,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,uBAAuB,EAAE,IAAI,CAAC,EAAE,0BAA0B;IAexF,OAAO,CAAC,aAAa;IAerB;;;OAGG;YACW,gBAAgB;IAgC9B;;;OAGG;YACW,SAAS;IAWvB;;;OAGG;YACW,SAAS;YAcT,UAAU;YA2BV,aAAa;YA0Eb,WAAW;YAgHX,SAAS;YAiBT,cAAc;IA0B5B;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAO7B;IAED;;;;;;OAMG;IACG,KAAK,CAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgHhF;;OAEG;IACG,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAI7B;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -9,6 +9,7 @@ import { peerIdFromString } from '@libp2p/peer-id';
|
|
|
9
9
|
import { Key } from 'interface-datastore';
|
|
10
10
|
import { exporter } from 'ipfs-unixfs-exporter';
|
|
11
11
|
import toBrowserReadableStream from 'it-to-browser-readablestream';
|
|
12
|
+
import { LRUCache } from 'lru-cache';
|
|
12
13
|
import { code as jsonCode } from 'multiformats/codecs/json';
|
|
13
14
|
import { code as rawCode } from 'multiformats/codecs/raw';
|
|
14
15
|
import { identity } from 'multiformats/hashes/identity';
|
|
@@ -24,10 +25,13 @@ import { getResolvedAcceptHeader } from './utils/get-resolved-accept-header.js';
|
|
|
24
25
|
import { getStreamFromAsyncIterable } from './utils/get-stream-from-async-iterable.js';
|
|
25
26
|
import { tarStream } from './utils/get-tar-stream.js';
|
|
26
27
|
import { parseResource } from './utils/parse-resource.js';
|
|
28
|
+
import { resourceToSessionCacheKey } from './utils/resource-to-cache-key.js';
|
|
27
29
|
import { setCacheControlHeader } from './utils/response-headers.js';
|
|
28
30
|
import { badRequestResponse, movedPermanentlyResponse, notAcceptableResponse, notSupportedResponse, okResponse, badRangeResponse, okRangeResponse, badGatewayResponse, notFoundResponse } from './utils/responses.js';
|
|
29
31
|
import { selectOutputType } from './utils/select-output-type.js';
|
|
30
32
|
import { isObjectNode, walkPath } from './utils/walk-path.js';
|
|
33
|
+
const SESSION_CACHE_MAX_SIZE = 100;
|
|
34
|
+
const SESSION_CACHE_TTL_MS = 60 * 1000;
|
|
31
35
|
function convertOptions(options) {
|
|
32
36
|
if (options == null) {
|
|
33
37
|
return undefined;
|
|
@@ -80,13 +84,32 @@ export class VerifiedFetch {
|
|
|
80
84
|
ipns;
|
|
81
85
|
log;
|
|
82
86
|
contentTypeParser;
|
|
87
|
+
blockstoreSessions;
|
|
83
88
|
constructor({ helia, ipns }, init) {
|
|
84
89
|
this.helia = helia;
|
|
85
90
|
this.log = helia.logger.forComponent('helia:verified-fetch');
|
|
86
91
|
this.ipns = ipns ?? heliaIpns(helia);
|
|
87
92
|
this.contentTypeParser = init?.contentTypeParser;
|
|
93
|
+
this.blockstoreSessions = new LRUCache({
|
|
94
|
+
max: init?.sessionCacheSize ?? SESSION_CACHE_MAX_SIZE,
|
|
95
|
+
ttl: init?.sessionTTLms ?? SESSION_CACHE_TTL_MS,
|
|
96
|
+
dispose: (store) => {
|
|
97
|
+
store.close();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
88
100
|
this.log.trace('created VerifiedFetch instance');
|
|
89
101
|
}
|
|
102
|
+
getBlockstore(root, key, useSession, options) {
|
|
103
|
+
if (!useSession) {
|
|
104
|
+
return this.helia.blockstore;
|
|
105
|
+
}
|
|
106
|
+
let session = this.blockstoreSessions.get(key);
|
|
107
|
+
if (session == null) {
|
|
108
|
+
session = this.helia.blockstore.createSession(root, options);
|
|
109
|
+
this.blockstoreSessions.set(key, session);
|
|
110
|
+
}
|
|
111
|
+
return session;
|
|
112
|
+
}
|
|
90
113
|
/**
|
|
91
114
|
* Accepts an `ipns://...` URL as a string and returns a `Response` containing
|
|
92
115
|
* a raw IPNS record.
|
|
@@ -121,8 +144,9 @@ export class VerifiedFetch {
|
|
|
121
144
|
* Accepts a `CID` and returns a `Response` with a body stream that is a CAR
|
|
122
145
|
* of the `DAG` referenced by the `CID`.
|
|
123
146
|
*/
|
|
124
|
-
async handleCar({ resource, cid, options }) {
|
|
125
|
-
const
|
|
147
|
+
async handleCar({ resource, cid, session, cacheKey, options }) {
|
|
148
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
149
|
+
const c = car({ blockstore, dagWalkers: this.helia.dagWalkers });
|
|
126
150
|
const stream = toBrowserReadableStream(c.stream(cid, options));
|
|
127
151
|
const response = okResponse(resource, stream);
|
|
128
152
|
response.headers.set('content-type', 'application/vnd.ipld.car; version=1');
|
|
@@ -132,18 +156,20 @@ export class VerifiedFetch {
|
|
|
132
156
|
* Accepts a UnixFS `CID` and returns a `.tar` file containing the file or
|
|
133
157
|
* directory structure referenced by the `CID`.
|
|
134
158
|
*/
|
|
135
|
-
async handleTar({ resource, cid, path, options }) {
|
|
159
|
+
async handleTar({ resource, cid, path, session, cacheKey, options }) {
|
|
136
160
|
if (cid.code !== dagPbCode && cid.code !== rawCode) {
|
|
137
161
|
return notAcceptableResponse('only UnixFS data can be returned in a TAR file');
|
|
138
162
|
}
|
|
139
|
-
const
|
|
163
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
164
|
+
const stream = toBrowserReadableStream(tarStream(`/ipfs/${cid}/${path}`, blockstore, options));
|
|
140
165
|
const response = okResponse(resource, stream);
|
|
141
166
|
response.headers.set('content-type', 'application/x-tar');
|
|
142
167
|
return response;
|
|
143
168
|
}
|
|
144
|
-
async handleJson({ resource, cid, path, accept, options }) {
|
|
169
|
+
async handleJson({ resource, cid, path, accept, session, cacheKey, options }) {
|
|
145
170
|
this.log.trace('fetching %c/%s', cid, path);
|
|
146
|
-
const
|
|
171
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
172
|
+
const block = await blockstore.get(cid, options);
|
|
147
173
|
let body;
|
|
148
174
|
if (accept === 'application/vnd.ipld.dag-cbor' || accept === 'application/cbor') {
|
|
149
175
|
try {
|
|
@@ -166,13 +192,14 @@ export class VerifiedFetch {
|
|
|
166
192
|
response.headers.set('content-type', accept ?? 'application/json');
|
|
167
193
|
return response;
|
|
168
194
|
}
|
|
169
|
-
async handleDagCbor({ resource, cid, path, accept, options }) {
|
|
195
|
+
async handleDagCbor({ resource, cid, path, accept, session, cacheKey, options }) {
|
|
170
196
|
this.log.trace('fetching %c/%s', cid, path);
|
|
171
197
|
let terminalElement;
|
|
172
198
|
let ipfsRoots;
|
|
199
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
173
200
|
// need to walk path, if it exists, to get the terminal element
|
|
174
201
|
try {
|
|
175
|
-
const pathDetails = await walkPath(
|
|
202
|
+
const pathDetails = await walkPath(blockstore, `${cid.toString()}/${path}`, options);
|
|
176
203
|
ipfsRoots = pathDetails.ipfsRoots;
|
|
177
204
|
const potentialTerminalElement = pathDetails.terminalElement;
|
|
178
205
|
if (potentialTerminalElement == null) {
|
|
@@ -190,7 +217,7 @@ export class VerifiedFetch {
|
|
|
190
217
|
this.log.error('error walking path %s', path, err);
|
|
191
218
|
return badGatewayResponse(resource, 'Error walking path');
|
|
192
219
|
}
|
|
193
|
-
const block = terminalElement?.node ?? await
|
|
220
|
+
const block = terminalElement?.node ?? await blockstore.get(cid, options);
|
|
194
221
|
let body;
|
|
195
222
|
if (accept === 'application/octet-stream' || accept === 'application/vnd.ipld.dag-cbor' || accept === 'application/cbor') {
|
|
196
223
|
// skip decoding
|
|
@@ -232,13 +259,14 @@ export class VerifiedFetch {
|
|
|
232
259
|
}
|
|
233
260
|
return response;
|
|
234
261
|
}
|
|
235
|
-
async handleDagPb({ cid, path, resource, options }) {
|
|
262
|
+
async handleDagPb({ cid, path, resource, cacheKey, session, options }) {
|
|
236
263
|
let terminalElement;
|
|
237
264
|
let ipfsRoots;
|
|
238
265
|
let redirected = false;
|
|
239
266
|
const byteRangeContext = new ByteRangeContext(this.helia.logger, options?.headers);
|
|
267
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
240
268
|
try {
|
|
241
|
-
const pathDetails = await walkPath(
|
|
269
|
+
const pathDetails = await walkPath(blockstore, `${cid.toString()}/${path}`, options);
|
|
242
270
|
ipfsRoots = pathDetails.ipfsRoots;
|
|
243
271
|
terminalElement = pathDetails.terminalElement;
|
|
244
272
|
}
|
|
@@ -332,9 +360,10 @@ export class VerifiedFetch {
|
|
|
332
360
|
return badGatewayResponse(resource.toString(), 'Unable to stream content');
|
|
333
361
|
}
|
|
334
362
|
}
|
|
335
|
-
async handleRaw({ resource, cid, path, options, accept }) {
|
|
363
|
+
async handleRaw({ resource, cid, path, session, cacheKey, options, accept }) {
|
|
336
364
|
const byteRangeContext = new ByteRangeContext(this.helia.logger, options?.headers);
|
|
337
|
-
const
|
|
365
|
+
const blockstore = this.getBlockstore(cid, cacheKey, session, options);
|
|
366
|
+
const result = await blockstore.get(cid, options);
|
|
338
367
|
byteRangeContext.setBody(result);
|
|
339
368
|
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext, log: this.log }, {
|
|
340
369
|
redirected: false
|
|
@@ -422,7 +451,8 @@ export class VerifiedFetch {
|
|
|
422
451
|
}
|
|
423
452
|
let response;
|
|
424
453
|
let reqFormat;
|
|
425
|
-
const
|
|
454
|
+
const cacheKey = resourceToSessionCacheKey(resource);
|
|
455
|
+
const handlerArgs = { resource: resource.toString(), cid, path, accept, cacheKey, session: options?.session ?? true, options };
|
|
426
456
|
if (accept === 'application/vnd.ipfs.ipns-record') {
|
|
427
457
|
// the user requested a raw IPNS record
|
|
428
458
|
reqFormat = 'ipns-record';
|