2025-06-30 12:21:09 -05:00
|
|
|
import 'package:drift/drift.dart';
|
2025-07-01 03:38:15 +08:00
|
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
2025-07-02 23:54:37 +05:30
|
|
|
import 'package:immich_mobile/domain/models/exif.model.dart';
|
|
|
|
|
import 'package:immich_mobile/infrastructure/entities/exif.entity.dart'
|
|
|
|
|
hide ExifInfo;
|
2025-07-02 00:52:11 +08:00
|
|
|
import 'package:immich_mobile/infrastructure/entities/exif.entity.drift.dart';
|
2025-06-30 12:21:09 -05:00
|
|
|
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
|
|
|
|
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
2025-07-02 00:52:11 +08:00
|
|
|
import 'package:maplibre_gl/maplibre_gl.dart';
|
2025-06-30 12:21:09 -05:00
|
|
|
|
2025-07-02 23:54:37 +05:30
|
|
|
class RemoteAssetRepository extends DriftDatabaseRepository {
|
2025-06-30 12:21:09 -05:00
|
|
|
final Drift _db;
|
2025-07-02 23:54:37 +05:30
|
|
|
const RemoteAssetRepository(this._db) : super(_db);
|
|
|
|
|
|
|
|
|
|
Future<ExifInfo?> getExif(String id) {
|
|
|
|
|
return _db.managers.remoteExifEntity
|
|
|
|
|
.filter((row) => row.assetId.id.equals(id))
|
|
|
|
|
.map((row) => row.toDto())
|
|
|
|
|
.getSingleOrNull();
|
|
|
|
|
}
|
2025-06-30 12:21:09 -05:00
|
|
|
|
|
|
|
|
Future<void> updateFavorite(List<String> ids, bool isFavorite) {
|
|
|
|
|
return _db.batch((batch) async {
|
|
|
|
|
for (final id in ids) {
|
|
|
|
|
batch.update(
|
|
|
|
|
_db.remoteAssetEntity,
|
|
|
|
|
RemoteAssetEntityCompanion(isFavorite: Value(isFavorite)),
|
|
|
|
|
where: (e) => e.id.equals(id),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-01 03:38:15 +08:00
|
|
|
|
|
|
|
|
Future<void> updateVisibility(List<String> ids, AssetVisibility visibility) {
|
|
|
|
|
return _db.batch((batch) async {
|
|
|
|
|
for (final id in ids) {
|
|
|
|
|
batch.update(
|
|
|
|
|
_db.remoteAssetEntity,
|
|
|
|
|
RemoteAssetEntityCompanion(visibility: Value(visibility)),
|
|
|
|
|
where: (e) => e.id.equals(id),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-02 00:52:11 +08:00
|
|
|
|
2025-07-03 01:26:07 +08:00
|
|
|
Future<void> trash(List<String> ids) {
|
|
|
|
|
return _db.batch((batch) async {
|
|
|
|
|
for (final id in ids) {
|
|
|
|
|
batch.update(
|
|
|
|
|
_db.remoteAssetEntity,
|
|
|
|
|
RemoteAssetEntityCompanion(deletedAt: Value(DateTime.now())),
|
|
|
|
|
where: (e) => e.id.equals(id),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> delete(List<String> ids) {
|
|
|
|
|
return _db.remoteAssetEntity.deleteWhere((row) => row.id.isIn(ids));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 00:52:11 +08:00
|
|
|
Future<void> updateLocation(List<String> ids, LatLng location) {
|
|
|
|
|
return _db.batch((batch) async {
|
|
|
|
|
for (final id in ids) {
|
|
|
|
|
batch.update(
|
|
|
|
|
_db.remoteExifEntity,
|
|
|
|
|
RemoteExifEntityCompanion(
|
|
|
|
|
latitude: Value(location.latitude),
|
|
|
|
|
longitude: Value(location.longitude),
|
|
|
|
|
),
|
|
|
|
|
where: (e) => e.assetId.equals(id),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-06-30 12:21:09 -05:00
|
|
|
}
|