2023-04-13 08:22:06 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-04-30 19:36:40 -07:00
|
|
|
import 'package:immich_mobile/entities/exif_info.entity.dart';
|
2024-05-02 13:59:14 -07:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/db.provider.dart';
|
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2023-04-13 08:22:06 -07:00
|
|
|
import 'package:isar/isar.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
class AssetDescriptionService {
|
|
|
|
AssetDescriptionService(this._db, this._api);
|
|
|
|
|
|
|
|
final Isar _db;
|
|
|
|
final ApiService _api;
|
|
|
|
|
|
|
|
setDescription(
|
|
|
|
String description,
|
|
|
|
String remoteAssetId,
|
|
|
|
int localExifId,
|
|
|
|
) async {
|
|
|
|
final result = await _api.assetApi.updateAsset(
|
|
|
|
remoteAssetId,
|
|
|
|
UpdateAssetDto(description: description),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (result?.exifInfo?.description != null) {
|
|
|
|
var exifInfo = await _db.exifInfos.get(localExifId);
|
|
|
|
|
|
|
|
if (exifInfo != null) {
|
|
|
|
exifInfo.description = result!.exifInfo!.description;
|
|
|
|
await _db.writeTxn(
|
|
|
|
() => _db.exifInfos.put(exifInfo),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> readLatest(String assetRemoteId, int localExifId) async {
|
|
|
|
final latestAssetFromServer =
|
2024-02-08 14:57:54 -07:00
|
|
|
await _api.assetApi.getAssetInfo(assetRemoteId);
|
2023-04-13 08:22:06 -07:00
|
|
|
final localExifInfo = await _db.exifInfos.get(localExifId);
|
|
|
|
|
|
|
|
if (latestAssetFromServer != null && localExifInfo != null) {
|
|
|
|
localExifInfo.description =
|
|
|
|
latestAssetFromServer.exifInfo?.description ?? '';
|
|
|
|
|
|
|
|
await _db.writeTxn(
|
|
|
|
() => _db.exifInfos.put(localExifInfo),
|
|
|
|
);
|
|
|
|
|
|
|
|
return localExifInfo.description!;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final assetDescriptionServiceProvider = Provider(
|
|
|
|
(ref) => AssetDescriptionService(
|
|
|
|
ref.watch(dbProvider),
|
|
|
|
ref.watch(apiServiceProvider),
|
|
|
|
),
|
|
|
|
);
|