2021-03-25 20:09:56 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:selfprivacy/config/hive_config.dart';
|
2022-05-14 02:54:40 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
2023-06-16 01:28:45 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/backups_credential.dart';
|
2022-05-14 02:54:40 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
2022-05-18 08:27:36 +00:00
|
|
|
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
|
|
|
|
2022-05-13 13:57:56 +00:00
|
|
|
ServerHostingDetails? get serverDetails => _serverDetails;
|
2023-07-22 14:15:43 +00:00
|
|
|
String? get localeCode => _localeCode;
|
2022-10-11 20:11:13 +00:00
|
|
|
String? get serverProviderKey => _serverProviderKey;
|
2022-10-16 00:51:10 +00:00
|
|
|
String? get serverLocation => _serverLocation;
|
2022-10-15 21:51:37 +00:00
|
|
|
String? get serverType => _serverType;
|
2023-05-12 19:32:19 +00:00
|
|
|
String? get dnsProviderKey => _dnsProviderKey;
|
2023-01-30 15:44:52 +00:00
|
|
|
ServerProviderType? get serverProvider => _serverProvider;
|
|
|
|
DnsProviderType? get dnsProvider => _dnsProvider;
|
2023-05-09 06:15:48 +00:00
|
|
|
|
2023-06-16 01:28:45 +00:00
|
|
|
BackupsCredential? get backblazeCredential => _backblazeCredential;
|
2022-05-13 13:57:56 +00:00
|
|
|
ServerDomain? get serverDomain => _serverDomain;
|
2021-12-06 18:31:19 +00:00
|
|
|
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
2021-03-25 20:09:56 +00:00
|
|
|
|
2023-07-22 14:15:43 +00:00
|
|
|
String? _localeCode;
|
2022-10-11 20:11:13 +00:00
|
|
|
String? _serverProviderKey;
|
2022-10-16 00:51:10 +00:00
|
|
|
String? _serverLocation;
|
2023-05-12 19:32:19 +00:00
|
|
|
String? _dnsProviderKey;
|
2022-10-15 21:51:37 +00:00
|
|
|
String? _serverType;
|
2023-01-30 15:44:52 +00:00
|
|
|
ServerProviderType? _serverProvider;
|
|
|
|
DnsProviderType? _dnsProvider;
|
2022-05-13 13:57:56 +00:00
|
|
|
ServerHostingDetails? _serverDetails;
|
2023-06-16 01:28:45 +00:00
|
|
|
BackupsCredential? _backblazeCredential;
|
2022-05-13 13:57:56 +00:00
|
|
|
ServerDomain? _serverDomain;
|
2021-12-06 18:31:19 +00:00
|
|
|
BackblazeBucket? _backblazeBucket;
|
2021-03-25 20:09:56 +00:00
|
|
|
|
2023-07-22 14:15:43 +00:00
|
|
|
Future<void> setLocaleCode(final String value) async {
|
|
|
|
_localeCode = value;
|
|
|
|
}
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
2022-10-20 14:36:15 +00:00
|
|
|
await _box.put(BNames.serverProvider, value);
|
|
|
|
_serverProvider = value;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setDnsProviderType(final DnsProviderType value) async {
|
2023-05-09 06:15:48 +00:00
|
|
|
await _box.put(BNames.dnsProvider, value);
|
|
|
|
_dnsProvider = value;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setServerProviderKey(final String value) async {
|
2021-03-25 20:09:56 +00:00
|
|
|
await _box.put(BNames.hetznerKey, value);
|
2022-10-11 20:11:13 +00:00
|
|
|
_serverProviderKey = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setDnsProviderKey(final String value) async {
|
2021-03-25 20:09:56 +00:00
|
|
|
await _box.put(BNames.cloudFlareKey, value);
|
2023-05-12 19:32:19 +00:00
|
|
|
_dnsProviderKey = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setServerTypeIdentifier(final String typeIdentifier) async {
|
2022-10-15 21:51:37 +00:00
|
|
|
await _box.put(BNames.serverTypeIdentifier, typeIdentifier);
|
|
|
|
_serverType = typeIdentifier;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setServerLocation(final String serverLocation) async {
|
2022-10-16 00:51:10 +00:00
|
|
|
await _box.put(BNames.serverLocation, serverLocation);
|
|
|
|
_serverLocation = serverLocation;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setBackblazeCredential(final BackupsCredential value) async {
|
2022-05-17 20:08:28 +00:00
|
|
|
await _box.put(BNames.backblazeCredential, value);
|
2021-03-25 20:09:56 +00:00
|
|
|
_backblazeCredential = value;
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setServerDomain(final ServerDomain value) async {
|
2022-05-13 13:57:56 +00:00
|
|
|
await _box.put(BNames.serverDomain, value);
|
|
|
|
_serverDomain = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setServerDetails(final ServerHostingDetails value) async {
|
2022-05-13 13:57:56 +00:00
|
|
|
await _box.put(BNames.serverDetails, value);
|
|
|
|
_serverDetails = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:09 +00:00
|
|
|
Future<void> setBackblazeBucket(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() {
|
2023-07-22 14:15:43 +00:00
|
|
|
_localeCode = null;
|
2022-10-11 20:11:13 +00:00
|
|
|
_serverProviderKey = null;
|
2023-05-09 06:15:48 +00:00
|
|
|
_dnsProvider = null;
|
2022-10-16 00:51:10 +00:00
|
|
|
_serverLocation = null;
|
2023-05-12 19:32:19 +00:00
|
|
|
_dnsProviderKey = null;
|
2021-03-25 20:09:56 +00:00
|
|
|
_backblazeCredential = null;
|
2022-05-13 13:57:56 +00:00
|
|
|
_serverDomain = null;
|
|
|
|
_serverDetails = null;
|
2021-12-06 18:31:19 +00:00
|
|
|
_backblazeBucket = null;
|
2022-10-16 00:51:10 +00:00
|
|
|
_serverType = null;
|
2022-10-21 04:34:36 +00:00
|
|
|
_serverProvider = null;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
2023-07-22 14:15:43 +00:00
|
|
|
_localeCode = 'en';
|
2022-10-11 20:11:13 +00:00
|
|
|
_serverProviderKey = _box.get(BNames.hetznerKey);
|
2022-10-16 00:51:10 +00:00
|
|
|
_serverLocation = _box.get(BNames.serverLocation);
|
2023-05-12 19:32:19 +00:00
|
|
|
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
2022-05-17 20:08:28 +00:00
|
|
|
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
2022-05-13 13:57:56 +00:00
|
|
|
_serverDomain = _box.get(BNames.serverDomain);
|
|
|
|
_serverDetails = _box.get(BNames.serverDetails);
|
2021-12-06 18:31:19 +00:00
|
|
|
_backblazeBucket = _box.get(BNames.backblazeBucket);
|
2022-10-16 00:51:10 +00:00
|
|
|
_serverType = _box.get(BNames.serverTypeIdentifier);
|
2022-10-21 04:34:36 +00:00
|
|
|
_serverProvider = _box.get(BNames.serverProvider);
|
2023-05-09 06:15:48 +00:00
|
|
|
_dnsProvider = _box.get(BNames.dnsProvider);
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
}
|