2024-08-13 19:39:25 +00:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
dynamic upgradeDto(dynamic value, String targetType) {
|
|
|
|
switch (targetType) {
|
|
|
|
case 'UserPreferencesResponseDto':
|
|
|
|
if (value is Map) {
|
2024-08-29 19:29:04 +00:00
|
|
|
addDefault(value, 'download.includeEmbeddedVideos', false);
|
|
|
|
addDefault(value, 'folders', FoldersResponse().toJson());
|
|
|
|
addDefault(value, 'memories', MemoriesResponse().toJson());
|
|
|
|
addDefault(value, 'ratings', RatingsResponse().toJson());
|
|
|
|
addDefault(value, 'people', PeopleResponse().toJson());
|
|
|
|
addDefault(value, 'tags', TagsResponse().toJson());
|
2024-08-13 19:39:25 +00:00
|
|
|
}
|
2024-08-25 05:09:37 +00:00
|
|
|
break;
|
2024-09-23 20:30:23 +00:00
|
|
|
case 'ServerConfigDto':
|
|
|
|
if (value is Map) {
|
|
|
|
addDefault(
|
|
|
|
value,
|
|
|
|
'mapLightStyleUrl',
|
|
|
|
'https://tiles.immich.cloud/v1/style/light.json',
|
|
|
|
);
|
|
|
|
addDefault(
|
|
|
|
value,
|
|
|
|
'mapDarkStyleUrl',
|
|
|
|
'https://tiles.immich.cloud/v1/style/dark.json',
|
|
|
|
);
|
|
|
|
}
|
2024-09-18 15:59:30 +00:00
|
|
|
case 'UserResponseDto':
|
|
|
|
if (value is Map) {
|
|
|
|
addDefault(value, 'profileChangedAt', DateTime.now().toIso8601String());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'UserAdminResponseDto':
|
|
|
|
if (value is Map) {
|
|
|
|
addDefault(value, 'profileChangedAt', DateTime.now().toIso8601String());
|
|
|
|
}
|
|
|
|
break;
|
2024-08-13 19:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-29 19:29:04 +00:00
|
|
|
|
|
|
|
addDefault(dynamic value, String keys, dynamic defaultValue) {
|
|
|
|
// Loop through the keys and assign the default value if the key is not present
|
|
|
|
List<String> keyList = keys.split('.');
|
|
|
|
dynamic current = value;
|
|
|
|
|
|
|
|
for (int i = 0; i < keyList.length - 1; i++) {
|
|
|
|
if (current[keyList[i]] == null) {
|
|
|
|
current[keyList[i]] = {};
|
|
|
|
}
|
|
|
|
current = current[keyList[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current[keyList.last] == null) {
|
|
|
|
current[keyList.last] = defaultValue;
|
|
|
|
}
|
|
|
|
}
|