You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
// ignore_for_file: unnecessary_lambdas |
|
|
|
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>(); |
|
|
|
/// Task progress in percent [0, 1]. |
|
late final progress = streamController.stream.asBroadcastStream(); |
|
} |
|
|
|
class FilesDownloadTask extends FilesTask { |
|
FilesDownloadTask({ |
|
required super.path, |
|
required super.file, |
|
}); |
|
|
|
Future<void> execute(final NextcloudClient client) async { |
|
await client.webdav.getFile( |
|
Uri(pathSegments: path), |
|
file, |
|
onProgress: (final progress) { |
|
streamController.add(progress); |
|
}, |
|
); |
|
} |
|
} |
|
|
|
class FilesUploadTask extends FilesTask { |
|
FilesUploadTask({ |
|
required super.path, |
|
required super.file, |
|
}); |
|
|
|
FileStat? _stat; |
|
FileStat get stat => _stat ??= file.statSync(); |
|
|
|
Future<void> execute(final NextcloudClient client) async { |
|
await client.webdav.putFile( |
|
file, |
|
stat, |
|
Uri(pathSegments: path), |
|
lastModified: stat.modified, |
|
onProgress: (final progress) { |
|
streamController.add(progress); |
|
}, |
|
); |
|
} |
|
}
|
|
|