-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
38 lines (31 loc) · 922 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
const express = require("express");
const router = express.Router();
const { getIPFromStorage, storeData } = require("./IPFSLinker");
router.post("/decrypt", async (req, res) => {
const publicKey = req.body.key;
console.log("publicKey: ,", publicKey);
const IPAddr = await getIPFromStorage(publicKey);
if (IPAddr) {
console.log("Ip address found: ", IPAddr);
res.status(201);
} else {
console.log("Invalid Input");
res.status(400);
}
res.send({ worker_ipaddress: IPAddr });
});
router.post("/register-worker", async (req, res) => {
const IPAddr = req.body.ip;
const pubKey = req.body.pubKey;
const retVal = await storeData(IPAddr, pubKey);
console.log(retVal);
if (retVal == true) {
console.log("Successfully Stored in IPFS");
res.status(201);
} else {
console.log("Failed storing in IPFS");
res.status(400);
}
res.send();
});
module.exports = router;