|
|
@ -3,10 +3,13 @@ part of '../neon_files.dart'; |
|
|
|
sealed class FilesTask { |
|
|
|
sealed class FilesTask { |
|
|
|
FilesTask({ |
|
|
|
FilesTask({ |
|
|
|
required this.path, |
|
|
|
required this.path, |
|
|
|
|
|
|
|
required this.file, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
final List<String> path; |
|
|
|
final List<String> path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final File file; |
|
|
|
|
|
|
|
|
|
|
|
@protected |
|
|
|
@protected |
|
|
|
final streamController = StreamController<double>(); |
|
|
|
final streamController = StreamController<double>(); |
|
|
|
|
|
|
|
|
|
|
@ -17,50 +20,38 @@ sealed class FilesTask { |
|
|
|
class FilesDownloadTask extends FilesTask { |
|
|
|
class FilesDownloadTask extends FilesTask { |
|
|
|
FilesDownloadTask({ |
|
|
|
FilesDownloadTask({ |
|
|
|
required super.path, |
|
|
|
required super.path, |
|
|
|
|
|
|
|
required super.file, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Future execute(final NextcloudClient client, final IOSink sink) async { |
|
|
|
Future execute(final NextcloudClient client) async { |
|
|
|
final completer = Completer(); |
|
|
|
await client.webdav.getFile( |
|
|
|
|
|
|
|
path.join('/'), |
|
|
|
final response = await client.webdav.getStream(path.join('/')); |
|
|
|
file, |
|
|
|
var downloaded = 0; |
|
|
|
onProgress: (final progress) { |
|
|
|
|
|
|
|
streamController.add(progress); |
|
|
|
response.listen((final chunk) async { |
|
|
|
}, |
|
|
|
sink.add(chunk); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
downloaded += chunk.length; |
|
|
|
|
|
|
|
streamController.add(downloaded / response.contentLength); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (downloaded >= response.contentLength) { |
|
|
|
|
|
|
|
completer.complete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return completer.future; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class FilesUploadTask extends FilesTask { |
|
|
|
class FilesUploadTask extends FilesTask { |
|
|
|
FilesUploadTask({ |
|
|
|
FilesUploadTask({ |
|
|
|
required super.path, |
|
|
|
required super.path, |
|
|
|
required this.size, |
|
|
|
required super.file, |
|
|
|
required this.lastModified, |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
final int size; |
|
|
|
FileStat? _stat; |
|
|
|
final DateTime lastModified; |
|
|
|
FileStat get stat => _stat ??= file.statSync(); |
|
|
|
|
|
|
|
|
|
|
|
Future execute(final NextcloudClient client, final Stream<List<int>> stream) async { |
|
|
|
|
|
|
|
var uploaded = 0; |
|
|
|
|
|
|
|
await client.webdav.putStream( |
|
|
|
|
|
|
|
stream.map((final chunk) { |
|
|
|
|
|
|
|
uploaded += chunk.length; |
|
|
|
|
|
|
|
streamController.add(uploaded / size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Uint8List.fromList(chunk); |
|
|
|
Future execute(final NextcloudClient client) async { |
|
|
|
}), |
|
|
|
await client.webdav.putFile( |
|
|
|
|
|
|
|
file, |
|
|
|
|
|
|
|
stat, |
|
|
|
path.join('/'), |
|
|
|
path.join('/'), |
|
|
|
lastModified: lastModified, |
|
|
|
lastModified: stat.modified, |
|
|
|
|
|
|
|
onProgress: (final progress) { |
|
|
|
|
|
|
|
streamController.add(progress); |
|
|
|
|
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|