image_url_builder.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:immich_mobile/shared/models/album.dart';
  2. import 'package:immich_mobile/shared/models/asset.dart';
  3. import 'package:immich_mobile/shared/models/store.dart';
  4. import 'package:isar/isar.dart';
  5. import 'package:openapi/api.dart';
  6. String getThumbnailUrl(
  7. final Asset asset, {
  8. ThumbnailFormat type = ThumbnailFormat.WEBP,
  9. }) {
  10. return getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
  11. }
  12. String getThumbnailCacheKey(
  13. final Asset asset, {
  14. ThumbnailFormat type = ThumbnailFormat.WEBP,
  15. }) {
  16. return getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
  17. }
  18. String getThumbnailCacheKeyForRemoteId(
  19. final String id, {
  20. ThumbnailFormat type = ThumbnailFormat.WEBP,
  21. }) {
  22. if (type == ThumbnailFormat.WEBP) {
  23. return 'thumbnail-image-$id';
  24. } else {
  25. return '${id}_previewStage';
  26. }
  27. }
  28. String getAlbumThumbnailUrl(
  29. final Album album, {
  30. ThumbnailFormat type = ThumbnailFormat.WEBP,
  31. }) {
  32. if (album.thumbnail.value?.remoteId == null) {
  33. return '';
  34. }
  35. return getThumbnailUrlForRemoteId(
  36. album.thumbnail.value!.remoteId!,
  37. type: type,
  38. );
  39. }
  40. String getAlbumThumbNailCacheKey(
  41. final Album album, {
  42. ThumbnailFormat type = ThumbnailFormat.WEBP,
  43. }) {
  44. if (album.thumbnail.value?.remoteId == null) {
  45. return '';
  46. }
  47. return getThumbnailCacheKeyForRemoteId(
  48. album.thumbnail.value!.remoteId!,
  49. type: type,
  50. );
  51. }
  52. String getImageUrl(final Asset asset) {
  53. return '${Store.get(StoreKey.serverEndpoint)}/asset/file/${asset.remoteId}?isThumb=false';
  54. }
  55. String getImageCacheKey(final Asset asset) {
  56. // Assets from response DTOs do not have an isar id, querying which would give us the default autoIncrement id
  57. final isFromDto = asset.id == Isar.autoIncrement;
  58. return '${isFromDto ? asset.remoteId : asset.id}_fullStage';
  59. }
  60. String getThumbnailUrlForRemoteId(
  61. final String id, {
  62. ThumbnailFormat type = ThumbnailFormat.WEBP,
  63. }) {
  64. return '${Store.get(StoreKey.serverEndpoint)}/asset/thumbnail/$id?format=${type.value}';
  65. }
  66. String getFaceThumbnailUrl(final String personId) {
  67. return '${Store.get(StoreKey.serverEndpoint)}/person/$personId/thumbnail';
  68. }