mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-28 19:56:50 +00:00
before change api_client
This commit is contained in:
parent
7d12b85f89
commit
20cca91e00
|
@ -1,4 +1,5 @@
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
|
import 'package:selfprivacy/logic/get_it/api_config.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/console.dart';
|
import 'package:selfprivacy/logic/get_it/console.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/navigation.dart';
|
import 'package:selfprivacy/logic/get_it/navigation.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/timer.dart';
|
import 'package:selfprivacy/logic/get_it/timer.dart';
|
||||||
|
@ -9,9 +10,12 @@ export 'package:selfprivacy/logic/get_it/timer.dart';
|
||||||
|
|
||||||
final getIt = GetIt.instance;
|
final getIt = GetIt.instance;
|
||||||
|
|
||||||
void getItSetup() {
|
Future<void> getItSetup() async {
|
||||||
getIt.registerSingleton<NavigationService>(NavigationService());
|
getIt.registerSingleton<NavigationService>(NavigationService());
|
||||||
|
|
||||||
getIt.registerSingleton<ConsoleModel>(ConsoleModel());
|
getIt.registerSingleton<ConsoleModel>(ConsoleModel());
|
||||||
getIt.registerSingleton<TimerModel>(TimerModel());
|
getIt.registerSingleton<TimerModel>(TimerModel());
|
||||||
|
getIt.registerSingleton<ApiConfigModel>(ApiConfigModel()..init());
|
||||||
|
|
||||||
|
await getIt.allReady();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/console.dart';
|
import 'package:selfprivacy/logic/get_it/console.dart';
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
|
|
||||||
abstract class ApiMap {
|
abstract class ApiMapOld {
|
||||||
ApiMap() {
|
ApiMapOld() {
|
||||||
var client = Dio()..interceptors.add(ConsoleInterceptor());
|
var client = Dio()..interceptors.add(ConsoleInterceptor());
|
||||||
(client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
(client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
(HttpClient client) {
|
(HttpClient client) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
|
|
||||||
class BackblazeApi extends ApiMap {
|
class BackblazeApi extends ApiMapOld {
|
||||||
BackblazeApi([String? token]) {
|
BackblazeApi([String? token]) {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
loggedClient.options = BaseOptions(
|
loggedClient.options = BaseOptions(
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/dns_records.dart';
|
import 'package:selfprivacy/logic/models/dns_records.dart';
|
||||||
|
|
||||||
class CloudflareApi extends ApiMap {
|
class CloudflareApi extends ApiMapOld {
|
||||||
CloudflareApi([String? token]) {
|
CloudflareApi([String? token]) {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
loggedClient.options =
|
loggedClient.options =
|
||||||
|
|
|
@ -7,7 +7,7 @@ import 'package:selfprivacy/logic/models/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator2.dart';
|
import 'package:selfprivacy/utils/password_generator2.dart';
|
||||||
|
|
||||||
class HetznerApi extends ApiMap {
|
class HetznerApi extends ApiMapOld {
|
||||||
HetznerApi([String? token]) {
|
HetznerApi([String? token]) {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
loggedClient.options = BaseOptions(
|
loggedClient.options = BaseOptions(
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:dio/dio.dart';
|
||||||
|
|
||||||
import 'api_map.dart';
|
import 'api_map.dart';
|
||||||
|
|
||||||
class ServerApi extends ApiMap {
|
class ServerApi extends ApiMapOld {
|
||||||
ServerApi(String? domainName) {
|
ServerApi(String? domainName) {
|
||||||
loggedClient.options = BaseOptions(
|
loggedClient.options = BaseOptions(
|
||||||
baseUrl: 'https://api.$domainName',
|
baseUrl: 'https://api.$domainName',
|
||||||
|
|
|
@ -219,7 +219,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCloudflareKey(String cloudFlareKey) {
|
void setCloudflareKey(String cloudFlareKey) {
|
||||||
repository.saveCloudFlare(cloudFlareKey);
|
repository.saveCloudFlareKey(cloudFlareKey);
|
||||||
emit(state.copyWith(cloudFlareKey: cloudFlareKey));
|
emit(state.copyWith(cloudFlareKey: cloudFlareKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
|
import 'package:selfprivacy/logic/get_it/api_config.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/server_details.dart';
|
||||||
|
@ -22,12 +23,12 @@ class AppConfigRepository {
|
||||||
|
|
||||||
AppConfigState load() {
|
AppConfigState load() {
|
||||||
return AppConfigState(
|
return AppConfigState(
|
||||||
hetznerKey: box.get(BNames.hetznerKey),
|
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
|
||||||
cloudFlareKey: box.get(BNames.cloudFlareKey),
|
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
|
||||||
cloudFlareDomain: box.get(BNames.cloudFlareDomain),
|
cloudFlareDomain: getIt<ApiConfigModel>().cloudFlareDomain,
|
||||||
backblazeCredential: box.get(BNames.backblazeKey),
|
backblazeCredential: getIt<ApiConfigModel>().backblazeCredential,
|
||||||
|
hetznerServer: getIt<ApiConfigModel>().hetznerServer,
|
||||||
rootUser: box.get(BNames.rootUser),
|
rootUser: box.get(BNames.rootUser),
|
||||||
hetznerServer: box.get(BNames.hetznerServer),
|
|
||||||
isServerStarted: box.get(BNames.isServerStarted, defaultValue: false),
|
isServerStarted: box.get(BNames.isServerStarted, defaultValue: false),
|
||||||
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
|
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
|
||||||
hasFinalChecked: box.get(BNames.hasFinalChecked, defaultValue: false),
|
hasFinalChecked: box.get(BNames.hasFinalChecked, defaultValue: false),
|
||||||
|
@ -185,33 +186,33 @@ class AppConfigRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
|
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
|
||||||
await box.put(BNames.hetznerServer, serverDetails);
|
await getIt<ApiConfigModel>().storeServerDetails(serverDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveHetznerKey(String key) async {
|
||||||
|
await getIt<ApiConfigModel>().storeHetznerKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveBackblazeKey(BackblazeCredential backblazeCredential) async {
|
||||||
|
await getIt<ApiConfigModel>().storeBackblazeCredential(backblazeCredential);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveCloudFlareKey(String key) async {
|
||||||
|
await getIt<ApiConfigModel>().storeCloudFlareKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveDomain(CloudFlareDomain cloudFlareDomain) async {
|
||||||
|
await getIt<ApiConfigModel>().storeCloudFlareDomain(cloudFlareDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveIsServerStarted(bool value) async {
|
Future<void> saveIsServerStarted(bool value) async {
|
||||||
await box.put(BNames.isServerStarted, value);
|
await box.put(BNames.isServerStarted, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveHetznerKey(String key) async {
|
|
||||||
await box.put(BNames.hetznerKey, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> saveIsServerReseted(bool value) async {
|
Future<void> saveIsServerReseted(bool value) async {
|
||||||
await box.put(BNames.isServerReseted, value);
|
await box.put(BNames.isServerReseted, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveBackblazeKey(BackblazeCredential backblazeCredential) async {
|
|
||||||
await box.put(BNames.backblazeKey, backblazeCredential);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> saveCloudFlare(String key) async {
|
|
||||||
await box.put(BNames.cloudFlareKey, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveDomain(CloudFlareDomain cloudFlareDomain) async {
|
|
||||||
await box.put(BNames.cloudFlareDomain, cloudFlareDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveRootUser(User rootUser) async {
|
void saveRootUser(User rootUser) async {
|
||||||
await box.put(BNames.rootUser, rootUser);
|
await box.put(BNames.rootUser, rootUser);
|
||||||
}
|
}
|
||||||
|
|
63
lib/logic/get_it/api_config.dart
Normal file
63
lib/logic/get_it/api_config.dart
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/server_details.dart';
|
||||||
|
|
||||||
|
class ApiConfigModel {
|
||||||
|
Box _box = Hive.box(BNames.appConfig);
|
||||||
|
|
||||||
|
HetznerServerDetails? get hetznerServer => _hetznerServer;
|
||||||
|
String? get hetznerKey => _hetznerKey;
|
||||||
|
String? get cloudFlareKey => _cloudFlareKey;
|
||||||
|
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||||
|
CloudFlareDomain? get cloudFlareDomain => _cloudFlareDomain;
|
||||||
|
|
||||||
|
String? _hetznerKey;
|
||||||
|
String? _cloudFlareKey;
|
||||||
|
HetznerServerDetails? _hetznerServer;
|
||||||
|
BackblazeCredential? _backblazeCredential;
|
||||||
|
CloudFlareDomain? _cloudFlareDomain;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
await _box.put(BNames.backblazeKey, value);
|
||||||
|
|
||||||
|
_backblazeCredential = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> storeCloudFlareDomain(CloudFlareDomain value) async {
|
||||||
|
await _box.put(BNames.cloudFlareDomain, value);
|
||||||
|
_cloudFlareDomain = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> storeServerDetails(HetznerServerDetails value) async {
|
||||||
|
await _box.put(BNames.hetznerServer, value);
|
||||||
|
_hetznerServer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
_hetznerKey = null;
|
||||||
|
_cloudFlareKey = null;
|
||||||
|
_backblazeCredential = null;
|
||||||
|
_cloudFlareDomain = null;
|
||||||
|
_hetznerServer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
_hetznerKey = _box.get(BNames.hetznerKey);
|
||||||
|
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
|
||||||
|
_backblazeCredential = _box.get(BNames.backblazeKey);
|
||||||
|
_cloudFlareDomain = _box.get(BNames.cloudFlareDomain);
|
||||||
|
_hetznerServer = _box.get(BNames.hetznerServer);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,12 +15,11 @@ import 'config/get_it_config.dart';
|
||||||
import 'config/localization.dart';
|
import 'config/localization.dart';
|
||||||
import 'logic/cubit/app_settings/app_settings_cubit.dart';
|
import 'logic/cubit/app_settings/app_settings_cubit.dart';
|
||||||
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
await HiveConfig.init();
|
await HiveConfig.init();
|
||||||
Bloc.observer = SimpleBlocObserver();
|
Bloc.observer = SimpleBlocObserver();
|
||||||
Wakelock.enable();
|
Wakelock.enable();
|
||||||
getItSetup();
|
await getItSetup();
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await EasyLocalization.ensureInitialized();
|
await EasyLocalization.ensureInitialized();
|
||||||
|
|
||||||
|
|
|
@ -378,6 +378,21 @@ class _ServiceDetails extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _launchURL(url) async =>
|
void _launchURL(url) async {
|
||||||
await canLaunch(url) ? await launch(url) : throw 'Could not launch $url';
|
var _possible = await canLaunch(url);
|
||||||
|
|
||||||
|
if (_possible) {
|
||||||
|
try {
|
||||||
|
await launch(
|
||||||
|
url,
|
||||||
|
forceSafariVC: true,
|
||||||
|
enableJavaScript: true,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw 'Could not launch $url';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue