mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
Merge pull request 'Fix installation Timer errors' (#105) from installation-timer into develop
Reviewed-on: https://git.selfprivacy.org/kherel/selfprivacy.org.app/pulls/105
This commit is contained in:
commit
dcf120bdbc
|
@ -284,7 +284,7 @@
|
|||
"22": "Create master account",
|
||||
"23": "Enter a nickname and strong password",
|
||||
"finish": "Everything is initialized",
|
||||
"checks": "Checks have been completed \n{} ouf of {}"
|
||||
"checks": "Checks have been completed \n{} out of {}"
|
||||
},
|
||||
"recovering": {
|
||||
"recovery_main_header": "Connect to an existing server",
|
||||
|
|
|
@ -46,7 +46,10 @@ class ServerApi extends ApiMap {
|
|||
|
||||
@override
|
||||
BaseOptions get options {
|
||||
BaseOptions options = BaseOptions();
|
||||
BaseOptions options = BaseOptions(
|
||||
connectTimeout: 10000,
|
||||
receiveTimeout: 10000,
|
||||
);
|
||||
|
||||
if (isWithToken) {
|
||||
final ServerDomain? cloudFlareDomain =
|
||||
|
@ -56,6 +59,8 @@ class ServerApi extends ApiMap {
|
|||
|
||||
options = BaseOptions(
|
||||
baseUrl: 'https://api.$domainName',
|
||||
connectTimeout: 10000,
|
||||
receiveTimeout: 10000,
|
||||
headers: {
|
||||
'Authorization': 'Bearer $apiToken',
|
||||
},
|
||||
|
@ -65,6 +70,8 @@ class ServerApi extends ApiMap {
|
|||
if (overrideDomain != null) {
|
||||
options = BaseOptions(
|
||||
baseUrl: 'https://api.$overrideDomain',
|
||||
connectTimeout: 10000,
|
||||
receiveTimeout: 10000,
|
||||
headers: customToken != null
|
||||
? {'Authorization': 'Bearer $customToken'}
|
||||
: null,
|
||||
|
@ -619,7 +626,7 @@ class ServerApi extends ApiMap {
|
|||
}
|
||||
}
|
||||
|
||||
Future<String?> getDkim() async {
|
||||
Future<String> getDkim() async {
|
||||
Response response;
|
||||
|
||||
final Dio client = await getClient();
|
||||
|
@ -627,13 +634,13 @@ class ServerApi extends ApiMap {
|
|||
response = await client.get('/services/mailserver/dkim');
|
||||
} on DioError catch (e) {
|
||||
print(e.message);
|
||||
return null;
|
||||
throw Exception('No DKIM key found');
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
if (response.statusCode == null) {
|
||||
return null;
|
||||
throw Exception('No DKIM key found');
|
||||
}
|
||||
|
||||
if (response.statusCode == HttpStatus.notFound || response.data == null) {
|
||||
|
@ -641,7 +648,7 @@ class ServerApi extends ApiMap {
|
|||
}
|
||||
|
||||
if (response.statusCode != HttpStatus.ok) {
|
||||
return '';
|
||||
throw Exception('No DKIM key found');
|
||||
}
|
||||
|
||||
final Codec<String, String> base64toString = utf8.fuse(base64);
|
||||
|
|
|
@ -271,10 +271,6 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
dataBase: newVolume,
|
||||
);
|
||||
|
||||
if (details == null) {
|
||||
deleteVolume(newVolume.id);
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
|
@ -320,6 +316,8 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
print('Decoded data: $data');
|
||||
|
||||
ServerHostingDetails? serverDetails;
|
||||
DioError? hetznerError;
|
||||
bool success = false;
|
||||
|
||||
try {
|
||||
final Response serverCreateResponse = await client.post(
|
||||
|
@ -335,16 +333,25 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
apiToken: apiToken,
|
||||
provider: ServerProvider.hetzner,
|
||||
);
|
||||
success = true;
|
||||
} on DioError catch (e) {
|
||||
print(e);
|
||||
deleteVolume(dataBase.id);
|
||||
rethrow;
|
||||
hetznerError = e;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
await deleteVolume(dbId);
|
||||
}
|
||||
|
||||
if (hetznerError != null) {
|
||||
throw hetznerError;
|
||||
}
|
||||
|
||||
return serverDetails;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,8 @@ class SshFormCubit extends FormCubit {
|
|||
@override
|
||||
FutureOr<void> onSubmit() {
|
||||
print(key.state.isValid);
|
||||
jobsCubit.addJob(CreateSSHKeyJob(user: user, publicKey: key.state.value));
|
||||
jobsCubit
|
||||
.addJob(CreateSSHKeyJob(user: user, publicKey: key.state.value.trim()));
|
||||
}
|
||||
|
||||
late FieldCubit<String> key;
|
||||
|
|
|
@ -195,24 +195,10 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
|
||||
if (matches.values.every((final bool value) => value)) {
|
||||
final ServerHostingDetails? server = await repository.startServer(
|
||||
final ServerHostingDetails server = await repository.startServer(
|
||||
dataState.serverDetails!,
|
||||
);
|
||||
|
||||
if (server == null) {
|
||||
final ServerInstallationNotFinished newState = dataState.copyWith(
|
||||
isLoading: false,
|
||||
dnsMatches: matches,
|
||||
);
|
||||
emit(newState);
|
||||
runDelayed(
|
||||
startServerIfDnsIsOkay,
|
||||
const Duration(seconds: 30),
|
||||
newState,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.saveServerDetails(server);
|
||||
await repository.saveIsServerStarted(true);
|
||||
|
||||
|
@ -338,10 +324,22 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
final bool isServerWorking = await repository.isHttpServerWorking();
|
||||
|
||||
if (isServerWorking) {
|
||||
await repository.createDkimRecord(dataState.serverDomain!);
|
||||
await repository.saveHasFinalChecked(true);
|
||||
|
||||
emit(dataState.finish());
|
||||
bool dkimCreated = true;
|
||||
try {
|
||||
await repository.createDkimRecord(dataState.serverDomain!);
|
||||
} catch (e) {
|
||||
dkimCreated = false;
|
||||
}
|
||||
if (dkimCreated) {
|
||||
await repository.saveHasFinalChecked(true);
|
||||
emit(dataState.finish());
|
||||
} else {
|
||||
runDelayed(
|
||||
finishCheckIfServerIsOkay,
|
||||
const Duration(seconds: 60),
|
||||
dataState,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
runDelayed(
|
||||
finishCheckIfServerIsOkay,
|
||||
|
|
|
@ -151,10 +151,10 @@ class ServerInstallationRepository {
|
|||
usersBox.clear();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails?> startServer(
|
||||
Future<ServerHostingDetails> startServer(
|
||||
final ServerHostingDetails hetznerServer,
|
||||
) async {
|
||||
ServerHostingDetails? serverDetails;
|
||||
ServerHostingDetails serverDetails;
|
||||
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
serverDetails = await api.powerOn();
|
||||
|
@ -359,20 +359,20 @@ class ServerInstallationRepository {
|
|||
dnsProviderApiFactory!.getDnsProvider();
|
||||
final ServerApi api = ServerApi();
|
||||
|
||||
final String? dkimRecordString = await api.getDkim();
|
||||
String dkimRecordString = '';
|
||||
try {
|
||||
dkimRecordString = await api.getDkim();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
rethrow;
|
||||
}
|
||||
|
||||
await dnsProviderApi.setDkim(dkimRecordString ?? '', cloudFlareDomain);
|
||||
await dnsProviderApi.setDkim(dkimRecordString, cloudFlareDomain);
|
||||
}
|
||||
|
||||
Future<bool> isHttpServerWorking() async {
|
||||
final ServerApi api = ServerApi();
|
||||
final bool isHttpServerWorking = await api.isHttpServerWorking();
|
||||
try {
|
||||
await api.getDkim();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return isHttpServerWorking;
|
||||
return api.isHttpServerWorking();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> restart() async {
|
||||
|
|
|
@ -35,11 +35,11 @@ abstract class ServerInstallationState extends Equatable {
|
|||
final bool isServerResetedFirstTime;
|
||||
final bool isServerResetedSecondTime;
|
||||
|
||||
bool get isProviderFilled => providerApiToken != null;
|
||||
bool get isCloudFlareFilled => cloudFlareKey != null;
|
||||
bool get isBackblazeFilled => backblazeCredential != null;
|
||||
bool get isDomainFilled => serverDomain != null;
|
||||
bool get isUserFilled => rootUser != null;
|
||||
bool get isServerProviderFilled => providerApiToken != null;
|
||||
bool get isDnsProviderFilled => cloudFlareKey != null;
|
||||
bool get isBackupsProviderFilled => backblazeCredential != null;
|
||||
bool get isDomainSelected => serverDomain != null;
|
||||
bool get isPrimaryUserFilled => rootUser != null;
|
||||
bool get isServerCreated => serverDetails != null;
|
||||
|
||||
bool get isFullyInitilized => _fulfilementList.every((final el) => el!);
|
||||
|
@ -58,11 +58,11 @@ abstract class ServerInstallationState extends Equatable {
|
|||
|
||||
List<bool?> get _fulfilementList {
|
||||
final List<bool> res = [
|
||||
isProviderFilled,
|
||||
isCloudFlareFilled,
|
||||
isBackblazeFilled,
|
||||
isDomainFilled,
|
||||
isUserFilled,
|
||||
isServerProviderFilled,
|
||||
isDnsProviderFilled,
|
||||
isBackupsProviderFilled,
|
||||
isDomainSelected,
|
||||
isPrimaryUserFilled,
|
||||
isServerCreated,
|
||||
isServerStarted,
|
||||
isServerResetedFirstTime,
|
||||
|
|
|
@ -104,7 +104,7 @@ class _Card extends StatelessWidget {
|
|||
context.watch<ServerInstallationCubit>().state;
|
||||
|
||||
final String domainName =
|
||||
appConfig.isDomainFilled ? appConfig.serverDomain!.domainName : '';
|
||||
appConfig.isDomainSelected ? appConfig.serverDomain!.domainName : '';
|
||||
|
||||
switch (provider.type) {
|
||||
case ProviderType.server:
|
||||
|
|
|
@ -42,7 +42,7 @@ class InitializingPage extends StatelessWidget {
|
|||
() => _stepCheck(cubit),
|
||||
() => _stepCheck(cubit),
|
||||
() => _stepCheck(cubit),
|
||||
() => Center(child: Text('initializing.finish'.tr()))
|
||||
() => _stepCheck(cubit)
|
||||
][cubit.state.progress.index]();
|
||||
|
||||
return BlocListener<ServerInstallationCubit, ServerInstallationState>(
|
||||
|
@ -60,7 +60,7 @@ class InitializingPage extends StatelessWidget {
|
|||
children: [
|
||||
Padding(
|
||||
padding: paddingH15V0.copyWith(top: 10, bottom: 10),
|
||||
child: cubit.state.isFullyInitilized
|
||||
child: cubit.state is ServerInstallationFinished
|
||||
? const SizedBox(
|
||||
height: 80,
|
||||
)
|
||||
|
|
|
@ -4,5 +4,5 @@ import 'package:selfprivacy/logic/cubit/server_installation/server_installation_
|
|||
|
||||
class UiHelpers {
|
||||
static String getDomainName(final ServerInstallationState config) =>
|
||||
config.isDomainFilled ? config.serverDomain!.domainName : 'example.com';
|
||||
config.isDomainSelected ? config.serverDomain!.domainName : 'example.com';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue