1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00
immich/mobile/lib/utils/image_url_builder.dart
Fynn Petersen-Frey 202082f62e
refactor(mobile): use repositories in a number of services (#12891)
* UserService
* PartnerService
* HashService
* MemoryService
* PersonService
* SearchService
* StackService
2024-09-24 12:50:21 +00:00

77 lines
2.1 KiB
Dart

import 'package:immich_mobile/constants/constants.dart';
import 'package:immich_mobile/entities/album.entity.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:openapi/api.dart';
String getThumbnailUrl(
final Asset asset, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
return getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
}
String getThumbnailCacheKey(
final Asset asset, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
return getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
}
String getThumbnailCacheKeyForRemoteId(
final String id, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
if (type == AssetMediaSize.thumbnail) {
return 'thumbnail-image-$id';
} else {
return '${id}_previewStage';
}
}
String getAlbumThumbnailUrl(
final Album album, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
if (album.thumbnail.value?.remoteId == null) {
return '';
}
return getThumbnailUrlForRemoteId(
album.thumbnail.value!.remoteId!,
type: type,
);
}
String getAlbumThumbNailCacheKey(
final Album album, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
if (album.thumbnail.value?.remoteId == null) {
return '';
}
return getThumbnailCacheKeyForRemoteId(
album.thumbnail.value!.remoteId!,
type: type,
);
}
String getOriginalUrlForRemoteId(final String id) {
return '${Store.get(StoreKey.serverEndpoint)}/assets/$id/original';
}
String getImageCacheKey(final Asset asset) {
// Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
final isFromDto = asset.id == noDbId;
return '${isFromDto ? asset.remoteId : asset.id}_fullStage';
}
String getThumbnailUrlForRemoteId(
final String id, {
AssetMediaSize type = AssetMediaSize.thumbnail,
}) {
return '${Store.get(StoreKey.serverEndpoint)}/assets/$id/thumbnail?size=${type.value}';
}
String getFaceThumbnailUrl(final String personId) {
return '${Store.get(StoreKey.serverEndpoint)}/people/$personId/thumbnail';
}