Skip to content

Commit

Permalink
fix(uploader)
Browse files Browse the repository at this point in the history
if the download failed don't show the upload in progress without progress text
  • Loading branch information
thiagocarvalhodev committed Oct 12, 2023
1 parent aec969f commit ec8ac32
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
9 changes: 5 additions & 4 deletions lib/blocs/upload/limits.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:flutter/foundation.dart';

final privateFileSizeLimit = const MiB(100000).size;

final mobilePrivateFileSizeLimit = const GiB(10).size;

final publicFileSafeSizeLimit = const GiB(5).size;

final bundleSizeLimit = kIsWeb ? webBundleSizeLimit : mobileBundleSizeLimit;
int bundleSizeLimit(bool isTurbo) =>
isTurbo ? turboBundleSizeLimit : d2nBundleSizeLimit;

final webBundleSizeLimit = const MiB(65000).size;
final mobileBundleSizeLimit = const MiB(65000).size;
final d2nBundleSizeLimit = const GiB(65).size;
final turboBundleSizeLimit = const MiB(1).size;
final mobileBundleSizeLimit = const GiB(65).size;
const maxBundleDataItemCount = 500;
const maxFilesPerBundle = maxBundleDataItemCount ~/ 2;
const maxFilesSizePerBundleUsingTurbo = 1;
22 changes: 11 additions & 11 deletions lib/blocs/upload/models/upload_plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:ardrive/blocs/upload/upload_handles/upload_handle.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/utils/bundles/next_fit_bundle_packer.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:flutter/foundation.dart';

import '../upload_handles/file_data_item_upload_handle.dart';
import '../upload_handles/file_v2_upload_handle.dart';
Expand All @@ -23,14 +22,14 @@ class UploadPlan {
required this.maxDataItemCount,
});

static Future<UploadPlan> create({
required Map<String, FileV2UploadHandle> fileV2UploadHandles,
required Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles,
required Map<String, FolderDataItemUploadHandle>
folderDataItemUploadHandles,
required TurboUploadService turboUploadService,
required int maxDataItemCount,
}) async {
static Future<UploadPlan> create(
{required Map<String, FileV2UploadHandle> fileV2UploadHandles,
required Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles,
required Map<String, FolderDataItemUploadHandle>
folderDataItemUploadHandles,
required TurboUploadService turboUploadService,
required int maxDataItemCount,
required bool useTurbo}) async {
final uploadPlan = UploadPlan._create(
fileV2UploadHandles: fileV2UploadHandles,
maxDataItemCount: maxDataItemCount,
Expand All @@ -43,13 +42,15 @@ class UploadPlan {
folderDataItemUploadHandles: folderDataItemUploadHandles,
turboUploadService: turboUploadService,
maxDataItemCount: maxDataItemCount,
useTurbo: useTurbo,
);
}

return uploadPlan;
}

Future<void> createBundleHandlesFromDataItemHandles({
required bool useTurbo,
Map<String, FileDataItemUploadHandle> fileDataItemUploadHandles = const {},
Map<String, FolderDataItemUploadHandle> folderDataItemUploadHandles =
const {},
Expand All @@ -58,8 +59,7 @@ class UploadPlan {
}) async {
logger.i(
'Creating bundle handles from data item handles with a max number of files of $maxDataItemCount');
final int maxBundleSize =
(kIsWeb ? bundleSizeLimit : mobileBundleSizeLimit);
final int maxBundleSize = bundleSizeLimit(useTurbo);

final folderItems = await NextFitBundlePacker<UploadHandle>(
maxBundleSize: maxBundleSize,
Expand Down
3 changes: 0 additions & 3 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/upload/limits.dart';
import 'package:ardrive/blocs/upload/models/models.dart';
import 'package:ardrive/blocs/upload/upload_file_checker.dart';
import 'package:ardrive/core/upload/cost_calculator.dart';
Expand Down Expand Up @@ -90,8 +89,6 @@ class UploadCubit extends Cubit<UploadState> {
final Map<String, String> conflictingFiles = {};
final List<String> conflictingFolders = [];

bool fileSizeWithinBundleLimits(int size) => size < bundleSizeLimit;

UploadCubit({
required this.driveId,
required this.parentFolderId,
Expand Down
6 changes: 4 additions & 2 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,10 @@ class _UploadFormState extends State<UploadForm> {
'${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...';
if (task.status == UploadStatus.inProgress) {
progressText =
'Your upload is in progress, but for large files the progress it not available. Please wait...';
}
}

return Column(
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/upload_plan_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UploadPlanUtils {
? RevisionAction.uploadNewVersion
: RevisionAction.create;

if (fileSize < bundleSizeLimit) {
if (fileSize < bundleSizeLimit(useTurbo)) {
fileDataItemUploadHandles[fileEntity.id!] = FileDataItemUploadHandle(
entity: fileEntity,
path: filePath,
Expand Down Expand Up @@ -129,6 +129,7 @@ class UploadPlanUtils {
turboUploadService: turboUploadService,
maxDataItemCount:
useTurbo ? maxFilesSizePerBundleUsingTurbo : maxFilesPerBundle,
useTurbo: useTurbo,
);
}

Expand Down
7 changes: 7 additions & 0 deletions packages/ardrive_uploader/lib/src/ardrive_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class _ArDriveUploader implements ArDriveUploader {
metadataGenerator: _metadataGenerator,
type: type,
),
numOfWorkers: 1,
maxTasksPerWorker: 1,
);

final metadata = await _metadataGenerator.generateMetadata(
Expand Down Expand Up @@ -124,6 +126,8 @@ class _ArDriveUploader implements ArDriveUploader {
metadataGenerator: _metadataGenerator,
type: type,
),
numOfWorkers: driveKey != null ? 3 : 5,
maxTasksPerWorker: driveKey != null ? 1 : 5,
);

for (var f in files) {
Expand All @@ -135,6 +139,7 @@ class _ArDriveUploader implements ArDriveUploader {
final fileTask = FileUploadTask(
file: f.$2,
metadata: metadata as ARFSFileUploadMetadata,
content: [metadata],
encryptionKey: driveKey,
streamedUpload: _streamedUploadFactory.fromUploadType(
type,
Expand Down Expand Up @@ -195,6 +200,8 @@ class _ArDriveUploader implements ArDriveUploader {
StreamController<UploadProgress>(),
streamedUpload,
dataBundler,
numOfWorkers: driveKey != null ? 3 : 5,
maxTasksPerWorker: driveKey != null ? 1 : 5,
);

if (folderMetadatas.isNotEmpty) {
Expand Down
22 changes: 18 additions & 4 deletions packages/ardrive_uploader/lib/src/upload_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,16 @@ abstract class UploadController {
factory UploadController(
StreamController<UploadProgress> progressStream,
StreamedUpload streamedUpload,
DataBundler dataBundler,
) {
DataBundler dataBundler, {
int numOfWorkers = 5,
int maxTasksPerWorker = 5,
}) {
return _UploadController(
progressStream: progressStream,
streamedUpload: streamedUpload,
dataBundler: dataBundler,
numOfWorkers: numOfWorkers,
maxTasksPerWorker: maxTasksPerWorker,
);
}
}
Expand All @@ -268,12 +272,18 @@ class _UploadController implements UploadController {
final StreamController<UploadProgress> _progressStream;
final StreamedUpload _streamedUpload;
final DataBundler _dataBundler;
final int _numOfWorkers;
final int _maxTasksPerWorker;

_UploadController({
required StreamController<UploadProgress> progressStream,
required StreamedUpload streamedUpload,
required DataBundler dataBundler,
int numOfWorkers = 5,
int maxTasksPerWorker = 5,
}) : _dataBundler = dataBundler,
_numOfWorkers = numOfWorkers,
_maxTasksPerWorker = maxTasksPerWorker,
_progressStream = progressStream,
_streamedUpload = streamedUpload {
init();
Expand Down Expand Up @@ -434,6 +444,10 @@ class _UploadController implements UploadController {
for (var task in tasks) {
if (task.uploadItem != null) {
totalSize += task.uploadItem!.size;
} else {
if (task is FileUploadTask) {
totalSize += task.metadata.size;
}
}
}

Expand Down Expand Up @@ -488,8 +502,8 @@ class _UploadController implements UploadController {
} else {
// creates a worker pool and initializes it with the tasks
workerPool = WorkerPool(
numWorkers: 5,
maxTasksPerWorker: 5,
numWorkers: _numOfWorkers,
maxTasksPerWorker: _maxTasksPerWorker,
taskQueue: tasks.values
.where((element) => element.status == UploadStatus.notStarted)
.toList(),
Expand Down

0 comments on commit ec8ac32

Please sign in to comment.