selfprivacy.org.app/lib/logic/get_it/api_config.dart

98 lines
3.3 KiB
Dart
Raw Normal View History

2021-03-25 20:09:56 +00:00
import 'package:hive/hive.dart';
import 'package:selfprivacy/config/hive_config.dart';
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
import 'package:selfprivacy/logic/models/hive/server_details.dart';
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
2021-03-25 20:09:56 +00:00
class ApiConfigModel {
2022-05-24 18:55:39 +00:00
final Box _box = Hive.box(BNames.serverInstallationBox);
2021-03-25 20:09:56 +00:00
ServerHostingDetails? get serverDetails => _serverDetails;
String? get serverProviderKey => _serverProviderKey;
String? get serverLocation => _serverLocation;
String? get serverType => _serverType;
2021-03-25 20:09:56 +00:00
String? get cloudFlareKey => _cloudFlareKey;
ServerProvider? get serverProvider => _serverProvider;
2021-03-25 20:09:56 +00:00
BackblazeCredential? get backblazeCredential => _backblazeCredential;
ServerDomain? get serverDomain => _serverDomain;
2021-12-06 18:31:19 +00:00
BackblazeBucket? get backblazeBucket => _backblazeBucket;
2021-03-25 20:09:56 +00:00
String? _serverProviderKey;
String? _serverLocation;
2021-03-25 20:09:56 +00:00
String? _cloudFlareKey;
String? _serverType;
ServerProvider? _serverProvider;
ServerHostingDetails? _serverDetails;
2021-03-25 20:09:56 +00:00
BackblazeCredential? _backblazeCredential;
ServerDomain? _serverDomain;
2021-12-06 18:31:19 +00:00
BackblazeBucket? _backblazeBucket;
2021-03-25 20:09:56 +00:00
Future<void> storeServerProviderType(final ServerProvider value) async {
await _box.put(BNames.serverProvider, value);
_serverProvider = value;
}
Future<void> storeServerProviderKey(final String value) async {
2021-03-25 20:09:56 +00:00
await _box.put(BNames.hetznerKey, value);
_serverProviderKey = value;
2021-03-25 20:09:56 +00:00
}
2022-06-05 19:36:32 +00:00
Future<void> storeCloudFlareKey(final String value) async {
2021-03-25 20:09:56 +00:00
await _box.put(BNames.cloudFlareKey, value);
_cloudFlareKey = value;
}
Future<void> storeServerTypeIdentifier(final String typeIdentifier) async {
await _box.put(BNames.serverTypeIdentifier, typeIdentifier);
_serverType = typeIdentifier;
}
Future<void> storeServerLocation(final String serverLocation) async {
await _box.put(BNames.serverLocation, serverLocation);
_serverLocation = serverLocation;
}
2022-06-05 19:36:32 +00:00
Future<void> storeBackblazeCredential(final BackblazeCredential value) async {
await _box.put(BNames.backblazeCredential, value);
2021-03-25 20:09:56 +00:00
_backblazeCredential = value;
}
2022-06-05 19:36:32 +00:00
Future<void> storeServerDomain(final ServerDomain value) async {
await _box.put(BNames.serverDomain, value);
_serverDomain = value;
2021-03-25 20:09:56 +00:00
}
2022-06-05 19:36:32 +00:00
Future<void> storeServerDetails(final ServerHostingDetails value) async {
await _box.put(BNames.serverDetails, value);
_serverDetails = value;
2021-03-25 20:09:56 +00:00
}
2022-06-05 19:36:32 +00:00
Future<void> storeBackblazeBucket(final BackblazeBucket value) async {
2021-12-06 18:31:19 +00:00
await _box.put(BNames.backblazeBucket, value);
_backblazeBucket = value;
}
2022-06-05 19:36:32 +00:00
void clear() {
_serverProviderKey = null;
_serverLocation = null;
2021-03-25 20:09:56 +00:00
_cloudFlareKey = null;
_backblazeCredential = null;
_serverDomain = null;
_serverDetails = null;
2021-12-06 18:31:19 +00:00
_backblazeBucket = null;
_serverType = null;
2021-03-25 20:09:56 +00:00
}
void init() {
_serverProviderKey = _box.get(BNames.hetznerKey);
_serverLocation = _box.get(BNames.serverLocation);
2021-03-25 20:09:56 +00:00
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
_backblazeCredential = _box.get(BNames.backblazeCredential);
_serverDomain = _box.get(BNames.serverDomain);
_serverDetails = _box.get(BNames.serverDetails);
2021-12-06 18:31:19 +00:00
_backblazeBucket = _box.get(BNames.backblazeBucket);
_serverType = _box.get(BNames.serverTypeIdentifier);
2021-03-25 20:09:56 +00:00
}
}