Compare commits

..

1 Commits

Author SHA1 Message Date
Renovate Bot
62a6070bfd Update dependency fastify to v5.3.3
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-05-14 02:07:19 +00:00
4 changed files with 12 additions and 19 deletions

View File

@ -41,20 +41,15 @@ export const load = (id: string) =>
return res;
});
var version_add = 1
export const save = async (id: string, v: journey) => {
let body = JSON.parse(JSON.stringify(v))
body.version +=version_add;
return fetch("/api/" + id, { method: "post", body: JSON.stringify(body) })
export const save = (id: string, v: journey) =>
fetch("/api/" + id, { method: "post", body: JSON.stringify(v) })
.then((res) => {
if (!res.ok) throw new Error("Error " + res.statusText);
return res.json();
})
.then((_res) => {
version_add+=1;
console.log("Saved...");
});
}
export const query_nominatim = (
q: string,

View File

@ -35,7 +35,6 @@ declare global {
interface journey {
fmt_ver: number
version: number
title: string
main: leg[]
}
@ -53,7 +52,6 @@ const leg_template: leg = {
}
const journey_template: journey = {
fmt_ver: 1,
version: 0,
title: "New Journey",
main: [leg_template],
}

View File

@ -10,7 +10,6 @@ function migrate_A_to_0(e: journey): journey {
v.travel = v.travel || [];
v.day_title = typeof (v.day_title) == "string" ? [v.day_title] : []
})
e.version = e.version || 0;
console.log(e)
return e;
}

View File

@ -75,15 +75,16 @@ export default function (server, opts, done) {
if (req.params.id == undefined)
return reply.code(400).send({ error: "No ID query parameter" });
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 || db_version == -1)
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."});
})
})
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;
});
done();
};