mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(digital-ocean): Change /locations to /regions and fix tokens validation
This commit is contained in:
parent
5ddbfcb342
commit
a69b096d6f
|
@ -195,7 +195,9 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
|
||||
@override
|
||||
Future<bool> attachVolume(
|
||||
final ServerVolume volume, final int serverId) async {
|
||||
final ServerVolume volume,
|
||||
final int serverId,
|
||||
) async {
|
||||
bool success = false;
|
||||
|
||||
final Response dbPostResponse;
|
||||
|
@ -518,10 +520,10 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get(
|
||||
'/locations',
|
||||
'/regions',
|
||||
);
|
||||
|
||||
locations = response.data!['locations'].map<ServerProviderLocation>(
|
||||
locations = response.data!['regions'].map<ServerProviderLocation>(
|
||||
(final location) => ServerProviderLocation(
|
||||
title: location['slug'],
|
||||
description: location['name'],
|
||||
|
@ -586,4 +588,11 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
}) async {
|
||||
/// TODO remove from provider interface
|
||||
}
|
||||
|
||||
@override
|
||||
ProviderApiTokenValidation getApiTokenValidation() =>
|
||||
ProviderApiTokenValidation(
|
||||
regexp: RegExp(r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]'),
|
||||
length: 71,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -81,8 +81,11 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
RegExp getApiTokenValidation() =>
|
||||
RegExp(r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||
ProviderApiTokenValidation getApiTokenValidation() =>
|
||||
ProviderApiTokenValidation(
|
||||
regexp: RegExp(r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]'),
|
||||
length: 64,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Price?> getPricePerGb() async {
|
||||
|
|
|
@ -6,6 +6,15 @@ import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
|||
import 'package:selfprivacy/logic/models/server_provider_location.dart';
|
||||
import 'package:selfprivacy/logic/models/server_type.dart';
|
||||
|
||||
class ProviderApiTokenValidation {
|
||||
ProviderApiTokenValidation({
|
||||
required this.length,
|
||||
required this.regexp,
|
||||
});
|
||||
final int length;
|
||||
final RegExp regexp;
|
||||
}
|
||||
|
||||
abstract class ServerProviderApi extends ApiMap {
|
||||
Future<List<ServerBasicInfo>> getServers();
|
||||
Future<List<ServerProviderLocation>> getAvailableLocations();
|
||||
|
@ -29,7 +38,5 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
});
|
||||
|
||||
Future<bool> isApiTokenValid(final String token);
|
||||
RegExp getApiTokenValidation() => RegExp(
|
||||
r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]',
|
||||
);
|
||||
ProviderApiTokenValidation getApiTokenValidation();
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
|||
|
||||
class ProviderFormCubit extends FormCubit {
|
||||
ProviderFormCubit(this.serverInstallationCubit) {
|
||||
//final int tokenLength =
|
||||
// serverInstallationCubit.serverProviderApiTokenValidation().length;
|
||||
apiKey = FieldCubit(
|
||||
initalValue: '',
|
||||
validations: [
|
||||
RequiredStringValidation('validations.required'.tr()),
|
||||
LengthStringNotEqualValidation(64)
|
||||
//LengthStringNotEqualValidation(tokenLength),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
@ -65,7 +66,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
}
|
||||
|
||||
RegExp getServerProviderApiTokenValidation() =>
|
||||
ProviderApiTokenValidation serverProviderApiTokenValidation() =>
|
||||
repository.serverProviderApiFactory!
|
||||
.getServerProvider()
|
||||
.getApiTokenValidation();
|
||||
|
|
Loading…
Reference in a new issue