Add relay node management and pin manager header layout
- server: add, delete and set-default node endpoints writing cluster.json with validation - deploy: grant ads-server write access to /etc/ads - flutter: relay node page with admin token plumbing, stop reconnecting devices removed from device list - flutter: fixed header heights and strut so tab switching never shifts refresh/notice
This commit is contained in:
1 parent
e12cb76d68
commit
0a04d5990f
9 files changed
+606
-75
No files matched your search
@@ -10,6 +10,7 @@ typedef JsonMap = Map<String, Object?>;
|
||||
|
||||
abstract interface class AgentApi {
|
||||
String get connectionKey;
|
||||
String get adminToken;
|
||||
Future<List<JsonMap>> list();
|
||||
Future<Object?> request(String agent, JsonMap operation);
|
||||
Future<Object?> local(String config, JsonMap operation);
|
||||
@@ -29,6 +30,8 @@ class AgentService implements AgentApi {
|
||||
String _token = '';
|
||||
final Set<String> _secrets = {};
|
||||
@override
|
||||
String get adminToken => _token;
|
||||
@override
|
||||
String redact(String message) {
|
||||
for (final secret in _secrets) {
|
||||
message = message.replaceAll(secret, '[REDACTED]');
|
||||
|
||||
@@ -85,6 +85,7 @@ class Session {
|
||||
bool screenEmbedded = false;
|
||||
String state = '连接中', route = '协商中';
|
||||
bool ready = false, stopping = false, exited = false;
|
||||
int missingPasses = 0;
|
||||
Session(this.id, this.tunnel, this.adb, this.statusFile, this.process);
|
||||
}
|
||||
|
||||
@@ -194,6 +195,7 @@ class ManagerRepository {
|
||||
String? bearer,
|
||||
Map<String, Object?>? payload,
|
||||
Map<String, String>? query,
|
||||
String? method,
|
||||
}) async {
|
||||
final authorization = bearer ?? token;
|
||||
if (authorization.length < 32) {
|
||||
@@ -231,9 +233,10 @@ class ManagerRepository {
|
||||
}
|
||||
try {
|
||||
final uri = settings.uri(suffix).replace(queryParameters: query);
|
||||
final request = payload == null
|
||||
? await client.getUrl(uri)
|
||||
: await client.postUrl(uri);
|
||||
final request = await client.openUrl(
|
||||
method ?? (payload == null ? 'GET' : 'POST'),
|
||||
uri,
|
||||
);
|
||||
request.followRedirects = false;
|
||||
request.headers.set('Authorization', 'Bearer $authorization');
|
||||
if (payload != null) {
|
||||
@@ -250,8 +253,14 @@ class ManagerRepository {
|
||||
if (suffix == 'v2/nodes' && response.statusCode == 404) {
|
||||
return {'nodes': <dynamic>[]};
|
||||
}
|
||||
if (response.statusCode != 200) {
|
||||
throw HttpException('控制中心 HTTP ${response.statusCode}');
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
final detail = body.trim();
|
||||
throw HttpException(
|
||||
'控制中心 HTTP ${response.statusCode}${detail.isEmpty ? '' : ':${detail.length > 200 ? detail.substring(0, 200) : detail}'}',
|
||||
);
|
||||
}
|
||||
if (body.trim().isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return jsonDecode(body);
|
||||
} finally {
|
||||
@@ -483,7 +492,32 @@ class ManagerRepository {
|
||||
|
||||
Future<void> monitor() async {
|
||||
final listings = <String, String>{};
|
||||
Set<String>? online;
|
||||
if (sessions.values.any((s) => s.usb != null)) {
|
||||
try {
|
||||
online = (await devices()).map((d) => d.id).toSet();
|
||||
} catch (_) {
|
||||
// Inventory unavailable; keep the current connection states.
|
||||
}
|
||||
}
|
||||
for (final s in sessions.values.toList()) {
|
||||
if (s.stopping) {
|
||||
continue;
|
||||
}
|
||||
if (online != null && s.usb != null) {
|
||||
if (online.contains(s.id)) {
|
||||
s.missingPasses = 0;
|
||||
} else {
|
||||
s.missingPasses++;
|
||||
if (s.missingPasses >= 3) {
|
||||
log('[${s.id}] 设备已不在设备列表,停止自动重连');
|
||||
await disconnect(s.id);
|
||||
continue;
|
||||
}
|
||||
s.state = '设备已下线 · 等待恢复';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (s.usb == null && !s.stopping && s.exited) {
|
||||
await disconnect(s.id);
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user