101 lines
2.6 KiB
Dart
101 lines
2.6 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'package:hiddify/data/local/database.dart';
|
|
import 'package:hiddify/domain/profiles/profiles.dart';
|
|
import 'package:hiddify/domain/rules/geo_asset.dart';
|
|
|
|
extension ProfileMapper on Profile {
|
|
ProfileEntriesCompanion toCompanion() {
|
|
return switch (this) {
|
|
RemoteProfile(:final url, :final options, :final subInfo) =>
|
|
ProfileEntriesCompanion.insert(
|
|
id: id,
|
|
type: ProfileType.remote,
|
|
active: active,
|
|
name: name,
|
|
url: Value(url),
|
|
lastUpdate: lastUpdate,
|
|
updateInterval: Value(options?.updateInterval),
|
|
upload: Value(subInfo?.upload),
|
|
download: Value(subInfo?.download),
|
|
total: Value(subInfo?.total),
|
|
expire: Value(subInfo?.expire),
|
|
webPageUrl: Value(subInfo?.webPageUrl),
|
|
supportUrl: Value(subInfo?.supportUrl),
|
|
),
|
|
LocalProfile() => ProfileEntriesCompanion.insert(
|
|
id: id,
|
|
type: ProfileType.local,
|
|
active: active,
|
|
name: name,
|
|
lastUpdate: lastUpdate,
|
|
),
|
|
};
|
|
}
|
|
|
|
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!,
|
|
webPageUrl: e.webPageUrl,
|
|
supportUrl: e.supportUrl,
|
|
);
|
|
}
|
|
|
|
return switch (e.type) {
|
|
ProfileType.remote => RemoteProfile(
|
|
id: e.id,
|
|
active: e.active,
|
|
name: e.name,
|
|
url: e.url!,
|
|
lastUpdate: e.lastUpdate,
|
|
options: options,
|
|
subInfo: subInfo,
|
|
),
|
|
ProfileType.local => LocalProfile(
|
|
id: e.id,
|
|
active: e.active,
|
|
name: e.name,
|
|
lastUpdate: e.lastUpdate,
|
|
),
|
|
};
|
|
}
|
|
}
|
|
|
|
extension GeoAssetMapper on GeoAsset {
|
|
GeoAssetEntriesCompanion toCompanion() {
|
|
return GeoAssetEntriesCompanion.insert(
|
|
id: id,
|
|
type: type,
|
|
active: active,
|
|
name: name,
|
|
providerName: providerName,
|
|
version: Value(version),
|
|
lastCheck: Value(lastCheck),
|
|
);
|
|
}
|
|
|
|
static GeoAsset fromEntry(GeoAssetEntry e) {
|
|
return GeoAsset(
|
|
id: e.id,
|
|
name: e.name,
|
|
type: e.type,
|
|
active: e.active,
|
|
providerName: e.providerName,
|
|
version: e.version,
|
|
lastCheck: e.lastCheck,
|
|
);
|
|
}
|
|
}
|