Skip to content

Commit b52f180

Browse files
committed
ref(ipos): /pinFile car file to v0 cid
1 parent 8aa6e5e commit b52f180

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
"engines": {
1313
"pnpm": ">=9",
1414
"node": ">=20"
15+
},
16+
"pnpm": {
17+
"patchedDependencies": {
18+
19+
}
1520
}
1621
}

patches/[email protected]

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/dist/esm/pack/index.js b/dist/esm/pack/index.js
2+
index 97e262734c587f31b89aeaf370d11bb4760f33f0..fe0f34ce16a9a5a79174a0d9f7a33c6d63a9e637 100644
3+
--- a/dist/esm/pack/index.js
4+
+++ b/dist/esm/pack/index.js
5+
@@ -13,6 +13,7 @@ export async function pack({ input, blockstore: userBlockstore, hasher, maxChunk
6+
// Consume the source
7+
const rootEntry = await last(pipe(getNormaliser(input), (source) => importer(source, blockstore, {
8+
...unixfsImporterOptionsDefault,
9+
+ cidVersion: 0,
10+
hasher: hasher || unixfsImporterOptionsDefault.hasher,
11+
maxChunkSize: maxChunkSize || unixfsImporterOptionsDefault.maxChunkSize,
12+
maxChildrenPerNode: maxChildrenPerNode || unixfsImporterOptionsDefault.maxChildrenPerNode,

pnpm-lock.yaml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/ipos/biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"enabled": true
55
},
66
"files": {
7-
"ignore": ["node_modules", ".wrangler", ".papi"]
7+
"ignore": ["node_modules", ".wrangler", ".papi", "patches"]
88
},
99
"linter": {
1010
"enabled": true,

services/ipos/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@aws-sdk/client-s3": "^3.609.0",
2323
"@hono/valibot-validator": "^0.2.5",
2424
"hono": "^4.4.12",
25-
"ipfs-car": "^0.9.0",
25+
"ipfs-car": "0.9.2",
2626
"ipfs-only-hash": "^4.0.0",
2727
"ipfs-unixfs-importer": "^15.2.5",
2828
"multiformats": "^13.1.3",

services/ipos/src/routes/pinning.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
6666
const s3 = getS3(c)
6767

6868
let cid: string
69-
let file: Uint8Array | File
70-
let size: number
69+
let file: Blob | File
7170
let type: string
7271

7372
if (files.length > 1) {
@@ -78,9 +77,8 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
7877
})),
7978
)
8079

81-
cid = root.toString() as string
80+
cid = root.toString()
8281
file = car
83-
size = file.byteLength
8482
type = 'directory'
8583

8684
await s3.putObject({
@@ -97,7 +95,6 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
9795
cid = (await hashOf(content)).toV0().toString()
9896

9997
file = f
100-
size = f.size
10198
type = f.type
10299

103100
await s3.putObject({
@@ -114,7 +111,7 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
114111
getPinResponse({
115112
cid: cid,
116113
type: type,
117-
size: size,
114+
size: file.size,
118115
}),
119116
)
120117
})

services/ipos/src/utils/ipfs.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
import { MemoryBlockStore } from 'ipfs-car/blockstore/memory'
2-
import { pack } from 'ipfs-car/pack'
1+
// Patch: `ipfs-car` library has been patched to work with CID v0 which is not supported by the original implementation.
2+
// see `import { pack } from 'ipfs-car/pack'`
3+
import { packToBlob } from 'ipfs-car/pack/blob'
34
import type { CID } from 'multiformats'
45

56
export default async function toCar(
67
input: { path: string; content: Uint8Array }[],
78
) {
8-
const { root, out } = await pack({
9+
const { root, car } = await packToBlob({
910
input: input,
10-
blockstore: new MemoryBlockStore(),
1111
wrapWithDirectory: true,
1212
})
1313

14-
const chunks = []
15-
for await (const chunk of out) {
16-
chunks.push(chunk)
17-
}
18-
19-
const car = new Uint8Array(
20-
chunks.reduce((acc, chunk) => acc.concat(Array.from(chunk)), []),
21-
)
22-
2314
return {
2415
root: root as CID,
25-
car,
16+
car: car as Blob,
2617
}
2718
}

0 commit comments

Comments
 (0)