image_url_builder.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:hive/hive.dart';
  2. import 'package:openapi/api.dart';
  3. import '../constants/hive_box.dart';
  4. String getThumbnailUrl(
  5. final AssetResponseDto asset, {
  6. ThumbnailFormat type = ThumbnailFormat.WEBP,
  7. }) {
  8. return _getThumbnailUrl(asset.id, type: type);
  9. }
  10. String getThumbnailCacheKey(
  11. final AssetResponseDto asset, {
  12. ThumbnailFormat type = ThumbnailFormat.WEBP,
  13. }) {
  14. return _getThumbnailCacheKey(asset.id, type);
  15. }
  16. String _getThumbnailCacheKey(final String id, final ThumbnailFormat type) {
  17. if (type == ThumbnailFormat.WEBP) {
  18. return 'thumbnail-image-$id';
  19. } else {
  20. return '${id}_previewStage';
  21. }
  22. }
  23. String getAlbumThumbnailUrl(
  24. final AlbumResponseDto album, {
  25. ThumbnailFormat type = ThumbnailFormat.WEBP,
  26. }) {
  27. if (album.albumThumbnailAssetId == null) {
  28. return '';
  29. }
  30. return _getThumbnailUrl(album.albumThumbnailAssetId!, type: type);
  31. }
  32. String getAlbumThumbNailCacheKey(
  33. final AlbumResponseDto album, {
  34. ThumbnailFormat type = ThumbnailFormat.WEBP,
  35. }) {
  36. if (album.albumThumbnailAssetId == null) {
  37. return '';
  38. }
  39. return _getThumbnailCacheKey(album.albumThumbnailAssetId!, type);
  40. }
  41. String getImageUrl(final AssetResponseDto asset) {
  42. final box = Hive.box(userInfoBox);
  43. return '${box.get(serverEndpointKey)}/asset/file/${asset.id}?isThumb=false';
  44. }
  45. String getImageCacheKey(final AssetResponseDto asset) {
  46. return '${asset.id}_fullStage';
  47. }
  48. String _getThumbnailUrl(
  49. final String id, {
  50. ThumbnailFormat type = ThumbnailFormat.WEBP,
  51. }) {
  52. final box = Hive.box(userInfoBox);
  53. return '${box.get(serverEndpointKey)}/asset/thumbnail/$id?format=${type.value}';
  54. }