Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-4949: feat(bdi strategy upload) #1490

Merged
merged 19 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,16 @@ class UploadCubit extends Cubit<UploadState> {

bool? _containsLargeTurboUpload;

void retryUploads() {
if (state is UploadFailure) {
logger.d('Retrying uploads');

final controller = (state as UploadFailure).controller!;

controller.retryFailedTasks(_auth.currentUser.wallet);
}
}

Future<void> _uploadUsingArDriveUploader() async {
final ardriveUploader = ArDriveUploader(
turboUploadUri: Uri.parse(configService.config.defaultTurboUploadUrl!),
Expand Down Expand Up @@ -682,8 +692,15 @@ class UploadCubit extends Cubit<UploadState> {

uploadController.onError((tasks) {
logger.e('Error uploading', tasks);
addError(Exception('Error uploading'));
logger.d('Error uploading emiting error');
hasEmittedError = true;
emit(
UploadFailure(
error: UploadErrors.unknown,
failedTasks: tasks,
controller: uploadController,
),
);
});

uploadController.onProgressChange(
Expand Down
4 changes: 3 additions & 1 deletion lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ class UploadInProgressUsingNewUploader extends UploadState {
}

class UploadFailure extends UploadState {
final List<UploadTask>? failedTasks;
final UploadErrors error;
final UploadController? controller;

UploadFailure({required this.error});
UploadFailure({this.failedTasks, required this.error, this.controller});
}

class UploadComplete extends UploadState {}
Expand Down
1 change: 0 additions & 1 deletion lib/components/drive_attach_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/user_interaction_wrapper.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/theme/theme.dart';
import 'package:ardrive/utils/add_debounce.dart';
import 'package:ardrive/utils/app_localizations_wrapper.dart';
import 'package:ardrive/utils/validate_folder_name.dart';
import 'package:ardrive_ui/ardrive_ui.dart';
Expand Down
128 changes: 119 additions & 9 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ class _UploadFormState extends State<UploadForm> {
],
);
} else if (state is UploadFailure) {
logger.e('Upload failed: ${state.error}');
if (state.error == UploadErrors.turboTimeout) {
return ArDriveStandardModal(
title: appLocalizationsOf(context).uploadFailed,
Expand All @@ -746,14 +747,26 @@ class _UploadFormState extends State<UploadForm> {
}

return ArDriveStandardModal(
title: appLocalizationsOf(context).uploadFailed,
width: kLargeDialogWidth,
title: 'Problem with Upload',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be localized.

description: appLocalizationsOf(context).yourUploadFailed,
actions: [
ModalAction(
action: () => Navigator.of(context).pop(false),
title: appLocalizationsOf(context).okEmphasized,
),
],
content: state.failedTasks != null
? _failedUploadList(state.failedTasks!)
: null,
actions: state.failedTasks == null
? null
: [
ModalAction(
action: () => Navigator.of(context).pop(false),
title: 'Do Not Fix',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be localized.

),
ModalAction(
action: () {
context.read<UploadCubit>().retryUploads();
},
title: 'Re-Upload',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be localized.

),
],
);
} else if (state is UploadShowingWarning) {
return ArDriveStandardModal(
Expand Down Expand Up @@ -937,8 +950,10 @@ class _UploadFormState extends State<UploadForm> {
if (task.status == UploadStatus.inProgress ||
task.status == UploadStatus.complete ||
task.status == UploadStatus.failed) {
progressText =
'${filesize(((task.uploadItem!.size) * task.progress).ceil())}/${filesize(task.uploadItem!.size)}';
if (task.uploadItem != null) {
progressText =
'${filesize(((task.uploadItem!.size) * task.progress).ceil())}/${filesize(task.uploadItem!.size)}';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could factor this out into its own testable and atomic function.

}
}
} else {
if (task.status == UploadStatus.inProgress) {
Expand Down Expand Up @@ -1150,6 +1165,101 @@ class _UploadFormState extends State<UploadForm> {
);
}

Widget _failedUploadList(List<UploadTask> tasks) {
return ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 256 * 1.5, minWidth: kLargeDialogWidth),
child: Container(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'It seems there was a partial failure uploading the following file(s). The file(s) will show as failed in your drive. Please re-upload to fix.',
Comment on lines +1177 to +1178
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be localized.

style: ArDriveTypography.body.buttonLargeBold()),
const SizedBox(height: 8),
Expanded(
child: ArDriveScrollBar(
child: ListView.builder(
shrinkWrap: true,
itemCount: tasks.length,
itemBuilder: (BuildContext context, int index) {
final task = tasks[index];

if (task.content != null) {
for (var file in task.content!) {
return ListTile(
leading: file is ARFSFileUploadMetadata
? getIconForContentType(
file.dataContentType,
size: 24,
)
: file is ARFSFolderUploadMetatadata
? getIconForContentType(
'folder',
size: 24,
)
: null,
contentPadding: EdgeInsets.zero,
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
file.name,
style: ArDriveTypography.body
.buttonNormalBold(
color: ArDriveTheme.of(context)
.themeData
.colors
.themeFgDefault,
)
.copyWith(
fontWeight: FontWeight.bold),
),
AnimatedSwitcher(
duration: const Duration(seconds: 1),
child: Column(
children: [
if (file is ARFSFileUploadMetadata)
Text(
filesize(file.size),
style: ArDriveTypography.body
.buttonNormalBold(
color: ArDriveTheme.of(context)
.themeData
.colors
.themeFgOnDisabled,
),
),
],
),
),
],
),
),
],
),
);
}
}
return const SizedBox();
},
),
),
),
],
),
),
);
}

Color _getUploadStatusColor(
BuildContext context, UploadTask uploadStatusColor) {
final themeColors = ArDriveTheme.of(context).themeData.colors;
Expand Down
2 changes: 2 additions & 0 deletions packages/ardrive_uploader/lib/ardrive_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ library;

export 'src/ardrive_uploader.dart';
export 'src/arfs_upload_metadata.dart';
export 'src/factories.dart';
export 'src/metadata_generator.dart';
export 'src/upload_controller.dart';
export 'src/upload_strategy.dart';
Loading
Loading