diff --git a/lib/blocs/file_download/file_download_cubit.dart b/lib/blocs/file_download/file_download_cubit.dart index b4351ff63f..75496137db 100644 --- a/lib/blocs/file_download/file_download_cubit.dart +++ b/lib/blocs/file_download/file_download_cubit.dart @@ -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'; @@ -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'; diff --git a/lib/blocs/file_download/file_download_state.dart b/lib/blocs/file_download/file_download_state.dart index cb0da652e1..9299ef2288 100644 --- a/lib/blocs/file_download/file_download_state.dart +++ b/lib/blocs/file_download/file_download_state.dart @@ -81,6 +81,7 @@ class FileDownloadAborted extends FileDownloadState {} enum FileDownloadFailureReason { unknownError, fileAboveLimit, + browserDoesNotSupportLargeDownloads, networkConnectionError, fileNotFound } diff --git a/lib/blocs/file_download/personal_file_download_cubit.dart b/lib/blocs/file_download/personal_file_download_cubit.dart index 64de257da5..508768d694 100644 --- a/lib/blocs/file_download/personal_file_download_cubit.dart +++ b/lib/blocs/file_download/personal_file_download_cubit.dart @@ -42,6 +42,18 @@ class ProfileFileDownloadCubit extends FileDownloadCubit { _arfsRepository = arfsRepository, super(FileDownloadStarting()); + Future verifyUploadLimitationsAndDownload(SecretKey? cipherKey) async { + if (await AppPlatform.isSafari()) { + if (_file.size > publicDownloadSafariSizeLimit) { + emit(const FileDownloadFailure( + FileDownloadFailureReason.browserDoesNotSupportLargeDownloads)); + return; + } + } + + download(cipherKey); + } + Future download(SecretKey? cipherKey) async { try { final drive = await _arfsRepository.getDriveById(_file.driveId); diff --git a/lib/components/file_download_dialog.dart b/lib/components/file_download_dialog.dart index 3d86337058..4ef688bbe9 100644 --- a/lib/components/file_download_dialog.dart +++ b/lib/components/file_download_dialog.dart @@ -42,7 +42,7 @@ Future promptToDownloadProfileFile({ file: arfsFile, driveDao: context.read(), arweave: arweave, - )..download(cipherKey); + )..verifyUploadLimitationsAndDownload(cipherKey); return showArDriveDialog( context, barrierDismissible: false, @@ -77,7 +77,7 @@ Future promptToDownloadFileRevision({ file: arfsFile, driveDao: context.read(), arweave: arweave, - )..download(cipherKey); + )..verifyUploadLimitationsAndDownload(cipherKey); return showArDriveDialog( context, @@ -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); @@ -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, diff --git a/lib/download/limits.dart b/lib/download/limits.dart index 7b50686eb6..5cb217e31e 100644 --- a/lib/download/limits.dart +++ b/lib/download/limits.dart @@ -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;