Neeraj Gupta 3 роки тому
батько
коміт
76f279cb83
2 змінених файлів з 7 додано та 7 видалено
  1. 2 2
      lib/services/remote_sync_service.dart
  2. 5 5
      lib/utils/file_uploader.dart

+ 2 - 2
lib/services/remote_sync_service.dart

@@ -86,8 +86,6 @@ class RemoteSyncService {
       await TrashSyncService.instance
       await TrashSyncService.instance
           .syncTrash()
           .syncTrash()
           .onError((e, s) => _logger.severe('trash sync failed', e, s));
           .onError((e, s) => _logger.severe('trash sync failed', e, s));
-      // check if user can upload new files
-      await _uploader.canUpload();
       final filesToBeUploaded = await _getFilesToBeUploaded();
       final filesToBeUploaded = await _getFilesToBeUploaded();
       final hasUploadedFiles = await _uploadFiles(filesToBeUploaded);
       final hasUploadedFiles = await _uploadFiles(filesToBeUploaded);
       if (hasUploadedFiles) {
       if (hasUploadedFiles) {
@@ -272,6 +270,8 @@ class RemoteSyncService {
 
 
     if (toBeUploaded > 0) {
     if (toBeUploaded > 0) {
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparing_for_upload));
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparing_for_upload));
+      // verify if the files can b uploaded before initiating actual upload.
+      await _uploader.canUpload(toBeUploaded);
     }
     }
     final List<Future> futures = [];
     final List<Future> futures = [];
     for (final uploadedFileID in updatedFileIDs) {
     for (final uploadedFileID in updatedFileIDs) {

+ 5 - 5
lib/utils/file_uploader.dart

@@ -650,7 +650,7 @@ class FileUploader {
 
 
   Future<UploadURL> _getUploadURL() async {
   Future<UploadURL> _getUploadURL() async {
     if (_uploadURLs.isEmpty) {
     if (_uploadURLs.isEmpty) {
-      await _fetchUploadURLs(2 * _queue.length);
+      await _fetchUploadURLs(_queue.length);
     }
     }
     return _uploadURLs.removeFirst();
     return _uploadURLs.removeFirst();
   }
   }
@@ -659,19 +659,19 @@ class FileUploader {
   // new files or not based on their subscription plan and storage limit.
   // new files or not based on their subscription plan and storage limit.
   // To avoid creating new endpoint, we are using fetchUploadUrls as alternative
   // To avoid creating new endpoint, we are using fetchUploadUrls as alternative
   // method.
   // method.
-  Future<void> canUpload() async {
-    return await _fetchUploadURLs(2);
+  Future<void> canUpload(int fileCount) async {
+    return await _fetchUploadURLs(fileCount);
   }
   }
 
 
   Future<void> _uploadURLFetchInProgress;
   Future<void> _uploadURLFetchInProgress;
 
 
-  Future<void> _fetchUploadURLs(int urlCount) async {
+  Future<void> _fetchUploadURLs(int fileCount) async {
     _uploadURLFetchInProgress ??= Future<void>(() async {
     _uploadURLFetchInProgress ??= Future<void>(() async {
       try {
       try {
         final response = await _dio.get(
         final response = await _dio.get(
           Configuration.instance.getHttpEndpoint() + "/files/upload-urls",
           Configuration.instance.getHttpEndpoint() + "/files/upload-urls",
           queryParameters: {
           queryParameters: {
-            "count": min(42, urlCount), // m4gic number
+            "count": min(42, fileCount * 2), // m4gic number
           },
           },
           options: Options(
           options: Options(
             headers: {"X-Auth-Token": Configuration.instance.getToken()},
             headers: {"X-Auth-Token": Configuration.instance.getToken()},