refactor: type server identifiers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import '../media/ids.dart';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
@@ -39,7 +40,7 @@ class PlexApiCache extends ApiCache {
|
||||
|
||||
/// Delete cached data for a specific item (when removing a download).
|
||||
@override
|
||||
Future<void> deleteForItem(String serverId, String ratingKey) async {
|
||||
Future<void> deleteForItem(ServerId serverId, String ratingKey) async {
|
||||
final metadataKey = '$serverId:/library/metadata/$ratingKey';
|
||||
final childrenKey = '$serverId:/library/metadata/$ratingKey/children';
|
||||
|
||||
@@ -49,11 +50,11 @@ class PlexApiCache extends ApiCache {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pinForOffline(String serverId, String ratingKey) async {
|
||||
Future<void> pinForOffline(ServerId serverId, String ratingKey) async {
|
||||
return pin(serverId, '/library/metadata/$ratingKey');
|
||||
}
|
||||
|
||||
Future<void> unpinForOffline(String serverId, String ratingKey) async {
|
||||
Future<void> unpinForOffline(ServerId serverId, String ratingKey) async {
|
||||
return unpin(serverId, '/library/metadata/$ratingKey');
|
||||
}
|
||||
|
||||
@@ -61,14 +62,14 @@ class PlexApiCache extends ApiCache {
|
||||
///
|
||||
/// Named `isPinnedRatingKey` to avoid colliding with the inherited
|
||||
/// [ApiCache.isPinned]'s identical Dart signature.
|
||||
Future<bool> isPinnedRatingKey(String serverId, String ratingKey) {
|
||||
Future<bool> isPinnedRatingKey(ServerId serverId, String ratingKey) {
|
||||
return isPinned(serverId, '/library/metadata/$ratingKey');
|
||||
}
|
||||
|
||||
// Rating keys can be alphanumeric, not just numeric.
|
||||
static final RegExp _metadataKeyPattern = RegExp(r'/library/metadata/([^/]+)$');
|
||||
|
||||
Future<Set<String>> getPinnedKeys(String serverId) => extractPinnedIds(serverId, _metadataKeyPattern);
|
||||
Future<Set<String>> getPinnedKeys(ServerId serverId) => extractPinnedIds(serverId, _metadataKeyPattern);
|
||||
|
||||
/// Fetch and parse a [MediaItem] from cache.
|
||||
///
|
||||
@@ -77,7 +78,7 @@ class PlexApiCache extends ApiCache {
|
||||
/// [MediaItem] at the boundary. Returns `null` when the endpoint is not
|
||||
/// cached or contains no metadata.
|
||||
@override
|
||||
Future<MediaItem?> getMetadata(String serverId, String ratingKey) async {
|
||||
Future<MediaItem?> getMetadata(ServerId serverId, String ratingKey) async {
|
||||
final cached = await get(serverId, '/library/metadata/$ratingKey');
|
||||
final container = PlexCacheParser.extractMediaContainer(cached);
|
||||
final json = PlexCacheParser.extractFirstMetadata(cached);
|
||||
@@ -108,7 +109,7 @@ class PlexApiCache extends ApiCache {
|
||||
/// callers passing them have a more accurate read of server state.
|
||||
@override
|
||||
Future<void> applyWatchState({
|
||||
required String serverId,
|
||||
required ServerId serverId,
|
||||
required String itemId,
|
||||
required bool isWatched,
|
||||
int? viewOffsetMs,
|
||||
@@ -116,7 +117,7 @@ class PlexApiCache extends ApiCache {
|
||||
int? viewedLeafCount,
|
||||
}) async {
|
||||
final endpoint = '/library/metadata/$itemId';
|
||||
final cached = await get(serverId, endpoint);
|
||||
final cached = await get(ServerId(serverId), endpoint);
|
||||
final json = PlexCacheParser.extractFirstMetadata(cached);
|
||||
if (cached == null || json == null) return;
|
||||
if (isWatched) {
|
||||
@@ -130,12 +131,12 @@ class PlexApiCache extends ApiCache {
|
||||
if (lastViewedAt != null) json['lastViewedAt'] = lastViewedAt;
|
||||
}
|
||||
if (viewedLeafCount != null) json['viewedLeafCount'] = viewedLeafCount;
|
||||
await put(serverId, endpoint, cached);
|
||||
await put(ServerId(serverId), endpoint, cached);
|
||||
}
|
||||
|
||||
/// Load all pinned Plex metadata in a single query.
|
||||
///
|
||||
/// Returns a map keyed by `buildGlobalKey(serverId, ratingKey)` for O(1)
|
||||
/// Returns a map keyed by `buildGlobalKey(ServerId(serverId), ratingKey)` for O(1)
|
||||
/// lookups. Used by DownloadProvider to batch-load metadata on startup
|
||||
/// instead of issuing per-item DB queries.
|
||||
@override
|
||||
@@ -151,7 +152,7 @@ class PlexApiCache extends ApiCache {
|
||||
final container = PlexCacheParser.extractMediaContainer(data);
|
||||
final json = PlexCacheParser.extractFirstMetadata(data);
|
||||
if (json == null) continue;
|
||||
result[buildGlobalKey(entry.serverId, entry.id)] = PlexMappers.mediaItemFromCacheJson(
|
||||
result[buildGlobalKey(ServerId(entry.serverId), entry.id)] = PlexMappers.mediaItemFromCacheJson(
|
||||
_withContainerLibrary(json, container),
|
||||
serverId: entry.serverId,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user