From 8f5214724cdc58b0e4c39f6745f53ed889b5c6e1 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey <10599762+fyfrey@users.noreply.github.com> Date: Wed, 14 Jun 2023 16:35:32 +0200 Subject: [PATCH] feat(mobile): sync remote assets without thumbs (#2705) --- mobile/lib/shared/services/asset.service.dart | 7 +++++-- mobile/lib/shared/ui/immich_image.dart | 9 +++++++-- mobile/lib/utils/openapi_extensions.dart | 6 ++++++ mobile/pubspec.lock | 2 +- mobile/pubspec.yaml | 1 + 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mobile/lib/shared/services/asset.service.dart b/mobile/lib/shared/services/asset.service.dart index 6981cc5251..ce64a558a8 100644 --- a/mobile/lib/shared/services/asset.service.dart +++ b/mobile/lib/shared/services/asset.service.dart @@ -66,8 +66,11 @@ class AssetService { try { final etag = hasCache ? _db.eTags.getByIdSync(user.id)?.value : null; final (List? assets, String? newETag) = - await _apiService.assetApi - .getAllAssetsWithETag(eTag: etag, userId: user.id); + await _apiService.assetApi.getAllAssetsWithETag( + eTag: etag, + userId: user.id, + withoutThumbs: true, + ); if (assets == null) { return null; } else if (assets.isNotEmpty && assets.first.ownerId != user.id) { diff --git a/mobile/lib/shared/ui/immich_image.dart b/mobile/lib/shared/ui/immich_image.dart index 95308c5e61..223319207b 100644 --- a/mobile/lib/shared/ui/immich_image.dart +++ b/mobile/lib/shared/ui/immich_image.dart @@ -1,6 +1,7 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/models/store.dart'; import 'package:immich_mobile/utils/image_url_builder.dart'; @@ -110,8 +111,12 @@ class ImmichImage extends StatelessWidget { ); }, errorWidget: (context, url, error) { - debugPrint("Error getting thumbnail $url = $error"); - CachedNetworkImage.evictFromCache(thumbnailRequestUrl); + if (error is HttpExceptionWithStatus && + error.statusCode >= 400 && + error.statusCode < 500) { + debugPrint("Evicting thumbnail '$url' from cache: $error"); + CachedNetworkImage.evictFromCache(url); + } return Icon( Icons.image_not_supported_outlined, color: Theme.of(context).primaryColor, diff --git a/mobile/lib/utils/openapi_extensions.dart b/mobile/lib/utils/openapi_extensions.dart index 435410a344..0fd3f2be5d 100644 --- a/mobile/lib/utils/openapi_extensions.dart +++ b/mobile/lib/utils/openapi_extensions.dart @@ -15,10 +15,16 @@ extension WithETag on AssetApi { Future<(List? assets, String? eTag)> getAllAssetsWithETag({ String? eTag, String? userId, + bool? isFavorite, + bool? isArchived, + bool? withoutThumbs, }) async { final response = await getAllAssetsWithHttpInfo( ifNoneMatch: eTag, userId: userId, + isFavorite: isFavorite, + isArchived: isArchived, + withoutThumbs: withoutThumbs, ); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, await _decodeBodyBytes(response)); diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index 71585f92e7..1be8f40576 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -367,7 +367,7 @@ packages: source: hosted version: "0.7.0" flutter_cache_manager: - dependency: transitive + dependency: "direct main" description: name: flutter_cache_manager sha256: "32cd900555219333326a2d0653aaaf8671264c29befa65bbd9856d204a4c9fb3" diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index 0a5aa1350d..a7b85c3e67 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: flutter_hooks: ^0.18.6 hooks_riverpod: ^2.2.0 cached_network_image: ^3.2.2 + flutter_cache_manager: ^3.3.0 intl: ^0.18.0 auto_route: ^5.0.1 fluttertoast: ^8.0.8