more refactors
This commit is contained in:
@@ -10,16 +10,16 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class AlbumRepository with LogMixin implements IAlbumRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const AlbumRepository(this._db);
|
||||
const AlbumRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<Album?> upsert(Album album) async {
|
||||
try {
|
||||
final albumData = _toEntity(album);
|
||||
final data = await _db.into(_db.album).insertReturningOrNull(
|
||||
albumData,
|
||||
onConflict: DoUpdate((_) => albumData, target: [_db.album.localId]),
|
||||
);
|
||||
final data = await _db.album.insertReturningOrNull(
|
||||
albumData,
|
||||
onConflict: DoUpdate((_) => albumData, target: [_db.album.localId]),
|
||||
);
|
||||
if (data != null) {
|
||||
return _toModel(data);
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class AlbumToAssetRepository with LogMixin implements IAlbumToAssetRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const AlbumToAssetRepository(this._db);
|
||||
const AlbumToAssetRepository({required DriftDatabaseRepository db})
|
||||
: _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<bool> addAssetIds(int albumId, Iterable<int> assetIds) async {
|
||||
try {
|
||||
await _db.albumToAsset.insertAll(
|
||||
assetIds.map((a) => AlbumToAssetCompanion.insert(
|
||||
assetId: a,
|
||||
albumId: albumId,
|
||||
)),
|
||||
assetIds.map(
|
||||
(a) => AlbumToAssetCompanion.insert(assetId: a, albumId: albumId),
|
||||
),
|
||||
onConflict: DoNothing(
|
||||
target: [_db.albumToAsset.assetId, _db.albumToAsset.albumId],
|
||||
),
|
||||
|
||||
@@ -10,17 +10,16 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class AlbumETagRepository with LogMixin implements IAlbumETagRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const AlbumETagRepository(this._db);
|
||||
const AlbumETagRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<bool> upsert(AlbumETag albumETag) async {
|
||||
try {
|
||||
final entity = _toEntity(albumETag);
|
||||
await _db.into(_db.albumETag).insert(
|
||||
entity,
|
||||
onConflict:
|
||||
DoUpdate((_) => entity, target: [_db.albumETag.albumId]),
|
||||
);
|
||||
await _db.albumETag.insertOne(
|
||||
entity,
|
||||
onConflict: DoUpdate((_) => entity, target: [_db.albumETag.albumId]),
|
||||
);
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
log.e("Error while adding an album etag to the DB", e, s);
|
||||
@@ -30,10 +29,9 @@ class AlbumETagRepository with LogMixin implements IAlbumETagRepository {
|
||||
|
||||
@override
|
||||
FutureOr<AlbumETag?> get(int albumId) async {
|
||||
return await _db.managers.albumETag
|
||||
.filter((r) => r.albumId.id.equals(albumId))
|
||||
.map(_toModel)
|
||||
.getSingleOrNull();
|
||||
final query = _db.albumETag.select()
|
||||
..where((r) => r.albumId.equals(albumId));
|
||||
return await query.map(_toModel).getSingleOrNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class AssetRepository with LogMixin implements IAssetRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const AssetRepository(this._db);
|
||||
const AssetRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
Future<bool> upsertAll(Iterable<Asset> assets) async {
|
||||
|
||||
@@ -12,7 +12,8 @@ class DeviceAssetToHashRepository
|
||||
implements IDeviceAssetToHashRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const DeviceAssetToHashRepository(this._db);
|
||||
const DeviceAssetToHashRepository({required DriftDatabaseRepository db})
|
||||
: _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<bool> upsertAll(Iterable<DeviceAssetToHash> assetHash) async {
|
||||
@@ -31,10 +32,9 @@ class DeviceAssetToHashRepository
|
||||
|
||||
@override
|
||||
Future<List<DeviceAssetToHash>> getForIds(Iterable<String> localIds) async {
|
||||
return await _db.managers.deviceAssetToHash
|
||||
.filter((f) => f.localId.isIn(localIds))
|
||||
.map(_toModel)
|
||||
.get();
|
||||
final query = _db.deviceAssetToHash.select()
|
||||
..where((f) => f.localId.isIn(localIds));
|
||||
return await query.map(_toModel).get();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
class LogRepository implements ILogRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const LogRepository(this._db);
|
||||
const LogRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
Future<List<LogMessage>> getAll() async {
|
||||
@@ -32,7 +32,7 @@ class LogRepository implements ILogRepository {
|
||||
@override
|
||||
FutureOr<bool> create(LogMessage log) async {
|
||||
try {
|
||||
await _db.into(_db.logs).insert(_toEntity(log));
|
||||
await _db.logs.insertOne(_toEntity(log));
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint("Error while adding a log to the DB - $e");
|
||||
@@ -56,7 +56,7 @@ class LogRepository implements ILogRepository {
|
||||
@override
|
||||
FutureOr<bool> deleteAll() async {
|
||||
try {
|
||||
await _db.managers.logs.delete();
|
||||
await _db.logs.deleteAll();
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint("Error while clearning the logs in DB - $e");
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class RenderListRepository with LogMixin implements IRenderListRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const RenderListRepository(this._db);
|
||||
const RenderListRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
Stream<RenderList> watchAll() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class StoreRepository with LogMixin implements IStoreRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const StoreRepository(this._db);
|
||||
const StoreRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<T?> tryGet<T, U>(StoreKey<T, U> key) async {
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
class UserRepository with LogMixin implements IUserRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const UserRepository(this._db);
|
||||
const UserRepository({required DriftDatabaseRepository db}) : _db = db;
|
||||
|
||||
@override
|
||||
FutureOr<User?> getForId(String userId) async {
|
||||
|
||||
Reference in New Issue
Block a user