fix(plex): tolerate malformed activity rows
This commit is contained in:
@@ -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; // 0–100
|
||||
@JsonKey(defaultValue: false)
|
||||
@JsonKey(fromJson: flexibleBool)
|
||||
final bool cancellable;
|
||||
|
||||
const PlexActivity({
|
||||
|
||||
@@ -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']),
|
||||
);
|
||||
|
||||
@@ -826,7 +826,17 @@ class PlexClient
|
||||
if (container == null) return [];
|
||||
final activityList = container['Activity'] as List?;
|
||||
if (activityList == null) return [];
|
||||
return activityList.map((json) => PlexActivity.fromJson(json as Map<String, dynamic>)).toList();
|
||||
final activities = <PlexActivity>[];
|
||||
for (final json in activityList) {
|
||||
if (json is! Map<String, dynamic>) continue;
|
||||
try {
|
||||
final activity = PlexActivity.fromJson(json);
|
||||
if (activity.uuid.isNotEmpty) activities.add(activity);
|
||||
} catch (e) {
|
||||
appLogger.d('Skipping malformed Plex activity', error: e);
|
||||
}
|
||||
}
|
||||
return activities;
|
||||
} catch (e) {
|
||||
appLogger.e('Failed to get activities', error: e);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user