fix(upload_image): 修改媒体上传文件
This commit is contained in:
@@ -12,7 +12,8 @@ class VideoBatchUploadQueue {
|
||||
VideoBatchUploadQueue({
|
||||
required this.contextProvider,
|
||||
required this.uploadTask,
|
||||
required this.saveTask,
|
||||
this.saveTask,
|
||||
this.batchSaveTask,
|
||||
required this.onChanged,
|
||||
this.assetType = VideoBatchUploadAssetType.video,
|
||||
this.onCompleted,
|
||||
@@ -22,7 +23,8 @@ class VideoBatchUploadQueue {
|
||||
|
||||
final BuildContext? Function() contextProvider;
|
||||
final VideoBatchUploadUploadTask uploadTask;
|
||||
final VideoBatchUploadSaveTask saveTask;
|
||||
final VideoBatchUploadSaveTask? saveTask;
|
||||
final VideoBatchUploadBatchSaveTask? batchSaveTask;
|
||||
final VoidCallback onChanged;
|
||||
final VideoBatchUploadAssetType assetType;
|
||||
final FutureOr<void> Function()? onCompleted;
|
||||
@@ -58,6 +60,8 @@ class VideoBatchUploadQueue {
|
||||
int get finishedCount =>
|
||||
_completedRemovedCount + completedCount + failedCount;
|
||||
|
||||
bool get _usesBatchSave => batchSaveTask != null;
|
||||
|
||||
Future<void> pickAndStart() async {
|
||||
if (hasActiveUploads) {
|
||||
isExpanded = true;
|
||||
@@ -195,6 +199,7 @@ class VideoBatchUploadQueue {
|
||||
);
|
||||
await Future.wait(workers);
|
||||
_isRunning = false;
|
||||
await _saveUploadedBatchIfNeeded();
|
||||
await _notifyCompletedIfNeeded();
|
||||
}
|
||||
|
||||
@@ -251,9 +256,13 @@ class VideoBatchUploadQueue {
|
||||
..status = VideoBatchUploadStatus.uploaded;
|
||||
_notifyChanged();
|
||||
|
||||
if (_usesBatchSave) {
|
||||
return;
|
||||
}
|
||||
|
||||
task.status = VideoBatchUploadStatus.saving;
|
||||
_notifyChanged();
|
||||
final bool saved = await saveTask(task);
|
||||
final bool saved = await saveTask!(task);
|
||||
if (!tasks.contains(task)) {
|
||||
return;
|
||||
}
|
||||
@@ -290,6 +299,62 @@ class VideoBatchUploadQueue {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveUploadedBatchIfNeeded() async {
|
||||
if (!_usesBatchSave || _isDisposed) {
|
||||
return;
|
||||
}
|
||||
final List<VideoBatchUploadTask> successfulUploadTasks = tasks
|
||||
.where((VideoBatchUploadTask task) =>
|
||||
task.status == VideoBatchUploadStatus.uploaded)
|
||||
.toList();
|
||||
if (successfulUploadTasks.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final VideoBatchUploadTask task in successfulUploadTasks) {
|
||||
task.status = VideoBatchUploadStatus.saving;
|
||||
}
|
||||
_notifyChanged();
|
||||
|
||||
try {
|
||||
final bool saved = await batchSaveTask!(List<VideoBatchUploadTask>.of(
|
||||
successfulUploadTasks,
|
||||
growable: false,
|
||||
));
|
||||
if (_isDisposed) {
|
||||
return;
|
||||
}
|
||||
if (saved) {
|
||||
_completedRemovedCount += successfulUploadTasks.length;
|
||||
tasks.removeWhere(successfulUploadTasks.contains);
|
||||
if (tasks.isEmpty) {
|
||||
isExpanded = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (final VideoBatchUploadTask task in successfulUploadTasks) {
|
||||
if (tasks.contains(task)) {
|
||||
task
|
||||
..status = VideoBatchUploadStatus.failed
|
||||
..errorMessage = '入库失败';
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
if (_isDisposed) {
|
||||
return;
|
||||
}
|
||||
for (final VideoBatchUploadTask task in successfulUploadTasks) {
|
||||
if (tasks.contains(task)) {
|
||||
task
|
||||
..status = VideoBatchUploadStatus.failed
|
||||
..errorMessage = '入库失败';
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
_notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
String _networkErrorText(DioException error) {
|
||||
switch (error.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
|
||||
Reference in New Issue
Block a user