Skip to content

Commit 9a9123c

Browse files
authored
Merge pull request #343 from hassnian/fix-ipos-cid-mismatch
fix(ipos): invalid `cid`
2 parents 67da514 + 20ff2b1 commit 9a9123c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: services/ipos/src/routes/pinning.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ app.post('/pinJson', vValidator('json', object({})), async (c) => {
1919
const s3 = getS3(c)
2020

2121
const content = JSON.stringify(body)
22-
const cid = (await hashOf(content)).toV0().toString()
22+
const cid = (await hashOf(content)).toString()
2323

2424
await s3.putObject({
2525
Body: content,
@@ -91,7 +91,7 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
9191
},
9292
})
9393

94-
const promises: Promise<R2Object | null>[] = []
94+
const promises: Promise<R2Object | null>[] = []
9595
for (const { file } of files) {
9696
const path = `${cid}/${file.name}`
9797
promises.push(c.env.BUCKET.put(keyOf(path), file))
@@ -100,7 +100,7 @@ app.post('/pinFile', vValidator('form', pinFileRequestSchema), async (c) => {
100100
c.executionCtx.waitUntil(Promise.allSettled(promises))
101101
} else {
102102
const { content, file: f } = files[0]
103-
cid = (await hashOf(content)).toV0().toString()
103+
cid = (await hashOf(content)).toString()
104104

105105
file = f
106106
type = f.type

Diff for: services/ipos/src/utils/format.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export function getObjectSize(obj: Record<string, unknown>) {
1212
}
1313

1414
export async function hashOf(content: ImportContent | string): Promise<CID> {
15-
return CID.parse(await Hash.of(content, { onlyHash: true, cidVersion: 1 }))
15+
// note: generating the hash.of from cid v1 and then converting it to cid v0 generates a wrong cid with big file sizes
16+
return CID.parse(await Hash.of(content, { onlyHash: true, cidVersion: 0 }))
1617
}
1718

1819
export function keyOf(cid: string) {

0 commit comments

Comments
 (0)