-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrouter.js
39 lines (28 loc) · 861 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Router = require('koa-router');
const ipfs = require('./ipfs');
const db = require('./database');
const router = new Router();
router.get('/', async (ctx) => {
const { id } = await ipfs.id();
ctx.body = `Connected to IPFS node ${id}`;
});
router.get('/pin', async (ctx) => {
const files = await ipfs.pin.ls();
ctx.body = files;
});
router.post('/pin/:hash', async (ctx) => {
const files = await ipfs.pin.add(ctx.params.hash);
ctx.body = files;
});
router.delete('/pin/:hash', async (ctx) => {
const files = await ipfs.pin.rm(ctx.params.hash);
ctx.body = files;
});
router.get('/contract/:address', async (ctx) => {
const contract = db.getContract(ctx.params.address);
ctx.body = {
contract,
events: contract && contract.configHash ? await ipfs.getConfig(contract.configHash) : null,
};
})
module.exports = router;