fix(plex): tolerate malformed activity rows

This commit is contained in:
edde746
2026-07-12 08:42:25 +02:00
parent 34be331024
commit c81a1f9a97
5 changed files with 87 additions and 12 deletions
+8 -5
View File
@@ -1,20 +1,23 @@
import 'package:json_annotation/json_annotation.dart';
import '../../utils/json_utils.dart';
part 'plex_activity.g.dart';
/// Represents a running background task on a Plex Media Server (from /activities endpoint).
@JsonSerializable(createToJson: false)
class PlexActivity {
@JsonKey(defaultValue: '')
@JsonKey(fromJson: stringOrEmpty)
final String uuid;
@JsonKey(defaultValue: '')
@JsonKey(fromJson: stringOrEmpty)
final String type;
@JsonKey(defaultValue: '')
@JsonKey(fromJson: stringOrEmpty)
final String title;
@JsonKey(readValue: readStringField)
final String? subtitle;
@JsonKey(defaultValue: 0)
@JsonKey(fromJson: flexibleIntOrZero)
final int progress; // 0100
@JsonKey(defaultValue: false)
@JsonKey(fromJson: flexibleBool)
final bool cancellable;
const PlexActivity({
+6 -6
View File
@@ -7,10 +7,10 @@ part of 'plex_activity.dart';
// **************************************************************************
PlexActivity _$PlexActivityFromJson(Map<String, dynamic> json) => PlexActivity(
uuid: json['uuid'] as String? ?? '',
type: json['type'] as String? ?? '',
title: json['title'] as String? ?? '',
subtitle: json['subtitle'] as String?,
progress: (json['progress'] as num?)?.toInt() ?? 0,
cancellable: json['cancellable'] as bool? ?? false,
uuid: stringOrEmpty(json['uuid']),
type: stringOrEmpty(json['type']),
title: stringOrEmpty(json['title']),
subtitle: readStringField(json, 'subtitle') as String?,
progress: flexibleIntOrZero(json['progress']),
cancellable: flexibleBool(json['cancellable']),
);