diff options
author | Marino Faggiana <marino@marinofaggiana.com> | 2022-09-28 10:17:54 +0300 |
---|---|---|
committer | Marino Faggiana <marino@marinofaggiana.com> | 2022-09-28 10:17:54 +0300 |
commit | 9a05cfcf3776fbfdfc6d5f814eb5339e57e60663 (patch) | |
tree | 14b6d3019362b153f764fe5c0e1db7d26b07759d | |
parent | f0e1726373857d2fcbc7fc9bd078fb0884291dd3 (diff) |
coding
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
-rw-r--r-- | Nextcloud.xcodeproj/project.pbxproj | 2 | ||||
-rw-r--r-- | iOSClient/Networking/NCAutoUpload.swift | 16 | ||||
-rw-r--r-- | iOSClient/Networking/NCNetworking.swift | 32 |
3 files changed, 29 insertions, 21 deletions
diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index fd8e79fe7..350fbdf35 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -358,7 +358,6 @@ F78F74342163757000C2ADAD /* NCTrash.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F78F74332163757000C2ADAD /* NCTrash.storyboard */; }; F78F74362163781100C2ADAD /* NCTrash.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78F74352163781100C2ADAD /* NCTrash.swift */; }; F790110E21415BF600D7B136 /* NCViewerRichdocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */; }; - F793E59B28B75FB0005E4B02 /* NCAutoUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72CD63925C19EBF00F46F9A /* NCAutoUpload.swift */; }; F793E59D28B761E7005E4B02 /* NCNetworking.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75A9EE523796C6F0044CFCE /* NCNetworking.swift */; }; F793E59E28B763C2005E4B02 /* NCAskAuthorization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F733598025C1C188002ABA72 /* NCAskAuthorization.swift */; }; F793E59F28B764F6005E4B02 /* NCContentPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F765608E23BF813500765969 /* NCContentPresenter.swift */; }; @@ -2743,7 +2742,6 @@ F77ED59328C9CEA000E24ED0 /* ToolbarWidgetProvider.swift in Sources */, F72A17D828B221E300F3F159 /* DashboardWidgetView.swift in Sources */, F77ED59528C9CEA400E24ED0 /* ToolbarWidgetView.swift in Sources */, - F793E59B28B75FB0005E4B02 /* NCAutoUpload.swift in Sources */, F78302FB28B4C3EE00B84583 /* NCManageDatabase+Video.swift in Sources */, F72EA95228B7BA2A00C88F0C /* DashboardWidgetProvider.swift in Sources */, F793E5A228B76580005E4B02 /* NCNetworkingChunkedUpload.swift in Sources */, diff --git a/iOSClient/Networking/NCAutoUpload.swift b/iOSClient/Networking/NCAutoUpload.swift index 4e2e47471..5fd32e5c7 100644 --- a/iOSClient/Networking/NCAutoUpload.swift +++ b/iOSClient/Networking/NCAutoUpload.swift @@ -86,19 +86,11 @@ class NCAutoUpload: NSObject { self.getCameraRollAssets(viewController: viewController, account: account, selector: selector, alignPhotoLibrary: false) { assets in guard let assets = assets, !assets.isEmpty else { - #if EXTENSION_WIDGET - NKCommon.shared.writeLog("Automatic upload widget, no new assets found [" + log + "]") - #else NKCommon.shared.writeLog("Automatic upload, no new assets found [" + log + "]") - #endif completion(0) return } - #if EXTENSION_WIDGET - NKCommon.shared.writeLog("Automatic upload widget, new \(assets.count) assets found [" + log + "]") - #else NKCommon.shared.writeLog("Automatic upload, new \(assets.count) assets found [" + log + "]") - #endif // Create the folder for auto upload & if request the subfolders if !NCNetworking.shared.createFolder(assets: assets, selector: selector, useSubFolder: account.autoUploadCreateSubfolder, account: account.account, urlBase: account.urlBase) { #if !EXTENSION @@ -172,11 +164,7 @@ class NCAutoUpload: NSObject { metadata.classFile = NKCommon.typeClassFile.image.rawValue } if selector == NCGlobal.shared.selectorUploadAutoUpload { - #if EXTENSION_WIDGET - NKCommon.shared.writeLog("Automatic upload widget added \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier)") - #else NKCommon.shared.writeLog("Automatic upload added \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier)") - #endif NCManageDatabase.shared.addPhotoLibrary([asset], account: account.account) } metadatas.append(metadata) @@ -271,11 +259,7 @@ class NCAutoUpload: NSObject { guard let assets = assets else { return } NCManageDatabase.shared.addPhotoLibrary(assets, account: activeAccount.account) - #if EXTENSION_WIDGET - NKCommon.shared.writeLog("Widget align Photo Library \(assets.count)") - #else NKCommon.shared.writeLog("Align Photo Library \(assets.count)") - #endif } } diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index ac6c81d11..f8b9d5e45 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -299,6 +299,26 @@ import Photos } } + func isInTaskUploadBackground(fileName: String, completion: @escaping (_ exists: Bool) -> Void) { + + let sessions: [URLSession] = [NCNetworking.shared.sessionManagerBackground, NCNetworking.shared.sessionManagerBackgroundWWan] + + for session in sessions { + session.getAllTasks(completionHandler: { tasks in + for task in tasks { + let url = task.originalRequest?.url + let urlFileName = url?.lastPathComponent + if urlFileName == fileName { + completion(true) + } + } + if session == sessions.last { + completion(false) + } + }) + } + } + // MARK: - Download @objc func cancelDownload(ocId: String, serverUrl: String, fileNameView: String) { @@ -403,9 +423,15 @@ import Photos } } } else { - uploadFileInBackground(metadata: metadata, start: start) { error in - DispatchQueue.main.async { - completion(error) + isInTaskUploadBackground(fileName: metadata.fileName) { exists in + if !exists { + self.uploadFileInBackground(metadata: metadata, start: start) { error in + DispatchQueue.main.async { + completion(error) + } + } + } else { + completion(NKError(errorCode: 0, errorDescription: "")) } } } |