diff --git a/lib/services/download_storage_service.dart b/lib/services/download_storage_service.dart index c3fde7f2..6054a141 100644 --- a/lib/services/download_storage_service.dart +++ b/lib/services/download_storage_service.dart @@ -8,7 +8,6 @@ import '../models/plex_metadata.dart'; import '../utils/app_logger.dart'; import '../utils/formatters.dart'; import 'settings_service.dart'; -import 'saf_storage_service.dart'; class DownloadStorageService { static DownloadStorageService? _instance; @@ -512,37 +511,6 @@ class DownloadStorageService { return path.join(cacheDir.path, fileName); } - /// Copy a file from temp cache to SAF and return the SAF URI - /// Returns null if SAF is not available or copy fails - /// Always cleans up temp file regardless of success/failure - Future copyToSaf(String tempFilePath, List pathComponents, String fileName, String mimeType) async { - if (!isUsingSaf || _customDownloadPath == null) return null; - - final safService = SafStorageService.instance; - - try { - // Create nested directory structure in SAF - final targetDirUri = await safService.createNestedDirectories(_customDownloadPath!, pathComponents); - - if (targetDirUri == null) { - return null; - } - - // Copy the file to SAF using native copy - return await safService.copyFileToSaf(tempFilePath, targetDirUri, fileName, mimeType); - } finally { - // Always clean up temp file regardless of success/failure - try { - final tempFile = File(tempFilePath); - if (await tempFile.exists()) { - await tempFile.delete(); - } - } catch (_) { - // Ignore cleanup errors - } - } - } - /// Get the MIME type for a file extension String getMimeType(String extension) { switch (extension.toLowerCase()) { diff --git a/lib/services/saf_storage_service.dart b/lib/services/saf_storage_service.dart index 7d1db297..d8c206c6 100644 --- a/lib/services/saf_storage_service.dart +++ b/lib/services/saf_storage_service.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:saf_util/saf_util.dart'; -import '../utils/future_extensions.dart'; import '../utils/platform_detector.dart'; import 'package:saf_util/saf_util_platform_interface.dart'; import 'package:saf_stream/saf_stream.dart'; @@ -130,40 +129,6 @@ class SafStorageService { } } - /// Copy a file from local storage to SAF directory using native copy - /// Returns the SAF URI of the copied file, or null on failure - Future copyFileToSaf( - String sourceFilePath, - String targetDirectoryUri, - String fileName, - String mimeType, - ) async { - if (!isAvailable) return null; - - try { - final sourceFile = File(sourceFilePath); - if (!await sourceFile.exists()) { - debugPrint('SAF copyFileToSaf: source file does not exist'); - return null; - } - - // Use pasteLocalFile for native-side copy (no method channel streaming) - // This is much more efficient for large files and avoids hangs - final result = await _safStream - .pasteLocalFile(sourceFilePath, targetDirectoryUri, fileName, mimeType, overwrite: true) - .namedTimeout(const Duration(minutes: 30), operation: 'SAF copy'); - - debugPrint('SAF copyFileToSaf: successfully copied to ${result.uri}'); - return result.uri.toString(); - } on TimeoutException catch (e) { - debugPrint('SAF copyFileToSaf timeout: $e'); - return null; - } catch (e) { - debugPrint('SAF copyFileToSaf error: $e'); - return null; - } - } - /// Write bytes directly to a SAF file /// Returns the SAF URI of the created file, or null on failure Future writeFileBytes(String directoryUri, String fileName, String mimeType, Uint8List bytes) async {