A cross platform Audiobookshelf client for Android and iOS
Dart
Bust cached covers when updated on the server
Nathan Poulsonbc9a5f66de4f
diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dartindex 37233026..baf161ac 100644--- a/lib/providers/library_provider.dart+++ b/lib/providers/library_provider.dart@@ -27,6 +27,9 @@ class LibraryProvider extends ChangeNotifier {bool _isLoadingSeries = false;String? _errorMessage;+ // Cache of item updatedAt timestamps for cover cache-busting+ final Map<String, int> _itemUpdatedAt = {};+// Fetch deduplication for loadPersonalizedViewFuture<void>? _personalizedInFlight;DateTime? _lastPersonalizedFetchAt;@@ -321,6 +324,7 @@ class LibraryProvider extends ChangeNotifier {_manualAbsorbRemoves.clear();_absorbingBookIds.clear();_absorbingItemCache.clear();+ _itemUpdatedAt.clear();_personalizedInFlight = null;_lastPersonalizedFetchAt = null;_lastPersonalizedFetchLibraryId = null;@@ -366,6 +370,7 @@ class LibraryProvider extends ChangeNotifier {_series = [];_progressMap = {};_localProgressOverrides.clear();+ _itemUpdatedAt.clear();_selectedLibraryId = null;_errorMessage = null;_connectivitySub?.cancel();@@ -581,6 +586,16 @@ class LibraryProvider extends ChangeNotifier {await _refreshProgress();_personalizedSections =await _api!.getPersonalizedView(_selectedLibraryId!);+ // Cache updatedAt timestamps for cover cache-busting+ for (final section in _personalizedSections) {+ for (final e in (section['entities'] as List<dynamic>? ?? [])) {+ if (e is Map<String, dynamic>) {+ final id = e['id'] as String?;+ final ts = e['updatedAt'] as num?;+ if (id != null && ts != null) _itemUpdatedAt[id] = ts.toInt();+ }+ }+ }await _updateAbsorbingCache();} catch (e) {if (_isLikelyNetworkError(e)) {@@ -693,6 +708,9 @@ class LibraryProvider extends ChangeNotifier {notifyListeners();}+ /// Register an item's updatedAt timestamp for cover cache-busting.+ void registerUpdatedAt(String id, int ts) => _itemUpdatedAt[id] = ts;+/// Build a cover URL for an item./// When offline, prefers the locally cached cover file./// For podcast episodes stored under composite keys (e.g. "showId-epId"),@@ -707,7 +725,8 @@ class LibraryProvider extends ChangeNotifier {// Try API first when onlineif (_api != null && !isOffline) {- return _api!.getCoverUrl(apiItemId, width: width);+ final ts = _itemUpdatedAt[apiItemId];+ return _api!.getCoverUrl(apiItemId, width: width, updatedAt: ts);}// Offline or no API: prefer local cover pathdiff --git a/lib/screens/library_screen.dart b/lib/screens/library_screen.dartindex e0947c64..05385a17 100644--- a/lib/screens/library_screen.dart+++ b/lib/screens/library_screen.dart@@ -294,6 +294,10 @@ class LibraryScreenState extends State<LibraryScreen> {_totalItems = total;for (final r in results) {if (r is Map<String, dynamic>) {+ // Register updatedAt for cover cache-busting+ final id = r['id'] as String?;+ final ts = r['updatedAt'] as num?;+ if (id != null && ts != null) lib.registerUpdatedAt(id, ts.toInt());// Client-side filtersif (_filter == LibraryFilter.downloaded) {final id = r['id'] as String? ?? '';diff --git a/lib/services/api_service.dart b/lib/services/api_service.dartindex 412e22c2..ff880776 100644--- a/lib/services/api_service.dart+++ b/lib/services/api_service.dart@@ -188,8 +188,10 @@ class ApiService {}/// Build a cover image URL for a library item.- String getCoverUrl(String itemId, {int width = 400}) {- return '$_cleanBaseUrl/api/items/$itemId/cover?width=$width&token=$token';+ String getCoverUrl(String itemId, {int width = 400, int? updatedAt}) {+ var url = '$_cleanBaseUrl/api/items/$itemId/cover?width=$width&token=$token';+ if (updatedAt != null) url += '&ts=$updatedAt';+ return url;}/// Get current user info including all mediaProgress.@@ -264,8 +266,10 @@ class ApiService {}/// Build an author image URL.- String getAuthorImageUrl(String authorId, {int width = 200}) {- return '$_cleanBaseUrl/api/authors/$authorId/image?width=$width&token=$token';+ String getAuthorImageUrl(String authorId, {int width = 200, int? updatedAt}) {+ var url = '$_cleanBaseUrl/api/authors/$authorId/image?width=$width&token=$token';+ if (updatedAt != null) url += '&ts=$updatedAt';+ return url;}/// Get a library's filter data (authors, series, genres, etc.)diff --git a/lib/widgets/absorbing_card.dart b/lib/widgets/absorbing_card.dartindex 9a2f222a..a3db1724 100644--- a/lib/widgets/absorbing_card.dart+++ b/lib/widgets/absorbing_card.dart@@ -41,6 +41,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCliStreamSubscription<Duration>? _chapterTrackSub;int _lastChapterIdx = -1;ui.Image? _blurredCover; // Precached blurred background+ String? _blurredCoverUrl; // URL the blur was built fromList<String> _buttonOrder = PlayerSettings.defaultButtonOrder;@override@@ -246,6 +247,7 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveCli_rederiveCoverScheme();// Precache the blurred version of the coverif (_blurredCover == null) {+ _blurredCoverUrl = _coverUrl;_precacheBlur(provider);}}@@ -355,6 +357,12 @@ class AbsorbingCardState extends State<AbsorbingCard> with AutomaticKeepAliveClibookProgress = progress;}+ // Invalidate blurred background when cover URL changes (e.g. after server update)+ if (_blurredCover != null && _blurredCoverUrl != _coverUrl) {+ _blurredCover?.dispose();+ _blurredCover = null;+ }+return Container(decoration: BoxDecoration(borderRadius: BorderRadius.circular(24),diff --git a/lib/widgets/author_card.dart b/lib/widgets/author_card.dartindex 613049ea..727440f4 100644--- a/lib/widgets/author_card.dart+++ b/lib/widgets/author_card.dart@@ -20,9 +20,9 @@ class AuthorCard extends StatelessWidget {final authorId = author['id'] as String? ?? '';String? imageUrl;- if (authorId.isNotEmpty && auth.serverUrl != null && auth.token != null) {- imageUrl =- '${auth.serverUrl}/api/authors/$authorId/image?width=200&token=${auth.token}';+ if (authorId.isNotEmpty && auth.apiService != null) {+ final ts = (author['updatedAt'] as num?)?.toInt();+ imageUrl = auth.apiService!.getAuthorImageUrl(authorId, updatedAt: ts);}final headers = lib.mediaHeaders;diff --git a/lib/widgets/library_search_results.dart b/lib/widgets/library_search_results.dartindex 25d9ea50..6c6cc799 100644--- a/lib/widgets/library_search_results.dart+++ b/lib/widgets/library_search_results.dart@@ -37,6 +37,8 @@ class BookResultTile extends StatelessWidget {? serverUrl!.substring(0, serverUrl!.length - 1): serverUrl!;coverUrl = '$cleanUrl/api/items/$itemId/cover?width=200&token=$token';+ final ts = item['updatedAt'] as num?;+ if (ts != null) coverUrl = '$coverUrl&ts=${ts.toInt()}';}return Padding(@@ -234,6 +236,8 @@ class AuthorResultTile extends StatelessWidget {: serverUrl!;imageUrl ='$cleanUrl/api/authors/$authorId/image?width=200&token=$token';+ final ts = author['updatedAt'] as num?;+ if (ts != null) imageUrl = '$imageUrl&ts=${ts.toInt()}';}return Padding(