mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 11:16:45 +00:00
update
This commit is contained in:
parent
aabad65698
commit
29b08b111a
|
@ -144,28 +144,24 @@ class HetznerApi extends ApiMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> startServer({
|
Future<HetznerServerDetails> reset() async {
|
||||||
required HetznerServerDetails server,
|
var server = getIt<ApiConfigModel>().hetznerServer!;
|
||||||
}) async {
|
|
||||||
var client = await getClient();
|
|
||||||
|
|
||||||
await client.post('/servers/${server.id}/actions/poweron');
|
var client = await getClient();
|
||||||
|
await client.post('/servers/${server.id}/actions/reset');
|
||||||
close(client);
|
close(client);
|
||||||
|
|
||||||
return server.copyWith(
|
return server.copyWith(startTime: DateTime.now());
|
||||||
startTime: DateTime.now(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> restart({
|
Future<HetznerServerDetails> powerOn() async {
|
||||||
required HetznerServerDetails server,
|
var server = getIt<ApiConfigModel>().hetznerServer!;
|
||||||
}) async {
|
|
||||||
var client = await getClient();
|
var client = await getClient();
|
||||||
await client.post('/servers/${server.id}/actions/poweron');
|
await client.post('/servers/${server.id}/actions/poweron');
|
||||||
close(client);
|
close(client);
|
||||||
return server.copyWith(
|
|
||||||
startTime: DateTime.now(),
|
return server.copyWith(startTime: DateTime.now());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics() async {
|
metrics() async {
|
||||||
|
|
|
@ -47,8 +47,8 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
|
|
||||||
final repository = AppConfigRepository();
|
final repository = AppConfigRepository();
|
||||||
|
|
||||||
void load() {
|
Future<void> load() async {
|
||||||
var state = repository.load();
|
var state = await repository.load();
|
||||||
|
|
||||||
if (state.progress < 6 || state.isFullyInitilized) {
|
if (state.progress < 6 || state.isFullyInitilized) {
|
||||||
emit(state);
|
emit(state);
|
||||||
|
@ -81,8 +81,8 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
var server = await repository.startServer(
|
var server = await repository.startServer(
|
||||||
state.hetznerServer!,
|
state.hetznerServer!,
|
||||||
);
|
);
|
||||||
repository.saveServerDetails(server);
|
await repository.saveServerDetails(server);
|
||||||
repository.saveIsServerStarted(true);
|
await repository.saveIsServerStarted(true);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
|
@ -131,11 +131,9 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
duration: pauseDuration,
|
duration: pauseDuration,
|
||||||
));
|
));
|
||||||
timer = Timer(pauseDuration, () async {
|
timer = Timer(pauseDuration, () async {
|
||||||
var hetznerServerDetails = await repository.restart(
|
var hetznerServerDetails = await repository.restart();
|
||||||
dataState.hetznerServer!,
|
await repository.saveIsServerResetedSecondTime(true);
|
||||||
);
|
await repository.saveServerDetails(hetznerServerDetails);
|
||||||
repository.saveIsServerResetedSecondTime(true);
|
|
||||||
repository.saveServerDetails(hetznerServerDetails);
|
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
dataState.copyWith(
|
dataState.copyWith(
|
||||||
|
@ -186,11 +184,9 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
duration: pauseDuration,
|
duration: pauseDuration,
|
||||||
));
|
));
|
||||||
timer = Timer(pauseDuration, () async {
|
timer = Timer(pauseDuration, () async {
|
||||||
var hetznerServerDetails = await repository.restart(
|
var hetznerServerDetails = await repository.restart();
|
||||||
dataState.hetznerServer!,
|
await repository.saveIsServerResetedFirstTime(true);
|
||||||
);
|
await repository.saveServerDetails(hetznerServerDetails);
|
||||||
repository.saveIsServerResetedFirstTime(true);
|
|
||||||
repository.saveServerDetails(hetznerServerDetails);
|
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
dataState.copyWith(
|
dataState.copyWith(
|
||||||
|
@ -235,7 +231,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
var isServerWorking = await repository.isHttpServerWorking();
|
var isServerWorking = await repository.isHttpServerWorking();
|
||||||
|
|
||||||
if (isServerWorking) {
|
if (isServerWorking) {
|
||||||
repository.saveHasFinalChecked(true);
|
await repository.saveHasFinalChecked(true);
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
hasFinalChecked: true,
|
hasFinalChecked: true,
|
||||||
|
@ -267,32 +263,32 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
emit(InitialAppConfigState());
|
emit(InitialAppConfigState());
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHetznerKey(String hetznerKey) {
|
void setHetznerKey(String hetznerKey) async {
|
||||||
repository.saveHetznerKey(hetznerKey);
|
await repository.saveHetznerKey(hetznerKey);
|
||||||
emit(state.copyWith(hetznerKey: hetznerKey));
|
emit(state.copyWith(hetznerKey: hetznerKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCloudflareKey(String cloudFlareKey) {
|
void setCloudflareKey(String cloudFlareKey) async {
|
||||||
repository.saveCloudFlareKey(cloudFlareKey);
|
await repository.saveCloudFlareKey(cloudFlareKey);
|
||||||
emit(state.copyWith(cloudFlareKey: cloudFlareKey));
|
emit(state.copyWith(cloudFlareKey: cloudFlareKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackblazeKey(String keyId, String applicationKey) {
|
void setBackblazeKey(String keyId, String applicationKey) async {
|
||||||
var backblazeCredential = BackblazeCredential(
|
var backblazeCredential = BackblazeCredential(
|
||||||
keyId: keyId,
|
keyId: keyId,
|
||||||
applicationKey: applicationKey,
|
applicationKey: applicationKey,
|
||||||
);
|
);
|
||||||
repository.saveBackblazeKey(backblazeCredential);
|
await repository.saveBackblazeKey(backblazeCredential);
|
||||||
emit(state.copyWith(backblazeCredential: backblazeCredential));
|
emit(state.copyWith(backblazeCredential: backblazeCredential));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDomain(CloudFlareDomain cloudFlareDomain) {
|
void setDomain(CloudFlareDomain cloudFlareDomain) async {
|
||||||
repository.saveDomain(cloudFlareDomain);
|
await repository.saveDomain(cloudFlareDomain);
|
||||||
emit(state.copyWith(cloudFlareDomain: cloudFlareDomain));
|
emit(state.copyWith(cloudFlareDomain: cloudFlareDomain));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRootUser(User rootUser) {
|
void setRootUser(User rootUser) async {
|
||||||
repository.saveRootUser(rootUser);
|
await repository.saveRootUser(rootUser);
|
||||||
emit(state.copyWith(rootUser: rootUser));
|
emit(state.copyWith(rootUser: rootUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
class AppConfigRepository {
|
class AppConfigRepository {
|
||||||
Box box = Hive.box(BNames.appConfig);
|
Box box = Hive.box(BNames.appConfig);
|
||||||
|
|
||||||
AppConfigState load() {
|
Future<AppConfigState> load() async {
|
||||||
var res = AppConfigState(
|
var res = AppConfigState(
|
||||||
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
|
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
|
||||||
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
|
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
|
||||||
|
@ -39,8 +39,6 @@ class AppConfigRepository {
|
||||||
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
isLoading: box.get(BNames.isLoading, defaultValue: false),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +50,7 @@ class AppConfigRepository {
|
||||||
HetznerServerDetails hetznerServer,
|
HetznerServerDetails hetznerServer,
|
||||||
) async {
|
) async {
|
||||||
var hetznerApi = HetznerApi();
|
var hetznerApi = HetznerApi();
|
||||||
var serverDetails = await hetznerApi.startServer(server: hetznerServer);
|
var serverDetails = await hetznerApi.powerOn();
|
||||||
|
|
||||||
return serverDetails;
|
return serverDetails;
|
||||||
}
|
}
|
||||||
|
@ -173,11 +171,14 @@ class AppConfigRepository {
|
||||||
return isHttpServerWorking;
|
return isHttpServerWorking;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HetznerServerDetails> restart(
|
Future<HetznerServerDetails> restart() async {
|
||||||
HetznerServerDetails server,
|
|
||||||
) async {
|
|
||||||
var hetznerApi = HetznerApi();
|
var hetznerApi = HetznerApi();
|
||||||
return await hetznerApi.restart(server: server);
|
return await hetznerApi.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<HetznerServerDetails> powerOn() async {
|
||||||
|
var hetznerApi = HetznerApi();
|
||||||
|
return await hetznerApi.powerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
|
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
|
||||||
|
@ -212,11 +213,11 @@ class AppConfigRepository {
|
||||||
await box.put(BNames.isServerResetedSecondTime, value);
|
await box.put(BNames.isServerResetedSecondTime, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveRootUser(User rootUser) async {
|
Future<void> saveRootUser(User rootUser) async {
|
||||||
await box.put(BNames.rootUser, rootUser);
|
await box.put(BNames.rootUser, rootUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveHasFinalChecked(bool value) async {
|
Future<void> saveHasFinalChecked(bool value) async {
|
||||||
await box.put(BNames.hasFinalChecked, value);
|
await box.put(BNames.hasFinalChecked, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue