Compare commits

..

1 Commits

Author SHA1 Message Date
cef1cd01f4 Lock file maintenance
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-03-05 02:03:18 +00:00
8 changed files with 413 additions and 419 deletions

View File

@ -20,8 +20,8 @@
"dependencies": { "dependencies": {
"@fastify/leveldb": "^6.0.0", "@fastify/leveldb": "^6.0.0",
"@fastify/static": "^8.0.0", "@fastify/static": "^8.0.0",
"@fastify/view": "^11.0.0", "@fastify/view": "^10.0.0",
"@types/node": "^24.0.0", "@types/node": "^22.13.5",
"esbuild": "^0.25.0", "esbuild": "^0.25.0",
"fastify": "^5.2.1", "fastify": "^5.2.1",
"jsdom": "^26.0.0", "jsdom": "^26.0.0",

View File

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

View File

@ -1,96 +1,61 @@
import { getGeoLine } from "../types/geom"; import { getGeoLine } from "../types/geom";
import * as api from "../api"; import * as api from "../api";
const filter_existing = function ( const filter_existing = function (tpe: "nominatim" | "travel", leg: leg, r: geoloc[]) {
tpe: "nominatim" | "travel",
leg: leg,
r: geoloc[]
) {
switch (tpe) { switch (tpe) {
case "nominatim": case 'nominatim':
return r.filter((e) => { return r.filter(e => {
if (leg.hotel && leg.hotel.osm_id == e.osm_id) return false; if (leg.hotel && leg.hotel.osm_id == e.osm_id) return false;
if (leg.places.restaurants.find((i) => i.osm_id == e.osm_id)) if (leg.places.restaurants.find(i => i.osm_id == e.osm_id)) return false;
return false; if (leg.places.activities.find(i => i.osm_id == e.osm_id)) return false;
if (leg.places.activities.find((i) => i.osm_id == e.osm_id)) return true
return false; })
return true; case 'travel':
}); console.log(r)
case "travel": return r.filter(e => {
console.log(r); if (leg.travel.find(i => `${(e as any).from}->${(e as any).to}` == `${(i as any).from}->${(i as any).to}`)) return false;
return r.filter((e) => { return true
if ( })
leg.travel.find(
(i) =>
`${(e as any).from}->${(e as any).to}` ==
`${(i as any).from}->${(i as any).to}`
)
)
return false;
return true;
});
} }
}; }
const process_results = function (tpe: "nominatim" | "travel", r: geoloc[]) { const process_results = function (tpe: "nominatim" | "travel", r: geoloc[]) {
switch (tpe) { switch (tpe) {
case "nominatim": case 'nominatim':
return r.map((rr) => { return r.map((rr) => {
rr.latlon = [ rr.latlon = [parseFloat((rr as any).lat), parseFloat((rr as any).lon)];
parseFloat((rr as any).lat),
parseFloat((rr as any).lon),
];
rr.title = (rr as any).display_name.split(",")[0]; rr.title = (rr as any).display_name.split(",")[0];
return rr; return rr;
}); });
case "travel": case 'travel':
console.log(r); console.log(r)
return r.map((el) => { return r.map(el => {
(el as any).path = getGeoLine( (el as any).path = getGeoLine(
{ { lat: (el as any).from_geo.lat, lng: (el as any).from_geo.lon },
lat: (el as any).from_geo.lat, { lat: (el as any).to_geo.lat, lng: (el as any).to_geo.lon }, { dist: 2_500_000 }).map(v => [v.lat, v.lng]);
lng: (el as any).from_geo.lon,
},
{
lat: (el as any).to_geo.lat,
lng: (el as any).to_geo.lon,
},
{ dist: 2_500_000 }
).map((v) => [v.lat, v.lng]);
(el as any).type = "flight"; (el as any).type = "flight";
return el; return el;
}); });
} }
}; }
var _search_set_results: (...arg: any[]) => any; var _search_set_results: (...arg: any[]) => any;
export const set_search_set_results = function (f: (...arg: any[]) => any) { export const set_search_set_results = function (f: (...arg: any[]) => any) {
_search_set_results = f; _search_set_results = f;
}; }
export const search_nominatim = api.throttle( export const search_nominatim = api.throttle(
( (f: string, q: string, bb: [[number, number], [number, number]], leg: leg) =>
f: string, api.query_nominatim(q, bb, api.get_filter(f)).catch((_err) => console.log(_err)).then((r) => {
q: string, r = process_results('nominatim', r)
bb: [[number, number], [number, number]], r = filter_existing('nominatim', leg, r)
leg: leg _search_set_results(r)
) => }), 1000);
api
.query_nominatim(q, bb, api.get_filter(f))
.catch((_err) => console.log(_err))
.then((r) => {
r = process_results("nominatim", r);
r = filter_existing("nominatim", leg, r);
_search_set_results(r);
}),
1000
);
export const search_flight = api.throttle( export const search_flight = api.throttle(
(f: string, q: string, leg: leg) => (f: string, q: string, leg: leg) =>
api.query_flight(q).then((r) => { api.query_flight(q).then((r) => {
r = process_results("travel", r); r = process_results('travel', r)
r = filter_existing("travel", leg, r); r = filter_existing('travel', leg, r)
_search_set_results(r); _search_set_results(r)
}), }), 2000)
3000
);

View File

@ -141,12 +141,11 @@ const app = new Vue({
}, },
drawer_click_item: function (item) { drawer_click_item: function (item) {
const tpe = this.query.type
this.search_set_clear(item ? true : false); this.search_set_clear(item ? true : false);
this.drawer_hover_item(); this.drawer_hover_item();
if (item) { if (item) {
item.step = -1; item.step = -1;
journey_add_place(this.journey, tpe, item) journey_add_place(this.journey, this.query.type, item)
} }
}, },

View File

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

View File

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

View File

@ -60,27 +60,31 @@ export default function (server, opts, done) {
if (req.params.id == undefined) if (req.params.id == undefined)
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) server.level.db.get(req.params.id, (err, val) => {
.then(r=> reply.send(JSON.parse(r))) if (err) {
.catch(err=>{
console.warn(err); console.warn(err);
return reply.code(500).send({error: "Error with DB"}); reply.code(500).send();
}) } else {
reply.send(JSON.parse(val));
}
});
return reply;
}); });
server.post("/:id", async (req, reply) => { server.post("/:id", async (req, reply) => {
if (req.params.id == undefined) if (req.params.id == undefined)
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=>{ server.level.db.put(req.params.id, req.body, (err) => {
if(db_version+1 == req.body.version || db_version == -1) if (err) {
return server.level.db.put(req.params.id, req.body) console.warn(err);
.then(_=>reply.send({ content: "ok" })) reply.code(500).send({ error: "Error with DB" });
.catch(_=>reply.code(500).send({ error: "Error with DB" })) } else {
reply.send({ content: "ok" });
return reply.code(409).send({error:"Too old version, please refresh."}); }
}) });
}) return reply;
});
done(); done();
}; };

678
yarn.lock

File diff suppressed because it is too large Load Diff