@helia/verified-fetch 4.0.1 → 4.0.3
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 +48 -48
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +3 -3
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +5 -5
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.js +35 -25
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +2 -2
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.js +1 -1
- package/dist/src/plugins/plugin-handle-raw.js.map +1 -1
- package/dist/src/plugins/types.d.ts +1 -4
- package/dist/src/plugins/types.d.ts.map +1 -1
- package/dist/src/url-resolver.d.ts +4 -3
- package/dist/src/url-resolver.d.ts.map +1 -1
- package/dist/src/url-resolver.js +35 -47
- package/dist/src/url-resolver.js.map +1 -1
- package/dist/src/utils/dnslink-label.d.ts +26 -0
- package/dist/src/utils/dnslink-label.d.ts.map +1 -0
- package/dist/src/utils/dnslink-label.js +35 -0
- package/dist/src/utils/dnslink-label.js.map +1 -0
- package/dist/src/utils/get-content-type.d.ts +1 -1
- package/dist/src/utils/get-content-type.d.ts.map +1 -1
- package/dist/src/utils/get-content-type.js +2 -2
- package/dist/src/utils/get-content-type.js.map +1 -1
- package/dist/src/utils/get-stream-from-async-iterable.d.ts +1 -2
- package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +1 -1
- package/dist/src/utils/get-stream-from-async-iterable.js +1 -3
- package/dist/src/utils/get-stream-from-async-iterable.js.map +1 -1
- package/dist/src/utils/handle-redirects.js +2 -2
- package/dist/src/utils/ipfs-path-to-url.d.ts +16 -0
- package/dist/src/utils/ipfs-path-to-url.d.ts.map +1 -0
- package/dist/src/utils/ipfs-path-to-url.js +45 -0
- package/dist/src/utils/ipfs-path-to-url.js.map +1 -0
- package/dist/src/utils/parse-url-string.d.ts +18 -5
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +126 -44
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/resource-to-cache-key.js +2 -2
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +4 -0
- package/dist/src/utils/responses.js.map +1 -1
- package/dist/src/utils/walk-path.js +1 -1
- package/dist/src/utils/walk-path.js.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +4 -2
- package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +8 -8
- package/src/plugins/plugin-handle-dag-pb.ts +42 -24
- package/src/plugins/plugin-handle-ipns-record.ts +2 -2
- package/src/plugins/plugin-handle-raw.ts +1 -1
- package/src/plugins/types.ts +1 -4
- package/src/url-resolver.ts +37 -56
- package/src/utils/dnslink-label.ts +38 -0
- package/src/utils/get-content-type.ts +3 -3
- package/src/utils/get-stream-from-async-iterable.ts +1 -4
- package/src/utils/handle-redirects.ts +2 -2
- package/src/utils/ipfs-path-to-url.ts +54 -0
- package/src/utils/parse-url-string.ts +166 -49
- package/src/utils/resource-to-cache-key.ts +2 -2
- package/src/utils/responses.ts +6 -0
- package/src/utils/walk-path.ts +1 -1
package/dist/src/url-resolver.js
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
import { peerIdFromCID, peerIdFromString } from '@libp2p/peer-id';
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
|
-
import {
|
|
3
|
+
import { parseURLString } from "./utils/parse-url-string.js";
|
|
4
4
|
const CODEC_LIBP2P_KEY = 0x72;
|
|
5
|
-
function toQuery(query) {
|
|
6
|
-
if (query == null) {
|
|
7
|
-
return {};
|
|
8
|
-
}
|
|
9
|
-
const params = new URLSearchParams(query);
|
|
10
|
-
const output = {};
|
|
11
|
-
for (const [key, value] of params.entries()) {
|
|
12
|
-
output[key] = value;
|
|
13
|
-
if (value === 'true') {
|
|
14
|
-
output[key] = true;
|
|
15
|
-
}
|
|
16
|
-
if (value === 'false') {
|
|
17
|
-
output[key] = false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
5
|
export class URLResolver {
|
|
23
6
|
components;
|
|
24
7
|
constructor(components) {
|
|
@@ -30,46 +13,50 @@ export class URLResolver {
|
|
|
30
13
|
}
|
|
31
14
|
const cid = CID.asCID(resource);
|
|
32
15
|
if (cid != null) {
|
|
33
|
-
return this.resolveCIDResource(cid,
|
|
16
|
+
return this.resolveCIDResource(cid, {
|
|
17
|
+
url: new URL(`ipfs://${cid}`)
|
|
18
|
+
}, options);
|
|
34
19
|
}
|
|
35
20
|
throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${resource}`);
|
|
36
21
|
}
|
|
37
22
|
async parseUrlString(urlString, options = {}) {
|
|
38
|
-
const
|
|
39
|
-
if (protocol === 'ipfs') {
|
|
40
|
-
const cid = CID.parse(cidOrPeerIdOrDnsLink);
|
|
41
|
-
return this.resolveCIDResource(cid,
|
|
23
|
+
const result = parseURLString(urlString);
|
|
24
|
+
if (result.protocol === 'ipfs') {
|
|
25
|
+
const cid = CID.parse(result.cidOrPeerIdOrDnsLink);
|
|
26
|
+
return this.resolveCIDResource(cid, result, options);
|
|
42
27
|
}
|
|
43
|
-
if (protocol === 'ipns') {
|
|
28
|
+
if (result.protocol === 'ipns') {
|
|
44
29
|
// try to parse target as peer id
|
|
45
30
|
let peerId;
|
|
46
31
|
try {
|
|
47
|
-
peerId = peerIdFromString(cidOrPeerIdOrDnsLink);
|
|
32
|
+
peerId = peerIdFromString(result.cidOrPeerIdOrDnsLink);
|
|
48
33
|
}
|
|
49
34
|
catch {
|
|
50
35
|
// fall back to DNSLink (e.g. /ipns/example.com)
|
|
51
|
-
return this.resolveDNSLink(cidOrPeerIdOrDnsLink,
|
|
36
|
+
return this.resolveDNSLink(result.cidOrPeerIdOrDnsLink, result, options);
|
|
52
37
|
}
|
|
53
38
|
// parse multihash from string (e.g. /ipns/QmFoo...)
|
|
54
|
-
return this.resolveIPNSName(cidOrPeerIdOrDnsLink, peerId,
|
|
39
|
+
return this.resolveIPNSName(result.cidOrPeerIdOrDnsLink, peerId, result, options);
|
|
55
40
|
}
|
|
56
41
|
throw new TypeError(`Invalid resource. Cannot determine CID from resource: ${urlString}`);
|
|
57
42
|
}
|
|
58
|
-
async resolveCIDResource(cid,
|
|
43
|
+
async resolveCIDResource(cid, parsed, options = {}) {
|
|
59
44
|
if (cid.code === CODEC_LIBP2P_KEY) {
|
|
60
45
|
// special case - peer id encoded as a CID
|
|
61
|
-
return this.resolveIPNSName(cid.toString(), peerIdFromCID(cid),
|
|
46
|
+
return this.resolveIPNSName(cid.toString(), peerIdFromCID(cid), parsed, options);
|
|
62
47
|
}
|
|
63
48
|
return {
|
|
49
|
+
url: parsed.url,
|
|
64
50
|
cid,
|
|
65
51
|
protocol: 'ipfs',
|
|
66
|
-
query,
|
|
67
|
-
path,
|
|
52
|
+
query: parsed.query ?? {},
|
|
53
|
+
path: parsed.path ?? [],
|
|
54
|
+
fragment: parsed.fragment ?? '',
|
|
68
55
|
ttl: 29030400, // 1 year for ipfs content
|
|
69
|
-
ipfsPath: `/ipfs/${cid}${
|
|
56
|
+
ipfsPath: `/ipfs/${cid}${parsed.url.pathname}`
|
|
70
57
|
};
|
|
71
58
|
}
|
|
72
|
-
async resolveDNSLink(domain,
|
|
59
|
+
async resolveDNSLink(domain, parsed, options) {
|
|
73
60
|
const results = await this.components.timing.time('dnsLink.resolve', `Resolve DNSLink ${domain}`, this.components.dnsLink.resolve(domain, options));
|
|
74
61
|
const result = results?.[0];
|
|
75
62
|
if (result == null) {
|
|
@@ -77,7 +64,7 @@ export class URLResolver {
|
|
|
77
64
|
}
|
|
78
65
|
// dnslink resolved to IPNS name
|
|
79
66
|
if (result.namespace === 'ipns') {
|
|
80
|
-
return this.resolveIPNSName(domain, result.peerId,
|
|
67
|
+
return this.resolveIPNSName(domain, result.peerId, parsed, options);
|
|
81
68
|
}
|
|
82
69
|
// dnslink resolved to CID
|
|
83
70
|
if (result.namespace !== 'ipfs') {
|
|
@@ -85,34 +72,35 @@ export class URLResolver {
|
|
|
85
72
|
throw new TypeError(`Invalid resource. Unexpected DNSLink namespace ${result.namespace} from domain: ${domain}`);
|
|
86
73
|
}
|
|
87
74
|
return {
|
|
75
|
+
url: parsed.url,
|
|
88
76
|
cid: result.cid,
|
|
89
|
-
path: concatPaths(result.path, path),
|
|
77
|
+
path: concatPaths(...(result.path ?? '').split('/'), ...(parsed.path ?? [])),
|
|
78
|
+
fragment: parsed.fragment,
|
|
90
79
|
// dnslink is mutable so return 'ipns' protocol so we do not include immutable in cache-control header
|
|
91
80
|
protocol: 'ipns',
|
|
92
81
|
ttl: result.answer.TTL,
|
|
93
|
-
query,
|
|
94
|
-
ipfsPath: `/ipns/${domain}${
|
|
82
|
+
query: parsed.query,
|
|
83
|
+
ipfsPath: `/ipns/${domain}${parsed.url.pathname}`
|
|
95
84
|
};
|
|
96
85
|
}
|
|
97
|
-
async resolveIPNSName(resource, key,
|
|
86
|
+
async resolveIPNSName(resource, key, parsed, options) {
|
|
98
87
|
const result = await this.components.timing.time('ipns.resolve', `Resolve IPNS name ${key}`, this.components.ipnsResolver.resolve(key, options));
|
|
99
88
|
return {
|
|
89
|
+
url: parsed.url,
|
|
100
90
|
cid: result.cid,
|
|
101
|
-
path: concatPaths(result.path, path),
|
|
102
|
-
query,
|
|
91
|
+
path: concatPaths(...(result.path ?? '').split('/'), ...(parsed.path ?? [])),
|
|
92
|
+
query: parsed.query ?? {},
|
|
93
|
+
fragment: parsed.fragment ?? '',
|
|
103
94
|
protocol: 'ipns',
|
|
104
95
|
// IPNS ttl is in nanoseconds, convert to seconds
|
|
105
96
|
ttl: Number((result.record.ttl ?? 0n) / BigInt(1e9)),
|
|
106
|
-
ipfsPath: `/ipns/${resource}${
|
|
97
|
+
ipfsPath: `/ipns/${resource}${parsed.url.pathname}`
|
|
107
98
|
};
|
|
108
99
|
}
|
|
109
100
|
}
|
|
110
101
|
function concatPaths(...paths) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.
|
|
114
|
-
.replaceAll(/(\/+)/g, '/')
|
|
115
|
-
.replace(/^(\/)+/, '')
|
|
116
|
-
.replace(/(\/)+$/, '/')}`;
|
|
102
|
+
// @ts-expect-error undefined is filtered out
|
|
103
|
+
return paths
|
|
104
|
+
.filter(p => p != null && p !== '');
|
|
117
105
|
}
|
|
118
106
|
//# sourceMappingURL=url-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-resolver.js","sourceRoot":"","sources":["../../src/url-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"url-resolver.js","sourceRoot":"","sources":["../../src/url-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAQ5D,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAQ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C,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;QAEhJ,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC5E,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE;YAC/B,QAAQ,EAAE,MAAM;YAChB,iDAAiD;YACjD,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACpD,QAAQ,EAAE,SAAS,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;SACpD,CAAA;IACH,CAAC;CACF;AAED,SAAS,WAAW,CAAE,GAAG,KAAgC;IACvD,6CAA6C;IAC7C,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For DNSLink see https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header
|
|
3
|
+
* DNSLink names include . which means they must be inlined into a single DNS label to provide unique origin and work with wildcard TLS certificates.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Checks if label looks like inlined DNSLink.
|
|
7
|
+
* (https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header)
|
|
8
|
+
*/
|
|
9
|
+
export declare function isInlinedDnsLink(label: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* DNSLink label decoding
|
|
12
|
+
* - Every standalone - is replaced with .
|
|
13
|
+
* - Every remaining -- is replaced with -
|
|
14
|
+
*
|
|
15
|
+
* @example en-wikipedia--on--ipfs-org -> en.wikipedia-on-ipfs.org
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeDNSLinkLabel(label: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* DNSLink label encoding
|
|
20
|
+
* - Every - is replaced with --
|
|
21
|
+
* - Every . is replaced with -
|
|
22
|
+
*
|
|
23
|
+
* @example en.wikipedia-on-ipfs.org -> en-wikipedia--on--ipfs-org
|
|
24
|
+
*/
|
|
25
|
+
export declare function encodeDNSLinkLabel(name: string): string;
|
|
26
|
+
//# sourceMappingURL=dnslink-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dnslink-label.d.ts","sourceRoot":"","sources":["../../../src/utils/dnslink-label.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For DNSLink see https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header
|
|
3
|
+
* DNSLink names include . which means they must be inlined into a single DNS label to provide unique origin and work with wildcard TLS certificates.
|
|
4
|
+
*/
|
|
5
|
+
// DNS label can have up to 63 characters, consisting of alphanumeric
|
|
6
|
+
// characters or hyphens -, but it must not start or end with a hyphen.
|
|
7
|
+
const dnsLabelRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if label looks like inlined DNSLink.
|
|
10
|
+
* (https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header)
|
|
11
|
+
*/
|
|
12
|
+
export function isInlinedDnsLink(label) {
|
|
13
|
+
return dnsLabelRegex.test(label) && label.includes('-') && !label.includes('.');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DNSLink label decoding
|
|
17
|
+
* - Every standalone - is replaced with .
|
|
18
|
+
* - Every remaining -- is replaced with -
|
|
19
|
+
*
|
|
20
|
+
* @example en-wikipedia--on--ipfs-org -> en.wikipedia-on-ipfs.org
|
|
21
|
+
*/
|
|
22
|
+
export function decodeDNSLinkLabel(label) {
|
|
23
|
+
return label.replace(/--/g, '%').replace(/-/g, '.').replace(/%/g, '-');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* DNSLink label encoding
|
|
27
|
+
* - Every - is replaced with --
|
|
28
|
+
* - Every . is replaced with -
|
|
29
|
+
*
|
|
30
|
+
* @example en.wikipedia-on-ipfs.org -> en-wikipedia--on--ipfs-org
|
|
31
|
+
*/
|
|
32
|
+
export function encodeDNSLinkLabel(name) {
|
|
33
|
+
return name.replace(/-/g, '--').replace(/\./g, '-');
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=dnslink-label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dnslink-label.js","sourceRoot":"","sources":["../../../src/utils/dnslink-label.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qEAAqE;AACrE,uEAAuE;AACvE,MAAM,aAAa,GAAG,+CAA+C,CAAA;AAErE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAE,KAAa;IAC7C,OAAO,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACjF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAE,KAAa;IAC/C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAE,IAAY;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACrD,CAAC"}
|
|
@@ -2,7 +2,7 @@ import type { ContentTypeParser } from '../index.js';
|
|
|
2
2
|
import type { Logger } from '@libp2p/interface';
|
|
3
3
|
export interface GetContentTypeOptions {
|
|
4
4
|
bytes: Uint8Array;
|
|
5
|
-
path?: string;
|
|
5
|
+
path?: string[];
|
|
6
6
|
defaultContentType?: string;
|
|
7
7
|
contentTypeParser?: ContentTypeParser;
|
|
8
8
|
log: Logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-content-type.d.ts","sourceRoot":"","sources":["../../../src/utils/get-content-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"get-content-type.d.ts","sourceRoot":"","sources":["../../../src/utils/get-content-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,GAAG,EAAE,MAAM,CAAA;IAEX;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,wBAAsB,cAAc,CAAE,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAA+C,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmC/L"}
|
|
@@ -6,7 +6,7 @@ export async function getContentType({ bytes, path, contentTypeParser, log, defa
|
|
|
6
6
|
try {
|
|
7
7
|
let fileName;
|
|
8
8
|
if (filenameParam == null) {
|
|
9
|
-
fileName = path?.
|
|
9
|
+
fileName = path?.[path.length - 1]?.trim();
|
|
10
10
|
fileName = (fileName === '' || fileName?.split('.').length === 1) ? undefined : fileName;
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
@@ -22,7 +22,7 @@ export async function getContentType({ bytes, path, contentTypeParser, log, defa
|
|
|
22
22
|
else if (parsed != null) {
|
|
23
23
|
contentType = parsed;
|
|
24
24
|
}
|
|
25
|
-
log.trace('contentTypeParser returned %s', contentType);
|
|
25
|
+
log.trace('contentTypeParser returned %s for file with name %s', contentType, fileName);
|
|
26
26
|
}
|
|
27
27
|
catch (err) {
|
|
28
28
|
log.error('error parsing content type', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-content-type.js","sourceRoot":"","sources":["../../../src/utils/get-content-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAmB5C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAE,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB,GAAG,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AM,CAAA;gBAE3B,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;oBACnB,WAAW,GAAG,MAAM,CAAA;gBACtB,CAAC;YACH,CAAC;iBAAM,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBAC1B,WAAW,GAAG,MAAM,CAAA;YACtB,CAAC;YACD,GAAG,CAAC,KAAK,CAAC,qDAAqD,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;QACzF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;IAED,IAAI,WAAW,KAAK,eAAe,EAAE,CAAC;QACpC,wIAAwI;QACxI,WAAW,GAAG,kBAAkB,CAAA;IAClC,CAAC;IAED,OAAO,WAAW,IAAI,kBAAkB,CAAA;AAC1C,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { VerifiedFetchInit } from '../index.js';
|
|
2
|
-
import type { Logger } from '@libp2p/interface';
|
|
3
2
|
/**
|
|
4
3
|
* Converts an async iterator of Uint8Array bytes to a stream and returns the first chunk of bytes
|
|
5
4
|
*/
|
|
6
|
-
export declare function getStreamFromAsyncIterable(iterator: AsyncIterable<Uint8Array>,
|
|
5
|
+
export declare function getStreamFromAsyncIterable(iterator: AsyncIterable<Uint8Array>, options?: Pick<VerifiedFetchInit, 'onProgress' | 'signal'>): Promise<{
|
|
7
6
|
stream: ReadableStream<Uint8Array>;
|
|
8
7
|
firstChunk: Uint8Array;
|
|
9
8
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-stream-from-async-iterable.d.ts","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"get-stream-from-async-iterable.d.ts","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD;;GAEG;AACH,wBAAsB,0BAA0B,CAAE,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAwC1N"}
|
|
@@ -4,12 +4,10 @@ import { NoContentError } from '../errors.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts an async iterator of Uint8Array bytes to a stream and returns the first chunk of bytes
|
|
6
6
|
*/
|
|
7
|
-
export async function getStreamFromAsyncIterable(iterator,
|
|
8
|
-
const log = logger.newScope('get-stream-from-async-iterable');
|
|
7
|
+
export async function getStreamFromAsyncIterable(iterator, options) {
|
|
9
8
|
const reader = iterator[Symbol.asyncIterator]();
|
|
10
9
|
const { value: firstChunk, done } = await reader.next();
|
|
11
10
|
if (done === true) {
|
|
12
|
-
log.error('no content found for path "%s"', path);
|
|
13
11
|
throw new NoContentError();
|
|
14
12
|
}
|
|
15
13
|
const stream = new ReadableStream({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-stream-from-async-iterable.js","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"get-stream-from-async-iterable.js","sourceRoot":"","sources":["../../../src/utils/get-stream-from-async-iterable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAA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AC,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC3B,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,CAAA;gBAClB,OAAM;YACR,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAO,uCAAuC,CAAC,CAAC,CAAA;YAC7F,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;KACF,CAAC,CAAA;IAEF,OAAO;QACL,MAAM;QACN,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SubdomainNotSupportedError } from '../errors.js';
|
|
2
|
-
import {
|
|
2
|
+
import { parseURLString } from './parse-url-string.js';
|
|
3
3
|
import { movedPermanentlyResponse } from './responses.js';
|
|
4
4
|
function maybeAddTrailingSlash(path) {
|
|
5
5
|
// if it has an extension-like ending, don't add a trailing slash
|
|
@@ -26,7 +26,7 @@ export async function getRedirectResponse({ resource, options, logger, cid, fetc
|
|
|
26
26
|
// if x-forwarded-host is passed, we need to set the location header to the
|
|
27
27
|
// subdomain so that the browser can redirect to the correct subdomain
|
|
28
28
|
try {
|
|
29
|
-
const urlParts =
|
|
29
|
+
const urlParts = parseURLString(resource);
|
|
30
30
|
const reqUrl = new URL(resource);
|
|
31
31
|
const actualHost = forwardedHost ?? reqUrl.host;
|
|
32
32
|
const subdomainUrl = new URL(reqUrl);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an IPFS or IPNS path into a HTTP URL. Path gateway syntax is used to
|
|
3
|
+
* preserve any case sensitivity
|
|
4
|
+
*
|
|
5
|
+
* - `/ipfs/cid` -> `https://example.org/ipfs/cid`
|
|
6
|
+
* - `/ipns/name` -> `https://example.org/ipns/name`
|
|
7
|
+
*/
|
|
8
|
+
export declare function ipfsPathToUrl(path: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Turns an IPFS or IPNS URL into a HTTP URL. Path gateway syntax is used to
|
|
11
|
+
* preserve and case sensitivity
|
|
12
|
+
*
|
|
13
|
+
* `ipfs://cid` -> `https://example.org/ipfs/cid`
|
|
14
|
+
*/
|
|
15
|
+
export declare function ipfsUrlToUrl(url: string): string;
|
|
16
|
+
//# sourceMappingURL=ipfs-path-to-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs-path-to-url.d.ts","sourceRoot":"","sources":["../../../src/utils/ipfs-path-to-url.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2BnD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CASjD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InvalidParametersError } from '@libp2p/interface';
|
|
2
|
+
/**
|
|
3
|
+
* Turns an IPFS or IPNS path into a HTTP URL. Path gateway syntax is used to
|
|
4
|
+
* preserve any case sensitivity
|
|
5
|
+
*
|
|
6
|
+
* - `/ipfs/cid` -> `https://example.org/ipfs/cid`
|
|
7
|
+
* - `/ipns/name` -> `https://example.org/ipns/name`
|
|
8
|
+
*/
|
|
9
|
+
export function ipfsPathToUrl(path) {
|
|
10
|
+
if (!path.startsWith('/ipfs/') && !path.startsWith('/ipns/')) {
|
|
11
|
+
throw new InvalidParametersError(`Path ${path} did not start with /ipfs/ or /ipns/`);
|
|
12
|
+
}
|
|
13
|
+
// trim fragment
|
|
14
|
+
const fragmentIndex = path.indexOf('#');
|
|
15
|
+
let fragment = '';
|
|
16
|
+
if (fragmentIndex > -1) {
|
|
17
|
+
fragment = path.substring(fragmentIndex);
|
|
18
|
+
path = path.substring(0, fragmentIndex);
|
|
19
|
+
}
|
|
20
|
+
// trim query
|
|
21
|
+
const queryIndex = path.indexOf('?');
|
|
22
|
+
let query = '';
|
|
23
|
+
if (queryIndex > -1) {
|
|
24
|
+
query = path.substring(queryIndex);
|
|
25
|
+
path = path.substring(0, queryIndex);
|
|
26
|
+
}
|
|
27
|
+
const type = path.substring(1, 5);
|
|
28
|
+
const rest = path.substring(6);
|
|
29
|
+
return `https://example.org/${type}/${rest}${query}${fragment}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Turns an IPFS or IPNS URL into a HTTP URL. Path gateway syntax is used to
|
|
33
|
+
* preserve and case sensitivity
|
|
34
|
+
*
|
|
35
|
+
* `ipfs://cid` -> `https://example.org/ipfs/cid`
|
|
36
|
+
*/
|
|
37
|
+
export function ipfsUrlToUrl(url) {
|
|
38
|
+
if (!url.startsWith('ipfs://') && !url.startsWith('ipns://')) {
|
|
39
|
+
throw new InvalidParametersError(`URL ${url} did not start with ipfs:// or ipns://`);
|
|
40
|
+
}
|
|
41
|
+
const type = url.substring(0, 4);
|
|
42
|
+
const rest = url.substring(7);
|
|
43
|
+
return `https://example.org/${type}/${rest}`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=ipfs-path-to-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs-path-to-url.js","sourceRoot":"","sources":["../../../src/utils/ipfs-path-to-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAE,IAAY;IACzC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,sBAAsB,CAAC,QAAQ,IAAI,sCAAsC,CAAC,CAAA;IACtF,CAAC;IAED,gBAAgB;IAChB,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACvC,IAAI,QAAQ,GAAG,EAAE,CAAA;IAEjB,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;QACvB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ol: 'ipfs' | 'ipns';
|
|
3
4
|
cidOrPeerIdOrDnsLink: string;
|
|
4
|
-
path
|
|
5
|
-
query
|
|
5
|
+
path: string[];
|
|
6
|
+
query: Record<string, any>;
|
|
7
|
+
fragment: string;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Accepts the following url strings:
|
|
11
|
+
*
|
|
12
|
+
* - /ipfs/Qmfoo/path
|
|
13
|
+
* - /ipns/Qmfoo/path
|
|
14
|
+
* - ipfs://cid/path
|
|
15
|
+
* - ipns://name/path
|
|
16
|
+
* - http://cid.ipfs.example.com/path
|
|
17
|
+
* - http://name.ipns.example.com/path
|
|
18
|
+
* - http://example.com/ipfs/cid/path
|
|
19
|
+
* - http://example.com/ipns/name/path
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseURLString(urlString: string): ParsedURL;
|
|
9
22
|
//# sourceMappingURL=parse-url-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-url-string.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-url-string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-url-string.d.ts","sourceRoot":"","sources":["../../../src/utils/parse-url-string.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,MAAM,CAAA;CACjB;AAqED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CA8E5D"}
|