From 0be6455d46037a2e494e5772ea3ab82b659a5558 Mon Sep 17 00:00:00 2001 From: zarzet Date: Wed, 1 Jul 2026 23:46:27 +0700 Subject: [PATCH] fix(download): hand off native worker verification to interactive queue Detect verification-required failures from the Android native worker, cancel the worker, and route the item back through the interactive verification flow with the correct service identifier. --- lib/providers/download_queue_provider.dart | 55 +++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/providers/download_queue_provider.dart b/lib/providers/download_queue_provider.dart index a6b46424..6f8cc10d 100644 --- a/lib/providers/download_queue_provider.dart +++ b/lib/providers/download_queue_provider.dart @@ -6087,15 +6087,40 @@ class DownloadQueueNotifier extends Notifier { if (status == 'skipped') { updateItemStatus(itemId, DownloadStatus.skipped); } else { - final errorType = result is Map - ? _downloadErrorTypeFromBackend( - Map.from(result)['error_type']?.toString(), - ) - : DownloadErrorType.unknown; + final resultMap = result is Map + ? Map.from(result) + : null; + final errorMsg = (error == null || error.isEmpty) + ? (resultMap?['error']?.toString() ?? 'Download failed') + : error; + final backendErrorType = resultMap == null + ? DownloadErrorType.unknown + : _downloadErrorTypeFromBackend( + resultMap['error_type']?.toString(), + ); + final errorType = backendErrorType == DownloadErrorType.unknown + ? _downloadErrorTypeFromMessage(errorMsg) + : backendErrorType; + if (errorType == DownloadErrorType.verificationRequired) { + _log.i( + 'Android native worker requires verification for ${current.track.name}; switching back to interactive queue', + ); + try { + await PlatformBridge.cancelNativeDownloadWorker(); + } catch (e) { + _log.w('Failed to cancel native worker before verification: $e'); + } + await _handleVerificationRequiredDownload( + current, + errorMsg, + _nativeWorkerVerificationService(resultMap, context), + ); + continue; + } updateItemStatus( itemId, DownloadStatus.failed, - error: error == null || error.isEmpty ? 'Download failed' : error, + error: errorMsg, errorType: errorType, ); _failedInSession++; @@ -6919,6 +6944,24 @@ class DownloadQueueNotifier extends Notifier { } } + String _nativeWorkerVerificationService( + Map? result, + _NativeWorkerRequestContext context, + ) { + if (result != null) { + for (final key in const [ + 'service', + 'verification_service', + 'provider', + 'source', + ]) { + final value = result[key]?.toString().trim() ?? ''; + if (value.isNotEmpty) return value; + } + } + return context.item.service; + } + DownloadErrorType _downloadErrorTypeFromMessage(String errorMsg) { final lowerMsg = errorMsg.toLowerCase(); if (isExtensionVerificationRequired(errorMsg)) {