Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"docs": "aegir docs"
},
"dependencies": {
"@multiformats/multiaddr": "^12.0.0"
"@multiformats/multiaddr": "^12.3.0"
},
"devDependencies": {
"aegir": "^42.2.2"
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ const interpreters: Record<string, Interpreter> = {
baseVal = baseVal.replace('tcp://', '')
return `${protocol}${baseVal}`
},
'http-path': (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto === undefined) {
throw new Error('Unexpected end of multiaddr')
}
const baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
const decodedValue = decodeURIComponent(value)
return `${baseVal}/${decodedValue}`
},
tls: (value: string, restMa: StringTuple[]) => {
// Noop, the parent context knows that it's tls. We don't need to do
// anything here
Expand Down
5 changes: 5 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('multiaddr-to-uri', () => {
['/ip4/0.0.7.6/tcp/1234/https', 'https://0.0.7.6:1234'],
['/ip4/0.0.7.6/tcp/1234/tls/http', 'https://0.0.7.6:1234'],
['/ip4/1.2.3.4/tcp/1234/tls/sni/ipfs.io/http', 'https://ipfs.io'],
['/ip4/1.2.3.4/tcp/1234/tls/sni/ipfs.io/http/http-path/foo%2fbar', 'https://ipfs.io/foo/bar'],
['/ip4/0.0.7.6/udp/1234', 'udp://0.0.7.6:1234'],
['/ip6/::/udp/0', 'udp://[::]:0'],
['/dns/a.com/tcp/1234', 'http://a.com:1234'],
Expand Down Expand Up @@ -85,6 +86,10 @@ describe('multiaddr-to-uri', () => {
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'tcp://1.2.3.4:3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
],
[
'/ip4/1.2.3.4/tcp/3456/http/http-path/foo%2fbar',
'http://1.2.3.4:3456/foo/bar'
],
[
'/ip4/1.2.3.4/tcp/3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK',
'tcp://1.2.3.4:3456/p2p/QmcNwyju7SWoizsAuf6kjaaRoxe762ovsT3hz6qt3xxcsK'
Expand Down