Update src/server/api.ts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -73,6 +73,7 @@ export default function (server, opts, done) {
|
|||||||
return reply.code(400).send({ error: "No ID query parameter" });
|
return reply.code(400).send({ error: "No ID query parameter" });
|
||||||
|
|
||||||
return server.level.db.get(req.params.id).then(r=>JSON.parse(r)).then(r=>r.version||-1).catch(_=>-1).then(db_version=>{
|
return server.level.db.get(req.params.id).then(r=>JSON.parse(r)).then(r=>r.version||-1).catch(_=>-1).then(db_version=>{
|
||||||
|
console.log(`Received ${req.body.version}, expected ${db_version+1} (-1 if expected nothing)`)
|
||||||
if(db_version+1 == req.body.version || db_version == -1)
|
if(db_version+1 == req.body.version || db_version == -1)
|
||||||
return server.level.db.put(req.params.id, req.body)
|
return server.level.db.put(req.params.id, req.body)
|
||||||
.then(_=>reply.send({ content: "ok" }))
|
.then(_=>reply.send({ content: "ok" }))
|
||||||
|
Reference in New Issue
Block a user