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