2024-09-24 14:50:21 +02:00
|
|
|
import 'package:immich_mobile/constants/constants.dart';
|
2025-02-20 00:57:32 +05:30
|
|
|
import 'package:immich_mobile/domain/models/store.model.dart';
|
2024-04-30 21:36:40 -05: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 02:43:09 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getThumbnailUrl(final Asset asset, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2023-08-27 05:07:35 +00:00
|
|
|
return getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
|
2022-08-21 18:41:36 +02:00
|
|
|
}
|
2022-08-08 02:43:09 +02:00
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getThumbnailCacheKey(final Asset asset, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2023-08-27 05:07:35 +00:00
|
|
|
return getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
|
2022-12-04 04:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getThumbnailCacheKeyForRemoteId(final String id, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2024-05-31 13:44:04 -04:00
|
|
|
if (type == AssetMediaSize.thumbnail) {
|
2022-12-04 04:59:39 +01:00
|
|
|
return 'thumbnail-image-$id';
|
|
|
|
|
} else {
|
|
|
|
|
return '${id}_previewStage';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getAlbumThumbnailUrl(final Album album, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2023-03-03 23:38:30 +01:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-08-21 18:41:36 +02:00
|
|
|
return '';
|
|
|
|
|
}
|
2025-07-29 00:34:03 +05:30
|
|
|
return getThumbnailUrlForRemoteId(album.thumbnail.value!.remoteId!, type: type);
|
2022-08-08 02:43:09 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getAlbumThumbNailCacheKey(final Album album, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2023-03-03 23:38:30 +01:00
|
|
|
if (album.thumbnail.value?.remoteId == null) {
|
2022-12-04 04:59:39 +01:00
|
|
|
return '';
|
|
|
|
|
}
|
2025-07-29 00:34:03 +05:30
|
|
|
return getThumbnailCacheKeyForRemoteId(album.thumbnail.value!.remoteId!, type: type);
|
2022-12-04 04:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-14 14:52:19 -05:00
|
|
|
String getOriginalUrlForRemoteId(final String id) {
|
2025-07-31 13:38:14 -05:00
|
|
|
return ImageUrlBuilder.build('/assets/$id/original');
|
2022-08-08 02:43:09 +02:00
|
|
|
}
|
2022-08-21 18:41:36 +02:00
|
|
|
|
2023-02-04 21:42:42 +01: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 14:50:21 +02:00
|
|
|
final isFromDto = asset.id == noDbId;
|
2023-10-29 20:28:54 +00:00
|
|
|
return '${isFromDto ? asset.remoteId : asset.id}_fullStage';
|
2022-12-04 04:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 00:34:03 +05:30
|
|
|
String getThumbnailUrlForRemoteId(final String id, {AssetMediaSize type = AssetMediaSize.thumbnail}) {
|
2025-07-31 13:38:14 -05:00
|
|
|
return ImageUrlBuilder.build('/assets/$id/thumbnail?size=${type.value}');
|
2022-08-21 18:41:36 +02:00
|
|
|
}
|
2023-06-23 10:44:02 -05:00
|
|
|
|
2025-07-31 13:38:14 -05:00
|
|
|
String getPreviewUrlForRemoteId(final String id) {
|
|
|
|
|
return ImageUrlBuilder.build('/assets/$id/thumbnail?size=${AssetMediaSize.preview}');
|
|
|
|
|
}
|
2025-07-02 23:54:37 +05:30
|
|
|
|
2025-06-08 21:55:23 -05:00
|
|
|
String getPlaybackUrlForRemoteId(final String id) {
|
2025-07-31 13:38:14 -05:00
|
|
|
return ImageUrlBuilder.build('/assets/$id/video/playback?');
|
2025-06-08 21:55:23 -05:00
|
|
|
}
|
|
|
|
|
|
2023-06-23 10:44:02 -05:00
|
|
|
String getFaceThumbnailUrl(final String personId) {
|
2025-07-31 13:38:14 -05:00
|
|
|
return ImageUrlBuilder.build('/people/$personId/thumbnail');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ImageUrlBuilder {
|
|
|
|
|
static String? host;
|
|
|
|
|
static Map<String, String>? queryParams;
|
|
|
|
|
|
|
|
|
|
static void setHost(String? host) {
|
|
|
|
|
ImageUrlBuilder.host = host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isSharedLink() {
|
|
|
|
|
return ImageUrlBuilder.host != null && ImageUrlBuilder.queryParams!.containsKey('key');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void setParameter(String key, String value) {
|
|
|
|
|
ImageUrlBuilder.queryParams ??= {};
|
|
|
|
|
ImageUrlBuilder.queryParams![key] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static String build(String path) {
|
|
|
|
|
final endpoint = host ?? Store.get(StoreKey.serverEndpoint);
|
|
|
|
|
|
|
|
|
|
final uri = Uri.parse('$endpoint$path');
|
|
|
|
|
if (queryParams == null || queryParams!.isEmpty) {
|
|
|
|
|
return uri.toString();
|
|
|
|
|
}
|
|
|
|
|
final updatedUri = uri.replace(queryParameters: {...uri.queryParameters, ...queryParams!});
|
|
|
|
|
return updatedUri.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear() {
|
|
|
|
|
ImageUrlBuilder.host = null;
|
|
|
|
|
ImageUrlBuilder.queryParams = null;
|
|
|
|
|
}
|
2023-06-23 10:44:02 -05:00
|
|
|
}
|