|
@@ -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
|
|
|
|