Add BandwidthService and endpoint for retrieving bandwidth statistics
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:waylume_server/wireguard/peers.dart';
|
||||
import 'package:waylume_server/wireguard/utils.dart';
|
||||
import 'package:waylume_server/core/utils.dart';
|
||||
import 'package:waylume_server/services/vpn_session_service.dart';
|
||||
import 'package:waylume_server/services/bandwidth_service.dart';
|
||||
|
||||
class PeerRoutes {
|
||||
Router get router {
|
||||
@@ -17,6 +18,7 @@ class PeerRoutes {
|
||||
router.get('/peer/<publicKey>/config', _getPeerConfig);
|
||||
router.patch('/peer/<publicKey>/speed-limit', _setSpeedLimit);
|
||||
router.patch('/peer/<publicKey>/data-cap', _setDataCap);
|
||||
router.get('/bandwidth-stats', _getBandwidthStats);
|
||||
|
||||
return router;
|
||||
}
|
||||
@@ -251,4 +253,28 @@ class PeerRoutes {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> _getBandwidthStats(Request request) async {
|
||||
try {
|
||||
final collectorId = request.url.queryParameters['collector_id'];
|
||||
|
||||
final bandwidthData = await BandwidthService.getBandwidthStats(collectorId);
|
||||
|
||||
return Response.ok(
|
||||
jsonEncode({
|
||||
'success': true,
|
||||
'data': bandwidthData,
|
||||
}),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
} catch (e) {
|
||||
return Response.internalServerError(
|
||||
body: jsonEncode({
|
||||
'success': false,
|
||||
'error': e.toString(),
|
||||
}),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user