-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat(server): Helia Docker #1
Conversation
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything glaring, I'm good with this and had a few comments
|
||
export const DEFAULT_MIME_TYPE = 'text/html' | ||
|
||
const tests: Array<(input: testInput) => testOutput> = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to abstract the content-type tests to a type/interface and use that.
src/contentType.ts
Outdated
// testing file-type from buffer | ||
async ({ bytes }): testOutput => (await fileTypeFromBuffer(bytes))?.mime, | ||
// testing file-type from path | ||
// ts-expect-error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why expect error? add more info why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mime.lookup
complains about Unexpected value in conditional. A boolean expression is required.
src/contentType.ts
Outdated
export async function parseContentType (input: testInput): Promise<string> { | ||
let type = (await Promise.all(tests.map(async test => test(input)))).filter(Boolean)[0] as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is much harder to read than it needs to be. Also, we're always calling each of the type check fns (map), and then looping over all of the successful ones (filter), instead of returning quickly on the first success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
const regex = /^\/(?<namespace>ip[fn]s)\/(?<address>[^/$]+)(?<relativePath>[^$]*)/ | ||
const result = path.match(regex) | ||
if (result == null) { | ||
throw new Error('Path is not valid, provide path as /ipfs/<cid> or /ipns/<path>') | ||
} | ||
return result.groups as { namespace: string, address: string, relativePath: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is returning an error on a valid path:
http://localhost:8888/ipns/docs.ipfs.tech/how-to/run-ipfs-inside-docker/#set-up
see https://ipfs.io/ipns/docs.ipfs.tech/how-to/run-ipfs-inside-docker/#set-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though I gave approval, this needs fixed (can be in later PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
src/heliaFetch.ts
Outdated
const { Path } = await (await fetch(this.delegatedRoutingApi + address)).json() | ||
this.ipnsResolutionCache.set(address, Path) | ||
} | ||
return this.fetch(`${this.ipnsResolutionCache.get(address)}${options?.path ?? ''}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is hard to follow tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
export async function parseContentType (input: testInput): Promise<string> { | ||
for (const test of tests) { | ||
const type = await test(input) | ||
if (type !== undefined) { | ||
return overrideContentType(type) | ||
} | ||
} | ||
return DEFAULT_MIME_TYPE | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Testing instructions:
docker build . --tag helia
docker run -p 8080:8080 helia
Output:
ipns-resolve-helia.mov