2022-10-16 00:51:10 +00:00
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2022-07-14 13:34:08 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
2022-09-14 23:31:25 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
2022-07-13 11:58:23 +00:00
|
|
|
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
2022-02-08 21:01:08 +00:00
|
|
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
2021-03-26 13:38:39 +00:00
|
|
|
|
|
|
|
class ServerDetailsRepository {
|
2022-10-16 00:51:10 +00:00
|
|
|
HetznerApi hetzner = HetznerApi(
|
|
|
|
/// TODO: Hetzner hardcode (???)
|
|
|
|
region: getIt<ApiConfigModel>().serverLocation,
|
|
|
|
);
|
2022-09-12 17:38:22 +00:00
|
|
|
ServerApi server = ServerApi();
|
2022-02-08 21:01:08 +00:00
|
|
|
|
2022-09-14 23:31:25 +00:00
|
|
|
Future<ServerDetailsRepositoryDto> load() async {
|
|
|
|
final settings = await server.getSystemSettings();
|
|
|
|
return ServerDetailsRepositoryDto(
|
|
|
|
autoUpgradeSettings: settings.autoUpgradeSettings,
|
|
|
|
hetznerServerInfo: await hetzner.getInfo(),
|
|
|
|
serverTimezone: TimeZoneSettings.fromString(
|
|
|
|
settings.timezone,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setAutoUpgradeSettings(
|
|
|
|
final AutoUpgradeSettings settings,
|
|
|
|
) async {
|
|
|
|
await server.setAutoUpgradeSettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setTimezone(
|
|
|
|
final String timezone,
|
|
|
|
) async {
|
|
|
|
if (timezone.isNotEmpty) {
|
|
|
|
await server.setTimezone(timezone);
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 13:38:39 +00:00
|
|
|
}
|
2022-02-08 21:01:08 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
class ServerDetailsRepositoryDto {
|
|
|
|
ServerDetailsRepositoryDto({
|
2022-02-08 21:01:08 +00:00
|
|
|
required this.hetznerServerInfo,
|
|
|
|
required this.serverTimezone,
|
|
|
|
required this.autoUpgradeSettings,
|
|
|
|
});
|
2022-07-13 11:58:23 +00:00
|
|
|
final HetznerServerInfo hetznerServerInfo;
|
2022-06-05 19:36:32 +00:00
|
|
|
|
|
|
|
final TimeZoneSettings serverTimezone;
|
|
|
|
|
|
|
|
final AutoUpgradeSettings autoUpgradeSettings;
|
2022-02-08 21:01:08 +00:00
|
|
|
}
|