Change mapping
This commit is contained in:
@@ -1,117 +1,72 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dart_mappable/dart_mappable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/model/optional_range.dart';
|
||||
import 'package:hiddify/core/utils/json_converters.dart';
|
||||
import 'package:hiddify/features/log/model/log_level.dart';
|
||||
import 'package:hiddify/singbox/model/singbox_config_enum.dart';
|
||||
import 'package:hiddify/singbox/model/singbox_rule.dart';
|
||||
|
||||
part 'singbox_config_option.mapper.dart';
|
||||
part 'singbox_config_option.freezed.dart';
|
||||
part 'singbox_config_option.g.dart';
|
||||
|
||||
@MappableClass(
|
||||
caseStyle: CaseStyle.paramCase,
|
||||
includeCustomMappers: [
|
||||
OptionalRangeJsonMapper(),
|
||||
IntervalInSecondsMapper(),
|
||||
],
|
||||
)
|
||||
class SingboxConfigOption with SingboxConfigOptionMappable {
|
||||
const SingboxConfigOption({
|
||||
required this.executeConfigAsIs,
|
||||
required this.logLevel,
|
||||
required this.resolveDestination,
|
||||
required this.ipv6Mode,
|
||||
required this.remoteDnsAddress,
|
||||
required this.remoteDnsDomainStrategy,
|
||||
required this.directDnsAddress,
|
||||
required this.directDnsDomainStrategy,
|
||||
required this.mixedPort,
|
||||
required this.localDnsPort,
|
||||
required this.tunImplementation,
|
||||
required this.mtu,
|
||||
required this.strictRoute,
|
||||
required this.connectionTestUrl,
|
||||
required this.urlTestInterval,
|
||||
required this.enableClashApi,
|
||||
required this.clashApiPort,
|
||||
required this.enableTun,
|
||||
required this.enableTunService,
|
||||
required this.setSystemProxy,
|
||||
required this.bypassLan,
|
||||
required this.allowConnectionFromLan,
|
||||
required this.enableFakeDns,
|
||||
required this.enableDnsRouting,
|
||||
required this.independentDnsCache,
|
||||
required this.enableTlsFragment,
|
||||
required this.tlsFragmentSize,
|
||||
required this.tlsFragmentSleep,
|
||||
required this.enableTlsMixedSniCase,
|
||||
required this.enableTlsPadding,
|
||||
required this.tlsPaddingSize,
|
||||
required this.enableMux,
|
||||
required this.muxPadding,
|
||||
required this.muxMaxStreams,
|
||||
required this.muxProtocol,
|
||||
required this.enableWarp,
|
||||
required this.warpDetourMode,
|
||||
required this.warpLicenseKey,
|
||||
required this.warpCleanIp,
|
||||
required this.warpPort,
|
||||
required this.warpNoise,
|
||||
required this.geoipPath,
|
||||
required this.geositePath,
|
||||
required this.rules,
|
||||
});
|
||||
@freezed
|
||||
class SingboxConfigOption with _$SingboxConfigOption {
|
||||
const SingboxConfigOption._();
|
||||
|
||||
final bool executeConfigAsIs;
|
||||
final LogLevel logLevel;
|
||||
final bool resolveDestination;
|
||||
@MappableField(key: "ipv6-mode")
|
||||
final IPv6Mode ipv6Mode;
|
||||
final String remoteDnsAddress;
|
||||
final DomainStrategy remoteDnsDomainStrategy;
|
||||
final String directDnsAddress;
|
||||
final DomainStrategy directDnsDomainStrategy;
|
||||
final int mixedPort;
|
||||
final int localDnsPort;
|
||||
final TunImplementation tunImplementation;
|
||||
final int mtu;
|
||||
final bool strictRoute;
|
||||
final String connectionTestUrl;
|
||||
final Duration urlTestInterval;
|
||||
final bool enableClashApi;
|
||||
final int clashApiPort;
|
||||
final bool enableTun;
|
||||
final bool enableTunService;
|
||||
final bool setSystemProxy;
|
||||
final bool bypassLan;
|
||||
final bool allowConnectionFromLan;
|
||||
final bool enableFakeDns;
|
||||
final bool enableDnsRouting;
|
||||
final bool independentDnsCache;
|
||||
final bool enableTlsFragment;
|
||||
final OptionalRange tlsFragmentSize;
|
||||
final OptionalRange tlsFragmentSleep;
|
||||
final bool enableTlsMixedSniCase;
|
||||
final bool enableTlsPadding;
|
||||
final OptionalRange tlsPaddingSize;
|
||||
final bool enableMux;
|
||||
final bool muxPadding;
|
||||
final int muxMaxStreams;
|
||||
final MuxProtocol muxProtocol;
|
||||
final bool enableWarp;
|
||||
final WarpDetourMode warpDetourMode;
|
||||
final String warpLicenseKey;
|
||||
final String warpCleanIp;
|
||||
final int warpPort;
|
||||
final OptionalRange warpNoise;
|
||||
final String geoipPath;
|
||||
final String geositePath;
|
||||
final List<SingboxRule> rules;
|
||||
@JsonSerializable(fieldRename: FieldRename.kebab)
|
||||
const factory SingboxConfigOption({
|
||||
required bool executeConfigAsIs,
|
||||
required LogLevel logLevel,
|
||||
required bool resolveDestination,
|
||||
required IPv6Mode ipv6Mode,
|
||||
required String remoteDnsAddress,
|
||||
required DomainStrategy remoteDnsDomainStrategy,
|
||||
required String directDnsAddress,
|
||||
required DomainStrategy directDnsDomainStrategy,
|
||||
required int mixedPort,
|
||||
required int localDnsPort,
|
||||
required TunImplementation tunImplementation,
|
||||
required int mtu,
|
||||
required bool strictRoute,
|
||||
required String connectionTestUrl,
|
||||
@IntervalInSecondsConverter() required Duration urlTestInterval,
|
||||
required bool enableClashApi,
|
||||
required int clashApiPort,
|
||||
required bool enableTun,
|
||||
required bool enableTunService,
|
||||
required bool setSystemProxy,
|
||||
required bool bypassLan,
|
||||
required bool allowConnectionFromLan,
|
||||
required bool enableFakeDns,
|
||||
required bool enableDnsRouting,
|
||||
required bool independentDnsCache,
|
||||
required bool enableTlsFragment,
|
||||
@OptionalRangeJsonConverter() required OptionalRange tlsFragmentSize,
|
||||
@OptionalRangeJsonConverter() required OptionalRange tlsFragmentSleep,
|
||||
required bool enableTlsMixedSniCase,
|
||||
required bool enableTlsPadding,
|
||||
@OptionalRangeJsonConverter() required OptionalRange tlsPaddingSize,
|
||||
required bool enableMux,
|
||||
required bool muxPadding,
|
||||
required int muxMaxStreams,
|
||||
required MuxProtocol muxProtocol,
|
||||
required bool enableWarp,
|
||||
required WarpDetourMode warpDetourMode,
|
||||
required String warpLicenseKey,
|
||||
required String warpCleanIp,
|
||||
required int warpPort,
|
||||
@OptionalRangeJsonConverter() required OptionalRange warpNoise,
|
||||
required String geoipPath,
|
||||
required String geositePath,
|
||||
required List<SingboxRule> rules,
|
||||
}) = _SingboxConfigOption;
|
||||
|
||||
String format() {
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
return encoder.convert(toMap());
|
||||
return encoder.convert(toJson());
|
||||
}
|
||||
|
||||
factory SingboxConfigOption.fromJson(Map<String, dynamic> json) =>
|
||||
_$SingboxConfigOptionFromJson(json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user