2021-01-06 17:35:57 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2022-11-23 07:55:28 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/schema.graphql.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
part 'server_details.g.dart';
|
|
|
|
|
|
|
|
@HiveType(typeId: 2)
|
2022-05-13 13:57:56 +00:00
|
|
|
class ServerHostingDetails {
|
|
|
|
ServerHostingDetails({
|
2021-03-15 15:39:44 +00:00
|
|
|
required this.ip4,
|
|
|
|
required this.id,
|
|
|
|
required this.createTime,
|
2022-05-14 02:54:40 +00:00
|
|
|
required this.volume,
|
2021-11-18 19:10:40 +00:00
|
|
|
required this.apiToken,
|
2022-05-14 02:54:40 +00:00
|
|
|
required this.provider,
|
2024-05-15 14:16:59 +00:00
|
|
|
this.serverLocation,
|
|
|
|
this.serverType,
|
2021-01-19 12:05:40 +00:00
|
|
|
this.startTime,
|
2021-01-06 17:35:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
@HiveField(0)
|
2021-03-30 17:38:40 +00:00
|
|
|
final String ip4;
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
@HiveField(1)
|
2021-03-30 17:38:40 +00:00
|
|
|
final int id;
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2024-05-15 14:16:59 +00:00
|
|
|
// TODO: Check if it is still needed
|
2021-01-21 21:01:42 +00:00
|
|
|
@HiveField(2)
|
2021-03-15 15:39:44 +00:00
|
|
|
final DateTime? startTime;
|
2021-01-21 21:01:42 +00:00
|
|
|
|
2024-05-15 14:16:59 +00:00
|
|
|
@HiveField(3)
|
|
|
|
final DateTime? createTime;
|
|
|
|
|
2024-02-01 14:30:06 +00:00
|
|
|
// TODO: Check if it is still needed
|
2021-03-30 17:38:40 +00:00
|
|
|
@HiveField(4)
|
2024-01-29 16:49:20 +00:00
|
|
|
final ServerProviderVolume volume;
|
2021-03-30 17:38:40 +00:00
|
|
|
|
2021-11-18 19:10:40 +00:00
|
|
|
@HiveField(5)
|
|
|
|
final String apiToken;
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
@HiveField(6, defaultValue: ServerProviderType.hetzner)
|
|
|
|
final ServerProviderType provider;
|
2022-05-14 02:54:40 +00:00
|
|
|
|
2024-05-15 14:16:59 +00:00
|
|
|
@HiveField(7)
|
|
|
|
final String? serverLocation;
|
|
|
|
|
|
|
|
@HiveField(8)
|
|
|
|
final String? serverType;
|
|
|
|
|
|
|
|
ServerHostingDetails copyWith({
|
|
|
|
final DateTime? startTime,
|
|
|
|
final String? serverLocation,
|
|
|
|
final String? serverType,
|
|
|
|
}) =>
|
2022-06-09 21:13:06 +00:00
|
|
|
ServerHostingDetails(
|
|
|
|
startTime: startTime ?? this.startTime,
|
2024-05-15 14:16:59 +00:00
|
|
|
serverLocation: serverLocation ?? this.serverLocation,
|
|
|
|
serverType: serverType ?? this.serverType,
|
2022-06-09 21:13:06 +00:00
|
|
|
createTime: createTime,
|
|
|
|
id: id,
|
|
|
|
ip4: ip4,
|
|
|
|
volume: volume,
|
|
|
|
apiToken: apiToken,
|
|
|
|
provider: provider,
|
|
|
|
);
|
2021-01-19 12:05:40 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
@override
|
2021-01-06 17:35:57 +00:00
|
|
|
String toString() => id.toString();
|
|
|
|
}
|
2021-03-30 17:38:40 +00:00
|
|
|
|
|
|
|
@HiveType(typeId: 5)
|
2024-01-29 16:49:20 +00:00
|
|
|
class ServerProviderVolume {
|
|
|
|
ServerProviderVolume({
|
2021-03-30 17:38:40 +00:00
|
|
|
required this.id,
|
|
|
|
required this.name,
|
2022-06-28 18:06:52 +00:00
|
|
|
required this.sizeByte,
|
2022-06-27 07:07:11 +00:00
|
|
|
required this.serverId,
|
2022-07-31 23:10:37 +00:00
|
|
|
required this.linuxDevice,
|
2022-10-12 04:55:30 +00:00
|
|
|
this.uuid,
|
2024-08-14 03:12:47 +00:00
|
|
|
this.location,
|
2021-03-30 17:38:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
@HiveField(1)
|
|
|
|
int id;
|
|
|
|
@HiveField(2)
|
|
|
|
String name;
|
2022-06-28 18:06:52 +00:00
|
|
|
@HiveField(3, defaultValue: 10737418240) // 10 Gb
|
|
|
|
int sizeByte;
|
2022-06-27 07:07:11 +00:00
|
|
|
@HiveField(4, defaultValue: null)
|
|
|
|
int? serverId;
|
2022-07-31 23:10:37 +00:00
|
|
|
@HiveField(5, defaultValue: null)
|
|
|
|
String? linuxDevice;
|
2022-10-12 04:55:30 +00:00
|
|
|
@HiveField(6, defaultValue: null)
|
|
|
|
String? uuid;
|
2024-08-14 03:12:47 +00:00
|
|
|
@HiveField(7, defaultValue: null)
|
|
|
|
String? location;
|
2021-03-30 17:38:40 +00:00
|
|
|
}
|
2022-05-14 02:54:40 +00:00
|
|
|
|
|
|
|
@HiveType(typeId: 101)
|
2023-01-30 15:44:52 +00:00
|
|
|
enum ServerProviderType {
|
2022-05-14 02:54:40 +00:00
|
|
|
@HiveField(0)
|
2022-05-24 18:55:39 +00:00
|
|
|
unknown,
|
2022-05-14 02:54:40 +00:00
|
|
|
@HiveField(1)
|
2022-05-24 18:55:39 +00:00
|
|
|
hetzner,
|
2022-10-11 20:11:13 +00:00
|
|
|
@HiveField(2)
|
2022-11-23 07:55:28 +00:00
|
|
|
digitalOcean;
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
factory ServerProviderType.fromGraphQL(final Enum$ServerProvider provider) {
|
2022-11-23 07:55:28 +00:00
|
|
|
switch (provider) {
|
|
|
|
case Enum$ServerProvider.HETZNER:
|
|
|
|
return hetzner;
|
|
|
|
case Enum$ServerProvider.DIGITALOCEAN:
|
|
|
|
return digitalOcean;
|
|
|
|
default:
|
|
|
|
return unknown;
|
|
|
|
}
|
|
|
|
}
|
2022-12-31 04:16:10 +00:00
|
|
|
|
2023-07-28 23:42:41 +00:00
|
|
|
String get displayName => switch (this) {
|
|
|
|
digitalOcean => 'Digital Ocean',
|
|
|
|
hetzner => 'Hetzner Cloud',
|
|
|
|
unknown => 'Unknown',
|
|
|
|
};
|
2024-07-30 15:22:32 +00:00
|
|
|
|
|
|
|
String get supportArticle => switch (this) {
|
|
|
|
digitalOcean => 'how_digital_ocean',
|
|
|
|
hetzner => 'how_hetzner',
|
|
|
|
unknown => '',
|
|
|
|
};
|
2022-05-14 02:54:40 +00:00
|
|
|
}
|
2024-06-30 14:50:21 +00:00
|
|
|
|
|
|
|
extension ServerProviderTypeIsSpecified on ServerProviderType? {
|
|
|
|
bool get isSpecified => this != null && this != ServerProviderType.unknown;
|
|
|
|
}
|