Skip to content

Commit

Permalink
chore: rename upload item variable
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Oct 5, 2023
1 parent dfb1cc7 commit 1548f09
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,9 @@ class _UploadFormState extends State<UploadForm> {
break;
}

if (task.isProgressAvailable && task.dataItem != null) {
if (task.isProgressAvailable && task.uploadItem != null) {
progressText =
'${filesize(((task.dataItem!.size) * task.progress).ceil())}/${filesize(task.dataItem!.size)}';
'${filesize(((task.uploadItem!.size) * task.progress).ceil())}/${filesize(task.uploadItem!.size)}';
} else {
progressText =
'Your upload is in progress, but for large files the progress it not available. Please wait...';
Expand Down
8 changes: 4 additions & 4 deletions packages/ardrive_uploader/lib/src/ardrive_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ class _ArDriveUploader implements ArDriveUploader {
switch (type) {
case UploadType.d2n:
uploadTask = uploadTask.copyWith(
dataItem: TransactionUploadTask(
uploadItem: TransactionUploadTask(
data: bdi,
size: bdi.dataSize,
),
);
break;
case UploadType.turbo:
uploadTask = uploadTask.copyWith(
dataItem: DataItemUploadTask(
uploadItem: DataItemUploadTask(
data: bdi,
size: bdi.dataItemSize,
),
Expand Down Expand Up @@ -356,7 +356,7 @@ class _ArDriveUploader implements ArDriveUploader {
switch (type) {
case UploadType.turbo:
folderBDITask = folderBDITask.copyWith(
dataItem: DataItemUploadTask(
uploadItem: DataItemUploadTask(
size: bundleForFolders.dataItemResult.dataItemSize,
data: bundleForFolders.dataItemResult,
),
Expand All @@ -365,7 +365,7 @@ class _ArDriveUploader implements ArDriveUploader {

case UploadType.d2n:
folderBDITask = folderBDITask.copyWith(
dataItem: TransactionUploadTask(
uploadItem: TransactionUploadTask(
data: bundleForFolders.dataItemResult,
size: bundleForFolders.dataItemResult.dataSize,
),
Expand Down
8 changes: 4 additions & 4 deletions packages/ardrive_uploader/lib/src/d2n_streamed_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class D2NStreamedUpload implements StreamedUpload<UploadTask, dynamic> {
Wallet wallet,
UploadController controller,
) async {
if (handle.dataItem is! TransactionUploadTask) {
if (handle.uploadItem is! TransactionUploadTask) {
throw ArgumentError('handle must be of type TransactionUploadTask');
}

print('D2NStreamedUpload.send');

final progressStreamTask =
await uploadTransaction((handle.dataItem as TransactionUploadTask).data)
.run();
final progressStreamTask = await uploadTransaction(
(handle.uploadItem as TransactionUploadTask).data)
.run();

progressStreamTask.match((l) => print(''), (progressStream) async {
final listen = progressStream.listen(
Expand Down
6 changes: 3 additions & 3 deletions packages/ardrive_uploader/lib/src/turbo_streamed_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TurboStreamedUpload implements StreamedUpload<UploadTask, dynamic> {
handle = handle.copyWith(status: UploadStatus.inProgress);
controller.updateProgress(task: handle);

if (kIsWeb && handle.dataItem!.size > 1024 * 1024 * 500) {
if (kIsWeb && handle.uploadItem!.size > 1024 * 1024 * 500) {
handle.isProgressAvailable = false;
controller.updateProgress(task: handle);
}
Expand All @@ -58,8 +58,8 @@ class TurboStreamedUpload implements StreamedUpload<UploadTask, dynamic> {
'x-address': publicKey,
'x-signature': signature,
},
dataItem: handle.dataItem!.data,
size: handle.dataItem!.size,
dataItem: handle.uploadItem!.data,
size: handle.uploadItem!.size,
onSendProgress: (progress) {
handle.progress = progress;
controller.updateProgress(task: handle);
Expand Down
47 changes: 28 additions & 19 deletions packages/ardrive_uploader/lib/src/upload_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ class TransactionUploadTask extends UploadItem<TransactionResult> {

abstract class _UploadTask<T> {
abstract final String id;
abstract final UploadItem? dataItem;
abstract final UploadItem? uploadItem;
abstract final List<ARFSUploadMetadata>? content;
abstract double progress;
abstract bool isProgressAvailable;
abstract UploadStatus status;

UploadTask copyWith({
UploadItem? dataItem,
UploadItem? uploadItem,
double? progress,
bool? isProgressAvailable,
UploadStatus? status,
String? id,
List<ARFSUploadMetadata>? content,
});
}

class UploadTask implements _UploadTask<ARFSUploadMetadata> {
@override
final UploadItem? dataItem;
final UploadItem? uploadItem;

@override
final List<ARFSUploadMetadata>? content;
Expand All @@ -57,7 +59,7 @@ class UploadTask implements _UploadTask<ARFSUploadMetadata> {
bool isProgressAvailable = true;

UploadTask({
this.dataItem,
this.uploadItem,
this.isProgressAvailable = true,
this.status = UploadStatus.notStarted,
this.content,
Expand All @@ -69,15 +71,15 @@ class UploadTask implements _UploadTask<ARFSUploadMetadata> {

@override
UploadTask copyWith({
UploadItem? dataItem,
UploadItem? uploadItem,
double? progress,
bool? isProgressAvailable,
UploadStatus? status,
String? id,
List<ARFSUploadMetadata>? content,
}) {
return UploadTask(
dataItem: dataItem ?? this.dataItem,
uploadItem: uploadItem ?? this.uploadItem,
content: content ?? this.content,
id: id ?? this.id,
isProgressAvailable: isProgressAvailable ?? this.isProgressAvailable,
Expand All @@ -90,6 +92,7 @@ class UploadTask implements _UploadTask<ARFSUploadMetadata> {
abstract class UploadController {
abstract final Map<String, UploadTask> tasks;

/// TODO: implement the sendTasks method
Future<void> sendTasks();
Future<void> retryTask(UploadTask task, Wallet wallet);
Future<void> retryFailedTasks(Wallet wallet);
Expand Down Expand Up @@ -126,7 +129,6 @@ class _UploadController implements UploadController {

bool _isCanceled = false;
bool get isCanceled => _isCanceled;

DateTime? _start;

void init() {
Expand Down Expand Up @@ -167,12 +169,15 @@ class _UploadController implements UploadController {

@override
void cancel() {
// TODO: it's uploading closing the progress stream. We need to cancel the upload
_isCanceled = true;
_progressStream.close();
}

@override
void onCancel() {}
void onCancel() {
// TODO: implement onCancel
}

@override
void onDone(Function(List<UploadTask> tasks) callback) {
Expand Down Expand Up @@ -208,12 +213,7 @@ class _UploadController implements UploadController {
return;
}

UploadProgress _uploadProgress = UploadProgress(
progress: 0,
totalSize: 0,
task: [],
totalUploaded: 0,
);
UploadProgress _uploadProgress = UploadProgress.notStarted();

@override
void onError(Function() callback) {
Expand Down Expand Up @@ -246,8 +246,8 @@ class _UploadController implements UploadController {
int totalUploaded = 0;

for (var task in tasks) {
if (task.dataItem != null) {
totalUploaded += (task.progress * task.dataItem!.size).toInt();
if (task.uploadItem != null) {
totalUploaded += (task.progress * task.uploadItem!.size).toInt();
}
}

Expand All @@ -258,8 +258,8 @@ class _UploadController implements UploadController {
int totalSize = 0;

for (var task in tasks) {
if (task.dataItem != null) {
totalSize += task.dataItem!.size;
if (task.uploadItem != null) {
totalSize += task.uploadItem!.size;
}
}

Expand All @@ -268,7 +268,7 @@ class _UploadController implements UploadController {

@override
Future<void> sendTasks() async {
// _streamedUpload.send();
// TODO: implement sendTasks
}

@override
Expand Down Expand Up @@ -338,6 +338,15 @@ class UploadProgress {
this.startTime,
});

factory UploadProgress.notStarted() {
return UploadProgress(
progress: 0,
totalSize: 0,
task: [],
totalUploaded: 0,
);
}

UploadProgress copyWith({
double? progress,
int? totalSize,
Expand Down

0 comments on commit 1548f09

Please sign in to comment.