consolidate common process into resolveAndSetEndpoint

This commit is contained in:
Connery Noble
2023-01-14 16:41:10 -08:00
parent a485bb2010
commit 7a23c58be2
6 changed files with 34 additions and 21 deletions
@@ -357,7 +357,6 @@ class BackgroundService {
Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox),
]);
ApiService apiService = ApiService();
apiService.setEndpoint(Hive.box(userInfoBox).get(serverEndpointKey));
apiService.setAccessToken(Hive.box(userInfoBox).get(accessTokenKey));
BackupService backupService = BackupService(apiService);
AppSettingsService settingsService = AppSettingsService();
@@ -59,10 +59,8 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
) async {
try {
// Resolve API server endpoint from user provided serverUrl
final serverEndpoint = await _apiService.resolveEndpoint(serverUrl);
_apiService.setEndpoint(serverEndpoint);
await _apiService.resolveAndSetEndpoint(serverUrl);
await _apiService.serverInfoApi.pingServer();
Hive.box(userInfoBox).put(serverEndpointKey, serverEndpoint);
} catch (e) {
debugPrint('Invalid Server Endpoint Url $e');
return false;
@@ -14,8 +14,7 @@ class OAuthService {
String serverUrl,
) async {
// Resolve API server endpoint from user provided serverUrl
final serverEndpoint = await _apiService.resolveEndpoint(serverUrl);
_apiService.setEndpoint(serverEndpoint);
await _apiService.resolveAndSetEndpoint(serverUrl);
return await _apiService.oAuthApi.generateConfig(
OAuthConfigDto(redirectUri: '$callbackUrlScheme:/'),
+6 -8
View File
@@ -42,9 +42,7 @@ class LoginForm extends HookConsumerWidget {
if (serverUrl.isNotEmpty) {
isLoading.value = true;
final serverEndpoint =
await apiService.resolveEndpoint(serverUrl.toString());
apiService.setEndpoint(serverEndpoint);
Hive.box(userInfoBox).put(serverEndpointKey, serverEndpoint);
await apiService.resolveAndSetEndpoint(serverUrl.toString());
var loginConfig = await apiService.oAuthApi.generateConfig(
OAuthConfigDto(redirectUri: serverEndpoint),
@@ -218,11 +216,11 @@ class ServerEndpointInput extends StatelessWidget {
String? _validateInput(String? url) {
if (url == null || url.isEmpty) return null;
final validate = Uri.tryParse(sanitizeUrl(url));
if (validate == null ||
!validate.isAbsolute ||
!validate.scheme.startsWith("http") ||
validate.host.isEmpty) {
final parsedUrl = Uri.tryParse(sanitizeUrl(url));
if (parsedUrl == null ||
!parsedUrl.isAbsolute ||
!parsedUrl.scheme.startsWith("http") ||
parsedUrl.host.isEmpty) {
return 'login_form_err_invalid_url'.tr();
}
return null;