Skip to content

Commit

Permalink
fix: add warning on download modal
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Oct 25, 2023
1 parent 0c3f991 commit 687b0db
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/blocs/file_download/file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/core/arfs/repository/arfs_repository.dart';
import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/download/ardrive_downloader.dart';
import 'package:ardrive/download/limits.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand All @@ -13,6 +14,7 @@ import 'package:ardrive_io/ardrive_io.dart' as io;
import 'package:ardrive_io/ardrive_io.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:cryptography/cryptography.dart';
import 'package:drift/drift.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/blocs/file_download/file_download_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class FileDownloadAborted extends FileDownloadState {}
enum FileDownloadFailureReason {
unknownError,
fileAboveLimit,
browserDoesNotSupportLargeDownloads,
networkConnectionError,
fileNotFound
}
12 changes: 12 additions & 0 deletions lib/blocs/file_download/personal_file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
_arfsRepository = arfsRepository,
super(FileDownloadStarting());

Future<void> verifyUploadLimitationsAndDownload(SecretKey? cipherKey) async {
if (await AppPlatform.isSafari()) {
if (_file.size > publicDownloadSafariSizeLimit) {
emit(const FileDownloadFailure(
FileDownloadFailureReason.browserDoesNotSupportLargeDownloads));
return;
}
}

download(cipherKey);
}

Future<void> download(SecretKey? cipherKey) async {
try {
final drive = await _arfsRepository.getDriveById(_file.driveId);
Expand Down
22 changes: 20 additions & 2 deletions lib/components/file_download_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Future<void> promptToDownloadProfileFile({
file: arfsFile,
driveDao: context.read<DriveDao>(),
arweave: arweave,
)..download(cipherKey);
)..verifyUploadLimitationsAndDownload(cipherKey);
return showArDriveDialog(
context,
barrierDismissible: false,
Expand Down Expand Up @@ -77,7 +77,7 @@ Future<void> promptToDownloadFileRevision({
file: arfsFile,
driveDao: context.read<DriveDao>(),
arweave: arweave,
)..download(cipherKey);
)..verifyUploadLimitationsAndDownload(cipherKey);

return showArDriveDialog(
context,
Expand Down Expand Up @@ -142,6 +142,9 @@ class FileDownloadDialog extends StatelessWidget {
} else if (state is FileDownloadFailure) {
if (state.reason == FileDownloadFailureReason.unknownError) {
return _fileDownloadFailedDialog(context);
} else if (state.reason ==
FileDownloadFailureReason.browserDoesNotSupportLargeDownloads) {
return _fileDownloadFailedDueToAboveBrowserLimit(context);
}

return _fileDownloadFailedDueToFileAbovePrivateLimit(context);
Expand Down Expand Up @@ -181,6 +184,21 @@ class FileDownloadDialog extends StatelessWidget {
);
}

ArDriveStandardModal _fileDownloadFailedDueToAboveBrowserLimit(
BuildContext context) {
return _modalWrapper(
title: appLocalizationsOf(context).warningEmphasized,
description:
appLocalizationsOf(context).fileFailedToDownloadFileAbovePublicLimit,
actions: [
ModalAction(
action: () => Navigator.pop(context),
title: appLocalizationsOf(context).ok,
),
],
);
}

ArDriveStandardModal _warningToWaitDownloadFinishes(BuildContext context) {
return _modalWrapper(
title: appLocalizationsOf(context).warningEmphasized,
Expand Down
1 change: 1 addition & 0 deletions lib/download/limits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'download_utils.dart';
final publicDownloadUnknownPlatformSizeLimit = const GiB(2).size;
final publicDownloadWebSizeLimit = const MiB(500).size;
final publicDownloadFirefoxSizeLimit = const GiB(2).size;
final publicDownloadSafariSizeLimit = const GiB(1).size;
final publicDownloadMobileSizeLimit = const MiB(300).size;

final privateDownloadUnknownPlatformSizeLimit = const GiB(2).size;
Expand Down

0 comments on commit 687b0db

Please sign in to comment.