Skip to content

Commit 43e2d7c

Browse files
committed
added metadata to items
1 parent c9c4b4d commit 43e2d7c

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

client/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ async function scan() {
109109
}
110110

111111
// Add SHA
112-
async function addSHA(sha) {
112+
async function addSHA(sha, meta) {
113+
meta = btoa(meta)
113114
const response = await fetch("https://mycookie-monster.herokuapp.com/add-sha/"+sha, {
114-
headers: {'Content-Type': 'application/json'},
115+
headers: {'Content-Type': 'application/json', 'metadata': meta},
115116
method: 'GET'
116117
})
117118
return response.json()
@@ -167,14 +168,14 @@ nowFetch().then(response => {
167168
const optIn = document.querySelector('.optIn')
168169
optIn.addEventListener('click', (e) => {
169170
e.preventDefault()
170-
collectHASH(HASH).then(resp => {console.log(resp)})
171+
collectHASH(HASH, data).then(resp => {console.log(resp)})
171172
.catch(e => {console.log(e)})
172173
})
173174

174175
const scanButton = document.querySelector('.scanButton')
175176
scanButton.addEventListener('click', async (e) => {
176177
document.querySelector('.scan-results').textContent = `Scanning.....`;
177-
await collectHASH(HASH).then(resp => {console.log(resp)})
178+
await collectHASH(HASH, data).then(resp => {console.log(resp)})
178179
.catch(e => {console.log(e)})
179180

180181
scan().then(scanRes => {

index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const sequelize = new Sequelize('sqlite::memory:', {
1414

1515
const Item = sequelize.define("Item", {
1616
sha: { type: DataTypes.STRING, allowNull: false },
17-
ip: { type: DataTypes.STRING, allowNull: false }
17+
ip: { type: DataTypes.STRING, allowNull: false },
18+
headers: {type: DataTypes.STRING, allowNull: true},
19+
graphics: {type: DataTypes.STRING, allowNull: true},
20+
memory: {type: DataTypes.STRING, allowNull: true},
21+
platform: {type: DataTypes.STRING, allowNull: true},
22+
hardwareConcurrency: {type: DataTypes.STRING, allowNull: true},
1823
})
1924

2025
const {
@@ -106,14 +111,23 @@ app.get('/add-sha/:sha', (req, res) => {
106111
})
107112

108113
app.get('/collect-sha/:sha', async (req, res) => {
109-
const ip = req.headers['x-forwarded-for']
110-
const item = await Item.findOne({where: { sha: req.params.sha }})
111-
if (item !== null) {
112-
return res.json({message: "visited"})
113-
} else {
114-
console.log(JSON.stringify(item, null, 2))
115-
const newItem = await Item.create({ sha: req.params.sha, ip: ip })
116-
return res.json({item: newItem})
114+
try {
115+
const ip = req.headers['x-forwarded-for']
116+
const metadata = JSON.parse(Base64.decode(req.headers['metadata']))
117+
const {headers, isp, memory, platform, hardwareConcurrency, graphics} = metadata
118+
const item = await Item.findOne({where: { sha: req.params.sha }})
119+
if (item !== null) {
120+
return res.json({message: "visited"})
121+
} else {
122+
console.log(JSON.stringify(item, null, 2))
123+
const newItem = await Item.create({
124+
sha: req.params.sha,
125+
ip, headers, isp, platform, memory, hardwareConcurrency, graphics
126+
})
127+
return res.json({item: newItem})
128+
}
129+
} catch {
130+
return res.status(422).json({message: "Something Went Wrong"})
117131
}
118132
})
119133

0 commit comments

Comments
 (0)