marinofaggiana 4 vuotta sitten
vanhempi
commit
9d741428ed

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -1657,7 +1657,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 1130;
-				LastUpgradeCheck = 1020;
+				LastUpgradeCheck = 1200;
 				ORGANIZATIONNAME = "Marino Faggiana";
 				TargetAttributes = {
 					2C33C47E23E2C475005F963B = {

+ 4 - 7
Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1020"
+   LastUpgradeVersion = "1200"
    wasCreatedForAppExtension = "YES"
    version = "2.0">
    <BuildAction
@@ -42,8 +42,6 @@
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
       shouldUseLaunchSchemeArgsEnv = "YES">
-      <Testables>
-      </Testables>
       <MacroExpansion>
          <BuildableReference
             BuildableIdentifier = "primary"
@@ -53,14 +51,15 @@
             ReferencedContainer = "container:Nextcloud.xcodeproj">
          </BuildableReference>
       </MacroExpansion>
-      <AdditionalOptions>
-      </AdditionalOptions>
+      <Testables>
+      </Testables>
    </TestAction>
    <LaunchAction
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = ""
       selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
       launchStyle = "0"
+      askForAppToLaunch = "Yes"
       useCustomWorkingDirectory = "NO"
       ignoresPersistentStateOnLaunch = "NO"
       debugDocumentVersioning = "YES"
@@ -77,8 +76,6 @@
             ReferencedContainer = "container:Nextcloud.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
-      <AdditionalOptions>
-      </AdditionalOptions>
    </LaunchAction>
    <ProfileAction
       buildConfiguration = "Release"

+ 1 - 1
Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1020"
+   LastUpgradeVersion = "1200"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 4 - 7
Nextcloud.xcodeproj/xcshareddata/xcschemes/Share.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1020"
+   LastUpgradeVersion = "1200"
    wasCreatedForAppExtension = "YES"
    version = "2.0">
    <BuildAction
@@ -42,8 +42,6 @@
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
       shouldUseLaunchSchemeArgsEnv = "YES">
-      <Testables>
-      </Testables>
       <MacroExpansion>
          <BuildableReference
             BuildableIdentifier = "primary"
@@ -53,14 +51,15 @@
             ReferencedContainer = "container:Nextcloud.xcodeproj">
          </BuildableReference>
       </MacroExpansion>
-      <AdditionalOptions>
-      </AdditionalOptions>
+      <Testables>
+      </Testables>
    </TestAction>
    <LaunchAction
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = ""
       selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
       launchStyle = "0"
+      askForAppToLaunch = "Yes"
       useCustomWorkingDirectory = "NO"
       ignoresPersistentStateOnLaunch = "NO"
       debugDocumentVersioning = "YES"
@@ -77,8 +76,6 @@
             ReferencedContainer = "container:Nextcloud.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
-      <AdditionalOptions>
-      </AdditionalOptions>
    </LaunchAction>
    <ProfileAction
       buildConfiguration = "Release"

+ 125 - 10
iOSClient/Networking/NCNetworking.swift

@@ -294,17 +294,118 @@ import Queuer
     
     //MARK: - Upload
 
-    @objc func cancelUpload(ocId: String) {
-        guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) else { return }
-        guard let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else { return }
-        
-        if let request = uploadRequest[fileNameLocalPath] {
-            request.cancel()
-        } else {
-            CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
-            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+    func uploadFileAsset(assets: [PHAsset], serverUrl: String, useSubFolder: Bool, session: String, urlBase: String, account: String) {
+    
+        var serverUrl = serverUrl
+        var livePhoto: Bool = false
+        var metadatasMOV: [tableMetadata] = []
+        var metadatasNOConflict: [tableMetadata] = []
+        var metadatasUploadInConflict: [tableMetadata] = []
+
+        let autoUploadPath = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(urlBase: urlBase, account: account)
+        if autoUploadPath == serverUrl {
+                            
+            if createFolder(assets: assets, selector: selectorUploadFile, useSubFolder: useSubFolder, account: account, urlBase: urlBase) == false {
+                #if !EXTENSION
+                NCContentPresenter.shared.messageNotification("_error_", description: "_error_createsubfolders_upload_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError), forced: true)
+                #endif
+            }
             
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["metadata":metadata])
+            for asset in assets {
+                
+                let fileName = CCUtility.createFileName(asset.value(forKey: "filename") as? String, fileDate: asset.creationDate, fileType: asset.mediaType, keyFileName: k_keyFileNameMask, keyFileNameType: k_keyFileNameType, keyFileNameOriginal: k_keyFileNameOriginal)!
+                let assetDate = asset.creationDate ?? Date()
+                let dateFormatter = DateFormatter()
+                
+                // Detect LivePhoto Upload
+                if (asset.mediaSubtypes == PHAssetMediaSubtype.photoLive || asset.mediaSubtypes.rawValue == PHAssetMediaSubtype.photoLive.rawValue + PHAssetMediaSubtype.photoHDR.rawValue) && CCUtility.getLivePhoto() {
+                    livePhoto = true
+                }
+                
+                // Create serverUrl if use sub folder
+                dateFormatter.dateFormat = "yyyy"
+                let yearString = dateFormatter.string(from: assetDate)
+               
+                dateFormatter.dateFormat = "MM"
+                let monthString = dateFormatter.string(from: assetDate)
+                
+                serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
+                
+                // Check if is in upload
+                let isRecordInSessions = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", account, serverUrl, fileName), sorted: "fileName", ascending: false)
+                if isRecordInSessions.count > 0 {
+                    continue
+                }
+                
+                let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: account, fileName: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: urlBase, url: "", contentType: "", livePhoto: livePhoto)
+                
+                metadataForUpload.assetLocalIdentifier = asset.localIdentifier
+                metadataForUpload.session = session
+                metadataForUpload.sessionSelector = selectorUploadFile
+                metadataForUpload.size = Double(NCUtilityFileSystem.shared.getFileSize(asset: asset))
+                metadataForUpload.status = Int(k_metadataStatusWaitUpload)
+                
+                if livePhoto {
+                    
+                    let fileNameMove = (fileName as NSString).deletingPathExtension
+                    let ocId = NSUUID().uuidString
+                    let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameMove)!
+                    
+                    let semaphore = Semaphore()
+                    CCUtility.extractLivePhotoAsset(asset, filePath: filePath) { (url) in
+                        if let url = url {
+                            let fileSize = NCUtilityFileSystem.shared.getFileSize(filePath: url.path)
+                            let metadataMOVForUpload = NCManageDatabase.sharedInstance.createMetadata(account: account, fileName: fileNameMove, ocId:ocId, serverUrl: serverUrl, urlBase: urlBase, url: "", contentType: "", livePhoto: livePhoto)
+
+                            metadataForUpload.livePhoto = true
+                            metadataMOVForUpload.livePhoto = true
+                            
+                            metadataMOVForUpload.session = session
+                            metadataMOVForUpload.sessionSelector = selectorUploadFile
+                            metadataMOVForUpload.size = fileSize
+                            metadataMOVForUpload.status = Int(k_metadataStatusWaitUpload)
+                            metadataMOVForUpload.typeFile = k_metadataTypeFile_video
+
+                            metadatasMOV.append(metadataMOVForUpload)
+                        }
+                        semaphore.continue()
+                    }
+                    semaphore.wait()
+                }
+                
+                if NCUtility.shared.getMetadataConflict(account: account, serverUrl: serverUrl, fileName: fileName) != nil {
+                    metadatasUploadInConflict.append(metadataForUpload)
+                } else {
+                    metadatasNOConflict.append(metadataForUpload)
+                }
+            }
+            
+            // Verify if file(s) exists
+            if metadatasUploadInConflict.count > 0 {
+                
+                #if !EXTENSION
+                if let conflict = UIStoryboard.init(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
+                    
+                    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+                    
+                    conflict.serverUrl = serverUrl
+                    conflict.metadatasNOConflict = metadatasNOConflict
+                    conflict.metadatasMOV = metadatasMOV
+                    conflict.metadatasUploadInConflict = metadatasUploadInConflict
+                
+                    appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
+                }
+                #endif
+                
+            } else {
+                NCManageDatabase.sharedInstance.addMetadatas(metadatasNOConflict)
+                NCManageDatabase.sharedInstance.addMetadatas(metadatasMOV)
+                
+                #if !EXTENSION
+                let appDelegate = UIApplication.shared.delegate as! AppDelegate
+                appDelegate.networkingAutoUpload.startProcess()
+                #endif
+            }
         }
     }
     
@@ -631,6 +732,20 @@ import Queuer
             })
         })
     }
+    
+    @objc func cancelUpload(ocId: String) {
+        guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) else { return }
+        guard let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else { return }
+        
+        if let request = uploadRequest[fileNameLocalPath] {
+            request.cancel()
+        } else {
+            CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
+            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+            
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["metadata":metadata])
+        }
+    }
         
     //MARK: - WebDav Read file, folder