refactor: remove dead SAF copy methods
This commit is contained in:
@@ -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<String?> copyToSaf(String tempFilePath, List<String> 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()) {
|
||||
|
||||
@@ -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<String?> 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<String?> writeFileBytes(String directoryUri, String fileName, String mimeType, Uint8List bytes) async {
|
||||
|
||||
Reference in New Issue
Block a user