refactor: remove dead code
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class PlexAuth {
|
||||
static const String authUrl = 'https://plex.tv/api/v2';
|
||||
static const String clientsUrl = 'https://clients.plex.tv/api/v2';
|
||||
|
||||
final String clientIdentifier;
|
||||
final String product;
|
||||
|
||||
PlexAuth({
|
||||
required this.clientIdentifier,
|
||||
this.product = 'Plex Flutter Client',
|
||||
});
|
||||
|
||||
Map<String, String> get _headers => {
|
||||
'Accept': 'application/json',
|
||||
'X-Plex-Client-Identifier': clientIdentifier,
|
||||
'X-Plex-Product': product,
|
||||
};
|
||||
|
||||
/// Generate a PIN for authentication
|
||||
Future<Map<String, dynamic>> generatePin({bool strong = true}) async {
|
||||
final response = await http.post(
|
||||
Uri.parse('$authUrl/pins?strong=$strong'),
|
||||
headers: _headers,
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
throw Exception('Failed to generate PIN: ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
/// Check PIN status
|
||||
Future<Map<String, dynamic>> checkPin(int pinId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse('$authUrl/pins/$pinId'),
|
||||
headers: _headers,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
throw Exception('Failed to check PIN: ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get auth app URL for user to authenticate
|
||||
String getAuthAppUrl(String code, {String? forwardUrl}) {
|
||||
final params = {
|
||||
'clientID': clientIdentifier,
|
||||
'code': code,
|
||||
'context[device][product]': product,
|
||||
if (forwardUrl != null) 'forwardUrl': forwardUrl,
|
||||
};
|
||||
|
||||
final queryString = params.entries
|
||||
.map(
|
||||
(e) =>
|
||||
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}',
|
||||
)
|
||||
.join('&');
|
||||
|
||||
return 'https://app.plex.tv/auth#?$queryString';
|
||||
}
|
||||
|
||||
/// Verify token validity
|
||||
Future<bool> verifyToken(String token) async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$authUrl/user'),
|
||||
headers: {..._headers, 'X-Plex-Token': token},
|
||||
);
|
||||
return response.statusCode == 200;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get user info
|
||||
Future<Map<String, dynamic>> getUserInfo(String token) async {
|
||||
final response = await http.get(
|
||||
Uri.parse('$authUrl/user'),
|
||||
headers: {..._headers, 'X-Plex-Token': token},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
throw Exception('Failed to get user info: ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get available resources (servers)
|
||||
Future<List<dynamic>> getResources(String token) async {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
'$clientsUrl/resources?includeHttps=1&includeRelay=1&includeIPv6=1',
|
||||
),
|
||||
headers: {..._headers, 'X-Plex-Token': token},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
throw Exception('Failed to get resources: ${response.body}');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,20 +51,6 @@ class PlexClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Test connection to a specific URL with token (legacy method)
|
||||
static Future<bool> testConnectionUrl(
|
||||
String baseUrl,
|
||||
String token, {
|
||||
Duration timeout = const Duration(seconds: 5),
|
||||
}) async {
|
||||
final result = await testConnectionWithLatency(
|
||||
baseUrl,
|
||||
token,
|
||||
timeout: timeout,
|
||||
);
|
||||
return result.success;
|
||||
}
|
||||
|
||||
/// Test connection to a specific URL with token and measure latency
|
||||
static Future<ConnectionTestResult> testConnectionWithLatency(
|
||||
String baseUrl,
|
||||
|
||||
@@ -17,6 +17,7 @@ import '../utils/platform_detector.dart';
|
||||
import 'video_player_screen.dart';
|
||||
import 'main_screen.dart';
|
||||
import 'about_screen.dart';
|
||||
import 'auth_screen.dart';
|
||||
|
||||
class DiscoverScreen extends StatefulWidget {
|
||||
final PlexClient client;
|
||||
@@ -341,7 +342,10 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
await storage.clearCredentials();
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (context) => const AuthScreen()),
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,29 +351,6 @@ class PlexServer {
|
||||
yield bestConnection;
|
||||
}
|
||||
}
|
||||
|
||||
/// Legacy method for backward compatibility - returns first working connection
|
||||
/// For optimal performance, use findBestWorkingConnection() stream instead
|
||||
@Deprecated('Use findBestWorkingConnection() stream for optimized connection')
|
||||
Future<PlexConnection?> findBestWorkingConnectionLegacy() async {
|
||||
if (connections.isEmpty) return null;
|
||||
|
||||
// Test all connections simultaneously
|
||||
final working = <PlexConnection>[];
|
||||
await Future.wait(
|
||||
connections.map((connection) async {
|
||||
final works = await PlexClient.testConnectionUrl(
|
||||
connection.uri,
|
||||
accessToken,
|
||||
);
|
||||
if (works) {
|
||||
working.add(connection);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return _selectBest(working);
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a connection to a Plex server
|
||||
|
||||
@@ -112,7 +112,20 @@ ThemeData monoTheme({required bool dark}) {
|
||||
backgroundColor: WidgetStatePropertyAll(c.text),
|
||||
foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
),
|
||||
),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
style: ButtonStyle(
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 18, vertical: 14),
|
||||
),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
backgroundColor: WidgetStatePropertyAll(c.text),
|
||||
foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/// Utility class for building Plex API headers
|
||||
class PlexHeaders {
|
||||
/// Standard Plex headers required for API requests
|
||||
static const String plexClientIdentifier = 'X-Plex-Client-Identifier';
|
||||
static const String plexProduct = 'X-Plex-Product';
|
||||
static const String plexVersion = 'X-Plex-Version';
|
||||
static const String plexToken = 'X-Plex-Token';
|
||||
static const String plexPlatform = 'X-Plex-Platform';
|
||||
static const String plexPlatformVersion = 'X-Plex-Platform-Version';
|
||||
static const String plexDevice = 'X-Plex-Device';
|
||||
|
||||
/// Builds standard Plex headers with optional token
|
||||
static Map<String, String> buildHeaders({
|
||||
required String clientIdentifier,
|
||||
String? token,
|
||||
String product = 'Plezy',
|
||||
String version = '1.0',
|
||||
String platform = 'Flutter',
|
||||
String platformVersion = '1.0',
|
||||
String device = 'Mobile',
|
||||
}) {
|
||||
final headers = {
|
||||
plexClientIdentifier: clientIdentifier,
|
||||
plexProduct: product,
|
||||
plexVersion: version,
|
||||
plexPlatform: platform,
|
||||
plexPlatformVersion: platformVersion,
|
||||
plexDevice: device,
|
||||
};
|
||||
|
||||
if (token != null) {
|
||||
headers[plexToken] = token;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
+2
-74
@@ -185,14 +185,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.6"
|
||||
dart_service_protocol_shared:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_service_protocol_shared
|
||||
sha256: "1737875c176d7e3d87bb3a359182828b542fe20a0b34198b8d31a81af5c7a76d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.3"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -225,14 +217,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
dtd:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dtd
|
||||
sha256: "09ddb228b3d1478a093556357692a4c203ff4f9d5f8cda05dfdca0ff3fb7c5d3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -294,14 +278,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
flutter_svg:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_svg
|
||||
sha256: b9c2ad5872518a27507ab432d1fb97e8813b05f0fc693f9d40fad06d073e0678
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -329,7 +305,7 @@ packages:
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http
|
||||
sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007
|
||||
@@ -376,14 +352,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.9.0"
|
||||
json_rpc_2:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_rpc_2
|
||||
sha256: "3c46c2633aec07810c3d6a2eb08d575b5b4072980db08f1344e66aeb53d6e4a7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
json_serializable:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -585,14 +553,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
path_provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -982,14 +942,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
unified_analytics:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: unified_analytics
|
||||
sha256: "8d1429a4b27320a9c4fc854287d18c8fde1549bf622165c5837202a9f370b53d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.0.5"
|
||||
universal_platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1078,30 +1030,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.1"
|
||||
vector_graphics:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics
|
||||
sha256: a4f059dc26fc8295b5921376600a194c4ec7d55e72f2fe4c7d2831e103d461e6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.19"
|
||||
vector_graphics_codec:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_codec
|
||||
sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.13"
|
||||
vector_graphics_compiler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_compiler
|
||||
sha256: d354a7ec6931e6047785f4db12a1f61ec3d43b207fc0790f863818543f8ff0dc
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.19"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1199,7 +1127,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
xml:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xml
|
||||
sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025"
|
||||
|
||||
@@ -9,12 +9,9 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
http: ^1.2.0
|
||||
dio: ^5.4.0
|
||||
json_annotation: ^4.8.1
|
||||
xml: ^6.5.0
|
||||
shared_preferences: ^2.2.2
|
||||
dtd: ^4.0.0
|
||||
cached_network_image: ^3.4.1
|
||||
media_kit: ^1.1.10+1
|
||||
media_kit_video: ^1.2.4
|
||||
@@ -24,7 +21,6 @@ dependencies:
|
||||
uuid: ^4.4.0
|
||||
window_manager: ^0.4.3
|
||||
logger: ^2.0.2
|
||||
flutter_svg: ^2.0.10
|
||||
package_info_plus: ^9.0.0
|
||||
|
||||
dependency_overrides:
|
||||
|
||||
Reference in New Issue
Block a user