Add TLS trick config options

This commit is contained in:
problematicconsumer
2023-12-04 17:36:02 +03:30
parent d434467090
commit 5def216b57
13 changed files with 208 additions and 21 deletions

45
lib/core/model/range.dart Normal file
View File

@@ -0,0 +1,45 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'range.freezed.dart';
@freezed
class RangeWithOptionalCeil with _$RangeWithOptionalCeil {
const RangeWithOptionalCeil._();
const factory RangeWithOptionalCeil({
required int min,
int? max,
}) = _RangeWithOptionalCeil;
String format() => "$min${max != null ? "-$max" : ""}";
factory RangeWithOptionalCeil.fromString(String input) =>
switch (input.split("-")) {
[final String min] => RangeWithOptionalCeil(min: int.parse(min)),
[final String min, final String max] => RangeWithOptionalCeil(
min: int.parse(min),
max: int.parse(max),
),
_ => throw Exception("Invalid range: $input"),
};
static RangeWithOptionalCeil? tryParse(String input) {
try {
return RangeWithOptionalCeil.fromString(input);
} catch (_) {
return null;
}
}
}
class RangeWithOptionalCeilJsonConverter
implements JsonConverter<RangeWithOptionalCeil, String> {
const RangeWithOptionalCeilJsonConverter();
@override
RangeWithOptionalCeil fromJson(String json) =>
RangeWithOptionalCeil.fromString(json);
@override
String toJson(RangeWithOptionalCeil object) => object.format();
}