more refactors
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import 'package:immich_mobile/domain/interfaces/api/authentication_api.interface.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class AuthenticationApiRepository
|
||||
with LogMixin
|
||||
implements IAuthenticationApiRepository {
|
||||
final AuthenticationApi _authenticationApi;
|
||||
final OAuthApi _oAuthApi;
|
||||
|
||||
const AuthenticationApiRepository({
|
||||
required AuthenticationApi authenticationApi,
|
||||
required OAuthApi oAuthApi,
|
||||
}) : _authenticationApi = authenticationApi,
|
||||
_oAuthApi = oAuthApi;
|
||||
|
||||
@override
|
||||
Future<String?> login(String email, String password) async {
|
||||
try {
|
||||
final response = await _authenticationApi
|
||||
.login(LoginCredentialDto(email: email, password: password));
|
||||
return response?.accessToken;
|
||||
} catch (e, s) {
|
||||
log.e("Exception occured while performing password login", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> startOAuth({required String redirectUri}) async {
|
||||
try {
|
||||
final response =
|
||||
await _oAuthApi.startOAuth(OAuthConfigDto(redirectUri: redirectUri));
|
||||
return response?.url;
|
||||
} catch (e, s) {
|
||||
log.e("Exception occured while starting oauth login", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> finishOAuth(String url) async {
|
||||
try {
|
||||
final response = await _oAuthApi.finishOAuth(OAuthCallbackDto(url: url));
|
||||
return response?.accessToken;
|
||||
} catch (e, s) {
|
||||
log.e("Exception occured while finishing oauth login", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:immich_mobile/domain/interfaces/api/server_api.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/server-info/server_config.model.dart';
|
||||
import 'package:immich_mobile/domain/models/server-info/server_features.model.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
import 'package:openapi/api.dart' as api;
|
||||
|
||||
class ServerApiRepository with LogMixin implements IServerApiRepository {
|
||||
final api.ServerApi _serverApi;
|
||||
|
||||
const ServerApiRepository({required api.ServerApi serverApi})
|
||||
: _serverApi = serverApi;
|
||||
|
||||
@override
|
||||
Future<void> pingServer() async {
|
||||
await _serverApi.pingServer();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerConfig?> getServerConfig() async {
|
||||
try {
|
||||
final config = await _serverApi.getServerConfig();
|
||||
if (config != null) {
|
||||
return _fromConfigDto(config);
|
||||
}
|
||||
} catch (e, s) {
|
||||
log.e("Exception occured while fetching server config", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerFeatures?> getServerFeatures() async {
|
||||
try {
|
||||
final features = await _serverApi.getServerFeatures();
|
||||
if (features != null) {
|
||||
return _fromFeatureDto(features);
|
||||
}
|
||||
} catch (e, s) {
|
||||
log.e("Exception occured while fetching server features", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ServerConfig _fromConfigDto(api.ServerConfigDto dto) => ServerConfig(
|
||||
oauthButtonText: dto.oauthButtonText.isEmpty ? null : dto.oauthButtonText,
|
||||
);
|
||||
|
||||
ServerFeatures _fromFeatureDto(api.ServerFeaturesDto dto) => ServerFeatures(
|
||||
hasPasswordLogin: dto.passwordLogin,
|
||||
hasOAuthLogin: dto.oauth,
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:immich_mobile/domain/interfaces/api/sync_api.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/utils/extensions/string.extension.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class SyncApiRepository with LogMixin implements ISyncApiRepository {
|
||||
final SyncApi _syncApi;
|
||||
|
||||
const SyncApiRepository({required SyncApi syncApi}) : _syncApi = syncApi;
|
||||
|
||||
@override
|
||||
Future<List<Asset>?> getFullSyncForUser({
|
||||
String? lastId,
|
||||
required int limit,
|
||||
required DateTime updatedUntil,
|
||||
String? userId,
|
||||
}) async {
|
||||
try {
|
||||
final res = await _syncApi.getFullSyncForUser(AssetFullSyncDto(
|
||||
lastId: lastId,
|
||||
limit: limit,
|
||||
updatedUntil: updatedUntil,
|
||||
userId: userId,
|
||||
));
|
||||
return res?.map(_fromAssetResponseDto).toList();
|
||||
} catch (e) {
|
||||
log.e("Error fetching full asset sync for user", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Asset _fromAssetResponseDto(AssetResponseDto dto) => Asset(
|
||||
remoteId: dto.id,
|
||||
createdTime: dto.fileCreatedAt,
|
||||
duration: dto.duration.tryParseInt() ?? 0,
|
||||
height: dto.exifInfo?.exifImageHeight?.toInt(),
|
||||
width: dto.exifInfo?.exifImageWidth?.toInt(),
|
||||
hash: dto.checksum,
|
||||
name: dto.originalFileName,
|
||||
livePhotoVideoId: dto.livePhotoVideoId,
|
||||
modifiedTime: dto.fileModifiedAt,
|
||||
type: _toAssetType(dto.type),
|
||||
);
|
||||
|
||||
AssetType _toAssetType(AssetTypeEnum type) => switch (type) {
|
||||
AssetTypeEnum.AUDIO => AssetType.audio,
|
||||
AssetTypeEnum.IMAGE => AssetType.image,
|
||||
AssetTypeEnum.VIDEO => AssetType.video,
|
||||
_ => AssetType.other,
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:immich_mobile/domain/interfaces/api/user_api.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart' as model;
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class UserApiRepository with LogMixin implements IUserApiRepository {
|
||||
final UsersApi _usersApi;
|
||||
|
||||
const UserApiRepository({required UsersApi usersApi}) : _usersApi = usersApi;
|
||||
|
||||
@override
|
||||
Future<model.User?> getMyUser() async {
|
||||
try {
|
||||
final [
|
||||
userDto as UserAdminResponseDto?,
|
||||
preferencesDto as UserPreferencesResponseDto?
|
||||
] = await Future.wait([
|
||||
_usersApi.getMyUser(),
|
||||
_usersApi.getMyPreferences(),
|
||||
]);
|
||||
|
||||
if (userDto == null) {
|
||||
log.e("Cannot fetch my user.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return _fromAdminDto(userDto, preferencesDto);
|
||||
} catch (e, s) {
|
||||
log.e("Error while fetching my user", e, s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
model.User _fromAdminDto(
|
||||
UserAdminResponseDto userDto, [
|
||||
UserPreferencesResponseDto? userPreferences,
|
||||
]) {
|
||||
return model.User(
|
||||
id: userDto.id,
|
||||
updatedAt: DateTime.now(),
|
||||
name: userDto.name,
|
||||
email: userDto.email,
|
||||
isAdmin: userDto.isAdmin,
|
||||
quotaSizeInBytes: userDto.quotaSizeInBytes ?? 0,
|
||||
quotaUsageInBytes: userDto.quotaUsageInBytes ?? 0,
|
||||
inTimeline: true,
|
||||
profileImagePath: userDto.profileImagePath,
|
||||
memoryEnabled: userPreferences?.memories.enabled ?? true,
|
||||
avatarColor: userDto.avatarColor.toEnum(),
|
||||
);
|
||||
}
|
||||
|
||||
extension _AvatarColorEnumHelper on UserAvatarColor {
|
||||
model.UserAvatarColor toEnum() {
|
||||
switch (this) {
|
||||
case UserAvatarColor.primary:
|
||||
return model.UserAvatarColor.primary;
|
||||
case UserAvatarColor.pink:
|
||||
return model.UserAvatarColor.pink;
|
||||
case UserAvatarColor.red:
|
||||
return model.UserAvatarColor.red;
|
||||
case UserAvatarColor.yellow:
|
||||
return model.UserAvatarColor.yellow;
|
||||
case UserAvatarColor.blue:
|
||||
return model.UserAvatarColor.blue;
|
||||
case UserAvatarColor.green:
|
||||
return model.UserAvatarColor.green;
|
||||
case UserAvatarColor.purple:
|
||||
return model.UserAvatarColor.purple;
|
||||
case UserAvatarColor.orange:
|
||||
return model.UserAvatarColor.orange;
|
||||
case UserAvatarColor.gray:
|
||||
return model.UserAvatarColor.gray;
|
||||
case UserAvatarColor.amber:
|
||||
return model.UserAvatarColor.amber;
|
||||
}
|
||||
return model.UserAvatarColor.primary;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user