refactor(profiles): centralize Plex Home cache codec

This commit is contained in:
edde746
2026-07-12 08:42:20 +02:00
parent ac9c236b6b
commit 877e8880cf
4 changed files with 61 additions and 13 deletions
+19
View File
@@ -0,0 +1,19 @@
import 'dart:convert';
import '../models/plex/plex_home_user.dart';
List<Map<String, dynamic>> encodePlexHomeUsersCache(List<PlexHomeUser> users) {
return users.map((user) => user.toJson()).toList(growable: false);
}
String encodePlexHomeUsersCacheJson(List<PlexHomeUser> users) {
return jsonEncode(encodePlexHomeUsersCache(users));
}
List<PlexHomeUser> decodePlexHomeUsersCache(String raw) {
final decoded = jsonDecode(raw);
if (decoded is! List) {
throw const FormatException('Plex Home users cache is not a list');
}
return decoded.whereType<Map<String, dynamic>>().map(PlexHomeUser.fromJson).toList(growable: false);
}