|
@@ -386,12 +386,14 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
|
|
|
func upload(metadata: tableMetadata,
|
|
func upload(metadata: tableMetadata,
|
|
uploadE2EEDelegate: uploadE2EEDelegate? = nil,
|
|
uploadE2EEDelegate: uploadE2EEDelegate? = nil,
|
|
|
|
+ hudView: UIView?,
|
|
start: @escaping () -> Void = { },
|
|
start: @escaping () -> Void = { },
|
|
progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> Void = { _, _, _ in },
|
|
progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> Void = { _, _, _ in },
|
|
completion: @escaping (_ error: NKError) -> Void = { _ in }) {
|
|
completion: @escaping (_ error: NKError) -> Void = { _ in }) {
|
|
|
|
|
|
let hud = JGProgressHUD()
|
|
let hud = JGProgressHUD()
|
|
let metadata = tableMetadata.init(value: metadata)
|
|
let metadata = tableMetadata.init(value: metadata)
|
|
|
|
+ var numChunks: Int = 0
|
|
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNK \(metadata.chunk), E2EE \(metadata.isDirectoryE2EE)]")
|
|
NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNK \(metadata.chunk), E2EE \(metadata.isDirectoryE2EE)]")
|
|
|
|
|
|
if metadata.isDirectoryE2EE {
|
|
if metadata.isDirectoryE2EE {
|
|
@@ -402,20 +404,30 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
} else if metadata.chunk > 0 {
|
|
} else if metadata.chunk > 0 {
|
|
-#if !EXTENSION
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, let hudView = appDelegate.window?.rootViewController?.view else {
|
|
|
|
- return completion(.success)
|
|
|
|
|
|
+ if let hudView {
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ hud.indicatorView = JGProgressHUDRingIndicatorView()
|
|
|
|
+ if let indicatorView = hud.indicatorView as? JGProgressHUDRingIndicatorView {
|
|
|
|
+ indicatorView.ringWidth = 1.5
|
|
|
|
+ }
|
|
|
|
+ hud.tapOnHUDViewBlock = { _ in
|
|
|
|
+ NotificationCenter.default.postOnMainThread(name: "NextcloudKit.chunkedFile.stop")
|
|
|
|
+ }
|
|
|
|
+ hud.textLabel.text = NSLocalizedString("_wait_file_preparation_", comment: "")
|
|
|
|
+ hud.detailTextLabel.text = NSLocalizedString("_tap_to_cancel_", comment: "")
|
|
|
|
+ hud.show(in: hudView)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- hud.textLabel.text = NSLocalizedString("_wait_file_preparation_", comment: "")
|
|
|
|
- hud.show(in: hudView)
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
- uploadChunkFile(metadata: metadata) {
|
|
|
|
-#if !EXTENSION
|
|
|
|
|
|
+ uploadChunkFile(metadata: metadata) { num in
|
|
|
|
+ numChunks = num
|
|
|
|
+ } counterChunk: { counter in
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ hud.progress = Float(counter) / Float(numChunks)
|
|
|
|
+ }
|
|
|
|
+ } start: {
|
|
DispatchQueue.main.async { hud.dismiss() }
|
|
DispatchQueue.main.async { hud.dismiss() }
|
|
-#endif
|
|
|
|
} completion: { _, _, _, error in
|
|
} completion: { _, _, _, error in
|
|
|
|
+ DispatchQueue.main.async { hud.dismiss() }
|
|
completion(error)
|
|
completion(error)
|
|
}
|
|
}
|
|
} else if metadata.session == NextcloudKit.shared.nkCommonInstance.sessionIdentifierUpload {
|
|
} else if metadata.session == NextcloudKit.shared.nkCommonInstance.sessionIdentifierUpload {
|
|
@@ -483,6 +495,8 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
func uploadChunkFile(metadata: tableMetadata,
|
|
func uploadChunkFile(metadata: tableMetadata,
|
|
withUploadComplete: Bool = true,
|
|
withUploadComplete: Bool = true,
|
|
customHeaders: [String: String]? = nil,
|
|
customHeaders: [String: String]? = nil,
|
|
|
|
+ numChunks: @escaping (_ num: Int) -> Void = { _ in },
|
|
|
|
+ counterChunk: @escaping (_ counter: Int) -> Void = { _ in },
|
|
start: @escaping () -> Void = { },
|
|
start: @escaping () -> Void = { },
|
|
progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> Void = { _, _, _ in },
|
|
progressHandler: @escaping (_ totalBytesExpected: Int64, _ totalBytes: Int64, _ fractionCompleted: Double) -> Void = { _, _, _ in },
|
|
completion: @escaping (_ account: String, _ file: NKFile?, _ afError: AFError?, _ error: NKError) -> Void) {
|
|
completion: @escaping (_ account: String, _ file: NKFile?, _ afError: AFError?, _ error: NKError) -> Void) {
|
|
@@ -499,15 +513,15 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
}
|
|
}
|
|
let options = NKRequestOptions(customHeader: customHeaders, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
let options = NKRequestOptions(customHeader: customHeaders, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
|
|
|
|
|
|
- NextcloudKit.shared.uploadChunk(directory: directory,
|
|
|
|
- fileName: metadata.fileName,
|
|
|
|
- date: metadata.date as Date,
|
|
|
|
- creationDate: metadata.creationDate as Date,
|
|
|
|
- serverUrl: metadata.serverUrl,
|
|
|
|
- chunkFolder: chunkFolder,
|
|
|
|
- filesChunk: filesChunk,
|
|
|
|
- chunkSize: chunkSize,
|
|
|
|
- options: options) { filesChunk in
|
|
|
|
|
|
+ NextcloudKit.shared.uploadChunk(directory: directory, fileName: metadata.fileName, date: metadata.date as Date, creationDate: metadata.creationDate as Date, serverUrl: metadata.serverUrl, chunkFolder: chunkFolder, filesChunk: filesChunk, chunkSize: chunkSize, options: options) { num in
|
|
|
|
+
|
|
|
|
+ numChunks(num)
|
|
|
|
+
|
|
|
|
+ } counterChunk: { counter in
|
|
|
|
+
|
|
|
|
+ counterChunk(counter)
|
|
|
|
+
|
|
|
|
+ } start: { filesChunk in
|
|
|
|
|
|
start()
|
|
start()
|
|
NCManageDatabase.shared.addChunks(account: metadata.account, ocId: metadata.ocId, chunkFolder: chunkFolder, filesChunk: filesChunk)
|
|
NCManageDatabase.shared.addChunks(account: metadata.account, ocId: metadata.ocId, chunkFolder: chunkFolder, filesChunk: filesChunk)
|
|
@@ -558,17 +572,20 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
switch error.errorCode {
|
|
switch error.errorCode {
|
|
- case NKError.chunkResourceNotFound:
|
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
|
case NKError.chunkNoEnoughMemory:
|
|
case NKError.chunkNoEnoughMemory:
|
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCContentPresenter().messageNotification("_chunk_enough_memory_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
NCContentPresenter().messageNotification("_chunk_enough_memory_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
case NKError.chunkCreateFolder:
|
|
case NKError.chunkCreateFolder:
|
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
|
+ NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCContentPresenter().messageNotification("_chunk_create_folder_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
NCContentPresenter().messageNotification("_chunk_create_folder_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
case NKError.chunkFilesNull:
|
|
case NKError.chunkFilesNull:
|
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCContentPresenter().messageNotification("_chunk_files_null_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
NCContentPresenter().messageNotification("_chunk_files_null_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
case NKError.chunkFileNull: // (fileSize == 0)
|
|
case NKError.chunkFileNull: // (fileSize == 0)
|
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
case NKError.chunkFileUpload:
|
|
case NKError.chunkFileUpload:
|
|
if let afError, (afError.isExplicitlyCancelledError || sessionTaskFailedCode == NCGlobal.shared.errorExplicitlyCancelled ) {
|
|
if let afError, (afError.isExplicitlyCancelledError || sessionTaskFailedCode == NCGlobal.shared.errorExplicitlyCancelled ) {
|