From 12949c1bba81976adb208ddaaf5bc449a1cedcee Mon Sep 17 00:00:00 2001 From: cediackermann Date: Mon, 20 Apr 2026 18:16:23 +0200 Subject: [PATCH] fix search --- config.json | 8 ++++---- src/server.ts | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index a3603b4..041f864 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "stationId": "9192", - "stationName": "Slussen", - "refreshRate": 10000 -} + "stationId": "9182", + "stationName": "Hökarängen", + "refreshRate": 30000 +} \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index 34c5b21..c446b5c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -51,11 +51,18 @@ app.get('/api/sl/departures/:siteId', async (req, res) => { app.get('/api/sl/search', async (req, res) => { const query = req.query.q as string; if (!query) return res.status(400).json({ error: 'Query required' }); - + try { - const response = await fetch(`https://journeyplanner.integration.sl.se/v2/stop-finder?name_sf=${encodeURIComponent(query)}&format=json`); + const response = await fetch(`https://journeyplanner.integration.sl.se/v2/stop-finder?name_sf=${encodeURIComponent(query)}&format=json&type_sf=any&any_obj_filter_sf=2`); const data = await response.json(); - res.json(data); + const locations: any[] = data.locations || []; + const StopLocation = locations + .filter((loc) => loc.type === 'stop' && loc.properties?.stopId) + .map((loc) => ({ + id: loc.properties.stopId.replace(/^1800/, ''), + name: loc.disassembledName || loc.name, + })); + res.json({ StopLocation }); } catch (error) { res.status(500).json({ error: 'Failed to search for station' }); }