marinofaggiana 4 жил өмнө
parent
commit
35aa1cf25d

+ 80 - 80
iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift

@@ -325,6 +325,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
         }
     }
     
+    /*
     @objc func save() {
         
         self.dismiss(animated: true, completion: {
@@ -342,8 +343,8 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
             self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.serverUrl, useSubFolder: useSubFolder, session: self.session)
         })
     }
+    */
     
-    /*
     @objc func save() {
         
         self.dismiss(animated: true, completion: {
@@ -363,103 +364,102 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
             
             let autoUploadPath = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(urlBase: self.appDelegate.urlBase, account: self.appDelegate.account)
             if autoUploadPath == self.serverUrl {
-                
                 if NCNetworking.shared.createFolder(assets: self.assets, selector: selectorUploadFile, useSubFolder: useSubFolder, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase) == false {
                     NCContentPresenter.shared.messageNotification("_error_", description: "_error_createsubfolders_upload_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError), forced: true)
+                    return
                 }
-                
-                for asset in self.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)
-                    
-                    self.serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
-                    
-                    // Check if is in upload
-                    let isRecordInSessions = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", self.appDelegate.account, self.serverUrl, fileName), sorted: "fileName", ascending: false)
-                    if isRecordInSessions.count > 0 {
-                        continue
-                    }
+            }
+
+            for asset in self.assets {
                     
-                    let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: self.appDelegate.account, fileName: fileName, ocId: NSUUID().uuidString, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto)
+                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)
+                
+                self.serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
+                
+                // Check if is in upload
+                let isRecordInSessions = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", self.appDelegate.account, self.serverUrl, fileName), sorted: "fileName", ascending: false)
+                if isRecordInSessions.count > 0 {
+                    continue
+                }
+                
+                let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: self.appDelegate.account, fileName: fileName, ocId: NSUUID().uuidString, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto)
+                
+                metadataForUpload.assetLocalIdentifier = asset.localIdentifier
+                metadataForUpload.session = self.session
+                metadataForUpload.sessionSelector = selectorUploadFile
+                metadataForUpload.size = Double(NCUtilityFileSystem.shared.getFileSize(asset: asset))
+                metadataForUpload.status = Int(k_metadataStatusWaitUpload)
+                
+                if livePhoto {
                     
-                    metadataForUpload.assetLocalIdentifier = asset.localIdentifier
-                    metadataForUpload.session = self.session
-                    metadataForUpload.sessionSelector = selectorUploadFile
-                    metadataForUpload.size = Double(NCUtilityFileSystem.shared.getFileSize(asset: asset))
-                    metadataForUpload.status = Int(k_metadataStatusWaitUpload)
+                    let fileNameMove = (fileName as NSString).deletingPathExtension
+                    let ocId = NSUUID().uuidString
+                    let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameMove)!
                     
-                    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: self.appDelegate.account, fileName: fileNameMove, ocId:ocId, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto)
+                    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: self.appDelegate.account, fileName: fileNameMove, ocId:ocId, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto)
 
-                                metadataForUpload.livePhoto = true
-                                metadataMOVForUpload.livePhoto = true
-                                
-                                metadataMOVForUpload.session = self.session
-                                metadataMOVForUpload.sessionSelector = selectorUploadFile
-                                metadataMOVForUpload.size = fileSize
-                                metadataMOVForUpload.status = Int(k_metadataStatusWaitUpload)
-                                metadataMOVForUpload.typeFile = k_metadataTypeFile_video
+                            metadataForUpload.livePhoto = true
+                            metadataMOVForUpload.livePhoto = true
+                            
+                            metadataMOVForUpload.session = self.session
+                            metadataMOVForUpload.sessionSelector = selectorUploadFile
+                            metadataMOVForUpload.size = fileSize
+                            metadataMOVForUpload.status = Int(k_metadataStatusWaitUpload)
+                            metadataMOVForUpload.typeFile = k_metadataTypeFile_video
 
-                                metadatasMOV.append(metadataMOVForUpload)
-                            }
-                            semaphore.continue()
+                            metadatasMOV.append(metadataMOVForUpload)
                         }
-                        semaphore.wait()
-                    }
-                    
-                    if NCUtility.shared.getMetadataConflict(account: self.appDelegate.account, serverUrl: self.serverUrl, fileName: fileName) != nil {
-                        metadatasUploadInConflict.append(metadataForUpload)
-                    } else {
-                        metadatasNOConflict.append(metadataForUpload)
+                        semaphore.continue()
                     }
+                    semaphore.wait()
                 }
                 
-                // Verify if file(s) exists
-                if metadatasUploadInConflict.count > 0 {
-                    
-                    if let conflict = UIStoryboard.init(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
-                        
-                        conflict.serverUrl = self.serverUrl
-                        conflict.metadatasNOConflict = metadatasNOConflict
-                        conflict.metadatasMOV = metadatasMOV
-                        conflict.metadatasUploadInConflict = metadatasUploadInConflict
-                    
-                        self.appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
-                    }
-                    
+                if NCUtility.shared.getMetadataConflict(account: self.appDelegate.account, serverUrl: self.serverUrl, fileName: fileName) != nil {
+                    metadatasUploadInConflict.append(metadataForUpload)
                 } else {
-                    NCManageDatabase.sharedInstance.addMetadatas(metadatasNOConflict)
-                    NCManageDatabase.sharedInstance.addMetadatas(metadatasMOV)
+                    metadatasNOConflict.append(metadataForUpload)
+                }
+            }
+            
+            // Verify if file(s) exists
+            if metadatasUploadInConflict.count > 0 {
+                
+                if let conflict = UIStoryboard.init(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
                     
-                    self.appDelegate.networkingAutoUpload.startProcess()
+                    conflict.serverUrl = self.serverUrl
+                    conflict.metadatasNOConflict = metadatasNOConflict
+                    conflict.metadatasMOV = metadatasMOV
+                    conflict.metadatasUploadInConflict = metadatasUploadInConflict
+                
+                    self.appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
                 }
+                
+            } else {
+                NCManageDatabase.sharedInstance.addMetadatas(metadatasNOConflict)
+                NCManageDatabase.sharedInstance.addMetadatas(metadatasMOV)
+                
+                self.appDelegate.networkingAutoUpload.startProcess()
             }
         })
     }
-    */
     
     @objc func cancel() {
         

+ 0 - 115
iOSClient/Networking/NCNetworking.swift

@@ -294,121 +294,6 @@ import Queuer
     
     //MARK: - Upload
 
-    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
-            }
-            
-            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
-            }
-        }
-    }
-    
     @objc func upload(metadata: tableMetadata, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->())  {
            
         guard let account = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account)) else {