Skip to content

Commit

Permalink
Merge pull request #1429 from ardriveapp/PE-4754-revert_the_revert
Browse files Browse the repository at this point in the history
PE-4754: reverts the reverted changes for Large Uploads/Downloads
  • Loading branch information
thiagocarvalhodev authored Oct 26, 2023
2 parents aadf5b2 + 00dc4e9 commit 4df2848
Show file tree
Hide file tree
Showing 309 changed files with 12,141 additions and 1,834 deletions.
2 changes: 1 addition & 1 deletion .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutterSdkVersion": "3.10.0",
"flutterSdkVersion": "3.13.6",
"flavors": {}
}
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
run: flutter pub global activate script_runner

- name: Build app
run: scr setup
run: |
scr setup
- name: Lint
run: flutter analyze
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The ArDrive Web App allows a user to log in to securely view, upload and manage
Have any questions? Join the ArDrive Discord channel for support, news and updates. https://discord.gg/ya4hf2H

## Setting up the Development Environment

****
Install lefthook for your platform from the intructions [here](https://github.com/evilmartians/lefthook/blob/master/docs/other.md).
This will enable the use of git hooks.
After installing lefthook you need to enable it by running:
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = "1.7.10"
ext.kotlin_version = "1.9.10"
repositories {
google()
jcenter()
Expand Down
5 changes: 3 additions & 2 deletions assets/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"defaultArweaveGatewayUrl": "https://arweave.net",
"useTurboUpload": true,
"useTurboPayment": true,
"defaultTurboUploadUrl": "https://upload.ardrive.dev",
"defaultTurboUploadUrl": "https://upload.ardrive.io",
"defaultTurboPaymentUrl": "https://payment.ardrive.dev",
"allowedDataItemSizeForTurbo": 500000,
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": true,
"enableAudioPreview": true,
"stripePublishableKey": "pk_test_51JUAtwC8apPOWkDLh2FPZkQkiKZEkTo6wqgLCtQoClL6S4l2jlbbc5MgOdwOUdU9Tn93NNvqAGbu115lkJChMikG00XUfTmo2z",
"enablePins": true
"enablePins": true,
"useNewUploader": true
}
3 changes: 2 additions & 1 deletion assets/config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"enableVideoPreview": true,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true
"enablePins": true,
"useNewUploader": false
}
3 changes: 2 additions & 1 deletion assets/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"enableVideoPreview": true,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true
"enablePins": true,
"useNewUploader": true
}
2 changes: 1 addition & 1 deletion lib/app_shell.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:ardrive/components/profile_card.dart';
import 'package:ardrive/components/side_bar.dart';
import 'package:ardrive/pages/drive_detail/components/hover_widget.dart';
import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/size_constants.dart';
import 'package:ardrive_ui/ardrive_ui.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:responsive_builder/responsive_builder.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'package:ardrive/services/arconnect/arconnect.dart';
import 'package:ardrive/services/arconnect/arconnect_wallet.dart';
import 'package:ardrive/user/repositories/user_repository.dart';
import 'package:ardrive/user/user.dart';
import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive_io/ardrive_io.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/arweave.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:equatable/equatable.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'package:ardrive/services/authentication/biometric_permission_dialog.dart
import 'package:ardrive/services/config/config_service.dart';
import 'package:ardrive/user/repositories/user_repository.dart';
import 'package:ardrive/utils/app_localizations_wrapper.dart';
import 'package:ardrive/utils/app_platform.dart';
import 'package:ardrive/utils/io_utils.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/open_url.dart';
Expand All @@ -27,6 +26,7 @@ import 'package:ardrive/utils/pre_cache_assets.dart';
import 'package:ardrive/utils/show_general_dialog.dart';
import 'package:ardrive/utils/split_localizations.dart';
import 'package:ardrive_ui/ardrive_ui.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/arweave.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:flutter/gestures.dart';
Expand Down
5 changes: 2 additions & 3 deletions lib/blocs/create_snapshot/create_snapshot_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/profile/profile_cubit.dart';
import 'package:ardrive/blocs/upload/upload_cubit.dart';
import 'package:ardrive/core/upload/cost_calculator.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/entities/snapshot_entity.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/daos/daos.dart';
Expand All @@ -16,12 +15,12 @@ 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/turbo/utils/utils.dart';
import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/metadata_cache.dart';
import 'package:ardrive/utils/snapshots/height_range.dart';
import 'package:ardrive/utils/snapshots/range.dart';
import 'package:ardrive/utils/snapshots/snapshot_item_to_be_created.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/arweave.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -550,7 +549,7 @@ class CreateSnapshotCubit extends Cubit<CreateSnapshotState> {
Future<Uint8List> _jsonMetadataOfTxId(String txId) async {
final drive =
await _driveDao.driveById(driveId: _driveId).getSingleOrNull();
final isPrivate = drive != null && drive.privacy != DrivePrivacy.public;
final isPrivate = drive != null && drive.privacy != DrivePrivacyTag.public;

final metadataCache = await MetadataCache.fromCacheStore(
await newSharedPreferencesCacheStore(),
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/drive_attach/drive_attach_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'dart:async';
import 'dart:convert';

import 'package:ardrive/blocs/blocs.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';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/utils.dart';
import 'package:cryptography/cryptography.dart';
import 'package:equatable/equatable.dart';
Expand Down Expand Up @@ -218,7 +218,7 @@ class DriveAttachCubit extends Cubit<DriveAttachState> {
final drivePrivacy = await _arweave.getDrivePrivacyForId(driveId);

switch (drivePrivacy) {
case DrivePrivacy.private:
case DrivePrivacyTag.private:
emit(DriveAttachPrivate());
break;
case null:
Expand Down
10 changes: 4 additions & 6 deletions lib/blocs/drive_create/drive_create_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart'
show DrivePrivacy;
import 'package:ardrive/entities/constants.dart' as constants;
import 'package:ardrive/entities/drive_entity.dart';
import 'package:ardrive/entities/folder_entity.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:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -19,9 +19,7 @@ part 'drive_create_state.dart';
class DriveCreateCubit extends Cubit<DriveCreateState> {
final form = FormGroup({
'privacy': FormControl<String>(
value: DrivePrivacy.private.name,
validators: [Validators.required],
),
value: DrivePrivacyTag.private, validators: [Validators.required]),
});

final ArweaveService _arweave;
Expand Down Expand Up @@ -85,8 +83,8 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
name: driveName,
rootFolderId: createRes.rootFolderId,
privacy: drivePrivacy,
authMode: drivePrivacy == constants.DrivePrivacy.private
? constants.DriveAuthMode.password
authMode: drivePrivacy == DrivePrivacyTag.private
? DriveAuthModeTag.password
: null,
);

Expand Down
6 changes: 3 additions & 3 deletions lib/blocs/file_download/file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import 'package:ardrive/blocs/blocs.dart';
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/core/download_service.dart';
import 'package:ardrive/entities/constants.dart' as constants;
import 'package:ardrive/download/ardrive_downloader.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/utils/app_platform.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;
import 'package:ardrive_io/ardrive_io.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:cryptography/cryptography.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/blocs/file_download/file_download_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class FileDownloadWithProgress extends FileDownloadState {
required this.fileName,
required this.progress,
required this.fileSize,
required this.contentType,
});

final int progress;
final int fileSize;
final String fileName;
final String contentType;

@override
List<Object> get props => [progress, fileName];
Expand Down
101 changes: 55 additions & 46 deletions lib/blocs/file_download/personal_file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {

final DriveDao _driveDao;
final ArweaveService _arweave;
final ArDriveDownloader _downloader;
final DownloadService _downloadService;
final io.ArDriveMobileDownloader _downloader;
final ArDriveDownloader _arDriveDownloader;
final ARFSRepository _arfsRepository;
final ArDriveCrypto _crypto;

ProfileFileDownloadCubit({
required ARFSFileEntity file,
required DriveDao driveDao,
required ArweaveService arweave,
required ArDriveDownloader downloader,
required DownloadService downloadService,
required io.ArDriveMobileDownloader downloader,
required ArDriveDownloader arDriveDownloader,
required ARFSRepository arfsRepository,
required ArDriveCrypto crypto,
}) : _driveDao = driveDao,
_arweave = arweave,
_arDriveDownloader = arDriveDownloader,
_file = file,
_downloader = downloader,
_downloadService = downloadService,
_arfsRepository = arfsRepository,
_crypto = crypto,
super(FileDownloadStarting());

Future<void> download(SecretKey? cipherKey) async {
Expand Down Expand Up @@ -78,6 +76,7 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
final stream = _downloader.downloadFile(
'${_arweave.client.api.gatewayUrl.origin}/${_file.txId}',
_file.name,
_file.contentType,
);

await for (int progress in stream) {
Expand All @@ -90,6 +89,8 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
fileName: _file.name,
progress: progress,
fileSize: _file.size,
contentType: _file.contentType ??
lookupMimeTypeWithDefaultType(_file.name),
),
);
_downloadProgress.sink.add(FileDownloadProgress(progress / 100));
Expand Down Expand Up @@ -119,25 +120,16 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
),
);

final dataBytes = await _downloadService.download(
_file.txId, _file.contentType == constants.ContentType.manifest);
logger
.d('Downloading file ${_file.name} and dataTxId is ${_file.dataTxId}');

String? cipher;
String? cipherIvTag;
SecretKey? fileKey;

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

final isPinFile = _file.pinnedDataOwnerAddress != null;
if (isPinFile) {
emit(
FileDownloadSuccess(
bytes: dataBytes,
fileName: _file.name,
mimeType: _file.contentType ?? lookupMimeType(_file.name),
lastModified: _file.lastModifiedDate,
),
);
return;
}

if (cipherKey != null) {
driveKey = await _driveDao.getDriveKey(
drive.driveId,
Expand All @@ -146,41 +138,58 @@ 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 fileKey = await _driveDao.getFileKey(_file.id, driveKey);
final dataTx = await (_arweave.getTransactionDetails(_file.txId));

if (dataTx != null) {
final decryptedData = await _crypto.decryptTransactionData(
dataTx,
dataBytes,
fileKey,
);
if (dataTx == null) {
throw StateError('Data transaction not found');
}

emit(
FileDownloadSuccess(
bytes: decryptedData,
fileName: _file.name,
mimeType: _file.contentType ?? lookupMimeType(_file.name),
lastModified: _file.lastModifiedDate,
),
);
cipher = dataTx.getTag(EntityTag.cipher);
cipherIvTag = dataTx.getTag(EntityTag.cipherIv);
}

final downloadStream = _arDriveDownloader.downloadFile(
dataTx: _file.txId,
fileName: _file.name,
fileSize: _file.size,
lastModifiedDate: _file.lastModifiedDate,
contentType:
_file.contentType ?? lookupMimeTypeWithDefaultType(_file.name),
cipher: cipher,
cipherIvString: cipherIvTag,
fileKey: fileKey,
);

await for (var progress in downloadStream) {
if (state is FileDownloadAborted) {
return;
}

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

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

emit(
FileDownloadWithProgress(
fileName: _file.name,
progress: progress.toInt(),
fileSize: _file.size,
contentType:
_file.contentType ?? lookupMimeTypeWithDefaultType(_file.name),
),
);
_downloadProgress.sink.add(FileDownloadProgress(progress / 100));
}

emit(
FileDownloadSuccess(
bytes: dataBytes,
fileName: _file.name,
mimeType: _file.contentType ?? lookupMimeType(_file.name),
lastModified: _file.lastModifiedDate,
),
);
emit(FileDownloadFinishedWithSuccess(fileName: _file.name));
}

@visibleForTesting
Expand Down
Loading

0 comments on commit 4df2848

Please sign in to comment.