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';
|
|
|
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
|
|
|
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;
|
2021-03-25 20:09:56 +00:00
|
|
|
String? get hetznerKey => _hetznerKey;
|
|
|
|
String? get cloudFlareKey => _cloudFlareKey;
|
|
|
|
BackblazeCredential? 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
|
|
|
|
|
|
|
String? _hetznerKey;
|
|
|
|
String? _cloudFlareKey;
|
2022-05-13 13:57:56 +00:00
|
|
|
ServerHostingDetails? _serverDetails;
|
2021-03-25 20:09:56 +00:00
|
|
|
BackblazeCredential? _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
|
|
|
|
|
|
|
Future<void> storeHetznerKey(String value) async {
|
|
|
|
await _box.put(BNames.hetznerKey, value);
|
|
|
|
_hetznerKey = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> storeCloudFlareKey(String value) async {
|
|
|
|
await _box.put(BNames.cloudFlareKey, value);
|
|
|
|
_cloudFlareKey = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> storeBackblazeCredential(BackblazeCredential 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;
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:57:56 +00:00
|
|
|
Future<void> storeServerDomain(ServerDomain value) async {
|
|
|
|
await _box.put(BNames.serverDomain, value);
|
|
|
|
_serverDomain = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 13:57:56 +00:00
|
|
|
Future<void> storeServerDetails(ServerHostingDetails value) async {
|
|
|
|
await _box.put(BNames.serverDetails, value);
|
|
|
|
_serverDetails = value;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:31:19 +00:00
|
|
|
Future<void> storeBackblazeBucket(BackblazeBucket value) async {
|
|
|
|
await _box.put(BNames.backblazeBucket, value);
|
|
|
|
_backblazeBucket = value;
|
|
|
|
}
|
|
|
|
|
2021-03-25 20:09:56 +00:00
|
|
|
clear() {
|
|
|
|
_hetznerKey = null;
|
|
|
|
_cloudFlareKey = null;
|
|
|
|
_backblazeCredential = null;
|
2022-05-13 13:57:56 +00:00
|
|
|
_serverDomain = null;
|
|
|
|
_serverDetails = null;
|
2021-12-06 18:31:19 +00:00
|
|
|
_backblazeBucket = null;
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
_hetznerKey = _box.get(BNames.hetznerKey);
|
2021-10-13 21:49:24 +00:00
|
|
|
|
2021-03-25 20:09:56 +00:00
|
|
|
_cloudFlareKey = _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);
|
2021-03-25 20:09:56 +00:00
|
|
|
}
|
|
|
|
}
|