mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-18 10:07:22 +02:00
bunch of stuff, good luck. still need to fix user-by-mode thing
This commit is contained in:
@@ -9,8 +9,10 @@ import 'package:http/http.dart' as http;
|
||||
/// Handles PKCE OAuth login with OpenStreetMap.
|
||||
import '../app_state.dart';
|
||||
|
||||
import '../keys.dart';
|
||||
|
||||
class AuthService {
|
||||
static const String _clientId = 'Js6Fn3NR3HEGaD0ZIiHBQlV9LrVcHmsOsDmApHtSyuY';
|
||||
// Both client IDs from keys.dart
|
||||
static const _redirect = 'flockmap://auth';
|
||||
|
||||
late OAuth2Helper _helper;
|
||||
@@ -27,6 +29,7 @@ class AuthService {
|
||||
final authBase = isSandbox
|
||||
? 'https://master.apis.dev.openstreetmap.org' // sandbox auth
|
||||
: 'https://www.openstreetmap.org';
|
||||
final clientId = isSandbox ? kOsmSandboxClientId : kOsmProdClientId;
|
||||
final client = OAuth2Client(
|
||||
authorizeUrl: '$authBase/oauth2/authorize',
|
||||
tokenUrl: '$authBase/oauth2/token',
|
||||
@@ -35,11 +38,11 @@ class AuthService {
|
||||
);
|
||||
_helper = OAuth2Helper(
|
||||
client,
|
||||
clientId: _clientId,
|
||||
clientId: clientId,
|
||||
scopes: ['read_prefs', 'write_api'],
|
||||
enablePKCE: true,
|
||||
);
|
||||
print('AuthService: Initialized for $mode with $authBase');
|
||||
print('AuthService: Initialized for $mode with $authBase and clientId $clientId');
|
||||
}
|
||||
|
||||
Future<bool> isLoggedIn() async =>
|
||||
|
||||
@@ -6,12 +6,17 @@ import 'package:latlong2/latlong.dart';
|
||||
import '../models/camera_profile.dart';
|
||||
import '../models/osm_camera_node.dart';
|
||||
|
||||
class OverpassService {
|
||||
static const _endpoint = 'https://overpass-api.de/api/interpreter';
|
||||
import '../app_state.dart';
|
||||
|
||||
class OverpassService {
|
||||
static const _prodEndpoint = 'https://overpass-api.de/api/interpreter';
|
||||
static const _sandboxEndpoint = 'https://overpass-api.dev.openstreetmap.org/api/interpreter';
|
||||
|
||||
// You can pass UploadMode, or use production by default
|
||||
Future<List<OsmCameraNode>> fetchCameras(
|
||||
LatLngBounds bbox,
|
||||
List<CameraProfile> profiles,
|
||||
{UploadMode uploadMode = UploadMode.production}
|
||||
) async {
|
||||
if (profiles.isEmpty) return [];
|
||||
|
||||
@@ -31,25 +36,35 @@ class OverpassService {
|
||||
out body 250;
|
||||
''';
|
||||
|
||||
try {
|
||||
final resp =
|
||||
await http.post(Uri.parse(_endpoint), body: {'data': query.trim()});
|
||||
if (resp.statusCode != 200) return [];
|
||||
|
||||
final data = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
final elements = data['elements'] as List<dynamic>;
|
||||
|
||||
return elements.whereType<Map<String, dynamic>>().map((e) {
|
||||
return OsmCameraNode(
|
||||
id: e['id'],
|
||||
coord: LatLng(e['lat'], e['lon']),
|
||||
tags: Map<String, String>.from(e['tags'] ?? {}),
|
||||
);
|
||||
}).toList();
|
||||
} catch (_) {
|
||||
// Network error – return empty list silently
|
||||
return [];
|
||||
Future<List<OsmCameraNode>> fetchFromUri(String endpoint, String query) async {
|
||||
try {
|
||||
print('[Overpass] Querying $endpoint');
|
||||
print('[Overpass] Query:\n$query');
|
||||
final resp = await http.post(Uri.parse(endpoint), body: {'data': query.trim()});
|
||||
print('[Overpass] Status: \\${resp.statusCode}, Length: \\${resp.body.length}');
|
||||
if (resp.statusCode != 200) {
|
||||
print('[Overpass] Failed: \\${resp.body}');
|
||||
return [];
|
||||
}
|
||||
final data = jsonDecode(resp.body) as Map<String, dynamic>;
|
||||
final elements = data['elements'] as List<dynamic>;
|
||||
print('[Overpass] Retrieved elements: \\${elements.length}');
|
||||
return elements.whereType<Map<String, dynamic>>().map((e) {
|
||||
return OsmCameraNode(
|
||||
id: e['id'],
|
||||
coord: LatLng(e['lat'], e['lon']),
|
||||
tags: Map<String, String>.from(e['tags'] ?? {}),
|
||||
);
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
print('[Overpass] Exception: \\${e}');
|
||||
// Network error – return empty list silently
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch from production Overpass for all modes.
|
||||
return await fetchFromUri(_prodEndpoint, query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user