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-4754: Uploader/Downloader #1415

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
a19db07
refactor: add unawaited method
thiagocarvalhodev Oct 9, 2023
66621fc
Update ardrive_uploader.dart
thiagocarvalhodev Oct 9, 2023
c60dc5f
Update data_bundler.dart
thiagocarvalhodev Oct 9, 2023
914383c
refactor(UploadTask)
thiagocarvalhodev Oct 9, 2023
138ecbc
Update upload_controller.dart
thiagocarvalhodev Oct 9, 2023
c5b5521
Update data_bundler.dart
thiagocarvalhodev Oct 9, 2023
2e305fe
Update data_bundler.dart
thiagocarvalhodev Oct 9, 2023
7fb57ca
Merge branch 'PE-4754-address-code-review-comments-on-uploader-downlo…
thiagocarvalhodev Oct 9, 2023
d1a6970
refactor(UploadItem): renames the implementations for the UploadItem
thiagocarvalhodev Oct 9, 2023
68a784e
refactor(UploadController)
thiagocarvalhodev Oct 9, 2023
fb2105a
refactor(base2size)
thiagocarvalhodev Oct 9, 2023
07a767e
refactor(upload progress)
thiagocarvalhodev Oct 9, 2023
15f918b
refactor(streamed upload)
thiagocarvalhodev Oct 9, 2023
ab8816f
Update main.dart
thiagocarvalhodev Oct 9, 2023
90dae32
Update authenticate.dart
thiagocarvalhodev Oct 9, 2023
443f2e0
fix: lint warning
thiagocarvalhodev Oct 9, 2023
64005d1
Update upload_cubit.dart
thiagocarvalhodev Oct 9, 2023
238196e
feat(error handling)
thiagocarvalhodev Oct 10, 2023
3e35082
feat(uploader)
thiagocarvalhodev Oct 10, 2023
523c77d
Update upload_controller.dart
thiagocarvalhodev Oct 10, 2023
4780650
Update upload_form.dart
thiagocarvalhodev Oct 10, 2023
14f0c0b
use fetch client with abort
thiagocarvalhodev Oct 10, 2023
8baaefa
feat(uploader)
thiagocarvalhodev Oct 10, 2023
61bb03c
Update ardrive_uploader.dart
thiagocarvalhodev Oct 10, 2023
9dfdf70
feat(uploader)
thiagocarvalhodev Oct 10, 2023
aec969f
feat(uploader)
thiagocarvalhodev Oct 11, 2023
ec8ac32
fix(uploader)
thiagocarvalhodev Oct 12, 2023
fd4062f
feat(uploader)
thiagocarvalhodev Oct 12, 2023
65cb34b
fix(uploader)
thiagocarvalhodev Oct 12, 2023
7150377
Update crypto.dart
thiagocarvalhodev Oct 12, 2023
568a65c
Update app_info_services.dart
thiagocarvalhodev Oct 12, 2023
47d9b1a
fix: creation of a folder
thiagocarvalhodev Oct 12, 2023
3982133
feat(uploader): makes turbo uploads be marked as not possible when si…
matibat Oct 16, 2023
a79f08d
chore(limits): rename method PE-4754
matibat Oct 17, 2023
2481ace
feat(uploader)
thiagocarvalhodev Oct 17, 2023
764bf77
Update limits.dart
thiagocarvalhodev Oct 18, 2023
a13990d
Update upload_cubit.dart
thiagocarvalhodev Oct 18, 2023
0c41e0c
Update limits.dart
thiagocarvalhodev Oct 18, 2023
39c5b40
Update upload_form.dart
thiagocarvalhodev Oct 18, 2023
1fa946d
Update upload_form.dart
thiagocarvalhodev Oct 18, 2023
387f84a
Update ardrive_uploader.dart
thiagocarvalhodev Oct 18, 2023
69f8b66
Update d2n_streamed_upload.dart
thiagocarvalhodev Oct 18, 2023
65b6a74
Update data_bundler.dart
thiagocarvalhodev Oct 18, 2023
f0f389b
fix(cancel upload)
thiagocarvalhodev Oct 18, 2023
9e1291b
Update d2n_streamed_upload.dart
thiagocarvalhodev Oct 19, 2023
a123362
feat(abort upload)
thiagocarvalhodev Oct 19, 2023
959152a
feat(abort upload)
thiagocarvalhodev Oct 19, 2023
601c630
fix(cancel upload)
thiagocarvalhodev Oct 19, 2023
eeb8976
Update upload_form.dart
thiagocarvalhodev Oct 19, 2023
bdb8027
Merge remote-tracking branch 'origin/PE-4754-revert_the_revert' into …
matibat Oct 19, 2023
bf03fde
Update turbo_upload_service_dart_io.dart
thiagocarvalhodev Oct 19, 2023
41823ed
feat(json config): enables new uploader for prod; changes the default…
matibat Oct 19, 2023
e265996
Merge pull request #1430 from ardriveapp/PE-4844
matibat Oct 19, 2023
b68bea9
fix(cancel upload)
thiagocarvalhodev Oct 19, 2023
42af40e
Update ciphers.dart
thiagocarvalhodev Oct 20, 2023
360b54f
feat(dev tools)
thiagocarvalhodev Oct 23, 2023
7922632
Update side_bar.dart
thiagocarvalhodev Oct 23, 2023
b2d43e7
Update side_bar.dart
thiagocarvalhodev Oct 23, 2023
098a313
Update turbo_upload_service_web.dart
thiagocarvalhodev Oct 23, 2023
bbac1bb
add wakelock
thiagocarvalhodev Oct 23, 2023
33bdf43
Revert "add wakelock"
thiagocarvalhodev Oct 23, 2023
9e0c84c
Merge pull request #1426 from ardriveapp/PE-4812-cancel-button-fails-…
thiagocarvalhodev Oct 23, 2023
a3be366
Merge pull request #1434 from ardriveapp/PE-4856-adds-the-dev-tools-o…
thiagocarvalhodev Oct 23, 2023
83d5ba0
feat(pst package)
thiagocarvalhodev Oct 24, 2023
d5fc3ed
fix(donwloads)
thiagocarvalhodev Oct 24, 2023
c002919
feat(pst)
thiagocarvalhodev Oct 24, 2023
bcbb9ad
feat(pst)
thiagocarvalhodev Oct 24, 2023
07c9c6a
Update cost_calculator.dart
thiagocarvalhodev Oct 24, 2023
9aaf2d2
fix(download pins): dont decrypt the data if it is a pin
thiagocarvalhodev Oct 24, 2023
74e0b16
fix(upload warning)
thiagocarvalhodev Oct 24, 2023
2d9f8fa
fix(downloads)
thiagocarvalhodev Oct 24, 2023
3d394d5
refactor:
thiagocarvalhodev Oct 25, 2023
2445c41
upgrades the ardrive_io
thiagocarvalhodev Oct 25, 2023
49d7028
Merge pull request #1422 from ardriveapp/PE-4754_turbo_upload_possible
thiagocarvalhodev Oct 25, 2023
0c3f991
fix: add limitations warnings
thiagocarvalhodev Oct 25, 2023
687b0db
fix: add warning on download modal
thiagocarvalhodev Oct 25, 2023
7a802d4
feat(downloads)
thiagocarvalhodev Oct 25, 2023
6ecd7fd
fix: lints
thiagocarvalhodev Oct 25, 2023
56a7db4
Revert "fix: lints"
thiagocarvalhodev Oct 25, 2023
fad67b1
Revert "feat(downloads)"
thiagocarvalhodev Oct 25, 2023
2e51673
fix: downloads on firefox
thiagocarvalhodev Oct 25, 2023
fda00d8
fix lint
thiagocarvalhodev Oct 25, 2023
a1cbb70
feat(pst)
thiagocarvalhodev Oct 26, 2023
65c607d
refactor:
thiagocarvalhodev Oct 26, 2023
a290213
Update ardrive_contract_oracle.dart
thiagocarvalhodev Oct 26, 2023
ded60cc
Merge pull request #1440 from ardriveapp/PE-4876-add-warning-to-uploa…
thiagocarvalhodev Oct 26, 2023
855a946
Merge branch 'PE-4754-address-code-review-comments-on-uploader-downlo…
thiagocarvalhodev Oct 26, 2023
7c71a45
Merge branch 'PE-4754-address-code-review-comments-on-uploader-downlo…
thiagocarvalhodev Oct 26, 2023
1b4f080
Update community_oracle.dart
thiagocarvalhodev Oct 26, 2023
ac19f01
Merge pull request #1439 from ardriveapp/PE-4866-implement-a-contract…
thiagocarvalhodev Oct 26, 2023
6667841
Merge pull request #1432 from ardriveapp/PE-4851-change-the-return-ty…
thiagocarvalhodev Oct 26, 2023
097c448
Merge pull request #1438 from ardriveapp/PE-4864-unable-to-download-f…
thiagocarvalhodev Oct 26, 2023
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
2 changes: 1 addition & 1 deletion assets/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"defaultArweaveGatewayUrl": "https://arweave.net",
"useTurboUpload": true,
"useTurboPayment": true,
"defaultTurboUploadUrl": "https://upload.ardrive.io",
"defaultTurboUploadUrl": "https://upload.ardrive.dev",
"defaultTurboPaymentUrl": "https://payment.ardrive.dev",
"allowedDataItemSizeForTurbo": 500000,
"enableQuickSyncAuthoring": true,
Expand Down
2 changes: 1 addition & 1 deletion assets/config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true,
"useNewUploader": false
"useNewUploader": true
}
3 changes: 2 additions & 1 deletion lib/blocs/create_manifest/create_manifest_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import 'dart:async';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/entities/manifest_data.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/arweave.dart';
import 'package:arweave/utils.dart';
import 'package:collection/collection.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pst/pst.dart';
import 'package:uuid/uuid.dart';

import '../../core/upload/cost_calculator.dart';
Expand Down
8 changes: 4 additions & 4 deletions lib/blocs/create_snapshot/create_snapshot_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:ardrive/blocs/profile/profile_cubit.dart';
import 'package:ardrive/blocs/upload/upload_cubit.dart';
import 'package:ardrive/core/upload/cost_calculator.dart';
import 'package:ardrive/entities/snapshot_entity.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/daos/daos.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/payment_service.dart';
Expand All @@ -25,6 +24,7 @@ import 'package:arweave/arweave.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pst/pst.dart';
import 'package:stash_shared_preferences/stash_shared_preferences.dart';
import 'package:uuid/uuid.dart';

Expand Down Expand Up @@ -421,7 +421,7 @@ class CreateSnapshotCubit extends Cubit<CreateSnapshotState> {

_turboBalance = turboBalance;
_hasNoTurboBalance = turboBalance == BigInt.zero;
_turboCredits = convertCreditsToLiteralString(turboBalance);
_turboCredits = convertWinstonToLiteralString(turboBalance);
_sufficentCreditsBalance = _costEstimateTurbo.totalCost <= _turboBalance;
_computeIsTurboEnabled();
_computeIsButtonEnabled();
Expand Down Expand Up @@ -464,8 +464,8 @@ class CreateSnapshotCubit extends Cubit<CreateSnapshotState> {

_turboBalance = turboBalance;
_hasNoTurboBalance = turboBalance == BigInt.zero;
_turboCredits = convertCreditsToLiteralString(turboBalance);
_arBalance = convertCreditsToLiteralString(auth.currentUser.walletBalance);
_turboCredits = convertWinstonToLiteralString(turboBalance);
_arBalance = convertWinstonToLiteralString(auth.currentUser.walletBalance);
}

void _computeIsTurboEnabled() async {
Expand Down
1 change: 0 additions & 1 deletion lib/blocs/drive_attach/drive_attach_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:convert';

import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'dart:async';
import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/constants.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/pages.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/open_url.dart';
import 'package:ardrive/utils/user_utils.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:drift/drift.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/drives/drives_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';

import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/utils/user_utils.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:drift/drift.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/blocs/file_download/file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ 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/entities/constants.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/data_size.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive_http/ardrive_http.dart';
import 'package:ardrive_io/ardrive_io.dart' as io;
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
}
27 changes: 19 additions & 8 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 Expand Up @@ -127,7 +139,9 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
String? cipherIvTag;
SecretKey? fileKey;

if (drive.drivePrivacy == DrivePrivacy.private) {
final isPinFile = _file.pinnedDataOwnerAddress != null;

if (drive.drivePrivacy == DrivePrivacy.private && !isPinFile) {
SecretKey? driveKey;

if (cipherKey != null) {
Expand All @@ -138,9 +152,11 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
} else {
driveKey = await _driveDao.getDriveKeyFromMemory(_file.driveId);
}

if (driveKey == null) {
throw StateError('Drive Key not found');
}

fileKey = await _driveDao.getFileKey(_file.id, driveKey);

final dataTx = await (_arweave.getTransactionDetails(_file.txId));
Expand All @@ -158,6 +174,7 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
fileName: _file.name,
fileSize: _file.size,
lastModifiedDate: _file.lastModifiedDate,
isManifest: _file.contentType == ContentType.manifest,
contentType:
_file.contentType ?? lookupMimeTypeWithDefaultType(_file.name),
cipher: cipher,
Expand All @@ -170,13 +187,6 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
return;
}

if (progress == 100) {
emit(FileDownloadFinishedWithSuccess(fileName: _file.name));
return;
}

logger.d('Download progress: $progress');

emit(
FileDownloadWithProgress(
fileName: _file.name,
Expand All @@ -186,6 +196,7 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
_file.contentType ?? lookupMimeTypeWithDefaultType(_file.name),
),
);

_downloadProgress.sink.add(FileDownloadProgress(progress / 100));
}

Expand Down
1 change: 0 additions & 1 deletion lib/blocs/pin_file/pin_file_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/entities/entities.dart' show FileEntity;
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/misc/misc.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/blocs/shared_file/shared_file_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/blocs/sync/sync_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:ardrive/blocs/constants.dart';
import 'package:ardrive/blocs/sync/ghost_folder.dart';
import 'package:ardrive/core/activity_tracker.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand Down
19 changes: 11 additions & 8 deletions lib/blocs/sync/utils/add_file_entity_revisions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ Future<List<FileRevisionsCompanion>> _addNewFileEntityRevisions({
continue;
}
// If Parent-Folder-Id is missing for a file, put it in the root folder
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the line that will throw here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

final revision = entity.toRevisionCompanion(performedAction: revisionPerformedAction);

entity.parentFolderId = entity.parentFolderId ?? rootPath;
final revision =
entity.toRevisionCompanion(performedAction: revisionPerformedAction);

entity.parentFolderId = entity.parentFolderId ?? rootPath;
final revision =
entity.toRevisionCompanion(performedAction: revisionPerformedAction);
if (revision.action.value.isEmpty) {
continue;
}

if (revision.action.value.isEmpty) {
continue;
newRevisions.add(revision);
latestRevisions[entity.id!] = revision;
} catch (e) {
logger.e('Error adding revision for entity: ${entity.id}', e);
}

newRevisions.add(revision);
latestRevisions[entity.id!] = revision;
}

await database.batch((b) {
Expand Down
16 changes: 10 additions & 6 deletions lib/blocs/upload/limits.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import 'package:ardrive/utils/data_size.dart';
import 'package:flutter/foundation.dart';
import 'package:ardrive_utils/ardrive_utils.dart';

final privateFileSizeLimit = const MiB(100000).size;
final privateFileSizeLimit = const GiB(65).size;

final largeFileUploadSizeThreshold = const MiB(500).size;

final mobilePrivateFileSizeLimit = const GiB(10).size;

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

final bundleSizeLimit = kIsWeb ? webBundleSizeLimit : mobileBundleSizeLimit;
int getBundleSizeLimit(bool isTurbo) =>
isTurbo ? turboBundleSizeLimit : d2nBundleSizeLimit;

final webBundleSizeLimit = const MiB(65000).size;
final mobileBundleSizeLimit = const MiB(65000).size;
final d2nBundleSizeLimit = const GiB(65).size;
final turboBundleSizeLimit = const GiB(2).size;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be Gibibytes or Gigabytes? - 65000 MiB != 65 GiB.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be 65GiB.

final mobileBundleSizeLimit = const GiB(65).size;
const maxBundleDataItemCount = 500;
const maxFilesPerBundle = maxBundleDataItemCount ~/ 2;
const maxFilesSizePerBundleUsingTurbo = 1;
7 changes: 4 additions & 3 deletions lib/blocs/upload/models/upload_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:ardrive/blocs/upload/upload_handles/upload_handle.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/utils/bundles/next_fit_bundle_packer.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:flutter/foundation.dart';

import '../upload_handles/file_data_item_upload_handle.dart';
import '../upload_handles/file_v2_upload_handle.dart';
Expand All @@ -30,6 +29,7 @@ class UploadPlan {
folderDataItemUploadHandles,
required TurboUploadService turboUploadService,
required int maxDataItemCount,
required bool useTurbo,
}) async {
final uploadPlan = UploadPlan._create(
fileV2UploadHandles: fileV2UploadHandles,
Expand All @@ -43,13 +43,15 @@ class UploadPlan {
folderDataItemUploadHandles: folderDataItemUploadHandles,
turboUploadService: turboUploadService,
maxDataItemCount: maxDataItemCount,
useTurbo: useTurbo,
);
}

return uploadPlan;
}

Future<void> createBundleHandlesFromDataItemHandles({
required bool useTurbo,
Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles = const {},
Map<String, FolderDataItemUploadHandle> folderDataItemUploadHandles =
const {},
Expand All @@ -58,8 +60,7 @@ class UploadPlan {
}) async {
logger.i(
'Creating bundle handles from data item handles with a max number of files of $maxDataItemCount');
final int maxBundleSize =
(kIsWeb ? bundleSizeLimit : mobileBundleSizeLimit);
final int maxBundleSize = getBundleSizeLimit(useTurbo);

final folderItems = await NextFitBundlePacker<UploadHandle>(
maxBundleSize: maxBundleSize,
Expand Down
Loading
Loading