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-4823: revert uploader/downloader changes #1423

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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.13.6",
"flutterSdkVersion": "3.10.0",
"flavors": {}
}
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ 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.9.10"
ext.kotlin_version = "1.7.10"
repositories {
google()
jcenter()
Expand Down
5 changes: 2 additions & 3 deletions assets/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"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,
"enableMultipleFileDownload": true,
"enableVideoPreview": true,
"enableAudioPreview": true,
"stripePublishableKey": "pk_test_51JUAtwC8apPOWkDLh2FPZkQkiKZEkTo6wqgLCtQoClL6S4l2jlbbc5MgOdwOUdU9Tn93NNvqAGbu115lkJChMikG00XUfTmo2z",
"enablePins": true,
"useNewUploader": true
"enablePins": true
}
3 changes: 1 addition & 2 deletions assets/config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"enableVideoPreview": false,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true,
"useNewUploader": false
"enablePins": true
}
3 changes: 1 addition & 2 deletions assets/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"enableVideoPreview": false,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true,
"useNewUploader": true
"enablePins": 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 @@ -6,9 +6,9 @@ import 'package:ardrive/entities/profile_types.dart';
import 'package:ardrive/services/arconnect/arconnect.dart';
import 'package:ardrive/services/arconnect/arconnect_wallet.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 @@ -16,14 +16,14 @@ import 'package:ardrive/services/authentication/biometric_authentication.dart';
import 'package:ardrive/services/authentication/biometric_permission_dialog.dart';
import 'package:ardrive/services/config/config_service.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';
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: 3 additions & 2 deletions lib/blocs/create_snapshot/create_snapshot_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -15,12 +16,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 @@ -549,7 +550,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 != DrivePrivacyTag.public;
final isPrivate = drive != null && drive.privacy != DrivePrivacy.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 DrivePrivacyTag.private:
case DrivePrivacy.private:
emit(DriveAttachPrivate());
break;
case null:
Expand Down
10 changes: 6 additions & 4 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,7 +19,9 @@ part 'drive_create_state.dart';
class DriveCreateCubit extends Cubit<DriveCreateState> {
final form = FormGroup({
'privacy': FormControl<String>(
value: DrivePrivacyTag.private, validators: [Validators.required]),
value: DrivePrivacy.private.name,
validators: [Validators.required],
),
});

final ArweaveService _arweave;
Expand Down Expand Up @@ -83,8 +85,8 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
name: driveName,
rootFolderId: createRes.rootFolderId,
privacy: drivePrivacy,
authMode: drivePrivacy == DrivePrivacyTag.private
? DriveAuthModeTag.password
authMode: drivePrivacy == constants.DrivePrivacy.private
? constants.DriveAuthMode.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/download/ardrive_downloader.dart';
import 'package:ardrive/core/download_service.dart';
import 'package:ardrive/entities/constants.dart' as constants;
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: 0 additions & 2 deletions lib/blocs/file_download/file_download_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ 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: 46 additions & 55 deletions lib/blocs/file_download/personal_file_download_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {

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

ProfileFileDownloadCubit({
required ARFSFileEntity file,
required DriveDao driveDao,
required ArweaveService arweave,
required io.ArDriveMobileDownloader downloader,
required ArDriveDownloader arDriveDownloader,
required ArDriveDownloader downloader,
required DownloadService downloadService,
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 @@ -76,7 +78,6 @@ 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 @@ -89,8 +90,6 @@ 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 @@ -120,16 +119,25 @@ class ProfileFileDownloadCubit extends FileDownloadCubit {
),
);

logger
.d('Downloading file ${_file.name} and dataTxId is ${_file.dataTxId}');

String? cipher;
String? cipherIvTag;
SecretKey? fileKey;
final dataBytes = await _downloadService.download(
_file.txId, _file.contentType == constants.ContentType.manifest);

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 @@ -138,58 +146,41 @@ 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) {
throw StateError('Data transaction not found');
}

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 (dataTx != null) {
final decryptedData = await _crypto.decryptTransactionData(
dataTx,
dataBytes,
fileKey,
);

if (progress == 100) {
emit(FileDownloadFinishedWithSuccess(fileName: _file.name));
emit(
FileDownloadSuccess(
bytes: decryptedData,
fileName: _file.name,
mimeType: _file.contentType ?? lookupMimeType(_file.name),
lastModified: _file.lastModifiedDate,
),
);
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(FileDownloadFinishedWithSuccess(fileName: _file.name));
emit(
FileDownloadSuccess(
bytes: dataBytes,
fileName: _file.name,
mimeType: _file.contentType ?? lookupMimeType(_file.name),
lastModified: _file.lastModifiedDate,
),
);
}

@visibleForTesting
Expand Down
Loading