Skip to content

Commit 58883c1

Browse files
committed
chore: remove metadata constructors
1 parent 9773f7e commit 58883c1

File tree

2 files changed

+1
-93
lines changed

2 files changed

+1
-93
lines changed
Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import { PBNode } from '@ipld/dag-pb'
2-
import { BaseBlockstore } from 'blockstore-core'
31
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'
143

154
export type OffchainFileMetadata = {
165
type: 'file'
@@ -44,46 +33,3 @@ export const fileMetadata = (
4433
chunks,
4534
}
4635
}
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-
}

packages/auto-drive/src/metadata/offchain/folder.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { PBNode } from '@ipld/dag-pb'
22
import { CID } from 'multiformats'
33
import { cidOfNode, cidToString, stringToCid } from '../../cid/index.js'
4-
import { IPLDBlockstore } from '../../ipld/index.js'
54
import { decodeNode } from '../../ipld/utils.js'
65
import { decodeIPLDNodeData, IPLDNodeData, MetadataType } from '../onchain/index.js'
76

@@ -51,40 +50,3 @@ export const folderMetadata = (
5150
name: name ?? undefined,
5251
}
5352
}
54-
55-
export const constructFolderMetadataFromBlockstore = async (
56-
cid: CID | string,
57-
blockstore: IPLDBlockstore,
58-
): Promise<OffchainFolderMetadata> => {
59-
cid = typeof cid === 'string' ? stringToCid(cid) : cid
60-
61-
const node = await blockstore.get(cid)
62-
const decoded = decodeNode(node)
63-
const ipldData = IPLDNodeData.decode(decoded.Data!)
64-
65-
let children = await Promise.all(decoded.Links!.map((link) => blockstore.get(link.Hash)))
66-
let isAnyoneInLink = children.some((e) => decodeIPLDNodeData(e).linkDepth > 0)
67-
68-
while (isAnyoneInLink) {
69-
const unflattenedChildren = await Promise.all(
70-
children.map((e) => {
71-
const decoded = decodeNode(e)
72-
const ipldData = decodeIPLDNodeData(e)
73-
74-
return ipldData.linkDepth > 0
75-
? Promise.all(decoded.Links!.map((link) => blockstore.get(link.Hash)))
76-
: [e]
77-
}),
78-
)
79-
80-
children = unflattenedChildren.flat()
81-
const ipldData = children.map((e) => decodeIPLDNodeData(e))
82-
isAnyoneInLink = ipldData.some((e) => e.linkDepth > 0)
83-
}
84-
85-
return folderMetadata(
86-
cid,
87-
children.map((e) => childrenMetadataFromNode(decodeNode(e))),
88-
ipldData.name,
89-
)
90-
}

0 commit comments

Comments
 (0)