geolocation direkt von fs

This commit is contained in:
2025-11-11 10:14:58 +01:00
parent bbde08f89a
commit 8e308b0d99
7 changed files with 45 additions and 219 deletions

View File

@@ -12,7 +12,7 @@ const adminConfig = require('./services/adminConfig');
const { readNotificationSettings, writeNotificationSettings } = require('./services/userSettingsStore');
const notificationService = require('./services/notificationService');
const { readStoreWatch, writeStoreWatch, listWatcherProfiles } = require('./services/storeWatchStore');
const { readPreferences, writePreferences } = require('./services/userPreferencesStore');
const { readPreferences, writePreferences, sanitizeLocation } = require('./services/userPreferencesStore');
const { readStoreStatus, writeStoreStatus } = require('./services/storeStatusStore');
const ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
@@ -805,9 +805,29 @@ app.post('/api/store-watch/subscriptions', requireAuth, (req, res) => {
res.json({ success: true, stores: persisted });
});
app.get('/api/user/preferences', requireAuth, (req, res) => {
app.get('/api/user/preferences', requireAuth, async (req, res) => {
const preferences = readPreferences(req.session.profile.id);
res.json(preferences);
let location = preferences.location;
try {
const details = await foodsharingClient.fetchProfile(req.session.cookieHeader);
const coords = details?.coordinates;
const sanitized = sanitizeLocation({ lat: coords?.lat, lon: coords?.lon });
if (sanitized) {
const city = details?.city?.trim() || '';
location = {
...sanitized,
label: city || preferences.location?.label || 'Foodsharing-Profil',
city,
updatedAt: sanitized.updatedAt
};
}
} catch (error) {
console.error('[PREFERENCES] Profilstandort konnte nicht geladen werden:', error.message);
}
res.json({
...preferences,
location
});
});
app.post('/api/user/preferences/location', requireAuth, (req, res) => {