alroyso 1 year ago
parent
commit
18e203f061

+ 0 - 0
lib/app/server/core_base.dart


+ 0 - 0
lib/app/server/hysteria/config.dart


+ 0 - 0
lib/app/server/hysteria/server.dart


+ 56 - 0
lib/app/server/server_base.dart

@@ -0,0 +1,56 @@
+import 'package:speed_safe/app/server/hysteria/server.dart';
+import 'package:speed_safe/app/server/shadowsocks/server.dart';
+import 'package:speed_safe/app/server/trojan/server.dart';
+import 'package:speed_safe/app/server/xray/server.dart';
+
+abstract class ServerBase {
+  String protocol;
+  String address;
+  int port;
+  String remark;
+  int? uplink;
+  int? downlink;
+
+  ServerBase({
+    required this.protocol,
+    required this.address,
+    required this.port,
+    required this.remark,
+    this.uplink,
+    this.downlink,
+  });
+  // factory Server.fromJson(Map<String, dynamic> json) => _$ServerFromJson(json);
+  factory ServerBase.fromJson(Map<String, dynamic> json) {
+    switch (json['protocol']) {
+      case 'vmess':
+      case 'vless':
+      case 'socks':
+        return XrayServer.fromJson(json);
+      case 'shadowsocks':
+        return ShadowsocksServer.fromJson(json);
+      case 'trojan':
+        return TrojanServer.fromJson(json);
+      case 'hysteria':
+        return HysteriaServer.fromJson(json);
+      default:
+        throw FormatException('Failed to parse server: ${json['protocol']}');
+    }
+  }
+
+  Map<String, dynamic> toJson() {
+    switch (protocol) {
+      case 'vmess':
+      case 'vless':
+      case 'socks':
+        return (this as XrayServer).toJson();
+      case 'shadowsocks':
+        return (this as ShadowsocksServer).toJson();
+      case 'trojan':
+        return (this as TrojanServer).toJson();
+      case 'hysteria':
+        return (this as HysteriaServer).toJson();
+      default:
+        throw FormatException('Failed to parse server: $protocol');
+    }
+  }
+}

+ 0 - 0
lib/app/server/shadowsocks/server.dart


+ 0 - 0
lib/app/server/sing-box/config.dart


+ 0 - 0
lib/app/server/sing-box/generate.dart


+ 0 - 0
lib/app/server/trojan/server.dart


+ 0 - 0
lib/app/server/xray/config.dart


+ 0 - 0
lib/app/server/xray/server.dart