Skip to content

Commit b5c95e6

Browse files
authored
fix: allow contentTypeParser with Helia instance (#427)
* fix: allow contentTypeParser with helia instance * test: verified-fetch interop tests update
1 parent b39d07c commit b5c95e6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@
128128
*
129129
* const fetch = await createVerifiedFetch({
130130
* gateways: ['https://trustless-gateway.link'],
131-
* routers: ['http://delegated-ipfs.dev'],
131+
* routers: ['http://delegated-ipfs.dev']
132+
* }, {
132133
* contentTypeParser: async (bytes) => {
133134
* // call to some magic-byte recognition library like magic-bytes, file-type, or your own custom byte recognition
134135
* const result = await fileTypeFromBuffer(bytes)
@@ -285,10 +286,12 @@ export interface VerifiedFetch {
285286
* Instead of passing a Helia instance, you can pass a list of gateways and
286287
* routers, and a HeliaHTTP instance will be created for you.
287288
*/
288-
export interface CreateVerifiedFetchOptions {
289+
export interface CreateVerifiedFetchInit {
289290
gateways: string[]
290291
routers?: string[]
292+
}
291293

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

344347
if (!isHelia(init)) {
345-
contentTypeParser = init?.contentTypeParser
346348
init = await createHeliaHTTP({
347349
blockBrokers: [
348350
trustlessGateway({

0 commit comments

Comments
 (0)