Skip to content

Commit aff8916

Browse files
committed
unique sha
1 parent 3e09b2a commit aff8916

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ app.get('/add-sha/:sha', (req, res) => {
107107

108108
app.get('/collect-sha/:sha', async (req, res) => {
109109
const ip = req.headers['x-forwarded-for']
110-
// const ip = "176.10.112.40";
111-
const item = await Item.create({ sha: req.params.sha, ip: ip })
112-
return res.json({item})
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})
117+
}
113118
})
114119

115120
app.get('/scan/:ip', async (req, res) => {

0 commit comments

Comments
 (0)