mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
d346985457
* date time component * rename to info_sheet * simplify map info * Edit datetime sheet * fix janking when scroll on info sheet * Location refactor * refactor name * Update date time after editing * localize rebuild to smaller component * restore advanced bottom sheet * reassign EXIF back to local database * remove print statements
67 lines
1.7 KiB
Dart
67 lines
1.7 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
|
import 'package:immich_mobile/entities/exif_info.entity.dart';
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
import 'package:immich_mobile/providers/db.provider.dart';
|
|
import 'package:immich_mobile/services/api.service.dart';
|
|
import 'package:isar/isar.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
class AssetDescriptionService {
|
|
AssetDescriptionService(this._db, this._api);
|
|
|
|
final Isar _db;
|
|
final ApiService _api;
|
|
|
|
Future<void> setDescription(
|
|
Asset asset,
|
|
String newDescription,
|
|
) async {
|
|
final remoteAssetId = asset.remoteId;
|
|
final localExifId = asset.exifInfo?.id;
|
|
|
|
// Guard [remoteAssetId] and [localExifId] null
|
|
if (remoteAssetId == null || localExifId == null) {
|
|
return;
|
|
}
|
|
|
|
final result = await _api.assetsApi.updateAsset(
|
|
remoteAssetId,
|
|
UpdateAssetDto(description: newDescription),
|
|
);
|
|
|
|
final description = result?.exifInfo?.description;
|
|
|
|
if (description != null) {
|
|
var exifInfo = await _db.exifInfos.get(localExifId);
|
|
|
|
if (exifInfo != null) {
|
|
exifInfo.description = description;
|
|
await _db.writeTxn(
|
|
() => _db.exifInfos.put(exifInfo),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
String getAssetDescription(Asset asset) {
|
|
final localExifId = asset.exifInfo?.id;
|
|
|
|
// Guard [remoteAssetId] and [localExifId] null
|
|
if (localExifId == null) {
|
|
return "";
|
|
}
|
|
|
|
final exifInfo = _db.exifInfos.getSync(localExifId);
|
|
|
|
return exifInfo?.description ?? "";
|
|
}
|
|
}
|
|
|
|
final assetDescriptionServiceProvider = Provider(
|
|
(ref) => AssetDescriptionService(
|
|
ref.watch(dbProvider),
|
|
ref.watch(apiServiceProvider),
|
|
),
|
|
);
|