2023-02-06 09:13:32 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2023-02-04 22:42:42 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-10-29 22:28:54 +02:00
|
|
|
import 'package:isar/isar.dart';
|
2022-08-08 02:43:09 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
2022-08-21 18:41:36 +02:00
|
|
|
String getThumbnailUrl(
|
2023-02-04 22:42:42 +02:00
|
|
|
final Asset asset, {
|
2022-08-21 18:41:36 +02:00
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2023-08-27 07:07:35 +02:00
|
|
|
return getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
|
2022-08-21 18:41:36 +02:00
|
|
|
}
|
2022-08-08 02:43:09 +02:00
|
|
|
|
2023-01-26 16:40:19 +02:00
|
|
|
String getThumbnailCacheKey(
|
2023-02-04 22:42:42 +02:00
|
|
|
final Asset asset, {
|
2023-01-26 16:40:19 +02:00
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2023-08-27 07:07:35 +02:00
|
|
|
return getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
|
2022-12-04 05:59:39 +02:00
|
|
|
}
|
|
|
|
|
2023-08-27 07:07:35 +02:00
|
|
|
String getThumbnailCacheKeyForRemoteId(
|
|
|
|
final String id, {
|
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2022-12-04 05:59:39 +02:00
|
|
|
if (type == ThumbnailFormat.WEBP) {
|
|
|
|
return 'thumbnail-image-$id';
|
|
|
|
} else {
|
|
|
|
return '${id}_previewStage';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 18:41:36 +02:00
|
|
|
String getAlbumThumbnailUrl(
|
2023-02-06 09:13:32 +02:00
|
|
|
final Album album, {
|
2022-08-21 18:41:36 +02:00
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2023-03-04 00:38:30 +02:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-08-21 18:41:36 +02:00
|
|
|
return '';
|
|
|
|
}
|
2023-10-29 22:28:54 +02:00
|
|
|
return getThumbnailUrlForRemoteId(
|
|
|
|
album.thumbnail.value!.remoteId!,
|
|
|
|
type: type,
|
|
|
|
);
|
2022-08-08 02:43:09 +02:00
|
|
|
}
|
|
|
|
|
2022-12-04 05:59:39 +02:00
|
|
|
String getAlbumThumbNailCacheKey(
|
2023-02-06 09:13:32 +02:00
|
|
|
final Album album, {
|
2022-12-04 05:59:39 +02:00
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2023-03-04 00:38:30 +02:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-12-04 05:59:39 +02:00
|
|
|
return '';
|
|
|
|
}
|
2023-08-27 07:07:35 +02:00
|
|
|
return getThumbnailCacheKeyForRemoteId(
|
|
|
|
album.thumbnail.value!.remoteId!,
|
|
|
|
type: type,
|
|
|
|
);
|
2022-12-04 05:59:39 +02:00
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
String getImageUrl(final Asset asset) {
|
2024-02-13 23:30:32 +02:00
|
|
|
return getImageUrlFromId(asset.remoteId!);
|
|
|
|
}
|
|
|
|
|
|
|
|
String getImageUrlFromId(final String id) {
|
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/asset/file/$id?isThumb=false';
|
2022-08-08 02:43:09 +02:00
|
|
|
}
|
2022-08-21 18:41:36 +02:00
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
String getImageCacheKey(final Asset asset) {
|
2023-10-29 22:28:54 +02:00
|
|
|
// Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
|
|
|
|
final isFromDto = asset.id == Isar.autoIncrement;
|
|
|
|
return '${isFromDto ? asset.remoteId : asset.id}_fullStage';
|
2022-12-04 05:59:39 +02:00
|
|
|
}
|
|
|
|
|
2023-08-27 07:07:35 +02:00
|
|
|
String getThumbnailUrlForRemoteId(
|
2022-10-14 18:15:19 +02:00
|
|
|
final String id, {
|
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2023-03-23 03:36:44 +02:00
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/asset/thumbnail/$id?format=${type.value}';
|
2022-08-21 18:41:36 +02:00
|
|
|
}
|
2023-06-23 17:44:02 +02:00
|
|
|
|
|
|
|
String getFaceThumbnailUrl(final String personId) {
|
|
|
|
return '${Store.get(StoreKey.serverEndpoint)}/person/$personId/thumbnail';
|
|
|
|
}
|