mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
@@ -72,7 +72,7 @@ final class DockerImg implements ContainerImg {
|
|||||||
final String repository;
|
final String repository;
|
||||||
final String size;
|
final String size;
|
||||||
@override
|
@override
|
||||||
final String tag;
|
final String? tag;
|
||||||
|
|
||||||
DockerImg({
|
DockerImg({
|
||||||
required this.containers,
|
required this.containers,
|
||||||
@@ -95,14 +95,30 @@ final class DockerImg implements ContainerImg {
|
|||||||
|
|
||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
factory DockerImg.fromJson(Map<String, dynamic> json) => DockerImg(
|
factory DockerImg.fromJson(Map<String, dynamic> json) {
|
||||||
containers: json["Containers"],
|
final containers = switch (json["Containers"]) {
|
||||||
|
final String a => a,
|
||||||
|
final Object? a => a.toString(),
|
||||||
|
};
|
||||||
|
final repo = switch (json["Repository"] ?? json["Names"]) {
|
||||||
|
final String a => a,
|
||||||
|
final List a => a.firstOrNull.toString(),
|
||||||
|
final Object? a => a.toString(),
|
||||||
|
};
|
||||||
|
final size = switch (json["Size"]) {
|
||||||
|
final String a => a,
|
||||||
|
final int a => a.bytes2Str,
|
||||||
|
final Object? a => a.toString(),
|
||||||
|
};
|
||||||
|
return DockerImg(
|
||||||
|
containers: containers,
|
||||||
createdAt: json["CreatedAt"],
|
createdAt: json["CreatedAt"],
|
||||||
id: json["ID"],
|
id: json["ID"] ?? json["Id"] ?? '',
|
||||||
repository: json["Repository"],
|
repository: repo,
|
||||||
size: json["Size"],
|
size: size,
|
||||||
tag: json["Tag"],
|
tag: json["Tag"],
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"Containers": containers,
|
"Containers": containers,
|
||||||
|
|||||||
@@ -160,11 +160,18 @@ class ContainerProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse images
|
// Parse images
|
||||||
final imageRaw = ContainerCmdType.images.find(segments);
|
final imageRaw = ContainerCmdType.images.find(segments).trim();
|
||||||
|
final isEntireJson = imageRaw.startsWith('[') && imageRaw.endsWith(']');
|
||||||
try {
|
try {
|
||||||
final imgLines = imageRaw.split('\n');
|
if (isEntireJson) {
|
||||||
imgLines.removeWhere((element) => element.isEmpty);
|
images = (json.decode(imageRaw) as List)
|
||||||
images = imgLines.map((e) => ContainerImg.fromRawJson(e, type)).toList();
|
.map((e) => ContainerImg.fromRawJson(json.encode(e), type))
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
final lines = imageRaw.split('\n');
|
||||||
|
lines.removeWhere((element) => element.isEmpty);
|
||||||
|
images = lines.map((e) => ContainerImg.fromRawJson(e, type)).toList();
|
||||||
|
}
|
||||||
} catch (e, trace) {
|
} catch (e, trace) {
|
||||||
error = ContainerErr(
|
error = ContainerErr(
|
||||||
type: ContainerErrType.parseImages,
|
type: ContainerErrType.parseImages,
|
||||||
@@ -298,6 +305,6 @@ enum ContainerCmdType {
|
|||||||
}) {
|
}) {
|
||||||
return ContainerCmdType.values
|
return ContainerCmdType.values
|
||||||
.map((e) => e.exec(type, sudo: sudo, includeStats: includeStats))
|
.map((e) => e.exec(type, sudo: sudo, includeStats: includeStats))
|
||||||
.join(' && echo ${ShellFunc.seperator} && ');
|
.join('\necho ${ShellFunc.seperator}\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user