123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import 'package:dart_json_mapper/dart_json_mapper.dart';
- @jsonSerializable
- class NodeMode {
- final int id;
- final String name;
- final String host;
- final String group;
- final String type;
- final int port;
- final String? passwd;
- final String? sni;
- final int udp;
- final String? ip;
- @JsonProperty(name: 'online_users')
- final int onlineUsers;
- @JsonProperty(name: 'country_code')
- final String countryCode;
- @JsonProperty(name: 'uuid')
- final String? uuid;
- final String? method;
- @JsonProperty(name: 'v2_alter_id')
- final int? v2AlterId;
- @JsonProperty(name: 'v2_net')
- final String? v2Net;
- @JsonProperty(name: 'v2_type')
- final String? v2Type;
- @JsonProperty(name: 'v2_host')
- final String? v2Host;
- @JsonProperty(name: 'v2_path')
- final String? v2Path;
- @JsonProperty(name: 'v2_tls')
- final String? v2Tls;
- @JsonProperty(name: 'v2_sni')
- final String? v2Sni;
- final int? vless;
- @JsonProperty(name: 'vless_pulkey')
- final String? vlessPulkey;
- NodeMode({
- required this.id,
- required this.name,
- required this.host,
- required this.group,
- required this.type,
- required this.port,
- this.passwd,
- this.sni,
- required this.udp,
- this.ip,
- required this.onlineUsers,
- required this.countryCode,
- this.uuid,
- this.method,
- this.v2AlterId,
- this.v2Net,
- this.v2Type,
- this.v2Host,
- this.v2Path,
- this.v2Tls,
- this.v2Sni,
- this.vless,
- this.vlessPulkey,
- });
- }
- String nodeToYaml(NodeMode node) {
- switch (node.type) {
- case 'trojan':
- return '''- { name: ${node.name}, type: ${node.type}, server: ${node.host}, port: ${node.port}, password: ${node.passwd}, udp: 1 }''';
- case 'ss':
- return '''- { name: ${node.name}, type: ${node.type}, server: ${node.host}, port: ${node.port}, password: ${node.passwd}, cipher: ${node.method}, udp: 1 }''';
- case 'v2ray':
- final type = (node.v2Type == 'v2ray' && node.vless == 1) ? 'vless' : 'vmess';
- if (type == 'vless') {
- return '''- { name: ${node.name}, type: $type, server: ${node.host}, port: ${node.port}, uuid: ${node.uuid}, alterId: ${node.v2AlterId}, udp: 1, flow: xtls-rprx-vision, servername: www.amazon.com, tls: true, reality-opts: { public-key: ${node.vlessPulkey} } }''';
- } else {
- return '''- { name: ${node.name}, type: $type, server: ${node.host}, port: ${node.port}, uuid: ${node.uuid}, alterId: ${node.v2AlterId}, cipher: ${node.method}, udp: 1 }''';
- }
- default:
- return '';
- }
- }
|