2022-10-16 00:51:10 +00:00
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2022-11-16 00:24:40 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
2022-11-11 03:32:01 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
|
|
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
|
|
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
2022-09-14 23:31:25 +00:00
|
|
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
2022-11-11 03:32:01 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/server_metadata.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-09-12 17:38:22 +00:00
|
|
|
ServerApi server = ServerApi();
|
2022-11-11 03:32:01 +00:00
|
|
|
ServerProviderApiFactory? serverProviderApiFactory;
|
|
|
|
|
|
|
|
void _buildServerProviderFactory() {
|
|
|
|
final ServerProvider? providerType = getIt<ApiConfigModel>().serverProvider;
|
|
|
|
final String? location = getIt<ApiConfigModel>().serverLocation;
|
|
|
|
serverProviderApiFactory = ApiFactoryCreator.createServerProviderApiFactory(
|
|
|
|
ServerProviderApiFactorySettings(
|
|
|
|
provider: providerType ?? ServerProvider.unknown,
|
|
|
|
location: location,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-02-08 21:01:08 +00:00
|
|
|
|
2022-09-14 23:31:25 +00:00
|
|
|
Future<ServerDetailsRepositoryDto> load() async {
|
2022-11-11 03:32:01 +00:00
|
|
|
if (serverProviderApiFactory == null) {
|
|
|
|
_buildServerProviderFactory();
|
|
|
|
}
|
|
|
|
|
2022-09-14 23:31:25 +00:00
|
|
|
final settings = await server.getSystemSettings();
|
2022-11-11 03:32:01 +00:00
|
|
|
final serverId = getIt<ApiConfigModel>().serverDetails!.id;
|
|
|
|
final metadata = await serverProviderApiFactory!
|
|
|
|
.getServerProvider()
|
|
|
|
.getMetadata(serverId);
|
|
|
|
|
2022-09-14 23:31:25 +00:00
|
|
|
return ServerDetailsRepositoryDto(
|
|
|
|
autoUpgradeSettings: settings.autoUpgradeSettings,
|
2022-11-11 03:32:01 +00:00
|
|
|
metadata: metadata,
|
2022-09-14 23:31:25 +00:00
|
|
|
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-11-11 03:32:01 +00:00
|
|
|
required this.metadata,
|
2022-02-08 21:01:08 +00:00
|
|
|
required this.serverTimezone,
|
|
|
|
required this.autoUpgradeSettings,
|
|
|
|
});
|
2022-11-11 03:32:01 +00:00
|
|
|
final List<ServerMetadataEntity> metadata;
|
2022-06-05 19:36:32 +00:00
|
|
|
final TimeZoneSettings serverTimezone;
|
|
|
|
final AutoUpgradeSettings autoUpgradeSettings;
|
2022-02-08 21:01:08 +00:00
|
|
|
}
|