refactor: extract shared mixins and helpers

This commit is contained in:
edde746
2026-02-04 11:11:01 +01:00
parent 16884a7bca
commit a7ac681fdc
12 changed files with 313 additions and 337 deletions
+12
View File
@@ -3,6 +3,8 @@ import 'dart:convert';
import 'package:drift/drift.dart';
import '../database/app_database.dart';
import '../models/plex_metadata.dart';
import '../utils/plex_cache_parser.dart';
/// Key-value cache for Plex API responses using Drift/SQLite.
/// Stores raw JSON responses keyed by serverId:endpoint format.
@@ -110,6 +112,16 @@ class PlexApiCache {
return keys;
}
/// Fetch and parse a [PlexMetadata] item from cache.
///
/// Returns `null` when the endpoint is not cached or contains no metadata.
Future<PlexMetadata?> getMetadata(String serverId, String ratingKey) async {
final cached = await get(serverId, '/library/metadata/$ratingKey');
final json = PlexCacheParser.extractFirstMetadata(cached);
if (json == null) return null;
return PlexMetadata.fromJson(json).copyWith(serverId: serverId);
}
/// Clear all cached data (useful for debugging/testing)
Future<void> clearAll() async {
await _db.delete(_db.apiCache).go();