Skip to content

Commit

Permalink
fix: allow contentTypeParser with Helia instance (#427)
Browse files Browse the repository at this point in the history
* fix: allow contentTypeParser with helia instance

* test: verified-fetch interop tests update
  • Loading branch information
SgtPooki authored Feb 9, 2024
1 parent b39d07c commit b5c95e6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
*
* const fetch = await createVerifiedFetch({
* gateways: ['https://trustless-gateway.link'],
* routers: ['http://delegated-ipfs.dev'],
* routers: ['http://delegated-ipfs.dev']
* }, {
* contentTypeParser: async (bytes) => {
* // call to some magic-byte recognition library like magic-bytes, file-type, or your own custom byte recognition
* const result = await fileTypeFromBuffer(bytes)
Expand Down Expand Up @@ -285,10 +286,12 @@ export interface VerifiedFetch {
* Instead of passing a Helia instance, you can pass a list of gateways and
* routers, and a HeliaHTTP instance will be created for you.
*/
export interface CreateVerifiedFetchOptions {
export interface CreateVerifiedFetchInit {
gateways: string[]
routers?: string[]
}

export interface CreateVerifiedFetchOptions {
/**
* A function to handle parsing content type from bytes. The function you
* provide will be passed the first set of bytes we receive from the network,
Expand Down Expand Up @@ -338,11 +341,10 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledP
/**
* Create and return a Helia node
*/
export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchOptions): Promise<VerifiedFetch> {
let contentTypeParser: ContentTypeParser | undefined
export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchInit, options?: CreateVerifiedFetchOptions): Promise<VerifiedFetch> {
const contentTypeParser: ContentTypeParser | undefined = options?.contentTypeParser

if (!isHelia(init)) {
contentTypeParser = init?.contentTypeParser
init = await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
Expand Down

0 comments on commit b5c95e6

Please sign in to comment.