2024-09-24 12:50:21 +00:00
|
|
|
import 'package:immich_mobile/constants/constants.dart';
|
2024-05-01 02:36:40 +00:00
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
2022-08-08 00:43:09 +00:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
2022-08-21 16:41:36 +00:00
|
|
|
String getThumbnailUrl(
|
2023-02-04 20:42:42 +00:00
|
|
|
final Asset asset, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2022-08-21 16:41:36 +00:00
|
|
|
}) {
|
2023-08-27 05:07:35 +00:00
|
|
|
return getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
|
2022-08-21 16:41:36 +00:00
|
|
|
}
|
2022-08-08 00:43:09 +00:00
|
|
|
|
2023-01-26 14:40:19 +00:00
|
|
|
String getThumbnailCacheKey(
|
2023-02-04 20:42:42 +00:00
|
|
|
final Asset asset, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2023-01-26 14:40:19 +00:00
|
|
|
}) {
|
2023-08-27 05:07:35 +00:00
|
|
|
return getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
|
2022-12-04 03:59:39 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 05:07:35 +00:00
|
|
|
String getThumbnailCacheKeyForRemoteId(
|
|
|
|
final String id, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2023-08-27 05:07:35 +00:00
|
|
|
}) {
|
2024-05-31 17:44:04 +00:00
|
|
|
if (type == AssetMediaSize.thumbnail) {
|
2022-12-04 03:59:39 +00:00
|
|
|
return 'thumbnail-image-$id';
|
|
|
|
} else {
|
|
|
|
return '${id}_previewStage';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 16:41:36 +00:00
|
|
|
String getAlbumThumbnailUrl(
|
2023-02-06 07:13:32 +00:00
|
|
|
final Album album, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2022-08-21 16:41:36 +00:00
|
|
|
}) {
|
2023-03-03 22:38:30 +00:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-08-21 16:41:36 +00:00
|
|
|
return '';
|
|
|
|
}
|
2023-10-29 20:28:54 +00:00
|
|
|
return getThumbnailUrlForRemoteId(
|
|
|
|
album.thumbnail.value!.remoteId!,
|
|
|
|
type: type,
|
|
|
|
);
|
2022-08-08 00:43:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 03:59:39 +00:00
|
|
|
String getAlbumThumbNailCacheKey(
|
2023-02-06 07:13:32 +00:00
|
|
|
final Album album, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2022-12-04 03:59:39 +00:00
|
|
|
}) {
|
2023-03-03 22:38:30 +00:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-12-04 03:59:39 +00:00
|
|
|
return '';
|
|
|
|
}
|
2023-08-27 05:07:35 +00:00
|
|
|
return getThumbnailCacheKeyForRemoteId(
|
|
|
|
album.thumbnail.value!.remoteId!,
|
|
|
|
type: type,
|
|
|
|
);
|
2022-12-04 03:59:39 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 19:52:19 +00:00
|
|
|
String getOriginalUrlForRemoteId(final String id) {
|
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/assets/$id/original';
|
2022-08-08 00:43:09 +00:00
|
|
|
}
|
2022-08-21 16:41:36 +00:00
|
|
|
|
2023-02-04 20:42:42 +00:00
|
|
|
String getImageCacheKey(final Asset asset) {
|
2023-10-29 20:28:54 +00:00
|
|
|
// Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
|
2024-09-24 12:50:21 +00:00
|
|
|
final isFromDto = asset.id == noDbId;
|
2023-10-29 20:28:54 +00:00
|
|
|
return '${isFromDto ? asset.remoteId : asset.id}_fullStage';
|
2022-12-04 03:59:39 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 05:07:35 +00:00
|
|
|
String getThumbnailUrlForRemoteId(
|
2022-10-14 16:15:19 +00:00
|
|
|
final String id, {
|
2024-05-31 17:44:04 +00:00
|
|
|
AssetMediaSize type = AssetMediaSize.thumbnail,
|
2022-10-14 16:15:19 +00:00
|
|
|
}) {
|
2024-06-08 10:50:14 +00:00
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/assets/$id/thumbnail?size=${type.value}';
|
2022-08-21 16:41:36 +00:00
|
|
|
}
|
2023-06-23 15:44:02 +00:00
|
|
|
|
|
|
|
String getFaceThumbnailUrl(final String personId) {
|
2024-05-22 17:24:57 +00:00
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/people/$personId/thumbnail';
|
2023-06-23 15:44:02 +00:00
|
|
|
}
|