Skip to content

Commit

Permalink
Merge pull request #479 from ardriveapp/dev
Browse files Browse the repository at this point in the history
Release v1.14.0
  • Loading branch information
thiagocarvalhodev authored May 3, 2022
2 parents 6441d91 + bbb3df6 commit c796105
Show file tree
Hide file tree
Showing 69 changed files with 914 additions and 369 deletions.
3 changes: 1 addition & 2 deletions lib/blocs/drive_detail/drive_detail_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/drive_detail/selected_item.dart';
import 'package:ardrive/entities/constants.dart';
import 'package:ardrive/entities/string_types.dart';
Expand All @@ -12,8 +13,6 @@ import 'package:moor/moor.dart';
import 'package:rxdart/rxdart.dart';
import 'package:url_launcher/url_launcher.dart';

import '../blocs.dart';

part 'drive_detail_state.dart';

class DriveDetailCubit extends Cubit<DriveDetailState> {
Expand Down
3 changes: 1 addition & 2 deletions lib/blocs/drives/drives_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:async';

import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/models/models.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:moor/moor.dart';
import 'package:rxdart/rxdart.dart';

import '../blocs.dart';

part 'drives_state.dart';

/// [DrivesCubit] includes logic for displaying the drives attached in the app.
Expand Down
3 changes: 2 additions & 1 deletion lib/blocs/folder_create/folder_create_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class FolderCreateCubit extends Cubit<FolderCreateState> {
await _arweave.postTx(folderTx);
folderEntity.txId = folderTx.id;
await _driveDao.insertFolderRevision(folderEntity.toRevisionCompanion(
performedAction: RevisionAction.create));
performedAction: RevisionAction.create,
));
});
} catch (err) {
addError(err);
Expand Down
3 changes: 1 addition & 2 deletions lib/blocs/sync/sync_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math';

import 'package:ardrive/blocs/activity/activity_cubit.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/sync/ghost_folder.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/entities/string_types.dart';
Expand All @@ -17,8 +18,6 @@ import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:moor/moor.dart';

import '../blocs.dart';

part 'sync_state.dart';

const kRequiredTxConfirmationCount = 15;
Expand Down
12 changes: 6 additions & 6 deletions lib/blocs/upload/cost_estimate.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:ardrive/blocs/upload/bundle_upload_handle.dart';
import 'package:ardrive/blocs/upload/file_upload_handle.dart';
import 'package:ardrive/blocs/upload/upload_plan.dart';
import 'package:ardrive/blocs/upload/models/upload_plan.dart';
import 'package:ardrive/blocs/upload/upload_handles/bundle_upload_handle.dart';
import 'package:ardrive/blocs/upload/upload_handles/file_v2_upload_handle.dart';
import 'package:ardrive/entities/entity.dart';
import 'package:ardrive/services/arweave/arweave.dart';
import 'package:ardrive/services/pst/pst.dart';
Expand Down Expand Up @@ -42,7 +42,7 @@ class CostEstimate {
required PstService pstService,
required Wallet wallet,
}) async {
final _v2FileUploadHandles = uploadPlan.v2FileUploadHandles;
final _v2FileUploadHandles = uploadPlan.fileV2UploadHandles;
final dataItemsCost = await estimateCostOfAllBundles(
bundleUploadHandles: uploadPlan.bundleUploadHandles,
arweaveService: arweaveService,
Expand Down Expand Up @@ -128,7 +128,7 @@ class CostEstimate {
}

static Future<BigInt> estimateV2UploadsCost({
required List<FileUploadHandle> fileUploadHandles,
required List<FileV2UploadHandle> fileUploadHandles,
required ArweaveService arweaveService,
}) async {
var totalCost = BigInt.zero;
Expand All @@ -141,7 +141,7 @@ class CostEstimate {
}

static Future<BigInt> estimateV2FileUploadCost({
required FileUploadHandle fileUploadHandle,
required FileV2UploadHandle fileUploadHandle,
required ArweaveService arweaveService,
}) async {
return await arweaveService.getPrice(
Expand Down
11 changes: 11 additions & 0 deletions lib/blocs/upload/models/folder_prepare_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:ardrive/blocs/upload/models/web_file.dart';
import 'package:ardrive/blocs/upload/models/web_folder.dart';

class FolderPrepareResult {
List<WebFile> files;
Map<String, WebFolder> foldersByPath;
FolderPrepareResult({
required this.files,
required this.foldersByPath,
});
}
50 changes: 50 additions & 0 deletions lib/blocs/upload/models/io_file.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:typed_data';

// Use the crossfile package instead to make this suitable for use with mobile
import 'package:file_selector/file_selector.dart';

import 'upload_file.dart';

class IOFile extends UploadFile {
final XFile file;
@override
final DateTime lastModifiedDate;
@override
final int size;

@override
final String parentFolderId;

IOFile._create(
this.file,
this.lastModifiedDate,
this.size,
this.parentFolderId,
) : super(
name: file.name,
path: file.path,
lastModifiedDate: lastModifiedDate,
size: size,
parentFolderId: parentFolderId,
);

static Future<IOFile> fromXFile(XFile file, String parentFolderId) async {
final fileLastModified = await file.lastModified();
final fileSize = await file.length();

return IOFile._create(
file,
fileLastModified,
fileSize,
parentFolderId,
);
}

@override
Future<Uint8List> readAsBytes() => file.readAsBytes();

@override
String getIdentifier() {
return path.isEmpty ? name : path;
}
}
5 changes: 5 additions & 0 deletions lib/blocs/upload/models/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'folder_prepare_result.dart';
export 'upload_file.dart';
export 'upload_plan.dart';
export 'web_file.dart';
export 'web_folder.dart';
20 changes: 20 additions & 0 deletions lib/blocs/upload/models/upload_file.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:typed_data';

abstract class UploadFile {
String name;
String path;
DateTime lastModifiedDate;
int size;
String parentFolderId;
Future<Uint8List> readAsBytes();

String getIdentifier();

UploadFile({
required this.name,
required this.path,
required this.lastModifiedDate,
required this.parentFolderId,
required this.size,
});
}
68 changes: 68 additions & 0 deletions lib/blocs/upload/models/upload_plan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:ardrive/blocs/upload/upload_handles/bundle_upload_handle.dart';
import 'package:ardrive/blocs/upload/upload_handles/folder_data_item_upload_handle.dart';
import 'package:ardrive/blocs/upload/upload_handles/upload_handle.dart';
import 'package:ardrive/utils/bundles/next_fit_bundle_packer.dart';

import '../upload_handles/file_data_item_upload_handle.dart';
import '../upload_handles/file_v2_upload_handle.dart';

final bundleSizeLimit = 503316480;
final maxBundleDataItemCount = 500;
final maxFilesPerBundle = maxBundleDataItemCount ~/ 2;

class UploadPlan {
/// A map of [FileV2UploadHandle]s keyed by their respective file's id.
late Map<String, FileV2UploadHandle> fileV2UploadHandles;

final List<BundleUploadHandle> bundleUploadHandles = [];

UploadPlan._create({
required this.fileV2UploadHandles,
});

static Future<UploadPlan> create({
required Map<String, FileV2UploadHandle> fileV2UploadHandles,
required Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles,
required Map<String, FolderDataItemUploadHandle>
folderDataItemUploadHandles,
}) async {
final bundle = UploadPlan._create(
fileV2UploadHandles: fileV2UploadHandles,
);
if (fileDataItemUploadHandles.isNotEmpty ||
folderDataItemUploadHandles.isNotEmpty) {
await bundle.createBundleHandlesFromDataItemHandles(
fileDataItemUploadHandles: fileDataItemUploadHandles,
folderDataItemUploadHandles: folderDataItemUploadHandles,
);
}
return bundle;
}

Future<void> createBundleHandlesFromDataItemHandles({
Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles = const {},
Map<String, FolderDataItemUploadHandle> folderDataItemUploadHandles =
const {},
}) async {
final bundleItems = await NextFitBundlePacker<UploadHandle>(
maxBundleSize: bundleSizeLimit,
maxDataItemCount: maxFilesPerBundle,
).packItems([
...fileDataItemUploadHandles.values,
...folderDataItemUploadHandles.values
]);
for (var uploadHandles in bundleItems) {
final bundleToUpload = await BundleUploadHandle.create(
fileDataItemUploadHandles: List.from(
uploadHandles.whereType<FileDataItemUploadHandle>(),
),
folderDataItemUploadHandles: List.from(
uploadHandles.whereType<FolderDataItemUploadHandle>(),
),
);
bundleUploadHandles.add(bundleToUpload);
uploadHandles.clear();
}
fileDataItemUploadHandles.clear();
}
}
32 changes: 32 additions & 0 deletions lib/blocs/upload/models/web_file.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:html';
import 'dart:typed_data';

import 'package:ardrive/blocs/upload/models/upload_file.dart';

class WebFile extends UploadFile {
final File file;
@override
final String parentFolderId;
WebFile(this.file, this.parentFolderId)
: super(
name: file.name,
path: file.relativePath!,
lastModifiedDate:
DateTime.fromMillisecondsSinceEpoch(file.lastModified!),
size: file.size,
parentFolderId: parentFolderId,
);

@override
Future<Uint8List> readAsBytes() async {
final reader = FileReader();
reader.readAsArrayBuffer(file);
await reader.onLoad.first;
return reader.result as Uint8List;
}

@override
String getIdentifier() {
return path.isEmpty ? name : path;
}
}
13 changes: 13 additions & 0 deletions lib/blocs/upload/models/web_folder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class WebFolder {
final String name;
final String parentFolderPath;

String id;
late String parentFolderId;
late String path;
WebFolder({
required this.name,
required this.id,
required this.parentFolderPath,
});
}
Loading

0 comments on commit c796105

Please sign in to comment.