Skip to content

Commit

Permalink
Merge pull request #1478 from ardriveapp/PE-5011-missing-u-tags-in-di…
Browse files Browse the repository at this point in the history
…rect-to-network-bundles

PE-5011: fix: missing u tags in direct to network bundles
  • Loading branch information
thiagocarvalhodev authored Nov 14, 2023
2 parents 8f2b768 + 4becfd0 commit d651bd4
Show file tree
Hide file tree
Showing 19 changed files with 1,019 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ macos/flutter/ephemeral
linux/flutter/ephemeral
windows/flutter/ephemeral

scripts/build/.last_build_id
# Web related

# Symbolication related
Expand Down
149 changes: 30 additions & 119 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:ardrive/entities/file_entity.dart';
import 'package:ardrive/entities/folder_entity.dart';
import 'package:ardrive/main.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/turbo/utils/utils.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand Down Expand Up @@ -40,8 +39,6 @@ class UploadCubit extends Cubit<UploadState> {

final ProfileCubit _profileCubit;
final DriveDao _driveDao;
final ArweaveService _arweave;
final TurboUploadService _turbo;
final PstService _pst;
final UploadFileChecker _uploadFileChecker;
final ArDriveAuth _auth;
Expand Down Expand Up @@ -100,8 +97,6 @@ class UploadCubit extends Cubit<UploadState> {
required this.files,
required ProfileCubit profileCubit,
required DriveDao driveDao,
required ArweaveService arweave,
required TurboUploadService turbo,
required PstService pst,
required UploadFileChecker uploadFileChecker,
required ArDriveAuth auth,
Expand All @@ -112,8 +107,6 @@ class UploadCubit extends Cubit<UploadState> {
}) : _profileCubit = profileCubit,
_uploadFileChecker = uploadFileChecker,
_driveDao = driveDao,
_arweave = arweave,
_turbo = turbo,
_pst = pst,
_auth = auth,
_arDriveUploadManager = arDriveUploadManager,
Expand Down Expand Up @@ -461,57 +454,34 @@ class UploadCubit extends Cubit<UploadState> {
logger.d(
'Wallet verified. Starting bundle preparation.... Number of bundles: ${uploadPlanForAr.bundleUploadHandles.length}. Number of V2 files: ${uploadPlanForAr.fileV2UploadHandles.length}');

if (configService.config.useNewUploader) {
if (_uploadMethod == UploadMethod.turbo) {
await _verifyIfUploadContainsLargeFilesUsingTurbo();
if ((_containsLargeTurboUpload ?? false) &&
!hasEmittedWarning &&
kIsWeb &&
!await AppPlatform.isChrome()) {
emit(
UploadShowingWarning(
reason: UploadWarningReason.fileTooLargeOnNonChromeBrowser,
uploadPlanForAR: uploadPlanForAr,
uploadPlanForTurbo: uploadPlanForTurbo,
),
);
hasEmittedWarning = true;
return;
}
} else {
_containsLargeTurboUpload = false;
}

if (uploadFolders) {
await _uploadFolderUsingArDriveUploader();
if (_uploadMethod == UploadMethod.turbo) {
await _verifyIfUploadContainsLargeFilesUsingTurbo();
if ((_containsLargeTurboUpload ?? false) &&
!hasEmittedWarning &&
kIsWeb &&
!await AppPlatform.isChrome()) {
emit(
UploadShowingWarning(
reason: UploadWarningReason.fileTooLargeOnNonChromeBrowser,
uploadPlanForAR: uploadPlanForAr,
uploadPlanForTurbo: uploadPlanForTurbo,
),
);
hasEmittedWarning = true;
return;
}

await _uploadUsingArDriveUploader();

return;
} else {
_containsLargeTurboUpload = false;
}

logger.d('Uploading using the old uploader');
final uploader = _getUploader();

await for (final progress in uploader.uploadFromHandles(
bundleHandles: uploadPlan.bundleUploadHandles,
fileV2Handles: uploadPlan.fileV2UploadHandles.values.toList(),
)) {
emit(
UploadInProgress(
uploadPlan: uploadPlan,
progress: progress,
),
);
if (uploadFolders) {
await _uploadFolderUsingArDriveUploader();
return;
}

logger.d('Upload finished');
await _uploadUsingArDriveUploader();

unawaited(_profileCubit.refreshBalance());

emit(UploadComplete());
return;
}

Future<void> _uploadFolderUsingArDriveUploader() async {
Expand Down Expand Up @@ -543,6 +513,9 @@ class UploadCubit extends Cubit<UploadState> {
parentFolderId: folder.parentFolderId,
privacy: _targetDrive.isPrivate ? 'private' : 'public',
entityId: folder.id,
type: _uploadMethod == UploadMethod.ar
? UploadType.d2n
: UploadType.turbo,
);

entities.add((
Expand All @@ -568,6 +541,9 @@ class UploadCubit extends Cubit<UploadState> {
parentFolderId: file.parentFolderId,
privacy: _targetDrive.isPrivate ? 'private' : 'public',
entityId: id,
type: _uploadMethod == UploadMethod.ar
? UploadType.d2n
: UploadType.turbo,
);

entities.add((fileMetadata, file.ioFile));
Expand Down Expand Up @@ -662,6 +638,9 @@ class UploadCubit extends Cubit<UploadState> {
entityId: revisionAction == RevisionAction.uploadNewVersion
? conflictingFiles[file.getIdentifier()]
: null,
type: _uploadMethod == UploadMethod.ar
? UploadType.d2n
: UploadType.turbo,
);

uploadFiles.add((args, file.ioFile));
Expand Down Expand Up @@ -826,74 +805,6 @@ class UploadCubit extends Cubit<UploadState> {
}
}

ArDriveUploaderFromHandles _getUploader() {
final wallet = _auth.currentUser.wallet;

final turboUploader = TurboUploader(_turbo, wallet);
final arweaveUploader = ArweaveBundleUploader(_arweave.client);

logger.d(
'Uploaders created: Turbo: $turboUploader, Arweave: $arweaveUploader');

final bundleUploader = BundleUploader(
turboUploader,
arweaveUploader,
_uploadMethod == UploadMethod.turbo,
);

final v2Uploader = FileV2Uploader(_arweave.client, _arweave);

final uploader = ArDriveUploaderFromHandles(
bundleUploader: bundleUploader,
fileV2Uploader: v2Uploader,
prepareBundle: (handle) async {
logger.d(
'Preparing bundle.. using turbo: ${_uploadMethod == UploadMethod.turbo}');

await handle.prepareAndSignBundleTransaction(
tabVisibilitySingleton: TabVisibilitySingleton(),
arweaveService: _arweave,
turboUploadService: _turbo,
pstService: _pst,
wallet: _auth.currentUser.wallet,
isArConnect: await _profileCubit.isCurrentProfileArConnect(),
useTurbo: _uploadMethod == UploadMethod.turbo,
);

logger.d('Bundle preparation finished');
},
prepareFile: (handle) async {
logger.d('Preparing file...');

await handle.prepareAndSignTransactions(
arweaveService: _arweave,
wallet: wallet,
pstService: _pst,
);
},
onFinishFileUpload: (handle) async {
unawaited(handle.writeFileEntityToDatabase(driveDao: _driveDao));
},
onFinishBundleUpload: (handle) async {
unawaited(handle.writeBundleItemsToDatabase(driveDao: _driveDao));
},
onUploadBundleError: (handle, error) async {
if (!hasEmittedError) {
addError(error);
hasEmittedError = true;
}
},
onUploadFileError: (handle, error) async {
if (!hasEmittedError) {
addError(error);
hasEmittedError = true;
}
},
);

return uploader;
}

Future<void> skipLargeFilesAndCheckForConflicts() async {
emit(UploadPreparationInProgress());
final List<String> filesToSkip = await _uploadFileChecker
Expand Down
2 changes: 0 additions & 2 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ Future<void> promptToUpload(
parentFolderId: parentFolderId,
files: selectedFiles,
profileCubit: context.read<ProfileCubit>(),
arweave: context.read<ArweaveService>(),
turbo: context.read<TurboUploadService>(),
pst: context.read<PstService>(),
driveDao: context.read<DriveDao>(),
uploadFolders: isFolderUpload,
Expand Down
2 changes: 0 additions & 2 deletions lib/pages/drive_detail/components/drive_file_drop_zone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class DriveFileDropZoneState extends State<DriveFileDropZone> {
driveId: driveId,
parentFolderId: parentFolderId,
files: selectedFiles,
arweave: context.read<ArweaveService>(),
turbo: context.read<TurboUploadService>(),
pst: context.read<PstService>(),
profileCubit: context.read<ProfileCubit>(),
driveDao: context.read<DriveDao>(),
Expand Down
3 changes: 0 additions & 3 deletions lib/services/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AppConfig {
final int autoSyncIntervalInSeconds;
final bool enableSyncFromSnapshot;
final bool enableSeedPhraseLogin;
final bool useNewUploader;
final String stripePublishableKey;
final bool forceNoFreeThanksToTurbo;
final BigInt? fakeTurboCredits;
Expand All @@ -39,7 +38,6 @@ class AppConfig {
this.enableSyncFromSnapshot = true,
this.enableSeedPhraseLogin = true,
required this.stripePublishableKey,
this.useNewUploader = false,
this.forceNoFreeThanksToTurbo = false,
this.fakeTurboCredits,
this.topUpDryRun = false,
Expand Down Expand Up @@ -71,7 +69,6 @@ class AppConfig {
: fakeTurboCredits ?? this.fakeTurboCredits;

return AppConfig(
useNewUploader: useNewUploader ?? this.useNewUploader,
defaultArweaveGatewayUrl:
defaultArweaveGatewayUrl ?? this.defaultArweaveGatewayUrl,
useTurboUpload: useTurboUpload ?? this.useTurboUpload,
Expand Down
10 changes: 9 additions & 1 deletion packages/arconnect/test/arconnect_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
void main() {}
import 'package:flutter_test/flutter_test.dart';

void main() {
// TODO: Write tests
test('test', () {
var answer = 42;
expect(answer, 42);
});
}
8 changes: 8 additions & 0 deletions packages/ardrive_crypto/test/ardrive_crypto_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import 'package:flutter_test/flutter_test.dart';

void main() {
// TODO: Write tests
test('test', () {
var answer = 42;
expect(answer, 42);
});
}
1 change: 1 addition & 0 deletions packages/ardrive_uploader/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
/build/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
Expand Down
1 change: 1 addition & 0 deletions packages/ardrive_uploader/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class _UploadFormState extends State<UploadForm> {
driveId: driveIdController.text,
parentFolderId: parentFolderIdController.text,
isPrivate: false,
type: UploadType.turbo,
),
wallet: wallet,
);
Expand Down
1 change: 1 addition & 0 deletions packages/ardrive_uploader/lib/src/data_bundler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class DataTransactionBundler implements DataBundler<TransactionResult> {
isPrivate: driveKey != null,
driveId: driveId,
parentFolderId: metadata.id,
type: this is BDIDataBundler ? UploadType.turbo : UploadType.d2n,
),
);

Expand Down
Loading

0 comments on commit d651bd4

Please sign in to comment.