Skip to content

Commit

Permalink
Merge branch 'dev' into PE-5397
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Feb 20, 2024
2 parents 4d6d672 + 597896d commit 802c133
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 107 deletions.
2 changes: 2 additions & 0 deletions android/fastlane/metadata/android/en-US/changelogs/106.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixes web drag and drop upload issue.
- Fixes Turbo upload for small files when payment service is not available
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/107.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Sets the limit for free uploads to 100KB
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes private file download issue with missing bytes
2 changes: 1 addition & 1 deletion assets/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useTurboPayment": true,
"defaultTurboUploadUrl": "https://upload.ardrive.dev",
"defaultTurboPaymentUrl": "https://payment.ardrive.dev",
"allowedDataItemSizeForTurbo": 500000,
"allowedDataItemSizeForTurbo": 100000,
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": 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 @@ -4,7 +4,7 @@
"useTurboPayment": true,
"defaultTurboUploadUrl": "https://upload.ardrive.io",
"defaultTurboPaymentUrl": "https://payment.ardrive.io",
"allowedDataItemSizeForTurbo": 500000,
"allowedDataItemSizeForTurbo": 100000,
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": true,
Expand Down
2 changes: 1 addition & 1 deletion assets/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useTurboPayment": true,
"defaultTurboUploadUrl": "https://upload.ardrive.io",
"defaultTurboPaymentUrl": "https://payment.ardrive.io",
"allowedDataItemSizeForTurbo": 500000,
"allowedDataItemSizeForTurbo": 100000,
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": true,
Expand Down
39 changes: 26 additions & 13 deletions lib/core/upload/uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,19 @@ class UploadPaymentEvaluator {
);
}

uploadMethod = await _determineUploadMethod(
turboBalance,
turboBundleSizes,
_appConfig.allowedDataItemSizeForTurbo,
_isTurboAvailableToUploadAllFiles,
);
// Checking isFreeUploadPossibleUsingTurbo uses the 100KB file size check
// against the date, but using _determineUploadMethod() additionally uses the
// Turbo bundle headers as part of the size check. A 100KB file might be
// larger than _appConfig.allowedDataItemSizeForTurbo due to the headers,
// so we need to catch that here.
uploadMethod = isFreeUploadPossibleUsingTurbo
? UploadMethod.turbo
: await _determineUploadMethod(
turboBalance,
turboBundleSizes,
_appConfig.allowedDataItemSizeForTurbo,
_isTurboAvailableToUploadAllFiles,
);

if (uploadMethod == UploadMethod.turbo) {
totalSize = turboBundleSizes;
Expand Down Expand Up @@ -498,18 +505,23 @@ class UploadPaymentEvaluator {
}

Future<UploadMethod> _determineUploadMethod(
BigInt turboBalance,
int turboBundleSizes,
int allowedSizeForTurbo,
bool isTurboAvailableToUploadAllFiles) async {
BigInt turboBalance,
int turboBundleSizes,
int allowedSizeForTurbo,
bool isTurboAvailableToUploadAllFiles,
) async {
bool isFreeUploadPossibleUsingTurbo =
turboBundleSizes <= allowedSizeForTurbo;

if (isFreeUploadPossibleUsingTurbo) {
return UploadMethod.turbo;
}

try {
final turboCostEstimate = await _turboUploadCostCalculator.calculateCost(
totalSize: turboBundleSizes,
);

bool isFreeUploadPossibleUsingTurbo =
turboBundleSizes <= allowedSizeForTurbo;

if ((isTurboAvailableToUploadAllFiles &&
turboBalance >= turboCostEstimate.totalCost) ||
isFreeUploadPossibleUsingTurbo) {
Expand All @@ -519,6 +531,7 @@ class UploadPaymentEvaluator {
}
} catch (e) {
_isTurboAvailableToUploadAllFiles = false;

return UploadMethod.ar;
}
}
Expand Down
89 changes: 6 additions & 83 deletions lib/pages/drive_detail/components/drive_file_drop_zone.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import 'dart:ui';

import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/upload/models/upload_file.dart';
import 'package:ardrive/blocs/upload/upload_file_checker.dart';
import 'package:ardrive/components/upload_form.dart';
import 'package:ardrive/core/activity_tracker.dart';
import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/core/upload/cost_calculator.dart';
import 'package:ardrive/core/upload/uploader.dart';
import 'package:ardrive/models/daos/drive_dao/drive_dao.dart';
import 'package:ardrive/pages/congestion_warning_wrapper.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/payment_service.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/turbo/turbo.dart';
import 'package:ardrive/utils/app_localizations_wrapper.dart';
import 'package:ardrive/utils/show_general_dialog.dart';
import 'package:ardrive/utils/upload_plan_utils.dart';
import 'package:ardrive_io/ardrive_io.dart';
import 'package:ardrive_ui/ardrive_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dropzone/flutter_dropzone.dart';
import 'package:pst/pst.dart';

class DriveFileDropZone extends StatefulWidget {
final String driveId;
Expand Down Expand Up @@ -108,74 +91,14 @@ class DriveFileDropZoneState extends State<DriveFileDropZone> {
if (!isCurrentlyShown) {
isCurrentlyShown = true;
_onLeave();
final selectedFiles = files
.map((e) => UploadFile(
ioFile: e,
parentFolderId: parentFolderId,
))
.toList();

// ignore: use_build_context_synchronously
await showCongestionDependentModalDialog(
promptToUpload(
context,
() => showArDriveDialog(
context,
content: BlocProvider<UploadCubit>(
create: (context) => UploadCubit(
isDragNDrop: true,
activityTracker: context.read<ActivityTracker>(),
arDriveUploadManager: ArDriveUploadPreparationManager(
uploadPreparePaymentOptions: UploadPaymentEvaluator(
appConfig: context.read<ConfigService>().config,
auth: context.read<ArDriveAuth>(),
turboBalanceRetriever: TurboBalanceRetriever(
paymentService: context.read<PaymentService>(),
),
turboUploadCostCalculator: TurboUploadCostCalculator(
priceEstimator: TurboPriceEstimator(
wallet: context.read<ArDriveAuth>().currentUser.wallet,
costCalculator: TurboCostCalculator(
paymentService: context.read<PaymentService>(),
),
paymentService: context.read<PaymentService>(),
),
turboCostCalculator: TurboCostCalculator(
paymentService: context.read<PaymentService>(),
),
),
uploadCostEstimateCalculatorForAR:
UploadCostEstimateCalculatorForAR(
arweaveService: context.read<ArweaveService>(),
pstService: context.read<PstService>(),
arCostToUsd: ConvertArToUSD(
arweave: context.read<ArweaveService>(),
),
),
),
uploadPreparer: UploadPreparer(
uploadPlanUtils: UploadPlanUtils(
crypto: ArDriveCrypto(),
arweave: context.read<ArweaveService>(),
turboUploadService: context.read<TurboUploadService>(),
driveDao: context.read<DriveDao>(),
),
),
),
uploadFileSizeChecker: context.read<UploadFileSizeChecker>(),
driveId: driveId,
parentFolderId: parentFolderId,
files: selectedFiles,
pst: context.read<PstService>(),
profileCubit: context.read<ProfileCubit>(),
driveDao: context.read<DriveDao>(),
auth: context.read<ArDriveAuth>(),
licenseService: context.read<LicenseService>(),
)..startUploadPreparation(),
child: const UploadForm(),
),
barrierDismissible: false,
).then((value) => isCurrentlyShown = false),
);
driveId: driveId,
parentFolderId: parentFolderId,
isFolderUpload: false,
files: files,
).then((value) => isCurrentlyShown = false);
}
}

Expand Down
13 changes: 7 additions & 6 deletions packages/ardrive_crypto/lib/src/stream_aes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:webcrypto/webcrypto.dart';
const _aesBlockLengthBytes = 16;
const _aesNonceLengthBytes = 12;
const _aesCounterLengthBytes = _aesBlockLengthBytes - _aesNonceLengthBytes;
const _aesGcmTagLengthBytes = 16;

const _aes128KeyLengthBytes = 16;
const _aes192KeyLengthBytes = 24;
Expand Down Expand Up @@ -104,7 +103,7 @@ class AesCtrStream extends AesStream with EncryptStream, DecryptStream {
@override
StreamTransformer<Uint8List, Uint8List> decryptTransformer(
Uint8List nonce,
int streamLength,
int fileSize,
) {
return aesStreamTransformer(_aesCtr.decryptBytes, nonce);
}
Expand Down Expand Up @@ -133,15 +132,17 @@ class AesGcmStream extends AesStream with DecryptStream {

@override
StreamTransformer<Uint8List, Uint8List> decryptTransformer(
Uint8List nonce, int streamLength) {
Uint8List nonce,
int fileSize,
) {
debugPrint(
'WARNING: Decrypting AES-GCM without MAC verification! Only do this if you know what you are doing.');

final streamLengthNoMac = streamLength - _aesGcmTagLengthBytes;

return StreamTransformer.fromBind((ciphertextStream) {
// File size is used to trim the MAC from the end of the fileSize
// stream length = file size + 16 (MAC length)
final ciphertextStreamNoMac =
ciphertextStream.transform(trimData(streamLengthNoMac));
ciphertextStream.transform(trimData(fileSize));
return ciphertextStreamNoMac
.transform(aesStreamTransformer(_aesCtr.decryptBytes, nonce));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ardrive_crypto/lib/src/stream_cipher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mixin DecryptStream implements CipherStream {
@protected
StreamTransformer<Uint8List, Uint8List> decryptTransformer(
Uint8List nonce,
int streamLength,
int fileSize,
);

FutureOr<CipherStreamRes> decryptStream(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Secure, permanent storage

publish_to: 'none'

version: 2.34.0
version: 2.34.3

environment:
sdk: '>=3.0.2 <4.0.0'
Expand Down

0 comments on commit 802c133

Please sign in to comment.