Skip to content

Commit

Permalink
fix: add limitations warnings
Browse files Browse the repository at this point in the history
- warn the user if the upload is bigger than 500mib uploading for turbo
  • Loading branch information
thiagocarvalhodev committed Oct 25, 2023
1 parent 3d394d5 commit 0c3f991
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/blocs/upload/limits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ final largeFileUploadSizeThreshold = const MiB(500).size;
final mobilePrivateFileSizeLimit = const GiB(10).size;

final publicFileSafeSizeLimit = const GiB(5).size;
final nonChromeBrowserUploadSafeLimitUsingTurbo = const MiB(500).size;

int bundleSizeLimit(bool isTurbo) =>
isTurbo ? turboBundleSizeLimit : d2nBundleSizeLimit;
Expand Down
18 changes: 17 additions & 1 deletion lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ class UploadCubit extends Cubit<UploadState> {
}

bool hasEmittedError = false;
bool hasEmittedWarning = false;

Future<void> startUpload({
required UploadPlan uploadPlanForAr,
Expand Down Expand Up @@ -457,6 +458,17 @@ class UploadCubit extends Cubit<UploadState> {
if (configService.config.useNewUploader) {
if (_uploadMethod == UploadMethod.turbo) {
await _verifyIfUploadContainsLargeFilesUsingTurbo();
if (!hasEmittedWarning && kIsWeb && !await AppPlatform.isChrome()) {
emit(
UploadShowingWarning(
reason: UploadWarningReason.fileTooLargeOnNonChromeBrowser,
uploadPlanForAR: uploadPlanForAr,
uploadPlanForTurbo: uploadPlanForTurbo,
),
);
hasEmittedWarning = true;
return;
}
} else {
_containsLargeTurboUpload = false;
}
Expand Down Expand Up @@ -1006,7 +1018,11 @@ class UploadCubit extends Cubit<UploadState> {
);

if (fileAboveWarningLimit) {
emit(UploadShowingWarning(reason: UploadWarningReason.fileTooLarge));
emit(UploadShowingWarning(
reason: UploadWarningReason.fileTooLarge,
uploadPlanForAR: null,
uploadPlanForTurbo: null,
));

return;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,14 @@ class UploadWalletMismatch extends UploadState {}

class UploadShowingWarning extends UploadState {
final UploadWarningReason reason;
final UploadPlan? uploadPlanForAR;
final UploadPlan? uploadPlanForTurbo;

UploadShowingWarning({required this.reason});
UploadShowingWarning({
required this.reason,
this.uploadPlanForAR,
this.uploadPlanForTurbo,
});

@override
List<Object> get props => [reason];
Expand All @@ -256,6 +262,7 @@ class CancelD2NUploadWarning extends UploadState {}
enum UploadWarningReason {
/// The user is attempting to upload a file that is too large.
fileTooLarge,
fileTooLargeOnNonChromeBrowser,
}

enum UploadErrors {
Expand Down
21 changes: 18 additions & 3 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,11 @@ class _UploadFormState extends State<UploadForm> {
Text(
appLocalizationsOf(context)
.weDontRecommendUploadsAboveASafeLimit(
filesize(publicFileSafeSizeLimit),
filesize(
state.reason == UploadWarningReason.fileTooLarge
? publicFileSafeSizeLimit
: nonChromeBrowserUploadSafeLimitUsingTurbo,
),
),
style: ArDriveTypography.body.buttonNormalRegular(),
),
Expand All @@ -768,8 +772,19 @@ class _UploadFormState extends State<UploadForm> {
title: appLocalizationsOf(context).cancelEmphasized,
),
ModalAction(
action: () =>
context.read<UploadCubit>().checkFilesAboveLimit(),
action: () {
if (state.uploadPlanForAR != null &&
state.reason ==
UploadWarningReason
.fileTooLargeOnNonChromeBrowser) {
return context.read<UploadCubit>().startUpload(
uploadPlanForAr: state.uploadPlanForAR!,
uploadPlanForTurbo: state.uploadPlanForTurbo,
);
}

return context.read<UploadCubit>().checkFilesAboveLimit();
},
title: appLocalizationsOf(context).proceed,
),
],
Expand Down
10 changes: 10 additions & 0 deletions packages/ardrive_utils/lib/src/app_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class AppPlatform {
final info = await (deviceInfo ?? DeviceInfoPlugin()).deviceInfo;
return info is WebBrowserInfo && info.browserName == BrowserName.firefox;
}

static Future<bool> isChrome({DeviceInfoPlugin? deviceInfo}) async {
final info = await (deviceInfo ?? DeviceInfoPlugin()).deviceInfo;
return info is WebBrowserInfo && info.browserName == BrowserName.chrome;
}

static Future<bool> isSafari({DeviceInfoPlugin? deviceInfo}) async {
final info = await (deviceInfo ?? DeviceInfoPlugin()).deviceInfo;
return info is WebBrowserInfo && info.browserName == BrowserName.safari;
}
}

// ignore: constant_identifier_names
Expand Down

0 comments on commit 0c3f991

Please sign in to comment.