feat(web,server): external domain setting (#6146)

* feat: external domain setting

* chore: open api

* mobile: handle serverconfig-externalDomain

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
Jason Rasmussen
2024-01-03 21:54:48 -05:00
committed by GitHub
parent 1e503c3212
commit 317adc5c28
35 changed files with 433 additions and 23 deletions
@@ -9,6 +9,7 @@ import 'package:immich_mobile/modules/search/ui/thumbnail_with_info.dart';
import 'package:immich_mobile/modules/shared_link/models/shared_link.dart';
import 'package:immich_mobile/modules/shared_link/providers/shared_link.provider.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
import 'package:immich_mobile/shared/ui/confirm_dialog.dart';
import 'package:immich_mobile/shared/ui/immich_toast.dart';
import 'package:immich_mobile/utils/image_url_builder.dart';
@@ -71,7 +72,11 @@ class SharedLinkItem extends ConsumerWidget {
final imageSize = math.min(context.width / 4, 100.0);
void copyShareLinkToClipboard() {
final serverUrl = getServerUrl();
final externalDomain = ref.read(
serverInfoProvider.select((s) => s.serverConfig.externalDomain),
);
final serverUrl =
externalDomain.isNotEmpty ? externalDomain : getServerUrl();
if (serverUrl == null) {
ImmichToast.show(
context: context,
@@ -8,6 +8,7 @@ import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/modules/shared_link/models/shared_link.dart';
import 'package:immich_mobile/modules/shared_link/providers/shared_link.provider.dart';
import 'package:immich_mobile/modules/shared_link/services/shared_link.service.dart';
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
import 'package:immich_mobile/shared/ui/immich_toast.dart';
import 'package:immich_mobile/utils/url_helper.dart';
@@ -353,7 +354,11 @@ class SharedLinkEditPage extends HookConsumerWidget {
expiresAt: expiryAfter.value == 0 ? null : calculateExpiry(),
);
ref.invalidate(sharedLinksStateProvider);
final serverUrl = getServerUrl();
final externalDomain = ref.read(
serverInfoProvider.select((s) => s.serverConfig.externalDomain),
);
final serverUrl =
externalDomain.isNotEmpty ? externalDomain : getServerUrl();
if (newLink != null && serverUrl != null) {
newShareLink.value = "$serverUrl/share/${newLink.key}";
copyLinkToClipboard();
@@ -2,35 +2,40 @@ import 'package:openapi/api.dart';
class ServerConfig {
final int trashDays;
final String externalDomain;
const ServerConfig({
required this.trashDays,
required this.externalDomain,
});
ServerConfig copyWith({
int? trashDays,
String? externalDomain,
}) {
return ServerConfig(
trashDays: trashDays ?? this.trashDays,
externalDomain: externalDomain ?? this.externalDomain,
);
}
@override
String toString() {
return 'ServerConfig(trashDays: $trashDays)';
}
String toString() =>
'ServerConfig(trashDays: $trashDays, externalDomain: $externalDomain)';
ServerConfig.fromDto(ServerConfigDto dto) : trashDays = dto.trashDays;
ServerConfig.fromDto(ServerConfigDto dto)
: trashDays = dto.trashDays,
externalDomain = dto.externalDomain;
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is ServerConfig && other.trashDays == trashDays;
return other is ServerConfig &&
other.trashDays == trashDays &&
other.externalDomain == externalDomain;
}
@override
int get hashCode {
return trashDays.hashCode;
}
int get hashCode => trashDays.hashCode ^ externalDomain.hashCode;
}
@@ -29,6 +29,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
),
serverConfig: const ServerConfig(
trashDays: 30,
externalDomain: '',
),
serverDiskInfo: const ServerDiskInfo(
diskAvailable: "0",
@@ -74,7 +75,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
if (appVersion["major"]! > serverVersion.major) {
state = state.copyWith(
isVersionMismatch: true,
versionMismatchErrorMessage: "profile_drawer_server_out_of_date_major".tr(),
versionMismatchErrorMessage:
"profile_drawer_server_out_of_date_major".tr(),
);
return;
}
@@ -82,7 +84,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
if (appVersion["major"]! < serverVersion.major) {
state = state.copyWith(
isVersionMismatch: true,
versionMismatchErrorMessage: "profile_drawer_client_out_of_date_major".tr(),
versionMismatchErrorMessage:
"profile_drawer_client_out_of_date_major".tr(),
);
return;
}
@@ -90,7 +93,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
if (appVersion["minor"]! > serverVersion.minor) {
state = state.copyWith(
isVersionMismatch: true,
versionMismatchErrorMessage: "profile_drawer_server_out_of_date_minor".tr(),
versionMismatchErrorMessage:
"profile_drawer_server_out_of_date_minor".tr(),
);
return;
}
@@ -98,7 +102,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
if (appVersion["minor"]! < serverVersion.minor) {
state = state.copyWith(
isVersionMismatch: true,
versionMismatchErrorMessage: "profile_drawer_client_out_of_date_minor".tr(),
versionMismatchErrorMessage:
"profile_drawer_client_out_of_date_minor".tr(),
);
return;
}
+3
View File
@@ -149,6 +149,7 @@ doc/SystemConfigNewVersionCheckDto.md
doc/SystemConfigOAuthDto.md
doc/SystemConfigPasswordLoginDto.md
doc/SystemConfigReverseGeocodingDto.md
doc/SystemConfigServerDto.md
doc/SystemConfigStorageTemplateDto.md
doc/SystemConfigTemplateStorageOptionDto.md
doc/SystemConfigThemeDto.md
@@ -335,6 +336,7 @@ lib/model/system_config_new_version_check_dto.dart
lib/model/system_config_o_auth_dto.dart
lib/model/system_config_password_login_dto.dart
lib/model/system_config_reverse_geocoding_dto.dart
lib/model/system_config_server_dto.dart
lib/model/system_config_storage_template_dto.dart
lib/model/system_config_template_storage_option_dto.dart
lib/model/system_config_theme_dto.dart
@@ -508,6 +510,7 @@ test/system_config_new_version_check_dto_test.dart
test/system_config_o_auth_dto_test.dart
test/system_config_password_login_dto_test.dart
test/system_config_reverse_geocoding_dto_test.dart
test/system_config_server_dto_test.dart
test/system_config_storage_template_dto_test.dart
test/system_config_template_storage_option_dto_test.dart
test/system_config_theme_dto_test.dart
+1
View File
@@ -341,6 +341,7 @@ Class | Method | HTTP request | Description
- [SystemConfigOAuthDto](doc//SystemConfigOAuthDto.md)
- [SystemConfigPasswordLoginDto](doc//SystemConfigPasswordLoginDto.md)
- [SystemConfigReverseGeocodingDto](doc//SystemConfigReverseGeocodingDto.md)
- [SystemConfigServerDto](doc//SystemConfigServerDto.md)
- [SystemConfigStorageTemplateDto](doc//SystemConfigStorageTemplateDto.md)
- [SystemConfigTemplateStorageOptionDto](doc//SystemConfigTemplateStorageOptionDto.md)
- [SystemConfigThemeDto](doc//SystemConfigThemeDto.md)
+1
View File
@@ -8,6 +8,7 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**externalDomain** | **String** | |
**isInitialized** | **bool** | |
**loginPageMessage** | **String** | |
**oauthButtonText** | **String** | |
+1
View File
@@ -18,6 +18,7 @@ Name | Type | Description | Notes
**oauth** | [**SystemConfigOAuthDto**](SystemConfigOAuthDto.md) | |
**passwordLogin** | [**SystemConfigPasswordLoginDto**](SystemConfigPasswordLoginDto.md) | |
**reverseGeocoding** | [**SystemConfigReverseGeocodingDto**](SystemConfigReverseGeocodingDto.md) | |
**server** | [**SystemConfigServerDto**](SystemConfigServerDto.md) | |
**storageTemplate** | [**SystemConfigStorageTemplateDto**](SystemConfigStorageTemplateDto.md) | |
**theme** | [**SystemConfigThemeDto**](SystemConfigThemeDto.md) | |
**thumbnail** | [**SystemConfigThumbnailDto**](SystemConfigThumbnailDto.md) | |
+15
View File
@@ -0,0 +1,15 @@
# openapi.model.SystemConfigServerDto
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**externalDomain** | **String** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
+1
View File
@@ -177,6 +177,7 @@ part 'model/system_config_new_version_check_dto.dart';
part 'model/system_config_o_auth_dto.dart';
part 'model/system_config_password_login_dto.dart';
part 'model/system_config_reverse_geocoding_dto.dart';
part 'model/system_config_server_dto.dart';
part 'model/system_config_storage_template_dto.dart';
part 'model/system_config_template_storage_option_dto.dart';
part 'model/system_config_theme_dto.dart';
+2
View File
@@ -441,6 +441,8 @@ class ApiClient {
return SystemConfigPasswordLoginDto.fromJson(value);
case 'SystemConfigReverseGeocodingDto':
return SystemConfigReverseGeocodingDto.fromJson(value);
case 'SystemConfigServerDto':
return SystemConfigServerDto.fromJson(value);
case 'SystemConfigStorageTemplateDto':
return SystemConfigStorageTemplateDto.fromJson(value);
case 'SystemConfigTemplateStorageOptionDto':
+9 -1
View File
@@ -13,12 +13,15 @@ part of openapi.api;
class ServerConfigDto {
/// Returns a new [ServerConfigDto] instance.
ServerConfigDto({
required this.externalDomain,
required this.isInitialized,
required this.loginPageMessage,
required this.oauthButtonText,
required this.trashDays,
});
String externalDomain;
bool isInitialized;
String loginPageMessage;
@@ -29,6 +32,7 @@ class ServerConfigDto {
@override
bool operator ==(Object other) => identical(this, other) || other is ServerConfigDto &&
other.externalDomain == externalDomain &&
other.isInitialized == isInitialized &&
other.loginPageMessage == loginPageMessage &&
other.oauthButtonText == oauthButtonText &&
@@ -37,16 +41,18 @@ class ServerConfigDto {
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(externalDomain.hashCode) +
(isInitialized.hashCode) +
(loginPageMessage.hashCode) +
(oauthButtonText.hashCode) +
(trashDays.hashCode);
@override
String toString() => 'ServerConfigDto[isInitialized=$isInitialized, loginPageMessage=$loginPageMessage, oauthButtonText=$oauthButtonText, trashDays=$trashDays]';
String toString() => 'ServerConfigDto[externalDomain=$externalDomain, isInitialized=$isInitialized, loginPageMessage=$loginPageMessage, oauthButtonText=$oauthButtonText, trashDays=$trashDays]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'externalDomain'] = this.externalDomain;
json[r'isInitialized'] = this.isInitialized;
json[r'loginPageMessage'] = this.loginPageMessage;
json[r'oauthButtonText'] = this.oauthButtonText;
@@ -62,6 +68,7 @@ class ServerConfigDto {
final json = value.cast<String, dynamic>();
return ServerConfigDto(
externalDomain: mapValueOfType<String>(json, r'externalDomain')!,
isInitialized: mapValueOfType<bool>(json, r'isInitialized')!,
loginPageMessage: mapValueOfType<String>(json, r'loginPageMessage')!,
oauthButtonText: mapValueOfType<String>(json, r'oauthButtonText')!,
@@ -113,6 +120,7 @@ class ServerConfigDto {
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'externalDomain',
'isInitialized',
'loginPageMessage',
'oauthButtonText',
+9 -1
View File
@@ -23,6 +23,7 @@ class SystemConfigDto {
required this.oauth,
required this.passwordLogin,
required this.reverseGeocoding,
required this.server,
required this.storageTemplate,
required this.theme,
required this.thumbnail,
@@ -49,6 +50,8 @@ class SystemConfigDto {
SystemConfigReverseGeocodingDto reverseGeocoding;
SystemConfigServerDto server;
SystemConfigStorageTemplateDto storageTemplate;
SystemConfigThemeDto theme;
@@ -69,6 +72,7 @@ class SystemConfigDto {
other.oauth == oauth &&
other.passwordLogin == passwordLogin &&
other.reverseGeocoding == reverseGeocoding &&
other.server == server &&
other.storageTemplate == storageTemplate &&
other.theme == theme &&
other.thumbnail == thumbnail &&
@@ -87,13 +91,14 @@ class SystemConfigDto {
(oauth.hashCode) +
(passwordLogin.hashCode) +
(reverseGeocoding.hashCode) +
(server.hashCode) +
(storageTemplate.hashCode) +
(theme.hashCode) +
(thumbnail.hashCode) +
(trash.hashCode);
@override
String toString() => 'SystemConfigDto[ffmpeg=$ffmpeg, job=$job, library_=$library_, logging=$logging, machineLearning=$machineLearning, map=$map, newVersionCheck=$newVersionCheck, oauth=$oauth, passwordLogin=$passwordLogin, reverseGeocoding=$reverseGeocoding, storageTemplate=$storageTemplate, theme=$theme, thumbnail=$thumbnail, trash=$trash]';
String toString() => 'SystemConfigDto[ffmpeg=$ffmpeg, job=$job, library_=$library_, logging=$logging, machineLearning=$machineLearning, map=$map, newVersionCheck=$newVersionCheck, oauth=$oauth, passwordLogin=$passwordLogin, reverseGeocoding=$reverseGeocoding, server=$server, storageTemplate=$storageTemplate, theme=$theme, thumbnail=$thumbnail, trash=$trash]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
@@ -107,6 +112,7 @@ class SystemConfigDto {
json[r'oauth'] = this.oauth;
json[r'passwordLogin'] = this.passwordLogin;
json[r'reverseGeocoding'] = this.reverseGeocoding;
json[r'server'] = this.server;
json[r'storageTemplate'] = this.storageTemplate;
json[r'theme'] = this.theme;
json[r'thumbnail'] = this.thumbnail;
@@ -132,6 +138,7 @@ class SystemConfigDto {
oauth: SystemConfigOAuthDto.fromJson(json[r'oauth'])!,
passwordLogin: SystemConfigPasswordLoginDto.fromJson(json[r'passwordLogin'])!,
reverseGeocoding: SystemConfigReverseGeocodingDto.fromJson(json[r'reverseGeocoding'])!,
server: SystemConfigServerDto.fromJson(json[r'server'])!,
storageTemplate: SystemConfigStorageTemplateDto.fromJson(json[r'storageTemplate'])!,
theme: SystemConfigThemeDto.fromJson(json[r'theme'])!,
thumbnail: SystemConfigThumbnailDto.fromJson(json[r'thumbnail'])!,
@@ -193,6 +200,7 @@ class SystemConfigDto {
'oauth',
'passwordLogin',
'reverseGeocoding',
'server',
'storageTemplate',
'theme',
'thumbnail',
+98
View File
@@ -0,0 +1,98 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class SystemConfigServerDto {
/// Returns a new [SystemConfigServerDto] instance.
SystemConfigServerDto({
required this.externalDomain,
});
String externalDomain;
@override
bool operator ==(Object other) => identical(this, other) || other is SystemConfigServerDto &&
other.externalDomain == externalDomain;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(externalDomain.hashCode);
@override
String toString() => 'SystemConfigServerDto[externalDomain=$externalDomain]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'externalDomain'] = this.externalDomain;
return json;
}
/// Returns a new [SystemConfigServerDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static SystemConfigServerDto? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return SystemConfigServerDto(
externalDomain: mapValueOfType<String>(json, r'externalDomain')!,
);
}
return null;
}
static List<SystemConfigServerDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <SystemConfigServerDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SystemConfigServerDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, SystemConfigServerDto> mapFromJson(dynamic json) {
final map = <String, SystemConfigServerDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = SystemConfigServerDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of SystemConfigServerDto-objects as value to a dart map
static Map<String, List<SystemConfigServerDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<SystemConfigServerDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = SystemConfigServerDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'externalDomain',
};
}
+5
View File
@@ -16,6 +16,11 @@ void main() {
// final instance = ServerConfigDto();
group('test ServerConfigDto', () {
// String externalDomain
test('to test the property `externalDomain`', () async {
// TODO
});
// bool isInitialized
test('to test the property `isInitialized`', () async {
// TODO
+5
View File
@@ -66,6 +66,11 @@ void main() {
// TODO
});
// SystemConfigServerDto server
test('to test the property `server`', () async {
// TODO
});
// SystemConfigStorageTemplateDto storageTemplate
test('to test the property `storageTemplate`', () async {
// TODO
+27
View File
@@ -0,0 +1,27 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for SystemConfigServerDto
void main() {
// final instance = SystemConfigServerDto();
group('test SystemConfigServerDto', () {
// String externalDomain
test('to test the property `externalDomain`', () async {
// TODO
});
});
}