diff options
| author | Adam Soltys <[email protected]> | 2026-02-27 10:09:25 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-27 10:09:25 -0800 |
| commit | fd8f286e22f4f8b6a24123937c24c52b9c1407ba (patch) | |
| tree | 13aaf05b65dc510e05f7e5e53ce2de1de67d2d15 /routes | |
| parent | f3c7e821f12f55044689204ff2c4571be791bb9f (diff) | |
| download | coinos-server-fd8f286e22f4f8b6a24123937c24c52b9c1407ba.tar.gz coinos-server-fd8f286e22f4f8b6a24123937c24c52b9c1407ba.zip | |
map updates
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/locations.ts | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/routes/locations.ts b/routes/locations.ts index d7a5b636..23b0f3b4 100644 --- a/routes/locations.ts +++ b/routes/locations.ts @@ -1,8 +1,44 @@ -import { g } from "$lib/db"; +import { db, g } from "$lib/db"; export default { async list(_, res) { const locations = await g("locations"); res.send({ locations }); }, + + async nearby(req, res) { + const lat = parseFloat(req.query.lat); + const lon = parseFloat(req.query.lon); + const radius = parseFloat(req.query.radius) || 50; + const count = parseInt(req.query.count) || 50; + + if (isNaN(lat) || isNaN(lon)) { + return res.status(400).send({ error: "lat and lon required" }); + } + + try { + const ids = await db.geoSearch("locations:geo", { + longitude: lon, + latitude: lat, + }, { + radius, + unit: "km", + }, { + COUNT: count, + SORT: "ASC", + }); + + const locations = []; + for (const id of ids) { + const loc = await g(`location:${id}`); + if (loc) locations.push(loc); + } + + res.send({ locations }); + } catch (e) { + console.log("nearby search failed", e); + const locations = await g("locations"); + res.send({ locations }); + } + }, }; |
