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';
|
2024-01-29 15:57:22 +00:00
|
|
|
import 'package:equatable/equatable.dart';
|
2022-08-29 00:40:35 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/schema.graphql.dart';
|
2024-01-31 10:57:12 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/server_settings.graphql.dart';
|
2022-08-29 00:40:35 +00:00
|
|
|
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';
|
|
|
|
|
2024-01-29 15:57:22 +00:00
|
|
|
class Service extends Equatable {
|
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,
|
2024-07-22 23:47:53 +00:00
|
|
|
configuration: service.configuration
|
|
|
|
?.map(
|
|
|
|
(
|
|
|
|
final Query$AllServices$services$allServices$configuration
|
|
|
|
configItem,
|
|
|
|
) =>
|
|
|
|
ServiceConfigItem.fromGraphQL(configItem),
|
|
|
|
)
|
|
|
|
.toList() ??
|
|
|
|
[],
|
2022-10-26 16:26:09 +00:00
|
|
|
);
|
2024-01-29 15:57:22 +00:00
|
|
|
const Service({
|
2022-08-29 00:40:35 +00:00
|
|
|
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,
|
2024-07-22 23:47:53 +00:00
|
|
|
required this.configuration,
|
2022-08-29 00:40:35 +00:00
|
|
|
this.url,
|
|
|
|
});
|
|
|
|
|
2022-10-04 18:58:25 +00:00
|
|
|
/// TODO Turn loginInfo into dynamic data, not static!
|
|
|
|
String get loginInfo {
|
|
|
|
switch (id) {
|
2024-01-10 13:47:34 +00:00
|
|
|
case 'simple-nixos-mailserver':
|
2022-10-04 18:58:25 +00:00
|
|
|
return 'mail.login_info'.tr();
|
|
|
|
case 'bitwarden':
|
|
|
|
return 'password_manager.login_info'.tr();
|
2024-01-10 13:47:34 +00:00
|
|
|
case 'jitsi-meet':
|
2022-10-04 18:58:25 +00:00
|
|
|
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 '';
|
|
|
|
}
|
|
|
|
|
2024-01-29 15:57:22 +00:00
|
|
|
static Service empty = const Service(
|
2022-08-29 20:35:06 +00:00
|
|
|
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(
|
2024-01-29 15:57:22 +00:00
|
|
|
used: DiskSize(byte: 0),
|
2022-08-29 20:35:06 +00:00
|
|
|
volume: '',
|
|
|
|
),
|
|
|
|
svgIcon: '',
|
|
|
|
dnsRecords: [],
|
|
|
|
url: '',
|
2024-07-22 23:47:53 +00:00
|
|
|
configuration: [],
|
2022-08-29 20:35:06 +00:00
|
|
|
);
|
|
|
|
|
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;
|
2024-07-22 23:47:53 +00:00
|
|
|
final List<ServiceConfigItem> configuration;
|
2024-01-29 15:57:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props => [
|
|
|
|
id,
|
|
|
|
displayName,
|
|
|
|
description,
|
|
|
|
isEnabled,
|
|
|
|
isRequired,
|
|
|
|
isMovable,
|
|
|
|
canBeBackedUp,
|
|
|
|
backupDescription,
|
|
|
|
status,
|
|
|
|
storageUsage,
|
|
|
|
svgIcon,
|
|
|
|
dnsRecords,
|
|
|
|
url,
|
2024-07-22 23:47:53 +00:00
|
|
|
configuration,
|
2024-01-29 15:57:22 +00:00
|
|
|
];
|
2022-08-29 00:40:35 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 15:57:22 +00:00
|
|
|
class ServiceStorageUsage extends Equatable {
|
|
|
|
const ServiceStorageUsage({
|
2022-08-29 00:40:35 +00:00
|
|
|
required this.used,
|
|
|
|
required this.volume,
|
|
|
|
});
|
|
|
|
|
|
|
|
final DiskSize used;
|
|
|
|
final String? volume;
|
2024-01-29 15:57:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props => [used, volume];
|
2022-08-29 00:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 23:47:53 +00:00
|
|
|
|
|
|
|
sealed class ServiceConfigItem extends Equatable {
|
|
|
|
const ServiceConfigItem({
|
|
|
|
required this.id,
|
|
|
|
required this.description,
|
|
|
|
required this.widget,
|
|
|
|
required this.type,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory ServiceConfigItem.fromGraphQL(
|
|
|
|
final Query$AllServices$services$allServices$configuration configItem,
|
|
|
|
) =>
|
|
|
|
configItem.when<ServiceConfigItem>(
|
|
|
|
boolConfigItem: (final boolConfigItem) => BoolServiceConfigItem(
|
2024-07-23 16:56:09 +00:00
|
|
|
id: boolConfigItem.fieldId,
|
2024-07-22 23:47:53 +00:00
|
|
|
description: boolConfigItem.description,
|
|
|
|
widget: boolConfigItem.widget,
|
|
|
|
type: boolConfigItem.type,
|
|
|
|
value: boolConfigItem.boolValue,
|
|
|
|
defaultValue: boolConfigItem.defaultBoolValue,
|
|
|
|
),
|
|
|
|
enumConfigItem: (final enumConfigItem) => EnumServiceConfigItem(
|
2024-07-23 16:56:09 +00:00
|
|
|
id: enumConfigItem.fieldId,
|
2024-07-22 23:47:53 +00:00
|
|
|
description: enumConfigItem.description,
|
|
|
|
widget: enumConfigItem.widget,
|
|
|
|
type: enumConfigItem.type,
|
|
|
|
value: enumConfigItem.stringValue,
|
|
|
|
defaultValue: enumConfigItem.defaultStringValue,
|
|
|
|
options: enumConfigItem.options,
|
|
|
|
),
|
|
|
|
stringConfigItem: (final stringConfigItem) => StringServiceConfigItem(
|
2024-07-23 16:56:09 +00:00
|
|
|
id: stringConfigItem.fieldId,
|
2024-07-22 23:47:53 +00:00
|
|
|
description: stringConfigItem.description,
|
|
|
|
widget: stringConfigItem.widget,
|
|
|
|
type: stringConfigItem.type,
|
|
|
|
value: stringConfigItem.stringValue,
|
|
|
|
defaultValue: stringConfigItem.defaultStringValue,
|
|
|
|
regex: stringConfigItem.regex,
|
|
|
|
),
|
|
|
|
orElse: () => FallbackServiceConfigItem(
|
2024-07-23 16:56:09 +00:00
|
|
|
id: configItem.fieldId,
|
2024-07-22 23:47:53 +00:00
|
|
|
description: configItem.description,
|
|
|
|
type: configItem.type,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final String id;
|
|
|
|
final String description;
|
|
|
|
final String widget;
|
|
|
|
final String type;
|
|
|
|
}
|
|
|
|
|
|
|
|
class StringServiceConfigItem extends ServiceConfigItem {
|
|
|
|
const StringServiceConfigItem({
|
|
|
|
required super.id,
|
|
|
|
required super.description,
|
|
|
|
required super.widget,
|
|
|
|
required super.type,
|
|
|
|
required this.value,
|
|
|
|
required this.defaultValue,
|
|
|
|
this.regex,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String value;
|
|
|
|
final String defaultValue;
|
|
|
|
final String? regex;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props =>
|
|
|
|
[id, description, widget, type, value, defaultValue, regex];
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoolServiceConfigItem extends ServiceConfigItem {
|
|
|
|
const BoolServiceConfigItem({
|
|
|
|
required super.id,
|
|
|
|
required super.description,
|
|
|
|
required super.widget,
|
|
|
|
required super.type,
|
|
|
|
required this.value,
|
|
|
|
required this.defaultValue,
|
|
|
|
});
|
|
|
|
|
|
|
|
final bool value;
|
|
|
|
final bool defaultValue;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props =>
|
|
|
|
[id, description, widget, type, value, defaultValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
class EnumServiceConfigItem extends ServiceConfigItem {
|
|
|
|
const EnumServiceConfigItem({
|
|
|
|
required super.id,
|
|
|
|
required super.description,
|
|
|
|
required super.widget,
|
|
|
|
required super.type,
|
|
|
|
required this.value,
|
|
|
|
required this.defaultValue,
|
|
|
|
required this.options,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String value;
|
|
|
|
final String defaultValue;
|
|
|
|
final List<String> options;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props =>
|
|
|
|
[id, description, widget, type, value, defaultValue, options];
|
|
|
|
}
|
|
|
|
|
|
|
|
class FallbackServiceConfigItem extends ServiceConfigItem {
|
|
|
|
const FallbackServiceConfigItem({
|
|
|
|
required super.id,
|
|
|
|
required super.description,
|
|
|
|
required super.type,
|
|
|
|
}) : super(widget: 'fallback');
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props => [id, description, widget, type];
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Not used yet by the API
|
|
|
|
class IntServiceConfigItem extends ServiceConfigItem {
|
|
|
|
const IntServiceConfigItem({
|
|
|
|
required super.id,
|
|
|
|
required super.description,
|
|
|
|
required super.widget,
|
|
|
|
required super.type,
|
|
|
|
required this.value,
|
|
|
|
required this.defaultValue,
|
|
|
|
required this.min,
|
|
|
|
required this.max,
|
|
|
|
});
|
|
|
|
|
|
|
|
final int value;
|
|
|
|
final int defaultValue;
|
|
|
|
final int min;
|
|
|
|
final int max;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props =>
|
|
|
|
[id, description, widget, type, value, defaultValue, min, max];
|
|
|
|
}
|