Marino Faggiana vor 1 Jahr
Ursprung
Commit
c5a97bb479

+ 13 - 0
iOSClient/Networking/E2EE/NCNetworkingE2EEUpload.swift

@@ -193,4 +193,17 @@ class NCNetworkingE2EEUpload: NSObject {
             }
         })
     }
+
+    private func sendFileChunk(metadata: tableMetadata, e2eToken: String, uploadE2EEDelegate: uploadE2EEDelegate? = nil) async -> (ocId: String?, etag: String?, date: NSDate? ,afError: AFError?, error: NKError) {
+
+        return await withCheckedContinuation({ continuation in
+            NCNetworking.shared.uploadChunkFile(metadata: metadata, withUploadComplete: false) {
+                uploadE2EEDelegate?.start()
+            } progressHandler: { totalBytesExpected, totalBytes, fractionCompleted in
+                uploadE2EEDelegate?.uploadE2EEProgress(totalBytesExpected, totalBytes, fractionCompleted)
+            } completion: { account, file, afError, error in
+                continuation.resume(returning: (ocId: file?.ocId, etag: file?.etag, date: file?.date ,afError: afError, error: error))
+            }
+        })
+    }
 }

+ 15 - 10
iOSClient/Networking/NCNetworking.swift

@@ -418,7 +418,7 @@ class NCNetworking: NSObject, NKCommonDelegate {
             }
 #endif
         } else if metadata.chunk {
-            uploadChunkFile(metadata: metadata, start: start, progressHandler: progressHandler) { _, _, error in
+            uploadChunkFile(metadata: metadata, start: start, progressHandler: progressHandler) { _, _, _, error in
                 completion(error)
             }
         } else if metadata.session == NextcloudKit.shared.nkCommonInstance.sessionIdentifierUpload {
@@ -433,7 +433,10 @@ class NCNetworking: NSObject, NKCommonDelegate {
         }
     }
 
-    func uploadFile(metadata: tableMetadata, fileNameLocalPath: String, withUploadComplete: Bool = true, addCustomHeaders: [String: String]? = nil,
+    func uploadFile(metadata: tableMetadata,
+                    fileNameLocalPath: String,
+                    withUploadComplete: Bool = true,
+                    addCustomHeaders: [String: String]? = nil,
                     start: @escaping () -> () = { },
                     progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> () = { _, _, _ in },
                     completion: @escaping (_ account: String, _ ocId: String?, _ etag: String?, _ date: NSDate?, _ size: Int64, _ allHeaderFields: [AnyHashable : Any]?, _ afError: AFError?, _ error: NKError) -> Void) {
@@ -479,11 +482,12 @@ class NCNetworking: NSObject, NKCommonDelegate {
         }
     }
 
-    private func uploadChunkFile(metadata: tableMetadata,
-                                 withUploadComplete: Bool = true,
-                                 start: @escaping () -> () = { },
-                                 progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> () = { _, _, _ in },
-                                 completion: @escaping (_ account: String, _ file: NKFile?, _ error: NKError) -> Void) {
+    func uploadChunkFile(metadata: tableMetadata,
+                         withUploadComplete: Bool = true,
+                         addCustomHeaders: [String: String] = [:],
+                         start: @escaping () -> () = { },
+                         progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> () = { _, _, _ in },
+                         completion: @escaping (_ account: String, _ file: NKFile?, _ afError: AFError?, _ error: NKError) -> Void) {
 
         let directory = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)!
         let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
@@ -498,7 +502,8 @@ class NCNetworking: NSObject, NKCommonDelegate {
                                         serverUrl: metadata.serverUrl,
                                         chunkFolder: chunkFolder,
                                         filesChunk: filesChunk,
-                                        chunkSizeInMB: 10) { filesChunk in
+                                        chunkSizeInMB: 10,
+                                        addCustomHeaders: addCustomHeaders) { filesChunk in
 
             start()
             NCManageDatabase.shared.addChunks(account: metadata.account, ocId: metadata.ocId, chunkFolder: chunkFolder, filesChunk: filesChunk)
@@ -536,7 +541,7 @@ class NCNetworking: NSObject, NKCommonDelegate {
 
             NCManageDatabase.shared.deleteChunk(account: metadata.account, ocId: metadata.ocId, fileChunk: fileChunk)
 
-        } completion: { account, filesChunk, file, error in
+        } completion: { account, filesChunk, file, afError, error in
 
             self.uploadRequest.removeValue(forKey: fileNameLocalPath)
 
@@ -570,7 +575,7 @@ class NCNetworking: NSObject, NKCommonDelegate {
                 self.uploadComplete(fileName: metadata.fileName, serverUrl: metadata.serverUrl, ocId: file?.ocId, etag: file?.etag, date: file?.date, size: file?.size ?? 0, description: metadata.ocId, task: uploadTask, error: error)
             }
 
-            completion(account, file, error)
+            completion(account, file, afError, error)
         }
     }