Files
umbrix/lib/data/local/data_mappers.dart

62 lines
1.5 KiB
Dart
Raw Normal View History

2023-07-06 17:18:41 +03:30
import 'package:drift/drift.dart';
import 'package:hiddify/data/local/database.dart';
import 'package:hiddify/domain/profiles/profiles.dart';
extension ProfileMapper on Profile {
ProfileEntriesCompanion toCompanion() {
return ProfileEntriesCompanion.insert(
id: id,
active: active,
name: name,
url: url,
lastUpdate: lastUpdate,
2023-07-25 21:41:12 +03:30
updateInterval: Value(options?.updateInterval),
2023-07-06 17:18:41 +03:30
upload: Value(subInfo?.upload),
download: Value(subInfo?.download),
total: Value(subInfo?.total),
expire: Value(subInfo?.expire),
2023-07-25 21:41:12 +03:30
webPageUrl: Value(extra?.webPageUrl),
supportUrl: Value(extra?.supportUrl),
2023-07-06 17:18:41 +03:30
);
}
2023-07-25 21:41:12 +03:30
static Profile fromEntry(ProfileEntry e) {
ProfileOptions? options;
if (e.updateInterval != null) {
options = ProfileOptions(updateInterval: e.updateInterval!);
}
SubscriptionInfo? subInfo;
if (e.upload != null &&
e.download != null &&
e.total != null &&
e.expire != null) {
subInfo = SubscriptionInfo(
upload: e.upload!,
download: e.download!,
total: e.total!,
expire: e.expire!,
);
}
ProfileExtra? extra;
if (e.webPageUrl != null || e.supportUrl != null) {
extra = ProfileExtra(
webPageUrl: e.webPageUrl,
supportUrl: e.supportUrl,
);
}
2023-07-06 17:18:41 +03:30
return Profile(
2023-07-25 21:41:12 +03:30
id: e.id,
active: e.active,
name: e.name,
url: e.url,
lastUpdate: e.lastUpdate,
options: options,
subInfo: subInfo,
extra: extra,
2023-07-06 17:18:41 +03:30
);
}
}