fix(plex): coerce PlexHomeUser fields against account-API drift

Same clients.plex.tv surface that broke in #1488: /home/users powers
first sign-in and profile setup, so a drifted scalar shape would kill
the whole fetch. Coerce strings, bools, and ints tolerantly instead of
hard-casting.
This commit is contained in:
edde746
2026-07-05 06:23:41 +02:00
parent 96510f8aac
commit 31e8c2e1e0
2 changed files with 33 additions and 22 deletions
+20 -9
View File
@@ -1,30 +1,39 @@
import 'package:json_annotation/json_annotation.dart';
import '../../utils/json_utils.dart';
part 'plex_home_user.g.dart';
/// Parsed from the clients.plex.tv `/api/v2/home/users` account API — the
/// same drift-prone surface as PlexUserProfile (#1488), so scalar fields
/// coerce tolerantly instead of hard-casting.
@JsonSerializable()
class PlexHomeUser {
@JsonKey(defaultValue: 0)
@JsonKey(fromJson: _intOr0)
final int id;
@JsonKey(defaultValue: '')
@JsonKey(readValue: readStringField, defaultValue: '')
final String uuid;
@JsonKey(defaultValue: 'Unknown')
@JsonKey(readValue: readStringField, defaultValue: 'Unknown')
final String title;
@JsonKey(readValue: readStringField)
final String? username;
@JsonKey(readValue: readStringField)
final String? email;
@JsonKey(readValue: readStringField)
final String? friendlyName;
@JsonKey(defaultValue: '')
@JsonKey(readValue: readStringField, defaultValue: '')
final String thumb;
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool hasPassword;
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool restricted;
@JsonKey(fromJson: flexibleInt)
final int? updatedAt;
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool admin;
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool guest;
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool protected;
PlexHomeUser({
@@ -54,3 +63,5 @@ class PlexHomeUser {
bool get isGuestUser => guest;
bool get requiresPassword => protected;
}
int _intOr0(Object? v) => flexibleInt(v) ?? 0;
+13 -13
View File
@@ -7,19 +7,19 @@ part of 'plex_home_user.dart';
// **************************************************************************
PlexHomeUser _$PlexHomeUserFromJson(Map<String, dynamic> json) => PlexHomeUser(
id: (json['id'] as num?)?.toInt() ?? 0,
uuid: json['uuid'] as String? ?? '',
title: json['title'] as String? ?? 'Unknown',
username: json['username'] as String?,
email: json['email'] as String?,
friendlyName: json['friendlyName'] as String?,
thumb: json['thumb'] as String? ?? '',
hasPassword: json['hasPassword'] as bool? ?? false,
restricted: json['restricted'] as bool? ?? false,
updatedAt: (json['updatedAt'] as num?)?.toInt(),
admin: json['admin'] as bool? ?? false,
guest: json['guest'] as bool? ?? false,
protected: json['protected'] as bool? ?? false,
id: _intOr0(json['id']),
uuid: readStringField(json, 'uuid') as String? ?? '',
title: readStringField(json, 'title') as String? ?? 'Unknown',
username: readStringField(json, 'username') as String?,
email: readStringField(json, 'email') as String?,
friendlyName: readStringField(json, 'friendlyName') as String?,
thumb: readStringField(json, 'thumb') as String? ?? '',
hasPassword: flexibleBool(json['hasPassword']),
restricted: flexibleBool(json['restricted']),
updatedAt: flexibleInt(json['updatedAt']),
admin: flexibleBool(json['admin']),
guest: flexibleBool(json['guest']),
protected: flexibleBool(json['protected']),
);
Map<String, dynamic> _$PlexHomeUserToJson(PlexHomeUser instance) =>