Fix infinite sub expire date (#334)
* Fix infinite sub expire date * fix expire * fix build * refactor * make it better readable * Fix infinite sub * Add test for infinite sub --------- Co-authored-by: Hiddify <114227601+hiddify-com@users.noreply.github.com> Co-authored-by: problematicconsumer <problematicconsumer@protonmail.com>
This commit is contained in:
@@ -14,6 +14,9 @@ import 'package:uuid/uuid.dart';
|
||||
/// - url filename extension (example: `https://example.com/config.json`) -> name=`config`
|
||||
/// - if none of these methods return a non-blank string, fallback to `Remote Profile`
|
||||
abstract class ProfileParser {
|
||||
static const infiniteTrafficThreshold = 9223372036854775807;
|
||||
static const infiniteTimeThreshold = 92233720368;
|
||||
|
||||
static RemoteProfileEntity parse(
|
||||
String url,
|
||||
Map<String, List<String>> headers,
|
||||
@@ -89,16 +92,15 @@ abstract class ProfileParser {
|
||||
"upload": final upload?,
|
||||
"download": final download?,
|
||||
"total": var total,
|
||||
"expire": final expire
|
||||
"expire": var expire
|
||||
}) {
|
||||
total = total ?? 0;
|
||||
total = (total == null || total == 0) ? infiniteTrafficThreshold : total;
|
||||
expire = (expire == null || expire == 0) ? infiniteTimeThreshold : expire;
|
||||
return SubscriptionInfo(
|
||||
upload: upload,
|
||||
download: download,
|
||||
total: total == 0 ? 9223372036854775807 : total,
|
||||
expire: DateTime.fromMillisecondsSinceEpoch(
|
||||
(expire ?? 92233720368) * 1000,
|
||||
),
|
||||
total: total,
|
||||
expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -70,6 +70,36 @@ void main() {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
"with infinite traffic and time",
|
||||
() {
|
||||
final headers = <String, List<String>>{
|
||||
"profile-title": ["title"],
|
||||
"profile-update-interval": ["1"],
|
||||
"subscription-userinfo": [
|
||||
"upload=0;download=1024;total=0;expire=0",
|
||||
],
|
||||
"profile-web-page-url": [validBaseUrl],
|
||||
"support-url": [validSupportUrl],
|
||||
};
|
||||
final profile = ProfileParser.parse(validExtendedUrl, headers);
|
||||
|
||||
expect(profile.subInfo, isNotNull);
|
||||
expect(
|
||||
profile.subInfo!.total,
|
||||
equals(ProfileParser.infiniteTrafficThreshold),
|
||||
);
|
||||
expect(
|
||||
profile.subInfo!.expire,
|
||||
equals(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
ProfileParser.infiniteTimeThreshold * 1000,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user