Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: append query path to path resolved from IPNS name #3

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/verified-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@helia/json": "^3.0.1",
"@helia/utils": "^0.0.2",
"@ipld/car": "^5.3.0",
"@libp2p/interface-compliance-tests": "^5.3.2",
"@libp2p/logger": "^4.0.7",
"@libp2p/peer-id-factory": "^4.0.7",
"@sgtpooki/file-type": "^1.0.1",
Expand Down
15 changes: 10 additions & 5 deletions packages/verified-fetch/src/utils/parse-url-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ export async function parseUrlString ({ urlString, ipns, logger }: ParseUrlStrin
resolvedPath = resolveResult?.path
log.trace('resolved %s to %c', cidOrPeerIdOrDnsLink, cid)
ipnsCache.set(cidOrPeerIdOrDnsLink, resolveResult, 60 * 1000 * 2)
} catch (err) {
} catch (err: any) {
log.error('Could not resolve DnsLink for "%s"', cidOrPeerIdOrDnsLink, err)
errors.push(err as Error)
errors.push(err)
}
}
}
}

if (cid == null) {
if (errors.length === 1) {
throw errors[0]
}

throw new AggregateError(errors, `Invalid resource. Cannot determine CID from URL "${urlString}"`)
}

Expand Down Expand Up @@ -136,13 +140,14 @@ export async function parseUrlString ({ urlString, ipns, logger }: ParseUrlStrin
*/
const pathParts = []

if (resolvedPath != null && resolvedPath.length > 0) {
pathParts.push(resolvedPath)
}

if (urlPath.length > 0) {
pathParts.push(urlPath)
}

if (resolvedPath != null && resolvedPath.length > 0) {
pathParts.push(resolvedPath)
}
const path = pathParts.join('/')

return {
Expand Down
Loading
Loading