mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: ignore unknown pve res type
This commit is contained in:
@@ -11,22 +11,14 @@ enum PveResType {
|
|||||||
sdn,
|
sdn,
|
||||||
;
|
;
|
||||||
|
|
||||||
static PveResType fromString(String type) {
|
static PveResType? fromString(String type) => switch (type.toLowerCase()) {
|
||||||
switch (type) {
|
'lxc' => PveResType.lxc,
|
||||||
case 'lxc':
|
'qemu' => PveResType.qemu,
|
||||||
return PveResType.lxc;
|
'node' => PveResType.node,
|
||||||
case 'qemu':
|
'storage' => PveResType.storage,
|
||||||
return PveResType.qemu;
|
'sdn' => PveResType.sdn,
|
||||||
case 'node':
|
_ => null,
|
||||||
return PveResType.node;
|
};
|
||||||
case 'storage':
|
|
||||||
return PveResType.storage;
|
|
||||||
case 'sdn':
|
|
||||||
return PveResType.sdn;
|
|
||||||
default:
|
|
||||||
throw Exception('Unknown PveResType: $type');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String get toStr => switch (this) {
|
String get toStr => switch (this) {
|
||||||
PveResType.node => l10n.node,
|
PveResType.node => l10n.node,
|
||||||
@@ -42,8 +34,9 @@ sealed class PveResIface {
|
|||||||
String get status;
|
String get status;
|
||||||
PveResType get type;
|
PveResType get type;
|
||||||
|
|
||||||
static PveResIface fromJson(Map<String, dynamic> json) {
|
static PveResIface? fromJson(Map<String, dynamic> json) {
|
||||||
final type = PveResType.fromString(json['type']);
|
final type = PveResType.fromString(json['type']);
|
||||||
|
if (type == null) return null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PveResType.lxc:
|
case PveResType.lxc:
|
||||||
return PveLxc.fromJson(json);
|
return PveLxc.fromJson(json);
|
||||||
@@ -420,6 +413,7 @@ final class PveRes {
|
|||||||
final List<PveStorage> storages = [];
|
final List<PveStorage> storages = [];
|
||||||
final List<PveSdn> sdns = [];
|
final List<PveSdn> sdns = [];
|
||||||
for (final item in items) {
|
for (final item in items) {
|
||||||
|
if (item == null) continue;
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case PveResType.lxc:
|
case PveResType.lxc:
|
||||||
lxcs.add(item as PveLxc);
|
lxcs.add(item as PveLxc);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:toolbox/core/extension/context/common.dart';
|
import 'package:toolbox/core/extension/context/common.dart';
|
||||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||||
import 'package:toolbox/core/extension/context/locale.dart';
|
import 'package:toolbox/core/extension/context/locale.dart';
|
||||||
import 'package:toolbox/core/extension/status_cmd_type.dart';
|
|
||||||
import 'package:toolbox/data/model/app/server_detail_card.dart';
|
import 'package:toolbox/data/model/app/server_detail_card.dart';
|
||||||
|
import 'package:toolbox/data/model/app/shell_func.dart';
|
||||||
import 'package:toolbox/data/model/server/battery.dart';
|
import 'package:toolbox/data/model/server/battery.dart';
|
||||||
import 'package:toolbox/data/model/server/cpu.dart';
|
import 'package:toolbox/data/model/server/cpu.dart';
|
||||||
import 'package:toolbox/data/model/server/disk.dart';
|
import 'package:toolbox/data/model/server/disk.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user