From f27c433d968ea806c3be2310ac09353c9c78f30a Mon Sep 17 00:00:00 2001 From: fuwa Date: Wed, 27 Nov 2019 20:17:10 +0800 Subject: [PATCH] use incorrect json format as display format --- cyberwow/lib/controller/rpc/rpc.dart | 4 ++-- cyberwow/lib/controller/rpc/rpc2View.dart | 3 ++- cyberwow/lib/controller/rpc/rpcView.dart | 3 ++- cyberwow/lib/helper.dart | 7 ++++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cyberwow/lib/controller/rpc/rpc.dart b/cyberwow/lib/controller/rpc/rpc.dart index ed94923..3fa412a 100644 --- a/cyberwow/lib/controller/rpc/rpc.dart +++ b/cyberwow/lib/controller/rpc/rpc.dart @@ -26,9 +26,9 @@ import 'package:http/http.dart' as http; import 'package:flutter/foundation.dart'; import '../../config.dart' as config; +import 'rpcView.dart' as rpcView; import '../../helper.dart'; import '../../logging.dart'; -import 'rpcView.dart'; int rpcID = 0; @@ -129,7 +129,7 @@ Future> getConnectionsSimple() async { } ); - return _sortedConn.map(rpcPeerView).toList(); + return _sortedConn.map(rpcView.rpcPeerView).toList(); } diff --git a/cyberwow/lib/controller/rpc/rpc2View.dart b/cyberwow/lib/controller/rpc/rpc2View.dart index 3c6884f..54e8ed1 100644 --- a/cyberwow/lib/controller/rpc/rpc2View.dart +++ b/cyberwow/lib/controller/rpc/rpc2View.dart @@ -24,6 +24,7 @@ import 'dart:math'; import 'package:intl/intl.dart'; import '../../config.dart' as config; +import '../../helper.dart'; Map rpcTxView(Map x) { const _remove = @@ -53,7 +54,7 @@ Map rpcTxView(Map x) { ( (k, v) { if (k == 'id_hash') { - return MapEntry('id', v.substring(0, config.hashLength) + '...'); + return MapEntry('id', trimHash(v)); } else if (k == 'blob_size') { diff --git a/cyberwow/lib/controller/rpc/rpcView.dart b/cyberwow/lib/controller/rpc/rpcView.dart index 602e60c..c17734a 100644 --- a/cyberwow/lib/controller/rpc/rpcView.dart +++ b/cyberwow/lib/controller/rpc/rpcView.dart @@ -20,6 +20,7 @@ along with CyberWOW. If not, see . */ import '../../config.dart' as config; +import '../../helper.dart'; Map rpcPeerView(Map x) { const _remove = @@ -57,7 +58,7 @@ Map rpcPeerView(Map x) { ( (k, v) { if (k == 'connection_id') { - return MapEntry(k, v.substring(0, config.hashLength) + '...'); + return MapEntry(k, trimHash(v)); } const speedField = diff --git a/cyberwow/lib/helper.dart b/cyberwow/lib/helper.dart index 3b65e7e..e751af3 100644 --- a/cyberwow/lib/helper.dart +++ b/cyberwow/lib/helper.dart @@ -21,11 +21,16 @@ along with CyberWOW. If not, see . import 'dart:convert'; +import 'config.dart' as config; + String pretty(dynamic x) { final JsonEncoder encoder = JsonEncoder.withIndent(' '); - return encoder.convert(x); + return encoder.convert(x) + .replaceAll(RegExp(r'["\[\]{},]'), '') + .replaceAll('\n ', '\n'); } +String trimHash(String x) => x.substring(0, config.hashLength) + ' ...'; int asInt(dynamic x) => x?.toInt() ?? 0;