|
|
|
@ -3,13 +3,10 @@ part of '../neon_files.dart';
|
|
|
|
|
sealed class FilesTask { |
|
|
|
|
FilesTask({ |
|
|
|
|
required this.path, |
|
|
|
|
required this.file, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
final List<String> path; |
|
|
|
|
|
|
|
|
|
final File file; |
|
|
|
|
|
|
|
|
|
@protected |
|
|
|
|
final streamController = StreamController<double>(); |
|
|
|
|
|
|
|
|
@ -17,12 +14,18 @@ sealed class FilesTask {
|
|
|
|
|
late final progress = streamController.stream.asBroadcastStream(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FilesDownloadTask extends FilesTask { |
|
|
|
|
FilesDownloadTask({ |
|
|
|
|
abstract class FilesDownloadTask extends FilesTask { |
|
|
|
|
FilesDownloadTask({required super.path}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FilesDownloadFileTask extends FilesDownloadTask { |
|
|
|
|
FilesDownloadFileTask({ |
|
|
|
|
required super.path, |
|
|
|
|
required super.file, |
|
|
|
|
required this.file, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
final File file; |
|
|
|
|
|
|
|
|
|
Future<void> execute(final NextcloudClient client) async { |
|
|
|
|
await client.webdav.getFile( |
|
|
|
|
Uri(pathSegments: path), |
|
|
|
@ -33,15 +36,31 @@ class FilesDownloadTask extends FilesTask {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FilesUploadTask extends FilesTask { |
|
|
|
|
FilesUploadTask({ |
|
|
|
|
abstract class FilesUploadTask extends FilesTask { |
|
|
|
|
FilesUploadTask({required super.path}); |
|
|
|
|
|
|
|
|
|
int get size; |
|
|
|
|
|
|
|
|
|
DateTime? get modified; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FilesUploadFileTask extends FilesUploadTask { |
|
|
|
|
FilesUploadFileTask({ |
|
|
|
|
required super.path, |
|
|
|
|
required super.file, |
|
|
|
|
required this.file, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
final File file; |
|
|
|
|
|
|
|
|
|
FileStat? _stat; |
|
|
|
|
FileStat get stat => _stat ??= file.statSync(); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
int get size => stat.size; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
DateTime? get modified => stat.modified; |
|
|
|
|
|
|
|
|
|
Future<void> execute(final NextcloudClient client) async { |
|
|
|
|
await client.webdav.putFile( |
|
|
|
|
file, |
|
|
|
@ -53,3 +72,31 @@ class FilesUploadTask extends FilesTask {
|
|
|
|
|
await streamController.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FilesUploadBytesTask extends FilesUploadTask { |
|
|
|
|
FilesUploadBytesTask({ |
|
|
|
|
required super.path, |
|
|
|
|
required this.bytes, |
|
|
|
|
this.modified, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
final Uint8List bytes; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
int get size => bytes.lengthInBytes; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
DateTime? modified; |
|
|
|
|
|
|
|
|
|
Future<void> execute(final NextcloudClient client) async { |
|
|
|
|
await client.webdav.putStream( |
|
|
|
|
Stream.value(bytes), |
|
|
|
|
Uri(pathSegments: path), |
|
|
|
|
lastModified: modified, |
|
|
|
|
contentLength: bytes.lengthInBytes, |
|
|
|
|
onProgress: (final progress) { |
|
|
|
|
streamController.add(progress); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|