mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
fix: container parsing (#948)
This commit is contained in:
@@ -37,12 +37,12 @@ final class PodmanImg implements ContainerImg {
|
|||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
factory PodmanImg.fromJson(Map<String, dynamic> json) => PodmanImg(
|
factory PodmanImg.fromJson(Map<String, dynamic> json) => PodmanImg(
|
||||||
repository: json['repository'],
|
repository: _asString(json['repository']),
|
||||||
tag: json['tag'],
|
tag: _asString(json['tag']),
|
||||||
id: json['Id'],
|
id: _asString(json['Id']),
|
||||||
created: json['Created'],
|
created: _asInt(json['Created']),
|
||||||
size: json['Size'],
|
size: _asInt(json['Size']),
|
||||||
containers: json['Containers'],
|
containers: _asInt(json['Containers']),
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
@@ -119,3 +119,16 @@ final class DockerImg implements ContainerImg {
|
|||||||
'Tag': tag,
|
'Tag': tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? _asString(dynamic val) {
|
||||||
|
if (val == null) return null;
|
||||||
|
if (val is String) return val;
|
||||||
|
return val.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int? _asInt(dynamic val) {
|
||||||
|
if (val == null) return null;
|
||||||
|
if (val is int) return val;
|
||||||
|
if (val is double) return val.toInt();
|
||||||
|
return int.tryParse(val.toString());
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,22 +40,15 @@ class ContainerNotifier extends _$ContainerNotifier {
|
|||||||
ContainerState build(SSHClient? client, String userName, String hostId, BuildContext context) {
|
ContainerState build(SSHClient? client, String userName, String hostId, BuildContext context) {
|
||||||
final type = Stores.container.getType(hostId);
|
final type = Stores.container.getType(hostId);
|
||||||
final initialState = ContainerState(type: type);
|
final initialState = ContainerState(type: type);
|
||||||
|
|
||||||
// Async initialization
|
// Async initialization
|
||||||
Future.microtask(() => refresh());
|
Future.microtask(() => refresh());
|
||||||
|
|
||||||
return initialState;
|
return initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setType(ContainerType type) async {
|
Future<void> setType(ContainerType type) async {
|
||||||
state = state.copyWith(
|
state = state.copyWith(type: type, error: null, runLog: null, items: null, images: null, version: null);
|
||||||
type: type,
|
|
||||||
error: null,
|
|
||||||
runLog: null,
|
|
||||||
items: null,
|
|
||||||
images: null,
|
|
||||||
version: null,
|
|
||||||
);
|
|
||||||
Stores.container.setType(type, hostId);
|
Stores.container.setType(type, hostId);
|
||||||
sudoCompleter = Completer<bool>();
|
sudoCompleter = Completer<bool>();
|
||||||
await refresh();
|
await refresh();
|
||||||
@@ -180,9 +173,13 @@ class ContainerNotifier extends _$ContainerNotifier {
|
|||||||
try {
|
try {
|
||||||
final statsLines = statsRaw.split('\n');
|
final statsLines = statsRaw.split('\n');
|
||||||
statsLines.removeWhere((element) => element.isEmpty);
|
statsLines.removeWhere((element) => element.isEmpty);
|
||||||
for (var item in state.items!) {
|
final items = state.items;
|
||||||
|
if (items == null) return;
|
||||||
|
|
||||||
|
for (var item in items) {
|
||||||
final id = item.id;
|
final id = item.id;
|
||||||
if (id == null) continue;
|
if (id == null) continue;
|
||||||
|
if (id.length < 5) continue;
|
||||||
final statsLine = statsLines.firstWhereOrNull(
|
final statsLine = statsLines.firstWhereOrNull(
|
||||||
/// Use 5 characters to match the container id, possibility of mismatch
|
/// Use 5 characters to match the container id, possibility of mismatch
|
||||||
/// is very low.
|
/// is very low.
|
||||||
@@ -267,7 +264,6 @@ class ContainerNotifier extends _$ContainerNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const _jsonFmt = '--format "{{json .}}"';
|
const _jsonFmt = '--format "{{json .}}"';
|
||||||
|
|
||||||
enum ContainerCmdType {
|
enum ContainerCmdType {
|
||||||
|
|||||||
Reference in New Issue
Block a user