Files
plezy/lib/models/plex/plex_config.dart
T

93 lines
2.3 KiB
Dart
Raw Normal View History

2025-10-22 18:30:25 +02:00
import 'package:package_info_plus/package_info_plus.dart';
2025-10-18 00:05:20 +02:00
class PlexConfig {
final String baseUrl;
final String? token;
final String clientIdentifier;
final String product;
final String version;
final String platform;
final String? device;
final bool acceptJson;
2025-11-15 04:07:08 +01:00
final String? machineIdentifier;
2025-10-18 00:05:20 +02:00
PlexConfig({
required this.baseUrl,
this.token,
required this.clientIdentifier,
2025-10-22 18:30:25 +02:00
required this.product,
required this.version,
2025-10-18 00:05:20 +02:00
this.platform = 'Flutter',
this.device,
this.acceptJson = true,
2025-11-15 04:07:08 +01:00
this.machineIdentifier,
2025-10-18 00:05:20 +02:00
});
2025-10-22 18:30:25 +02:00
static Future<PlexConfig> create({
required String baseUrl,
String? token,
required String clientIdentifier,
String? product,
String? platform,
String? device,
bool acceptJson = true,
2025-11-15 04:07:08 +01:00
String? machineIdentifier,
2025-10-22 18:30:25 +02:00
}) async {
final packageInfo = await PackageInfo.fromPlatform();
return PlexConfig(
baseUrl: baseUrl,
token: token,
clientIdentifier: clientIdentifier,
product: product ?? 'Plezy',
version: packageInfo.version,
platform: platform ?? 'Flutter',
device: device,
acceptJson: acceptJson,
2025-11-15 04:07:08 +01:00
machineIdentifier: machineIdentifier,
2025-10-22 18:30:25 +02:00
);
}
2025-10-18 00:05:20 +02:00
Map<String, String> get headers {
final headers = {
'X-Plex-Client-Identifier': clientIdentifier,
'X-Plex-Product': product,
'X-Plex-Version': version,
'X-Plex-Platform': platform,
2025-12-23 19:54:05 +01:00
'X-Plex-Client-Profile-Name': 'Generic',
'X-Plex-Device': ?device,
2025-10-18 00:05:20 +02:00
if (acceptJson) 'Accept': 'application/json',
2025-11-04 14:29:49 +01:00
'Accept-Charset': 'utf-8',
2025-10-18 00:05:20 +02:00
};
if (token != null) {
headers['X-Plex-Token'] = token!;
}
return headers;
}
PlexConfig copyWith({
String? baseUrl,
String? token,
String? clientIdentifier,
String? product,
String? version,
String? platform,
String? device,
bool? acceptJson,
2025-11-15 04:07:08 +01:00
String? machineIdentifier,
2025-10-18 00:05:20 +02:00
}) {
return PlexConfig(
baseUrl: baseUrl ?? this.baseUrl,
token: token ?? this.token,
clientIdentifier: clientIdentifier ?? this.clientIdentifier,
product: product ?? this.product,
version: version ?? this.version,
platform: platform ?? this.platform,
device: device ?? this.device,
acceptJson: acceptJson ?? this.acceptJson,
2025-11-15 04:07:08 +01:00
machineIdentifier: machineIdentifier ?? this.machineIdentifier,
2025-10-18 00:05:20 +02:00
);
}
}