53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import '../github/github_auth_service.dart';
|
|
import '../github/github_sync_service.dart';
|
|
import 'sync_models.dart';
|
|
import 'sync_provider.dart';
|
|
|
|
/// Explicit developer/export provider for the historical GitHub ride-log
|
|
/// exporter. MotorCloud is the only default/normal cloud backup destination.
|
|
class GitHubSyncProvider implements SyncProvider {
|
|
final GitHubSyncService service;
|
|
final GitHubAuthService auth;
|
|
|
|
GitHubSyncProvider({
|
|
required this.service,
|
|
required this.auth,
|
|
});
|
|
|
|
@override
|
|
String get providerId => 'github';
|
|
|
|
@override
|
|
Future<bool> isAvailable() async => auth.getToken() != null;
|
|
|
|
@override
|
|
Future<bool> requiresAuthentication() async => auth.getToken() == null;
|
|
|
|
@override
|
|
Future<SyncResult> uploadRide(SyncItem item) async {
|
|
final hasAuth = auth.getToken() != null;
|
|
if (!hasAuth) {
|
|
return SyncResult.authRequired(
|
|
message: 'GitHub developer export requires an explicitly configured GitHub token.',
|
|
);
|
|
}
|
|
|
|
// This provider is intentionally the only path that may call the legacy
|
|
// GitHub exporter. Normal History -> Upload Now uses Firebase/MotorCloud.
|
|
final result = await service.uploadRideToGitHub(item.localRideId);
|
|
|
|
if (result.success) {
|
|
return SyncResult.success(
|
|
remoteId: result.commitSha ?? 'commit_${result.targetPath}',
|
|
timestamp: result.timestamp,
|
|
);
|
|
}
|
|
|
|
if (service.state == GitHubUploadState.authRequired) {
|
|
return SyncResult.authRequired(message: result.message);
|
|
}
|
|
|
|
return SyncResult.permanentFailure(result.message);
|
|
}
|
|
}
|