mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +02:00
The frontend CI job ran `flutter analyze` from the repo root, which also analyzed the bin/ server package without its dependencies resolved (shelf_router, sqlite3, bcrypt, test), producing hundreds of uri_does_not_exist errors. bin/ is a standalone package covered by the backend job, so it is now excluded from root analysis. Also: - Remove all unused fields/variables flagged as analyzer warnings (api_client, cache_service, player_screen, subtitle_service, live_tv_tab, mobile screens) - Run `flutter analyze --no-fatal-infos` in CI: pre-existing deprecation infos (withOpacity, dart:html) stay non-fatal while errors and warnings still fail the build Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
99 lines
2.4 KiB
Dart
99 lines
2.4 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'dart:html' as html;
|
|
|
|
/// API Client for communicating with the backend
|
|
class ApiClient {
|
|
static final ApiClient _instance = ApiClient._internal();
|
|
factory ApiClient() => _instance;
|
|
|
|
late final Dio _dio;
|
|
|
|
ApiClient._internal() {
|
|
_dio = Dio(BaseOptions(
|
|
baseUrl: _getBaseUrl(),
|
|
headers: {'Content-Type': 'application/json'},
|
|
connectTimeout: const Duration(seconds: 60),
|
|
receiveTimeout: const Duration(seconds: 60),
|
|
),);
|
|
|
|
// Debug-only logging; request bodies are never logged (login payloads
|
|
// contain passwords).
|
|
if (kDebugMode) {
|
|
_dio.interceptors.add(LogInterceptor(
|
|
requestBody: false,
|
|
responseBody: false,
|
|
),);
|
|
}
|
|
|
|
// Restore token from localStorage on initialization
|
|
_restoreTokenFromStorage();
|
|
}
|
|
|
|
/// Restore token from localStorage on app startup
|
|
void _restoreTokenFromStorage() {
|
|
final storedToken = getStoredToken();
|
|
if (storedToken != null) {
|
|
|
|
_dio.options.headers['Authorization'] = 'Bearer $storedToken';
|
|
}
|
|
}
|
|
|
|
/// Get base URL (same origin for production)
|
|
String _getBaseUrl() {
|
|
// Use current origin for API calls
|
|
return '';
|
|
}
|
|
|
|
/// Set authentication token
|
|
void setToken(String? token) {
|
|
|
|
if (token != null) {
|
|
_dio.options.headers['Authorization'] = 'Bearer $token';
|
|
// Store in localStorage for persistence
|
|
html.window.localStorage['auth_token'] = token;
|
|
} else {
|
|
_dio.options.headers.remove('Authorization');
|
|
html.window.localStorage.remove('auth_token');
|
|
}
|
|
}
|
|
|
|
/// Get stored token from localStorage
|
|
String? getStoredToken() {
|
|
return html.window.localStorage['auth_token'];
|
|
}
|
|
|
|
/// Restore token from localStorage
|
|
void restoreToken() {
|
|
final storedToken = getStoredToken();
|
|
if (storedToken != null) {
|
|
setToken(storedToken);
|
|
}
|
|
}
|
|
|
|
/// Clear token
|
|
void clearToken() {
|
|
setToken(null);
|
|
}
|
|
|
|
/// GET request
|
|
Future<Response> get(String path) async {
|
|
return _dio.get(path);
|
|
}
|
|
|
|
/// POST request
|
|
Future<Response> post(String path, {dynamic data}) async {
|
|
return _dio.post(path, data: data);
|
|
}
|
|
|
|
/// PUT request
|
|
Future<Response> put(String path, {dynamic data}) async {
|
|
return _dio.put(path, data: data);
|
|
}
|
|
|
|
/// DELETE request
|
|
Future<Response> delete(String path) async {
|
|
return _dio.delete(path);
|
|
}
|
|
}
|