2022-08-08 02:43:09 +02:00
|
|
|
import 'package:hive/hive.dart';
|
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';
|
2022-08-08 02:43:09 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
import '../constants/hive_box.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-02-04 22:42:42 +02:00
|
|
|
return _getThumbnailUrl(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-02-06 09:13:32 +02:00
|
|
|
return _getThumbnailCacheKey(asset.remoteId!, type);
|
2022-12-04 05:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String _getThumbnailCacheKey(final String id, final ThumbnailFormat type) {
|
|
|
|
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,
|
|
|
|
}) {
|
|
|
|
if (album.albumThumbnailAssetId == null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return _getThumbnailUrl(album.albumThumbnailAssetId!, 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,
|
|
|
|
}) {
|
|
|
|
if (album.albumThumbnailAssetId == null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return _getThumbnailCacheKey(album.albumThumbnailAssetId!, type);
|
|
|
|
}
|
|
|
|
|
2023-02-04 22:42:42 +02:00
|
|
|
String getImageUrl(final Asset asset) {
|
2022-08-08 02:43:09 +02:00
|
|
|
final box = Hive.box(userInfoBox);
|
2023-02-04 22:42:42 +02:00
|
|
|
return '${box.get(serverEndpointKey)}/asset/file/${asset.remoteId}?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) {
|
2022-12-04 05:59:39 +02:00
|
|
|
return '${asset.id}_fullStage';
|
|
|
|
}
|
|
|
|
|
2022-10-14 18:15:19 +02:00
|
|
|
String _getThumbnailUrl(
|
|
|
|
final String id, {
|
|
|
|
ThumbnailFormat type = ThumbnailFormat.WEBP,
|
|
|
|
}) {
|
2022-08-21 18:41:36 +02:00
|
|
|
final box = Hive.box(userInfoBox);
|
|
|
|
|
2022-10-14 18:15:19 +02:00
|
|
|
return '${box.get(serverEndpointKey)}/asset/thumbnail/$id?format=${type.value}';
|
2022-08-21 18:41:36 +02:00
|
|
|
}
|