Compare commits

...

4 Commits

Author SHA1 Message Date
Renovate Bot
83ae38edd1 Update dependency fastify to v5.3.3
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-05-15 02:07:05 +00:00
soraefir
38d895a959
WIP
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-15 00:55:06 +02:00
soraefir
6690b055b4
Fix noversion
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-15 00:47:04 +02:00
soraefir
09b9830fd0
Update
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-15 00:35:39 +02:00
5 changed files with 28 additions and 16 deletions

View File

@ -41,15 +41,20 @@ export const load = (id: string) =>
return res;
});
export const save = (id: string, v: journey) =>
fetch("/api/" + id, { method: "post", body: JSON.stringify(v) })
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) })
.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,6 +35,7 @@ declare global {
interface journey {
fmt_ver: number
version: number
title: string
main: leg[]
}
@ -52,6 +53,7 @@ const leg_template: leg = {
}
const journey_template: journey = {
fmt_ver: 1,
version: 0,
title: "New Journey",
main: [leg_template],
}

View File

@ -10,6 +10,7 @@ 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,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 || 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."});
})
})
done();
};

View File

@ -728,9 +728,9 @@ fastify-plugin@^5.0.0:
integrity sha512-HCxs+YnRaWzCl+cWRYFnHmeRFyR5GVnJTAaCJQiYzQSDwK9MgJdyAsuL3nh0EWRCYMgQ5MeziymvmAhUHYHDUQ==
fastify@^5.2.1:
version "5.3.2"
resolved "https://registry.yarnpkg.com/fastify/-/fastify-5.3.2.tgz#88c895a30c0f67166979077ac8649fe8b205a1b3"
integrity sha512-AIPqBgtqBAwkOkrnwesEE+dOyU30dQ4kh7udxeGVR05CRGwubZx+p2H8P0C4cRnQT0+EPK4VGea2DTL2RtWttg==
version "5.3.3"
resolved "https://registry.yarnpkg.com/fastify/-/fastify-5.3.3.tgz#14915c39a6198dbb0a3910e0d1f13e04234bbedc"
integrity sha512-nCBiBCw9q6jPx+JJNVgO8JVnTXeUyrGcyTKPQikRkA/PanrFcOIo4R+ZnLeOLPZPGgzjomqfVarzE0kYx7qWiQ==
dependencies:
"@fastify/ajv-compiler" "^4.0.0"
"@fastify/error" "^4.0.0"
@ -1504,11 +1504,16 @@ secure-json-parse@^4.0.0:
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-4.0.0.tgz#2ee1b7581be38ab348bab5a3e49280ba80a89c85"
integrity sha512-dxtLJO6sc35jWidmLxo7ij+Eg48PM/kleBsxpC8QJE0qJICe+KawkDQmvCMZUr9u7WKVHgMW6vy3fQ7zMiFZMA==
semver@^7.5.3, semver@^7.6.0:
semver@^7.5.3:
version "7.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.1.tgz#abd5098d82b18c6c81f6074ff2647fd3e7220c9f"
integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==
semver@^7.6.0:
version "7.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.2.tgz#67d99fdcd35cec21e6f8b87a7fd515a33f982b58"
integrity sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==
set-cookie-parser@^2.6.0:
version "2.7.1"
resolved "https://registry.yarnpkg.com/set-cookie-parser/-/set-cookie-parser-2.7.1.tgz#3016f150072202dfbe90fadee053573cc89d2943"