Add Android support with configurable server URL and location permissions
- Add shared_preferences for persisting server URL - Add SettingsService and PlatformService - Add server URL input field on non-web platforms - Make ApiConfig baseUrl configurable at runtime - Add Android location permissions (ACCESS_FINE/COURSE_LOCATION, INTERNET) - Request location permission on login and map init - Fix geo_id type: use String instead of int (UUID format) - Align share_service with API spec: remove unique_id, use share_id only - Fix watch endpoint response: last_update instead of created_at - Add error handling with SnackBars for geo operations - Wrap login screen in SingleChildScrollView for keyboard handling - Update map tile layer with userAgentPackageName for OSM
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<application
|
||||
android:label="family_safety_frontend"
|
||||
android:name="${applicationName}"
|
||||
|
||||
+16
-10
@@ -1,14 +1,20 @@
|
||||
class ApiConfig {
|
||||
static final String baseUrl = Uri.base.origin;
|
||||
|
||||
static String _baseUrl = 'https://family-safety.onrender.com/api';
|
||||
|
||||
static String get baseUrl => _baseUrl;
|
||||
|
||||
static void setBaseUrl(String url) {
|
||||
_baseUrl = url.endsWith('/') ? url.substring(0, url.length - 1) : url;
|
||||
}
|
||||
|
||||
// Auth endpoints
|
||||
static final String loginUrl = '$baseUrl/login';
|
||||
static final String regUrl = '$baseUrl/reg';
|
||||
|
||||
static String get loginUrl => '$baseUrl/login';
|
||||
static String get regUrl => '$baseUrl/reg';
|
||||
|
||||
// Geo endpoints
|
||||
static final String geoUrl = '$baseUrl/geo';
|
||||
|
||||
static String get geoUrl => '$baseUrl/geo';
|
||||
|
||||
// Share endpoints
|
||||
static final String shareUrl = '$baseUrl/share';
|
||||
static final String watchUrl = '$baseUrl/watch';
|
||||
}
|
||||
static String get shareUrl => '$baseUrl/share';
|
||||
static String get watchUrl => '$baseUrl/watch';
|
||||
}
|
||||
|
||||
+13
-4
@@ -1,22 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'config/api.dart';
|
||||
import 'providers/auth_provider.dart';
|
||||
import 'providers/map_provider.dart';
|
||||
import 'providers/share_provider.dart';
|
||||
import 'screens/login_screen.dart';
|
||||
import 'screens/map_screen.dart';
|
||||
import 'services/settings_service.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final settings = SettingsService();
|
||||
await settings.initialize();
|
||||
ApiConfig.setBaseUrl(settings.baseUrl);
|
||||
runApp(MyApp(settingsService: settings));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
final SettingsService settingsService;
|
||||
|
||||
const MyApp({super.key, required this.settingsService});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
Provider.value(value: settingsService),
|
||||
ChangeNotifierProvider(create: (_) => AuthProvider()),
|
||||
ChangeNotifierProvider(create: (_) => MapProvider()),
|
||||
ChangeNotifierProvider(create: (_) => ShareProvider()),
|
||||
@@ -37,4 +46,4 @@ class MyApp extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,24 @@ import '../services/auth_service.dart';
|
||||
|
||||
class AuthProvider with ChangeNotifier {
|
||||
final AuthService _authService;
|
||||
|
||||
|
||||
String _token = '';
|
||||
bool _isLoading = false;
|
||||
String _error = '';
|
||||
|
||||
AuthProvider({AuthService? authService})
|
||||
: _authService = authService ?? AuthService();
|
||||
|
||||
|
||||
AuthProvider({AuthService? authService})
|
||||
: _authService = authService ?? AuthService();
|
||||
|
||||
String get token => _token;
|
||||
bool get isLoggedIn => _token.isNotEmpty;
|
||||
bool get isLoading => _isLoading;
|
||||
String get error => _error;
|
||||
|
||||
|
||||
Future<void> login(String login, String password) async {
|
||||
_isLoading = true;
|
||||
_error = '';
|
||||
notifyListeners();
|
||||
|
||||
|
||||
try {
|
||||
var response = await _authService.login(login, password);
|
||||
var data = jsonDecode(response);
|
||||
@@ -37,14 +37,18 @@ class AuthProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> register(String login, String password) async {
|
||||
|
||||
Future<void> register(
|
||||
String login,
|
||||
String password,
|
||||
String secretKeyHash,
|
||||
) async {
|
||||
_isLoading = true;
|
||||
_error = '';
|
||||
notifyListeners();
|
||||
|
||||
|
||||
try {
|
||||
await _authService.register(login, password);
|
||||
await _authService.register(login, password, secretKeyHash);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
@@ -55,9 +59,14 @@ class AuthProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setError(String message) {
|
||||
_error = message;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void logout() {
|
||||
_token = '';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ class ShareProvider with ChangeNotifier {
|
||||
final ShareService _shareService;
|
||||
|
||||
String _shareId = '';
|
||||
int _geoId = 0;
|
||||
String _geoId = '';
|
||||
bool _isLoading = false;
|
||||
String _error = '';
|
||||
|
||||
@@ -19,7 +19,7 @@ class ShareProvider with ChangeNotifier {
|
||||
: _shareService = shareService ?? ShareService();
|
||||
|
||||
String get shareId => _shareId;
|
||||
int get geoId => _geoId;
|
||||
String get geoId => _geoId;
|
||||
bool get isLoading => _isLoading;
|
||||
String get error => _error;
|
||||
Map<String, dynamic>? get position => _position;
|
||||
@@ -34,8 +34,8 @@ class ShareProvider with ChangeNotifier {
|
||||
|
||||
try {
|
||||
final result = await _shareService.createShare(token, x, y);
|
||||
_geoId = result['geo_id'];
|
||||
_shareId = result['share_id'];
|
||||
_geoId = result['geo_id']?.toString() ?? '';
|
||||
_shareId = result['share_id']?.toString() ?? '';
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
@@ -47,13 +47,13 @@ class ShareProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getPosition(String token, String shareID) async {
|
||||
Future<void> getPosition(String token, String shareId) async {
|
||||
_isLoading = true;
|
||||
_error = '';
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_position = await _shareService.getPosition(token, shareID);
|
||||
_position = await _shareService.getPositionByShareId(token, shareId);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
@@ -67,7 +67,7 @@ class ShareProvider with ChangeNotifier {
|
||||
|
||||
void clearShare() {
|
||||
_shareId = '';
|
||||
_geoId = 0;
|
||||
_geoId = '';
|
||||
_position = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
+189
-83
@@ -1,102 +1,208 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
class LoginScreen extends StatelessWidget {
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../config/api.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
import '../services/settings_service.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final TextEditingController _loginController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final TextEditingController _secretKeyController = TextEditingController();
|
||||
final TextEditingController _serverUrlController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
_tabController.addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
final settings = context.read<SettingsService>();
|
||||
_serverUrlController.text = settings.baseUrl;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_loginController.dispose();
|
||||
_passwordController.dispose();
|
||||
_secretKeyController.dispose();
|
||||
_serverUrlController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
static const String _secretKey = 'FtracKer*1405.';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authProvider = context.watch<AuthProvider>();
|
||||
final TextEditingController loginController = TextEditingController();
|
||||
final TextEditingController passwordController = TextEditingController();
|
||||
|
||||
final settings = context.read<SettingsService>();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Family Safety',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextField(
|
||||
controller: loginController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (authProvider.error.isNotEmpty)
|
||||
Text(
|
||||
authProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
resizeToAvoidBottomInset: true,
|
||||
body: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
await authProvider.login(
|
||||
loginController.text,
|
||||
passwordController.text,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pushReplacementNamed('/map');
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
},
|
||||
child: const Text('Login'),
|
||||
const Text(
|
||||
'Family Safety',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (!kIsWeb) ...[
|
||||
TextField(
|
||||
controller: _serverUrlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Server URL',
|
||||
hintText: 'https://example.com/api',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.cloud_outlined),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
await authProvider.register(
|
||||
loginController.text,
|
||||
passwordController.text,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
},
|
||||
child: const Text('Register'),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
tabs: const [
|
||||
Tab(text: 'Login'),
|
||||
Tab(text: 'Register'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _loginController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
if (_tabController.index == 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _secretKeyController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Secret Key',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (authProvider.error.isNotEmpty)
|
||||
Text(
|
||||
authProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (!kIsWeb) {
|
||||
final status = await Geolocator.checkPermission();
|
||||
if (status == LocationPermission.denied) {
|
||||
final requested = await Geolocator.requestPermission();
|
||||
if (requested == LocationPermission.denied) {
|
||||
authProvider.setError('Location permission denied');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (status == LocationPermission.deniedForever) {
|
||||
authProvider.setError('Location permission permanently denied. Please enable it in settings.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!kIsWeb) {
|
||||
final newUrl = _serverUrlController.text.trim();
|
||||
if (newUrl.isNotEmpty && newUrl != settings.baseUrl) {
|
||||
ApiConfig.setBaseUrl(newUrl);
|
||||
await settings.setBaseUrl(newUrl);
|
||||
}
|
||||
}
|
||||
if (_tabController.index == 0) {
|
||||
try {
|
||||
await authProvider.login(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(
|
||||
context,
|
||||
).pushReplacementNamed('/map');
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
} else {
|
||||
if (_secretKeyController.text != _secretKey) {
|
||||
authProvider.setError('Invalid secret key');
|
||||
return;
|
||||
}
|
||||
Digest digest = md5.convert(
|
||||
utf8.encode(_secretKeyController.text),
|
||||
);
|
||||
String secretKeyHash = hex.encode(digest.bytes);
|
||||
try {
|
||||
await authProvider.register(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
secretKeyHash,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
}
|
||||
},
|
||||
child: authProvider.isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
_tabController.index == 0 ? 'Login' : 'Register',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
-29
@@ -43,6 +43,17 @@ class _MapScreenState extends State<MapScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
final status = await Geolocator.checkPermission();
|
||||
if (status == LocationPermission.denied) {
|
||||
final requested = await Geolocator.requestPermission();
|
||||
if (requested == LocationPermission.denied) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (status == LocationPermission.deniedForever) {
|
||||
return;
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
setState(() {
|
||||
_center = LatLng(position.latitude, position.longitude);
|
||||
@@ -54,11 +65,18 @@ class _MapScreenState extends State<MapScreen> {
|
||||
final shareProvider = context.read<ShareProvider>();
|
||||
|
||||
if (authProvider.token.isNotEmpty) {
|
||||
await shareProvider.createShare(
|
||||
authProvider.token,
|
||||
position.longitude,
|
||||
position.latitude,
|
||||
);
|
||||
try {
|
||||
await shareProvider.createShare(
|
||||
authProvider.token,
|
||||
position.longitude,
|
||||
position.latitude,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Ошибка геолокации: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
@@ -75,6 +93,11 @@ class _MapScreenState extends State<MapScreen> {
|
||||
|
||||
Future<void> _updateGeolocation() async {
|
||||
try {
|
||||
final status = await Geolocator.checkPermission();
|
||||
if (status == LocationPermission.denied) {
|
||||
final requested = await Geolocator.requestPermission();
|
||||
if (requested == LocationPermission.denied) return;
|
||||
}
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
setState(() {
|
||||
_center = LatLng(position.latitude, position.longitude);
|
||||
@@ -85,13 +108,20 @@ class _MapScreenState extends State<MapScreen> {
|
||||
final authProvider = context.read<AuthProvider>();
|
||||
final shareProvider = context.read<ShareProvider>();
|
||||
|
||||
await GeoService().updatePosition(
|
||||
authProvider.token,
|
||||
shareProvider.geoId,
|
||||
position.longitude,
|
||||
position.latitude,
|
||||
);
|
||||
} catch (_) {}
|
||||
if (shareProvider.geoId.isEmpty) return;
|
||||
|
||||
await GeoService().updatePosition(
|
||||
authProvider.token,
|
||||
shareProvider.geoId,
|
||||
position.longitude,
|
||||
position.latitude,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Ошибка обновления позиции: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _copyShareLink() {
|
||||
@@ -115,19 +145,22 @@ class _MapScreenState extends State<MapScreen> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
return AlertDialog(
|
||||
title: const Text('Отслеживание'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Введите Share ID для отслеживания:'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Введите Share ID',
|
||||
border: OutlineInputBorder(),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('Введите Share ID для отслеживания:'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Введите Share ID',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -174,8 +207,8 @@ class _MapScreenState extends State<MapScreen> {
|
||||
Marker? trackedMarker;
|
||||
if (shareProvider.trackedPosition != null) {
|
||||
final pos = shareProvider.trackedPosition!;
|
||||
final lat = pos['y'] as double;
|
||||
final lng = pos['x'] as double;
|
||||
final lat = pos['y'] is String ? double.parse(pos['y']) : pos['y'] as double;
|
||||
final lng = pos['x'] is String ? double.parse(pos['x']) : pos['x'] as double;
|
||||
trackedMarker = Marker(
|
||||
point: LatLng(lat, lng),
|
||||
width: 40,
|
||||
@@ -226,12 +259,14 @@ class _MapScreenState extends State<MapScreen> {
|
||||
),
|
||||
body: FlutterMap(
|
||||
options: MapOptions(
|
||||
center: _center,
|
||||
zoom: 12.0,
|
||||
initialCenter: _center,
|
||||
initialZoom: 12.0,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
maxZoom: 20,
|
||||
userAgentPackageName:'FamilySafety/1.0.0',
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
import '../providers/share_provider.dart';
|
||||
|
||||
class ShareScreen extends StatelessWidget {
|
||||
const ShareScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authProvider = context.watch<AuthProvider>();
|
||||
final shareProvider = context.watch<ShareProvider>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Share Location'),
|
||||
),
|
||||
body: Center(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Share Your Location',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Create a share link to share your location with family',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
if (shareProvider.shareId.isNotEmpty)
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
'Share ID: ${shareProvider.shareId}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Copy to clipboard functionality
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Share ID copied to clipboard'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Copy Share ID'),
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
ElevatedButton(
|
||||
onPressed: shareProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
await shareProvider.createShare(
|
||||
authProvider.token,
|
||||
55.7558, // Default Moscow coordinates
|
||||
37.6173,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
},
|
||||
child: const Text('Create Share Link'),
|
||||
),
|
||||
if (shareProvider.error.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
shareProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import '../config/api.dart';
|
||||
|
||||
class AuthService {
|
||||
final http.Client _client;
|
||||
|
||||
|
||||
AuthService({http.Client? client}) : _client = client ?? http.Client();
|
||||
|
||||
Future<String> login(String login, String password) async {
|
||||
@@ -13,7 +13,7 @@ class AuthService {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({'login': login, 'password': password}),
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
} else {
|
||||
@@ -21,15 +21,23 @@ class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> register(String login, String password) async {
|
||||
Future<void> register(
|
||||
String login,
|
||||
String password,
|
||||
String secretKeyHash,
|
||||
) async {
|
||||
final response = await _client.post(
|
||||
Uri.parse(ApiConfig.regUrl),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({'login': login, 'password': password}),
|
||||
body: jsonEncode({
|
||||
'login': login,
|
||||
'password': password,
|
||||
'secret_key_hash': secretKeyHash,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode != 201) {
|
||||
throw Exception('Registration failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class GeoService {
|
||||
|
||||
GeoService({http.Client? client}) : _client = client ?? http.Client();
|
||||
|
||||
Future<void> updatePosition(String token, int id, double x, double y) async {
|
||||
Future<void> updatePosition(String token, String id, double x, double y) async {
|
||||
final response = await _client.put(
|
||||
Uri.parse('${ApiConfig.geoUrl}?id=$id'),
|
||||
headers: {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
|
||||
class PlatformService {
|
||||
bool get isWeb => kIsWeb;
|
||||
bool get isNative => !kIsWeb;
|
||||
String get platformName => isWeb ? 'web' : Platform.isAndroid ? 'android' : Platform.isIOS ? 'ios' : Platform.isWindows ? 'windows' : Platform.isMacOS ? 'macos' : Platform.isLinux ? 'linux' : 'unknown';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsService {
|
||||
static const String _baseUrlKey = 'server_base_url';
|
||||
static const String _defaultBaseUrl = 'https://family-safety.onrender.com/api';
|
||||
|
||||
String _baseUrl = _defaultBaseUrl;
|
||||
bool _initialized = false;
|
||||
|
||||
String get baseUrl => _baseUrl;
|
||||
|
||||
Future<void> initialize() async {
|
||||
if (_initialized) return;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_baseUrl = prefs.getString(_baseUrlKey) ?? _defaultBaseUrl;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
Future<void> setBaseUrl(String url) async {
|
||||
_baseUrl = url;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_baseUrlKey, url);
|
||||
}
|
||||
|
||||
void resetToDefault() {
|
||||
_baseUrl = _defaultBaseUrl;
|
||||
}
|
||||
}
|
||||
@@ -18,35 +18,18 @@ class ShareService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
final data = jsonDecode(response.body);
|
||||
return {
|
||||
'geo_id': data['geo_id'],
|
||||
'share_id': data['share_id'],
|
||||
};
|
||||
try {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return {
|
||||
'geo_id': data['geo_id']?.toString() ?? '',
|
||||
'share_id': data['share_id']?.toString() ?? '',
|
||||
};
|
||||
} catch (e) {
|
||||
throw Exception('Failed to parse response: $e | Body: ${response.body.substring(0, response.body.length > 200 ? 200 : response.body.length)}');
|
||||
}
|
||||
} else {
|
||||
throw Exception('Failed to create share link');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getPosition(String token, String uniqueId) async {
|
||||
final response = await _client.get(
|
||||
Uri.parse('${ApiConfig.watchUrl}?unique_id=$uniqueId'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
return {
|
||||
'id': data['id'],
|
||||
'x': data['x'],
|
||||
'y': data['y'],
|
||||
'created_at': data['created_at'],
|
||||
'expires_at': data['expires_at'],
|
||||
};
|
||||
} else {
|
||||
throw Exception('Share link not found or no position available');
|
||||
final errorBody = response.body.length > 200 ? response.body.substring(0, 200) : response.body;
|
||||
throw Exception('Failed to create share link: ${response.statusCode} - $errorBody');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,15 +42,15 @@ class ShareService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return {
|
||||
'x': data['x'],
|
||||
'y': data['y'],
|
||||
'created_at': data['created_at'],
|
||||
'expires_at': data['expires_at'],
|
||||
'last_update': data['last_update']?.toString() ?? '',
|
||||
'expires_at': data['expires_at']?.toString() ?? '',
|
||||
};
|
||||
} else {
|
||||
throw Exception('Share link not found or no position available');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class AppConstants {
|
||||
static const String appName = 'Family Safety';
|
||||
static const String defaultMapsApiKey = 'YOUR_MAPS_API_KEY';
|
||||
|
||||
// Default coordinates (Moscow)
|
||||
static const double defaultLatitude = 55.7558;
|
||||
|
||||
+107
-3
@@ -2,7 +2,7 @@
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
args:
|
||||
dependency: "direct dev"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
|
||||
@@ -49,8 +49,16 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
convert:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: convert
|
||||
sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypto
|
||||
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
|
||||
@@ -89,6 +97,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: file
|
||||
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.1"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -349,6 +365,30 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_platform_interface
|
||||
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_windows
|
||||
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -357,6 +397,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.2"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: platform
|
||||
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.6"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -389,6 +437,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.5+1"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: c3025c5534b01739267eb7d76959bbc25a6d10f6988e1c2a3036940133dd10bf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.5"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: e8d4762b1e2e8578fc4d0fd548cebf24afd24f49719c08974df92834565e2c53
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.23"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "4e7eaffc2b17ba398759f1151415869a34771ba11ebbccd1b0145472a619a64f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.6"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: "649dc798a33931919ea356c4305c2d1f81619ea6e92244070b520187b5140ef9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: c49bd060261c9a3f0ff445892695d6212ff603ef3115edbb448509d407600019
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -524,4 +628,4 @@ packages:
|
||||
version: "6.6.1"
|
||||
sdks:
|
||||
dart: ">=3.10.1 <4.0.0"
|
||||
flutter: ">=3.19.0"
|
||||
flutter: ">=3.35.0"
|
||||
|
||||
+3
-1
@@ -38,9 +38,12 @@ dependencies:
|
||||
cupertino_icons: ^1.0.8
|
||||
provider: ^6.1.1
|
||||
http: ^1.2.0
|
||||
crypto: ^3.0.3
|
||||
convert: ^3.1.1
|
||||
flutter_map: ^6.1.0
|
||||
latlong2: ^0.9.1
|
||||
geolocator: ^14.0.2
|
||||
shared_preferences: ^2.2.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@@ -57,7 +60,6 @@ dev_dependencies:
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
args: any
|
||||
flutter:
|
||||
generate: true
|
||||
|
||||
|
||||
+8
-13
@@ -9,22 +9,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:family_safety_frontend/main.dart';
|
||||
import 'package:family_safety_frontend/services/settings_service.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
testWidgets('App loads login screen', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(MyApp(
|
||||
settingsService: SettingsService(),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
expect(find.text('Family Safety'), findsOneWidget);
|
||||
expect(find.byType(TabBar), findsOneWidget);
|
||||
expect(find.byType(ElevatedButton), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 665 B |
Binary file not shown.
|
After Width: | Height: | Size: 628 B |
@@ -0,0 +1,16 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="swagger-ui.css" />
|
||||
<link rel="stylesheet" type="text/css" href="index.css" />
|
||||
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="swagger-initializer.js" charset="UTF-8"> </script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,79 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<title>Swagger UI: OAuth2 Redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
'use strict';
|
||||
function run () {
|
||||
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||
var sentState = oauth2.state;
|
||||
var redirectUrl = oauth2.redirectUrl;
|
||||
var isValid, qp, arr;
|
||||
|
||||
if (/code|token|error/.test(window.location.hash)) {
|
||||
qp = window.location.hash.substring(1).replace('?', '&');
|
||||
} else {
|
||||
qp = location.search.substring(1);
|
||||
}
|
||||
|
||||
arr = qp.split("&");
|
||||
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
|
||||
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
||||
function (key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
}
|
||||
) : {};
|
||||
|
||||
isValid = qp.state === sentState;
|
||||
|
||||
if ((
|
||||
oauth2.auth.schema.get("flow") === "accessCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorization_code"
|
||||
) && !oauth2.auth.code) {
|
||||
if (!isValid) {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "warning",
|
||||
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
||||
});
|
||||
}
|
||||
|
||||
if (qp.code) {
|
||||
delete oauth2.state;
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||
} else {
|
||||
let oauthErrorMsg;
|
||||
if (qp.error) {
|
||||
oauthErrorMsg = "["+qp.error+"]: " +
|
||||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
|
||||
});
|
||||
}
|
||||
} else {
|
||||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
||||
if (document.readyState !== 'loading') {
|
||||
run();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
run();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
window.onload = function() {
|
||||
//<editor-fold desc="Changeable Configuration Block">
|
||||
|
||||
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: "/swagger/swagger.yaml",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: false,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "BaseLayout"
|
||||
});
|
||||
|
||||
//</editor-fold>
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,619 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Mesh backend REST API
|
||||
version: 1.0.0
|
||||
description: Описание API
|
||||
servers:
|
||||
- url: http://localhost:8888/api
|
||||
paths:
|
||||
/info:
|
||||
get:
|
||||
tags:
|
||||
- Common
|
||||
summary: Запрос статуса сервера
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BackendInfo'
|
||||
/blockRule:
|
||||
get:
|
||||
tags:
|
||||
- BlockRule
|
||||
summary: Запрос правил блокировок
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
delete:
|
||||
tags:
|
||||
- BlockRule
|
||||
summary: Удалить правило
|
||||
requestBody:
|
||||
description: Удалить правило
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
'404':
|
||||
description: Не найдено
|
||||
post:
|
||||
tags:
|
||||
- BlockRule
|
||||
summary: Добавить правило блокировки
|
||||
requestBody:
|
||||
description: Правило блокировки (объект json)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
/priorityRule:
|
||||
get:
|
||||
tags:
|
||||
- PriorityRule
|
||||
summary: Запрос правил приоритета (Qos)
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
delete:
|
||||
tags:
|
||||
- PriorityRule
|
||||
summary: Удалить правила приоритета
|
||||
requestBody:
|
||||
description: Удалить правило приоритета (Qos)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
'404':
|
||||
description: Не найдено
|
||||
post:
|
||||
tags:
|
||||
- PriorityRule
|
||||
summary: Добавить правило приоритета (Qos)
|
||||
requestBody:
|
||||
description: Правило приоритета (Qos) (объект json)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BlockPriorityRule'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
/interface:
|
||||
get:
|
||||
tags:
|
||||
- Interface
|
||||
summary: Запрос сетевых интерфейсов
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Interface'
|
||||
put:
|
||||
tags:
|
||||
- Interface
|
||||
summary: Обновить интерфейс
|
||||
parameters:
|
||||
- name: interface
|
||||
in: query
|
||||
description: Interface object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/Interface'
|
||||
requestBody:
|
||||
description: Обновить интерфейс
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Interface'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
/config:
|
||||
get:
|
||||
tags:
|
||||
- Config
|
||||
summary: Запрос настроек
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Config'
|
||||
put:
|
||||
tags:
|
||||
- Config
|
||||
summary: Обновить настройки
|
||||
parameters:
|
||||
- name: Config
|
||||
in: query
|
||||
description: Config object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/Config'
|
||||
requestBody:
|
||||
description: Обновить Config
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Config'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
/stats:
|
||||
get:
|
||||
tags:
|
||||
- Common
|
||||
summary: Запрос статистики сервера
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Stat'
|
||||
/commandList:
|
||||
get:
|
||||
tags:
|
||||
- CommandList
|
||||
summary: Запрос списка команд
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Command'
|
||||
put:
|
||||
tags:
|
||||
- CommandList
|
||||
summary: Перезапись списка команд
|
||||
requestBody:
|
||||
description: Перезапись списка команд
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Command'
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
/commandRun/{id}:
|
||||
post:
|
||||
tags:
|
||||
- CommandRun
|
||||
summary: Запустить команду
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: ID of command
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/CommandResult'
|
||||
'400':
|
||||
description: On error
|
||||
'404':
|
||||
description: Не найдено
|
||||
'405':
|
||||
description: Конфиг нельзя запустить
|
||||
delete:
|
||||
tags:
|
||||
- CommandRun
|
||||
summary: Остановить команду
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: ID of command
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/CommandResult'
|
||||
'400':
|
||||
description: On error
|
||||
/command:
|
||||
post:
|
||||
tags:
|
||||
- Command
|
||||
summary: Добавить команду
|
||||
parameters:
|
||||
- name: command
|
||||
in: query
|
||||
description: Command object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#'#/components/schemas/Command'
|
||||
requestBody:
|
||||
description: Добавить команду
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Command'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: Успех
|
||||
'400':
|
||||
description: ID занят
|
||||
'409':
|
||||
description: Конфиг или скрипт уже существуют
|
||||
get:
|
||||
tags:
|
||||
- Command
|
||||
summary: Запросить команду с телом
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
description: Command ID
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
delete:
|
||||
tags:
|
||||
- Command
|
||||
summary: Удалить команду
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
description: Command ID
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
'404':
|
||||
description: Не найдено
|
||||
put:
|
||||
tags:
|
||||
- Command
|
||||
summary: Обновить команду
|
||||
parameters:
|
||||
- name: command
|
||||
in: query
|
||||
description: Command object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#'#/components/schemas/Command'
|
||||
requestBody:
|
||||
description: Обновить команду
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Command'
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
/commandStatuses:
|
||||
get:
|
||||
tags:
|
||||
- CommandStatus
|
||||
summary: Запрос статусов выполнения команд
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/CommandResult'
|
||||
'400':
|
||||
description: On error
|
||||
/graphInfo:
|
||||
get:
|
||||
tags:
|
||||
- NodeInfo
|
||||
summary: Запрос связей между точками
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/NodeInfo'
|
||||
'400':
|
||||
description: On error
|
||||
/hotspot:
|
||||
get:
|
||||
tags:
|
||||
- Hotspot
|
||||
summary: Запросить информацию о точке
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
description: Hotspot ID
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: On success
|
||||
'400':
|
||||
description: On error
|
||||
components:
|
||||
schemas:
|
||||
Interface:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
default: eth0
|
||||
ip:
|
||||
type: string
|
||||
default: 192.168.1.1
|
||||
netmask:
|
||||
type: string
|
||||
default: 255.255.255.0
|
||||
mac:
|
||||
type: string
|
||||
default: 4A:30:10:21:10:1A
|
||||
mtu:
|
||||
type: integer
|
||||
default: 0
|
||||
active:
|
||||
type: boolean
|
||||
default: true
|
||||
loopback:
|
||||
type: boolean
|
||||
default: false
|
||||
readonly:
|
||||
type: boolean
|
||||
default: false
|
||||
Config:
|
||||
type: object
|
||||
properties:
|
||||
secret:
|
||||
type: string
|
||||
default: error
|
||||
channel:
|
||||
type: integer
|
||||
default: 0
|
||||
width:
|
||||
type: integer
|
||||
default: 0
|
||||
power:
|
||||
type: integer
|
||||
default: 0
|
||||
distance:
|
||||
type: integer
|
||||
default: 0
|
||||
Command:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
default: error
|
||||
contentType:
|
||||
type: string
|
||||
default: error
|
||||
path:
|
||||
type: string
|
||||
default: error
|
||||
content:
|
||||
type: string
|
||||
default: error
|
||||
needConfirmation:
|
||||
type: boolean
|
||||
default: false
|
||||
CommandResult:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
default: "name unknown"
|
||||
exitCode:
|
||||
type: integer
|
||||
default: 0
|
||||
output:
|
||||
type: string
|
||||
default: "command stdout"
|
||||
error:
|
||||
type: string
|
||||
default: "command stderr"
|
||||
running:
|
||||
type: boolean
|
||||
default: false
|
||||
Stat:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
default: "unknown"
|
||||
spots:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
default: 0.0
|
||||
interval:
|
||||
type: integer
|
||||
default: 5
|
||||
units:
|
||||
type: string
|
||||
default: "db"
|
||||
min:
|
||||
type: number
|
||||
default: 0.0
|
||||
max:
|
||||
type: number
|
||||
default: 100.0
|
||||
HotspotInfo:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
default: "unknown"
|
||||
signal:
|
||||
type: number
|
||||
default: 0.0
|
||||
hops:
|
||||
type: integer
|
||||
default: 5
|
||||
rx:
|
||||
type: integer
|
||||
default: 5
|
||||
tx:
|
||||
type: integer
|
||||
default: 5
|
||||
bytesReceived:
|
||||
type: integer
|
||||
default: 5
|
||||
bytesSent:
|
||||
type: integer
|
||||
default: 5
|
||||
connectionTime:
|
||||
type: integer
|
||||
default: 5,
|
||||
inactiveTime:
|
||||
type: integer
|
||||
default: 5,
|
||||
stats:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Stat'
|
||||
BackendInfo:
|
||||
type: object
|
||||
properties:
|
||||
version:
|
||||
type: string
|
||||
default: "unknown"
|
||||
arch:
|
||||
type: string
|
||||
default: "unknown"
|
||||
uptime:
|
||||
type: integer
|
||||
default: 0
|
||||
hostname:
|
||||
type: string
|
||||
default: "unknown"
|
||||
buildNum:
|
||||
type: integer
|
||||
default: 9999
|
||||
buildType:
|
||||
type: string
|
||||
default: "unknown"
|
||||
buildDate:
|
||||
type: string
|
||||
default: "unknown"
|
||||
pipVersion:
|
||||
type: string
|
||||
default: "unknown"
|
||||
frontVersion:
|
||||
type: string
|
||||
default: "unknown"
|
||||
frontBuild:
|
||||
type: string
|
||||
default: "unknown"
|
||||
NodeInfo:
|
||||
type: object
|
||||
properties:
|
||||
mac:
|
||||
type: string
|
||||
default: "unknown"
|
||||
connections:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
default: node
|
||||
BlockPriorityRule:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
default: "unknown"
|
||||
protocol:
|
||||
type: string
|
||||
default: "tcp"
|
||||
port:
|
||||
type: integer
|
||||
default: 389
|
||||
allow:
|
||||
type: boolean
|
||||
default: false
|
||||
direction:
|
||||
type: boolean
|
||||
default: true
|
||||
priority:
|
||||
type: integer
|
||||
default: 0
|
||||
Reference in New Issue
Block a user