Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mobile): auto api endpoint #15184

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

realashleybailey
Copy link

Code Addition: Automatically Adjust serverUrl with /api

This code addition ensures that the serverUrl string is correctly formatted to include /api at the end if it is missing, or remove any extra trailing slashes if the URL already ends with /api/.

Explanation

  • Trimming Whitespace:
    The serverUrl is trimmed of any leading or trailing whitespace using serverUrl.trim(). This ensures there are no accidental spaces that could cause issues when checking or modifying the URL.

  • Handling /api/ and /api:
    The logic checks if the serverUrl ends with /api/. If it does, the trailing slash is removed to standardize the URL format.

    If the serverUrl does not end with /api, the code appends /api to the URL. This ensures that the URL always contains /api at the end when needed.

Example Workflow

  1. If serverUrl = "http://example.com/api/", it will be trimmed to http://example.com/api.
  2. If serverUrl = "http://example.com", it will be changed to http://example.com/api.
  3. If serverUrl = "http://example.com/api", it will remain unchanged.

This addition helps prevent issues with inconsistent server URLs by ensuring they always contain the proper /api endpoint suffix. Additionally this alleviates confusion when inviting friends/family to use your Immich server and you wish to just share your server URL without the /api at the end.

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Label error. Requires exactly 1 of: changelog:.*. Found: 📱mobile. A maintainer will add the required label.

@@ -94,6 +94,17 @@ class LoginForm extends HookConsumerWidget {
);
}

// Automatically add /api to serverUrl if missing
serverUrl = serverUrl.trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the input field just doesn't accept whitespace to begin with

Comment on lines +101 to +105
if (serverUrl.endsWith('/api/')) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
} else if (!serverUrl.endsWith('/api')) {
serverUrl = '$serverUrl/api';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some .well-known endpoint autodiscovery code that already appends /api as one of the discovery steps, in https://github.com/immich-app/immich/blob/main/mobile/lib/services/api.service.dart.

@bo0tzz bo0tzz changed the title Feat/mobile auto api endpoint feat(mobile): auto api endpoint Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants