2024-05-01 02:36:40 +00:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
2023-10-22 15:05:10 +00:00
|
|
|
|
2023-01-19 15:45:37 +00:00
|
|
|
String sanitizeUrl(String url) {
|
|
|
|
// Add schema if none is set
|
|
|
|
final urlWithSchema =
|
2023-11-29 04:02:19 +00:00
|
|
|
url.trimLeft().startsWith(RegExp(r"https?://")) ? url : "https://$url";
|
2023-01-19 15:45:37 +00:00
|
|
|
|
|
|
|
// Remove trailing slash(es)
|
2023-11-29 04:02:19 +00:00
|
|
|
return urlWithSchema.trimRight().replaceFirst(RegExp(r"/+$"), "");
|
2023-01-19 15:45:37 +00:00
|
|
|
}
|
2023-10-22 15:05:10 +00:00
|
|
|
|
|
|
|
String? getServerUrl() {
|
|
|
|
final serverUrl = Store.tryGet(StoreKey.serverEndpoint);
|
|
|
|
final serverUri = serverUrl != null ? Uri.tryParse(serverUrl) : null;
|
|
|
|
if (serverUri == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return serverUri.hasPort
|
|
|
|
? "${serverUri.scheme}://${serverUri.host}:${serverUri.port}"
|
|
|
|
: "${serverUri.scheme}://${serverUri.host}";
|
|
|
|
}
|