Skip to content

Commit 89c2603

Browse files
committed
added count handlers
1 parent dc5eade commit 89c2603

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

client/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ async function addSHA(sha) {
109109
return response.json()
110110
}
111111

112+
//Find Count
113+
async function findCount(sha) {
114+
const response = await fetch("http://localhost:4000/get-count/"+sha, {
115+
headers: {'Content-Type': 'application/json'},
116+
method: 'GET'
117+
})
118+
return response.json()
119+
}
120+
112121
// init req
113122
async function nowFetch() {
114123
const response = await fetch("https://mycookie-monster.herokuapp.com/", {
@@ -160,6 +169,9 @@ nowFetch().then(response => {
160169
const HASH = sha1(encodedDynamic)
161170
addSHA(HASH).then(shaRESPONSE => {
162171
console.log(shaRESPONSE)
172+
findCount(HASH).then(countRes => {
173+
console.log(countRes)
174+
})
163175
})
164176
console.log("HASH:" + HASH)
165177
const hashPhrase = `Your identity HASH: ${HASH}`

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ app.get('/generate/:data', async (req, res) => { // Because URL PARAMS ARE COOLE
7777
})
7878
})
7979

80-
app.get('/add-sha/:sha', (req, res) => {
80+
app.get('/add-sha/:sha', async (req, res) => {
8181
const encoded = Base64.encode(1);
82-
Axios.put("https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req.params.sha, {
82+
await Axios.put("https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/" + req.params.sha, {
8383
message: "Added a document",
8484
content: encoded
8585
}, {
@@ -91,6 +91,17 @@ app.get('/add-sha/:sha', (req, res) => {
9191
})
9292
})
9393

94+
app.get("/get-count/:sha", async (req, res) => {
95+
const sha = req.params.sha;
96+
await Axios.get("https://api.github.com/repos/ujjwal-kr-data/ip-data/contents/"+sha, {
97+
headers: {'Authorization': "token "+KEY}
98+
}).then(res => {
99+
console.log(res)
100+
}).catch(e => {
101+
res.json({message: "ERRRR"})
102+
})
103+
})
104+
94105
const port = process.env.PORT || 4000;
95106
app.listen(port, () => {
96107
console.log(`Waiting on port for someone :) ${port}`);

0 commit comments

Comments
 (0)