-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from ardriveapp/dev
Release v1.14.0
- Loading branch information
Showing
69 changed files
with
914 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
Oops, something went wrong.