From 096705ce654581b774a1947ae293040e6143a827 Mon Sep 17 00:00:00 2001 From: KarthiKeyanZ Date: Mon, 20 Nov 2023 13:12:23 +0530 Subject: [PATCH] node distribution functionality --- package.json | 3 + server/controllers/BlockchainBlock.ts | 39 ++++++++++ .../components/header/header.component.html | 1 - src/app/view/location/location.component.css | 20 +++++ src/app/view/location/location.component.html | 8 ++ .../view/location/location.component.spec.ts | 25 +++++++ src/app/view/location/location.component.ts | 70 ++++++++++++++++++ src/app/view/view-routing.module.ts | 5 ++ src/app/view/view.module.ts | 4 +- src/assets/img/icons8-location-80.png | Bin 0 -> 2305 bytes 10 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 src/app/view/location/location.component.css create mode 100644 src/app/view/location/location.component.html create mode 100644 src/app/view/location/location.component.spec.ts create mode 100644 src/app/view/location/location.component.ts create mode 100644 src/assets/img/icons8-location-80.png diff --git a/package.json b/package.json index 9b648d5..bdf9306 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,11 @@ "dotenv": "^8.0.0", "express": "^4.15.2", "express-static-gzip": "^1.1.3", + "geoip-lite": "^1.4.7", "helmet": "^3.18.0", "jsdom": "^15.1.1", + "leaflet": "^1.9.4", + "leaflet.markercluster": "^1.5.3", "moment": "^2.24.0", "morgan": "^1.9.1", "ng2-odometer": "^1.1.3", diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index a4c8146..968dc11 100644 --- a/server/controllers/BlockchainBlock.ts +++ b/server/controllers/BlockchainBlock.ts @@ -26,6 +26,7 @@ import { latestBlockDetails, previousBlockDetails } from '../utils/common'; +const geoip = require('geoip-lite'); var moment = require('moment'); moment.updateLocale('en', { relativeTime: { @@ -270,6 +271,11 @@ export class BlockchainBlockController { redisMiddleware(process.env.REDIS_EXPIRY), this.getepicmineapi, ); + this.router.get( + `${this.path}/v1/peers/all`, + redisMiddleware(process.env.REDIS_EXPIRY), + this.getpeersallapi, + ); /** * @swagger @@ -758,6 +764,39 @@ export class BlockchainBlockController { console.log(error); } }; + // get /v1/peers/all + private getpeersallapi = async( request: Request,res: Response) => { + var axios = require('axios'); + try { + var config = { + method: 'get', + url: 'http://5.75.242.4:3413/v1/peers/all', + headers: { } + }; + await axios(config).then( (response) => { + const data = response.data; + + // Perform IP geolocation for each item in the 'data' array + data.forEach(peer => { + const ip = peer.addr.split(':')[0]; + const geo = geoip.lookup(ip); + + // Add the 'geo' data to the 'peer' object + peer.geo = geo; + }); + res.status(200).json({ + status: 200, + response: data + }); + }) + .catch(function (error) { + console.log('axios-error'); + console.log(error); + }); + } catch (error) { + console.log(error); + } + }; private BlockchainBlockCreate = async ( request: Request, diff --git a/src/app/shared/components/header/header.component.html b/src/app/shared/components/header/header.component.html index a68f7c1..248c3c3 100755 --- a/src/app/shared/components/header/header.component.html +++ b/src/app/shared/components/header/header.component.html @@ -56,7 +56,6 @@ -