@@ -3,11 +3,6 @@ import { UnixFS } from 'ipfs-unixfs'
3
3
import findShardCid from '../../utils/find-cid-in-shard.js'
4
4
import { decode } from '@ipld/dag-pb'
5
5
6
- // TODO Lazy load
7
- import contentFile from './content/file.js'
8
- import contentDirectory from './content/directory.js'
9
- import contentHamtShardedDirectory from './content/hamt-sharded-directory.js'
10
-
11
6
/**
12
7
* @typedef {import('../../types').Resolve } Resolve
13
8
* @typedef {import('../../types').Resolver } Resolver
@@ -26,18 +21,23 @@ const findLinkCid = (node, name) => {
26
21
}
27
22
28
23
/**
29
- * @type {{ [key: string]: UnixfsV1Resolver } }
24
+ * @param {string } key
25
+ * @returns {Promise<UnixfsV1Resolver|undefined> }
30
26
*/
31
- const contentExporters = {
32
- raw : contentFile ,
33
- file : contentFile ,
34
- directory : contentDirectory ,
35
- 'hamt-sharded-directory' : contentHamtShardedDirectory ,
36
- metadata : ( cid , node , unixfs , path , resolve , depth , blockstore ) => {
37
- return ( ) => [ ]
38
- } ,
39
- symlink : ( cid , node , unixfs , path , resolve , depth , blockstore ) => {
40
- return ( ) => [ ]
27
+ const importContentExporters = async ( key ) => {
28
+ switch ( key ) {
29
+ case 'raw' :
30
+ case 'file' :
31
+ return ( await ( import ( './content/file.js' ) ) ) . default
32
+ case 'directory' :
33
+ return ( await ( import ( './content/directory.js' ) ) ) . default
34
+ case 'hamt-sharded-directory' :
35
+ return ( await ( import ( './content/hamt-sharded-directory.js' ) ) ) . default
36
+ case 'metadata' :
37
+ case 'symlink' :
38
+ return ( ) => ( ) => [ ]
39
+ default :
40
+ return
41
41
}
42
42
}
43
43
@@ -95,14 +95,16 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks
95
95
}
96
96
}
97
97
98
+ const contentExporter = await importContentExporters ( unixfs . type )
99
+
98
100
return {
99
101
entry : {
100
102
type : unixfs . isDirectory ( ) ? 'directory' : 'file' ,
101
103
name,
102
104
path,
103
105
cid,
104
106
// @ts -ignore
105
- content : contentExporters [ unixfs . type ] ( cid , node , unixfs , path , resolve , depth , blockstore ) ,
107
+ content : contentExporter ( cid , node , unixfs , path , resolve , depth , blockstore ) ,
106
108
unixfs,
107
109
depth,
108
110
node,
0 commit comments