|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+import { createHelia } from 'helia'
|
|
|
2
|
+import { json } from '@helia/json'
|
|
|
3
|
+import * as winston from 'winston'
|
|
|
4
|
+
|
|
|
5
|
+const logger = winston.createLogger({
|
|
|
6
|
+ level: 'info',
|
|
|
7
|
+ defaultMeta: { service: 'helia-test' },
|
|
|
8
|
+ transports: [
|
|
|
9
|
+ new winston.transports.Console({ level: 'debug' }),
|
|
|
10
|
+ new winston.transports.File({ filename: 'log.txt' }),
|
|
|
11
|
+ ],
|
|
|
12
|
+});
|
|
|
13
|
+
|
|
|
14
|
+
|
|
|
15
|
+(async()=>{
|
|
|
16
|
+ const helia = await createHelia()
|
|
|
17
|
+ logger.info('Helia node started. Peer ID: ' + helia.libp2p.peerId.toString())
|
|
|
18
|
+
|
|
|
19
|
+ const j = json(helia)
|
|
|
20
|
+
|
|
|
21
|
+ const jsonCid = await j.add({ message: 'IPFS test 0', timestamp: Date.now() })
|
|
|
22
|
+ logger.info('Added JSON, CID: ' + jsonCid.toString())
|
|
|
23
|
+
|
|
|
24
|
+ try {
|
|
|
25
|
+ logger.info("Announcing " + jsonCid)
|
|
|
26
|
+ await helia.routing.provide(jsonCid)
|
|
|
27
|
+ } catch (error: any) {
|
|
|
28
|
+ logger.error(String(error))
|
|
|
29
|
+ throw error
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
|
32
|
+ logger.info(`https://ipfs.io/ipfs/${jsonCid}`)
|
|
|
33
|
+})()
|