image_url_builder.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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:openapi/api.dart';
  5. String getThumbnailUrl(
  6. final Asset asset, {
  7. ThumbnailFormat type = ThumbnailFormat.WEBP,
  8. }) {
  9. return _getThumbnailUrl(asset.remoteId!, type: type);
  10. }
  11. String getThumbnailCacheKey(
  12. final Asset asset, {
  13. ThumbnailFormat type = ThumbnailFormat.WEBP,
  14. }) {
  15. return _getThumbnailCacheKey(asset.remoteId!, type);
  16. }
  17. String _getThumbnailCacheKey(final String id, final ThumbnailFormat type) {
  18. if (type == ThumbnailFormat.WEBP) {
  19. return 'thumbnail-image-$id';
  20. } else {
  21. return '${id}_previewStage';
  22. }
  23. }
  24. String getAlbumThumbnailUrl(
  25. final Album album, {
  26. ThumbnailFormat type = ThumbnailFormat.WEBP,
  27. }) {
  28. if (album.thumbnail.value?.remoteId == null) {
  29. return '';
  30. }
  31. return _getThumbnailUrl(album.thumbnail.value!.remoteId!, type: type);
  32. }
  33. String getAlbumThumbNailCacheKey(
  34. final Album album, {
  35. ThumbnailFormat type = ThumbnailFormat.WEBP,
  36. }) {
  37. if (album.thumbnail.value?.remoteId == null) {
  38. return '';
  39. }
  40. return _getThumbnailCacheKey(album.thumbnail.value!.remoteId!, type);
  41. }
  42. String getImageUrl(final Asset asset) {
  43. return '${Store.get(StoreKey.serverEndpoint)}/asset/file/${asset.remoteId}?isThumb=false';
  44. }
  45. String getImageCacheKey(final Asset asset) {
  46. return '${asset.id}_fullStage';
  47. }
  48. String _getThumbnailUrl(
  49. final String id, {
  50. ThumbnailFormat type = ThumbnailFormat.WEBP,
  51. }) {
  52. return '${Store.get(StoreKey.serverEndpoint)}/asset/thumbnail/$id?format=${type.value}';
  53. }