2022-08-29 00:40:35 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-29 00:40:35 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/schema.graphql.dart';
|
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/services.graphql.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
|
|
|
|
2023-06-29 10:51:38 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/server_settings.graphql.dart';
|
2023-06-23 02:22:48 +00:00
|
|
|
|
2022-08-29 00:40:35 +00:00
|
|
|
class Service {
|
2022-10-26 16:26:09 +00:00
|
|
|
Service.fromGraphQL(final Query$AllServices$services$allServices service)
|
|
|
|
: this(
|
|
|
|
id: service.id,
|
|
|
|
displayName: service.displayName,
|
|
|
|
description: service.description,
|
|
|
|
isEnabled: service.isEnabled,
|
|
|
|
isRequired: service.isRequired,
|
|
|
|
isMovable: service.isMovable,
|
2023-06-29 10:51:38 +00:00
|
|
|
canBeBackedUp: service.canBeBackedUp,
|
2023-07-02 11:41:31 +00:00
|
|
|
backupDescription: service.backupDescription,
|
2022-10-26 16:26:09 +00:00
|
|
|
status: ServiceStatus.fromGraphQL(service.status),
|
|
|
|
storageUsage: ServiceStorageUsage(
|
|
|
|
used: DiskSize(byte: int.parse(service.storageUsage.usedSpace)),
|
|
|
|
volume: service.storageUsage.volume?.name,
|
|
|
|
),
|
|
|
|
// Decode the base64 encoded svg icon to text.
|
|
|
|
svgIcon: utf8.decode(base64.decode(service.svgIcon)),
|
|
|
|
dnsRecords: service.dnsRecords
|
2022-10-30 14:21:38 +00:00
|
|
|
?.map(
|
2023-06-23 02:22:48 +00:00
|
|
|
(
|
|
|
|
final Fragment$fragmentDnsRecords record,
|
|
|
|
) =>
|
2022-10-30 14:21:38 +00:00
|
|
|
DnsRecord.fromGraphQL(record),
|
|
|
|
)
|
2022-10-26 16:26:09 +00:00
|
|
|
.toList() ??
|
|
|
|
[],
|
|
|
|
url: service.url,
|
|
|
|
);
|
2022-08-29 00:40:35 +00:00
|
|
|
Service({
|
|
|
|
required this.id,
|
|
|
|
required this.displayName,
|
|
|
|
required this.description,
|
|
|
|
required this.isEnabled,
|
|
|
|
required this.isRequired,
|
2022-08-29 20:35:06 +00:00
|
|
|
required this.isMovable,
|
2023-06-29 10:51:38 +00:00
|
|
|
required this.canBeBackedUp,
|
2023-07-02 11:41:31 +00:00
|
|
|
required this.backupDescription,
|
2022-08-29 00:40:35 +00:00
|
|
|
required this.status,
|
|
|
|
required this.storageUsage,
|
|
|
|
required this.svgIcon,
|
|
|
|
required this.dnsRecords,
|
|
|
|
this.url,
|
|
|
|
});
|
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
/// TODO Turn loginInfo into dynamic data, not static!
|
|
|
|
String get loginInfo {
|
|
|
|
switch (id) {
|
2023-09-07 02:41:34 +00:00
|
|
|
case 'email':
|
2022-10-04 18:58:25 +00:00
|
|
|
return 'mail.login_info'.tr();
|
|
|
|
case 'bitwarden':
|
|
|
|
return 'password_manager.login_info'.tr();
|
|
|
|
case 'jitsi':
|
|
|
|
return 'video.login_info'.tr();
|
|
|
|
case 'nextcloud':
|
|
|
|
return 'cloud.login_info'.tr();
|
|
|
|
case 'pleroma':
|
|
|
|
return 'social_network.login_info'.tr();
|
|
|
|
case 'gitea':
|
|
|
|
return 'git.login_info'.tr();
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:35:06 +00:00
|
|
|
static Service empty = Service(
|
|
|
|
id: 'empty',
|
|
|
|
displayName: '',
|
|
|
|
description: '',
|
|
|
|
isEnabled: false,
|
|
|
|
isRequired: false,
|
|
|
|
isMovable: false,
|
2023-06-29 10:51:38 +00:00
|
|
|
canBeBackedUp: false,
|
2023-07-02 11:41:31 +00:00
|
|
|
backupDescription: '',
|
2022-08-29 20:35:06 +00:00
|
|
|
status: ServiceStatus.off,
|
|
|
|
storageUsage: ServiceStorageUsage(
|
2022-09-06 10:27:18 +00:00
|
|
|
used: const DiskSize(byte: 0),
|
2022-08-29 20:35:06 +00:00
|
|
|
volume: '',
|
|
|
|
),
|
|
|
|
svgIcon: '',
|
|
|
|
dnsRecords: [],
|
|
|
|
url: '',
|
|
|
|
);
|
|
|
|
|
2022-08-29 00:40:35 +00:00
|
|
|
final String id;
|
|
|
|
final String displayName;
|
|
|
|
final String description;
|
|
|
|
final bool isEnabled;
|
|
|
|
final bool isRequired;
|
2022-08-29 20:35:06 +00:00
|
|
|
final bool isMovable;
|
2023-06-29 10:51:38 +00:00
|
|
|
final bool canBeBackedUp;
|
2023-07-02 11:41:31 +00:00
|
|
|
final String backupDescription;
|
2022-08-29 00:40:35 +00:00
|
|
|
final ServiceStatus status;
|
|
|
|
final ServiceStorageUsage storageUsage;
|
|
|
|
final String svgIcon;
|
|
|
|
final String? url;
|
|
|
|
final List<DnsRecord> dnsRecords;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServiceStorageUsage {
|
|
|
|
ServiceStorageUsage({
|
|
|
|
required this.used,
|
|
|
|
required this.volume,
|
|
|
|
});
|
|
|
|
|
|
|
|
final DiskSize used;
|
|
|
|
final String? volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ServiceStatus {
|
2022-12-31 05:08:25 +00:00
|
|
|
failed,
|
|
|
|
reloading,
|
2022-08-29 00:40:35 +00:00
|
|
|
activating,
|
|
|
|
active,
|
|
|
|
deactivating,
|
|
|
|
inactive,
|
2022-12-31 05:08:25 +00:00
|
|
|
off;
|
2022-08-29 00:40:35 +00:00
|
|
|
|
|
|
|
factory ServiceStatus.fromGraphQL(final Enum$ServiceStatusEnum graphQL) {
|
|
|
|
switch (graphQL) {
|
|
|
|
case Enum$ServiceStatusEnum.ACTIVATING:
|
|
|
|
return activating;
|
|
|
|
case Enum$ServiceStatusEnum.ACTIVE:
|
|
|
|
return active;
|
|
|
|
case Enum$ServiceStatusEnum.DEACTIVATING:
|
|
|
|
return deactivating;
|
|
|
|
case Enum$ServiceStatusEnum.FAILED:
|
|
|
|
return failed;
|
|
|
|
case Enum$ServiceStatusEnum.INACTIVE:
|
|
|
|
return inactive;
|
|
|
|
case Enum$ServiceStatusEnum.OFF:
|
|
|
|
return off;
|
|
|
|
case Enum$ServiceStatusEnum.RELOADING:
|
|
|
|
return reloading;
|
|
|
|
case Enum$ServiceStatusEnum.$unknown:
|
|
|
|
return inactive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|