Skip to content

Commit 258a3b1

Browse files
committed
feat: add retrieval by cid of object mappings
1 parent 13844c3 commit 258a3b1

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

services/object-mapping-indexer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@auto-files/models": "workspace:*",
1818
"@auto-files/rpc-apis": "workspace:*",
19-
"@autonomys/auto-dag-data": "^1.0.5",
19+
"@autonomys/auto-dag-data": "^1.4.35",
2020
"@autonomys/rpc": "^1.4.31",
2121
"@peculiar/webcrypto": "^1.5.0",
2222
"@types/node": "^22.10.2",

services/object-mapping-indexer/src/http/controllers/objects.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ objectsController.get('/:hash', async (req, res, next) => {
2727
}
2828
})
2929

30+
objectsController.get('/by-cid/:cid', async (req, res, next) => {
31+
try {
32+
const { cid } = req.params
33+
34+
const object = await objectMappingUseCase.getObjectByCid(cid)
35+
36+
res.json(object)
37+
} catch (err) {
38+
next(err)
39+
}
40+
})
41+
3042
objectsController.get('/by-block/:blockNumber', async (req, res, next) => {
3143
try {
3244
const { blockNumber } = req.params

services/object-mapping-indexer/src/useCases/objectMapping.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@auto-files/models'
66
import { objectMappingRepository } from '../repositories/objectMapping.js'
77
import { objectMappingRouter } from '../services/objectMappingRouter/index.js'
8+
import { blake3HashFromCid, stringToCid } from '@autonomys/auto-dag-data'
89

910
const processObjectMapping = async (event: ObjectMappingListEntry) => {
1011
await Promise.all([
@@ -92,11 +93,26 @@ const getObjectMappings = async (
9293
})
9394
}
9495

96+
const getObjectByCid = async (cid: string): Promise<ObjectMapping> => {
97+
const hash = Buffer.from(blake3HashFromCid(stringToCid(cid))).toString('hex')
98+
const objectMapping = await objectMappingRepository.getByHash(hash)
99+
if (!objectMapping) {
100+
throw new Error('Object mapping not found')
101+
}
102+
103+
return [
104+
objectMapping.hash,
105+
objectMapping.pieceIndex,
106+
objectMapping.pieceOffset,
107+
]
108+
}
109+
95110
export const objectMappingUseCase = {
96111
processObjectMapping,
97112
getObject,
98113
getObjectByPieceIndex,
99114
getObjectByBlock,
100115
getObjectByPieceIndexAndStep,
101116
getObjectMappings,
117+
getObjectByCid,
102118
}

yarn.lock

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ __metadata:
3636
languageName: unknown
3737
linkType: soft
3838

39-
"@autonomys/asynchronous@npm:^1.4.17":
40-
version: 1.4.17
41-
resolution: "@autonomys/asynchronous@npm:1.4.17"
42-
checksum: 10c0/f3fe5f5849108a73b45ac9c05f68034730c5ca64fd77c1ed63b1e6f7d7e9d7c1a1d425ec0cc8f436f4e3d5021b904be61647940565d2d8b90277177eac846c3e
43-
languageName: node
44-
linkType: hard
45-
4639
"@autonomys/asynchronous@npm:^1.4.31":
4740
version: 1.4.31
4841
resolution: "@autonomys/asynchronous@npm:1.4.31"
@@ -52,11 +45,20 @@ __metadata:
5245
languageName: node
5346
linkType: hard
5447

55-
"@autonomys/auto-dag-data@npm:^1.0.5":
56-
version: 1.4.17
57-
resolution: "@autonomys/auto-dag-data@npm:1.4.17"
48+
"@autonomys/asynchronous@npm:^1.4.35":
49+
version: 1.4.35
50+
resolution: "@autonomys/asynchronous@npm:1.4.35"
51+
dependencies:
52+
stream-fork: "npm:^1.0.5"
53+
checksum: 10c0/493a64e21cc64eca6c252fef68b0de3f7fbccf3428cf0c9d6b74458aa0aff6ca74f139bb9790234a0c5d42d743b8672e10efd15cd567bf2096967fc1434a41c7
54+
languageName: node
55+
linkType: hard
56+
57+
"@autonomys/auto-dag-data@npm:^1.4.31":
58+
version: 1.4.31
59+
resolution: "@autonomys/auto-dag-data@npm:1.4.31"
5860
dependencies:
59-
"@autonomys/asynchronous": "npm:^1.4.17"
61+
"@autonomys/asynchronous": "npm:^1.4.31"
6062
"@ipld/dag-pb": "npm:^4.1.3"
6163
"@peculiar/webcrypto": "npm:^1.5.0"
6264
"@webbuf/blake3": "npm:^3.0.26"
@@ -67,15 +69,15 @@ __metadata:
6769
protobufjs: "npm:^7.4.0"
6870
protons: "npm:^7.6.0"
6971
protons-runtime: "npm:^5.5.0"
70-
checksum: 10c0/313b73af85452aec908a08483f946f41ebeb9be08a691e5d1b6cad20ca6e2c07aadd09f446499a693f192e688c2622c36e4c3142ac4f54aa8acda108e8779a0f
72+
checksum: 10c0/f06fbeeac5e2266e233539791d2435d1220e6c53c2bf3ee38a03b5e332526d84ad53bb6569e5b9607c06e09c53fcaf8339c1dc4d2421497807c882d8d7502ce2
7173
languageName: node
7274
linkType: hard
7375

74-
"@autonomys/auto-dag-data@npm:^1.4.31":
75-
version: 1.4.31
76-
resolution: "@autonomys/auto-dag-data@npm:1.4.31"
76+
"@autonomys/auto-dag-data@npm:^1.4.35":
77+
version: 1.4.35
78+
resolution: "@autonomys/auto-dag-data@npm:1.4.35"
7779
dependencies:
78-
"@autonomys/asynchronous": "npm:^1.4.31"
80+
"@autonomys/asynchronous": "npm:^1.4.35"
7981
"@ipld/dag-pb": "npm:^4.1.3"
8082
"@peculiar/webcrypto": "npm:^1.5.0"
8183
"@webbuf/blake3": "npm:^3.0.26"
@@ -86,7 +88,7 @@ __metadata:
8688
protobufjs: "npm:^7.4.0"
8789
protons: "npm:^7.6.0"
8890
protons-runtime: "npm:^5.5.0"
89-
checksum: 10c0/f06fbeeac5e2266e233539791d2435d1220e6c53c2bf3ee38a03b5e332526d84ad53bb6569e5b9607c06e09c53fcaf8339c1dc4d2421497807c882d8d7502ce2
91+
checksum: 10c0/bbe022a5b936e446f737f12a9f063704967b483ad0f1b59435f16908e38fc2551f27e0d46352d2f8fcea831323257f1995faf1589beec48dd2e4085dea7ede60
9092
languageName: node
9193
linkType: hard
9294

@@ -7307,7 +7309,7 @@ __metadata:
73077309
dependencies:
73087310
"@auto-files/models": "workspace:*"
73097311
"@auto-files/rpc-apis": "workspace:*"
7310-
"@autonomys/auto-dag-data": "npm:^1.0.5"
7312+
"@autonomys/auto-dag-data": "npm:^1.4.35"
73117313
"@autonomys/rpc": "npm:^1.4.31"
73127314
"@peculiar/webcrypto": "npm:^1.5.0"
73137315
"@types/cors": "npm:^2.8.17"

0 commit comments

Comments
 (0)