Update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
soraefir
2025-05-15 00:35:39 +02:00
parent d1c4a23e26
commit 09b9830fd0
4 changed files with 16 additions and 12 deletions

View File

@@ -75,16 +75,15 @@ export default function (server, opts, done) {
if (req.params.id == undefined)
return reply.code(400).send({ error: "No ID query parameter" });
server.level.db.put(req.params.id, req.body, (err) => {
if (err) {
console.warn(err);
reply.code(500).send({ error: "Error with DB" });
} else {
reply.send({ content: "ok" });
}
});
return reply;
});
return server.level.db.get(req.params.id).then(r=>r.version||-1).catch(_=>-1).then(db_version=>{
if(db_version+1 == req.body.version)
return server.level.db.put(req.params.id, req.body)
.then(_=>reply.send({ content: "ok" }))
.catch(_=>reply.code(500).send({ error: "Error with DB" }))
return reply.code(409).send({error:"Too old version, please refresh."});
})
})
done();
};