prevent overlapping api ports

This commit is contained in:
2025-03-22 15:27:50 -05:00
parent e3d036fcb8
commit 630c3463d8
6 changed files with 119 additions and 132 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
@@ -111,10 +112,19 @@ class MountList with ChangeNotifier {
Future<bool> add(
String type,
String name,
Map<String, dynamic> mountConfig,
Map<String, dynamic> settings,
) async {
var ret = false;
var apiPort = settings['ApiPort'] ?? 10000;
for (var mount in _mountList) {
var port = mount.mountConfig.settings['ApiPort'] as int?;
if (port != null) {
apiPort = max(apiPort, port + 1);
}
}
settings["ApiPort"] = apiPort;
displayError() {
if (constants.navigatorKey.currentContext == null) {
return;
@@ -129,7 +139,7 @@ class MountList with ChangeNotifier {
try {
final auth = await _auth.createAuth();
final map = await convertAllToString(
jsonDecode(jsonEncode(mountConfig)),
jsonDecode(jsonEncode(settings)),
_auth.key,
);
final response = await http.post(