mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
fix(mobile): server endpoint input auto parse https when not specified (#5326)
This fixes issue #4397 and automatically adds the https protocol to the server endpoint url if it is missing Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
2a45ad147c
commit
5a2fc20b20
@ -48,7 +48,7 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
/// Fetch the server login credential and enables oAuth login if necessary
|
/// Fetch the server login credential and enables oAuth login if necessary
|
||||||
/// Returns true if successful, false otherwise
|
/// Returns true if successful, false otherwise
|
||||||
Future<bool> getServerLoginCredential() async {
|
Future<bool> getServerLoginCredential() async {
|
||||||
final serverUrl = serverEndpointController.text.trim();
|
final serverUrl = sanitizeUrl(serverEndpointController.text);
|
||||||
|
|
||||||
// Guard empty URL
|
// Guard empty URL
|
||||||
if (serverUrl.isEmpty) {
|
if (serverUrl.isEmpty) {
|
||||||
@ -150,7 +150,7 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
await ref.read(authenticationProvider.notifier).login(
|
await ref.read(authenticationProvider.notifier).login(
|
||||||
usernameController.text,
|
usernameController.text,
|
||||||
passwordController.text,
|
passwordController.text,
|
||||||
serverEndpointController.text.trim(),
|
sanitizeUrl(serverEndpointController.text),
|
||||||
);
|
);
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
// Resume backup (if enable) then navigate
|
// Resume backup (if enable) then navigate
|
||||||
@ -187,7 +187,7 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
oAuthServerConfig = await oAuthService
|
oAuthServerConfig = await oAuthService
|
||||||
.getOAuthServerConfig(serverEndpointController.text);
|
.getOAuthServerConfig(sanitizeUrl(serverEndpointController.text));
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -209,7 +209,7 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
.watch(authenticationProvider.notifier)
|
.watch(authenticationProvider.notifier)
|
||||||
.setSuccessLoginInfo(
|
.setSuccessLoginInfo(
|
||||||
accessToken: loginResponseDto.accessToken,
|
accessToken: loginResponseDto.accessToken,
|
||||||
serverUrl: serverEndpointController.text,
|
serverUrl: sanitizeUrl(serverEndpointController.text),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
@ -305,7 +305,7 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
serverEndpointController.text,
|
sanitizeUrl(serverEndpointController.text),
|
||||||
style: context.textTheme.displaySmall,
|
style: context.textTheme.displaySmall,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
@ -3,10 +3,10 @@ import 'package:immich_mobile/shared/models/store.dart';
|
|||||||
String sanitizeUrl(String url) {
|
String sanitizeUrl(String url) {
|
||||||
// Add schema if none is set
|
// Add schema if none is set
|
||||||
final urlWithSchema =
|
final urlWithSchema =
|
||||||
url.startsWith(RegExp(r"https?://")) ? url : "https://$url";
|
url.trimLeft().startsWith(RegExp(r"https?://")) ? url : "https://$url";
|
||||||
|
|
||||||
// Remove trailing slash(es)
|
// Remove trailing slash(es)
|
||||||
return urlWithSchema.replaceFirst(RegExp(r"/+$"), "");
|
return urlWithSchema.trimRight().replaceFirst(RegExp(r"/+$"), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
String? getServerUrl() {
|
String? getServerUrl() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user