|
1 |
| -import { PBNode } from '@ipld/dag-pb' |
2 |
| -import { BaseBlockstore } from 'blockstore-core' |
3 | 1 | import { CID } from 'multiformats'
|
4 |
| -import { |
5 |
| - cidOfNode, |
6 |
| - cidToString, |
7 |
| - decodeIPLDNodeData, |
8 |
| - IPLDBlockstore, |
9 |
| - IPLDNodeData, |
10 |
| - MetadataType, |
11 |
| - stringToCid, |
12 |
| -} from '../../index.js' |
13 |
| -import { decodeNode } from '../../ipld/utils.js' |
| 2 | +import { cidToString } from '../../index.js' |
14 | 3 |
|
15 | 4 | export type OffchainFileMetadata = {
|
16 | 5 | type: 'file'
|
@@ -44,46 +33,3 @@ export const fileMetadata = (
|
44 | 33 | chunks,
|
45 | 34 | }
|
46 | 35 | }
|
47 |
| - |
48 |
| -export const constructFileMetadataFromBlockstore = async ( |
49 |
| - cid: CID | string, |
50 |
| - blockstore: IPLDBlockstore, |
51 |
| - mimeType?: string | null, |
52 |
| -): Promise<OffchainFileMetadata> => { |
53 |
| - cid = typeof cid === 'string' ? stringToCid(cid) : cid |
54 |
| - |
55 |
| - const node = await blockstore.get(cid) |
56 |
| - const decoded = decodeNode(node) |
57 |
| - const ipldData = IPLDNodeData.decode(decoded.Data!) |
58 |
| - |
59 |
| - let children = await Promise.all(decoded.Links!.map((link) => blockstore.get(link.Hash))) |
60 |
| - let isAnyoneInLink = children.some((e) => decodeIPLDNodeData(e).linkDepth > 0) |
61 |
| - |
62 |
| - while (isAnyoneInLink) { |
63 |
| - const unflattenedChildren = await Promise.all( |
64 |
| - children.map((e) => { |
65 |
| - const decoded = decodeNode(e) |
66 |
| - const ipldData = decodeIPLDNodeData(e) |
67 |
| - |
68 |
| - return ipldData.linkDepth > 0 |
69 |
| - ? Promise.all(decoded.Links!.map((link) => blockstore.get(link.Hash))) |
70 |
| - : [e] |
71 |
| - }), |
72 |
| - ) |
73 |
| - |
74 |
| - children = unflattenedChildren.flat() |
75 |
| - } |
76 |
| - |
77 |
| - const totalSize = children.reduce((acc, e) => acc + (decodeIPLDNodeData(e).size ?? 0), 0) |
78 |
| - |
79 |
| - return fileMetadata( |
80 |
| - cid, |
81 |
| - children.map((e) => ({ |
82 |
| - size: decodeIPLDNodeData(e).size ?? 0, |
83 |
| - cid: cidToString(cidOfNode(decodeNode(e))), |
84 |
| - })), |
85 |
| - totalSize, |
86 |
| - ipldData.name, |
87 |
| - mimeType, |
88 |
| - ) |
89 |
| -} |
0 commit comments