From 3ce83792f569dbc784d4a858e08ce21b594b0297 Mon Sep 17 00:00:00 2001 From: Connery Noble Date: Thu, 12 Jan 2023 15:35:54 -0800 Subject: [PATCH] fix casting issue with resovled url --- mobile/lib/modules/login/ui/login_form.dart | 2 +- mobile/lib/shared/services/api.service.dart | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart index 69202ac7e2..2d49e9fa5a 100644 --- a/mobile/lib/modules/login/ui/login_form.dart +++ b/mobile/lib/modules/login/ui/login_form.dart @@ -25,7 +25,7 @@ class LoginForm extends HookConsumerWidget { final passwordController = useTextEditingController.fromValue(TextEditingValue.empty); final serverEndpointController = - useTextEditingController(text: 'login_form_endpoint_hint'.tr()); + useTextEditingController.fromValue(TextEditingValue.empty); final apiService = ref.watch(apiServiceProvider); final serverEndpointFocusNode = useFocusNode(); final isSaveLoginInfo = useState(false); diff --git a/mobile/lib/shared/services/api.service.dart b/mobile/lib/shared/services/api.service.dart index 495a48448d..05c6231f66 100644 --- a/mobile/lib/shared/services/api.service.dart +++ b/mobile/lib/shared/services/api.service.dart @@ -36,7 +36,7 @@ class ApiService { /// host - required /// port - optional (default: based on schema) /// path - optional (default: /) - resolveEndpoint(String serverUrl) async { + Future resolveEndpoint(String serverUrl) async { // Add schema if none is set final urlWithSchema = serverUrl.startsWith(RegExp(r"https?://")) ? serverUrl @@ -51,14 +51,14 @@ class ApiService { if (path.isEmpty) { // No path provided, lets check for /.well-known/immich final wellKnownEndpoint = await getWellKnownEndpoint(origin); - if (wellKnownEndpoint) return wellKnownEndpoint; + if (wellKnownEndpoint.isNotEmpty) return wellKnownEndpoint; } // Otherwise, assume the URL provided is the api endpoint return "$origin$path"; } - getWellKnownEndpoint(String baseUrl) async { + Future getWellKnownEndpoint(String baseUrl) async { final Client client = Client(); try { @@ -69,7 +69,7 @@ class ApiService { if (res.statusCode == 200) { final data = jsonDecode(res.body); - final endpoint = data['api']['endpoint'] as String; + final endpoint = data['api']['endpoint'].toString(); if (endpoint.startsWith('/')) { // Full URL is relative to base @@ -81,7 +81,7 @@ class ApiService { debugPrint("Could not locate /.well-known/immich at $baseUrl"); } - return null; + return ""; } setAccessToken(String accessToken) {