jellyfin_models.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import '../../core/app_version.dart';
  2. /// The authenticated details needed by the library and playback services.
  3. /// Keep this out of widgets; [toString] deliberately omits the token.
  4. class JellyfinConnection {
  5. const JellyfinConnection({
  6. required this.baseUrl,
  7. required this.accessToken,
  8. required this.userId,
  9. required this.deviceId,
  10. required this.userName,
  11. });
  12. final Uri baseUrl;
  13. final String accessToken;
  14. final String userId;
  15. final String deviceId;
  16. final String userName;
  17. String get authorizationHeader {
  18. final parts = [
  19. 'Client="CarDash"',
  20. 'Device="CarDash"',
  21. 'DeviceId="$deviceId"',
  22. 'Version="$appVersion"',
  23. 'Token="$accessToken"',
  24. ];
  25. return 'MediaBrowser ${parts.join(', ')}';
  26. }
  27. Map<String, String> get apiHeaders => {
  28. 'Authorization': authorizationHeader,
  29. 'Accept': 'application/json',
  30. };
  31. @override
  32. String toString() => 'JellyfinConnection($baseUrl, user: $userName)';
  33. }
  34. /// Public identity of a Jellyfin server.
  35. class JellyfinServerInfo {
  36. const JellyfinServerInfo({required this.name, required this.version});
  37. final String name;
  38. final String version;
  39. }
  40. /// A pending Quick Connect request. The code is shown to the user; the secret
  41. /// is exchanged for an access token once the user approves the device.
  42. class JellyfinQuickConnect {
  43. const JellyfinQuickConnect({required this.code, required this.secret});
  44. final String code;
  45. final String secret;
  46. }
  47. /// The signed-in Jellyfin user for this device.
  48. class JellyfinUser {
  49. const JellyfinUser({required this.id, required this.name});
  50. final String id;
  51. final String name;
  52. }
  53. /// An access token plus the user it belongs to.
  54. class JellyfinSession {
  55. const JellyfinSession({
  56. required this.accessToken,
  57. required this.userId,
  58. required this.userName,
  59. });
  60. final String accessToken;
  61. final String userId;
  62. final String userName;
  63. }
  64. /// A Jellyfin request failed. [JellyfinUnreachable] means the server could not
  65. /// be contacted at all; [JellyfinAuthException] means the saved token is no
  66. /// longer accepted.
  67. class JellyfinException implements Exception {
  68. JellyfinException(this.message);
  69. final String message;
  70. @override
  71. String toString() => message;
  72. }
  73. class JellyfinUnreachable extends JellyfinException {
  74. JellyfinUnreachable(super.message);
  75. }
  76. class JellyfinAuthException extends JellyfinException {
  77. JellyfinAuthException(super.message);
  78. }