|
@@ -351,38 +351,53 @@ class FileProvider: NSFileProviderExtension {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
|
-
|
|
|
- // Copy file to Change Directory
|
|
|
- _ = self.copyFile(url.path, toPath: changeDocumentPath)
|
|
|
-
|
|
|
- let queue = NCManageDatabase.sharedInstance.getQueueUpload(predicate: NSPredicate(format: "account = %@ AND path = %@", account, changeDocumentPath))
|
|
|
+ // Copy file to Change Directory
|
|
|
+ _ = self.copyFile(url.path, toPath: changeDocumentPath)
|
|
|
+
|
|
|
+ let queue = NCManageDatabase.sharedInstance.getQueueUpload(predicate: NSPredicate(format: "account = %@ AND path = %@", account, changeDocumentPath))
|
|
|
+ if (queue?.count)! > 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let metadataNet = CCMetadataNet()
|
|
|
+ metadataNet.account = account
|
|
|
+ metadataNet.assetLocalIdentifier = k_assetLocalIdentifierFileProviderStorage + CCUtility.createRandomString(20)
|
|
|
+ metadataNet.fileName = fileName
|
|
|
+ metadataNet.path = changeDocumentPath
|
|
|
+ metadataNet.selector = selectorUploadFile
|
|
|
+ metadataNet.selectorPost = ""
|
|
|
+ metadataNet.serverUrl = serverUrl
|
|
|
+ metadataNet.session = k_upload_session
|
|
|
+ metadataNet.taskStatus = Int(k_taskStatusResume)
|
|
|
+ _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
|
|
|
|
|
|
- if queue?.count == 0 {
|
|
|
+ let ocNetworkingX = OCnetworking.init(delegate: nil, metadataNet: nil, withUser: accountUser, withUserID: accountUserID, withPassword: accountPassword, withUrl: accountUrl)
|
|
|
+ _ = ocNetworkingX?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: changeDocumentPath, communication: CCNetworking.shared().sharedOCCommunicationExtensionUpload(fileName), success: { (fileID, etag, date) in
|
|
|
|
|
|
- let metadataNet = CCMetadataNet()
|
|
|
-
|
|
|
- metadataNet.account = account
|
|
|
- metadataNet.assetLocalIdentifier = k_assetLocalIdentifierFileProviderStorage + CCUtility.createRandomString(20)
|
|
|
- metadataNet.fileName = fileName
|
|
|
- metadataNet.path = changeDocumentPath
|
|
|
- metadataNet.selector = selectorUploadFile
|
|
|
- metadataNet.selectorPost = ""
|
|
|
- metadataNet.serverUrl = serverUrl
|
|
|
- metadataNet.session = k_upload_session
|
|
|
- metadataNet.taskStatus = Int(k_taskStatusResume)
|
|
|
-
|
|
|
- _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
|
|
|
-
|
|
|
- } else {
|
|
|
- print("File already exists in queue")
|
|
|
- }
|
|
|
+ // Remove file on queueUpload
|
|
|
+ NCManageDatabase.sharedInstance.deleteQueueUpload(path: changeDocumentPath)
|
|
|
|
|
|
- // Upload on cloud
|
|
|
- if NCManageDatabase.sharedInstance.queueUploadLockPath(changeDocumentPath) != nil {
|
|
|
- self.uploadCloud(fileName, serverUrl: serverUrl, fileNameLocalPath: changeDocumentPath, metadata: metadata, identifier: identifier)
|
|
|
+ metadata.date = date! as NSDate
|
|
|
+
|
|
|
+ do {
|
|
|
+ let attributes = try FileManager.default.attributesOfItem(atPath: changeDocumentPath)
|
|
|
+ metadata.size = attributes[FileAttributeKey.size] as! Double
|
|
|
+ } catch let error {
|
|
|
+ print("error: \(error)")
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
|
|
|
+
|
|
|
+ // Remove file *changeDocument
|
|
|
+ _ = self.deleteFile(changeDocumentPath)
|
|
|
+
|
|
|
+ // Refresh
|
|
|
+ self.refreshEnumerator(identifier: identifier, serverUrl: serverUrl)
|
|
|
+
|
|
|
+ }, failure: { (message, errorCode) in
|
|
|
+ // unlock queueUpload
|
|
|
+ NCManageDatabase.sharedInstance.unlockQueueUpload(assetLocalIdentifier: nil, path: changeDocumentPath)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -840,8 +855,26 @@ class FileProvider: NSFileProviderExtension {
|
|
|
// MARK: - User Function
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
|
|
+ /*
|
|
|
func uploadCloud(_ fileName: String, serverUrl: String, fileNameLocalPath: String, metadata: tableMetadata, identifier: NSFileProviderItemIdentifier) {
|
|
|
|
|
|
+ let queue = NCManageDatabase.sharedInstance.getQueueUpload(predicate: NSPredicate(format: "account = %@ AND path = %@", account, fileNameLocalPath))
|
|
|
+ if (queue?.count)! > 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let metadataNet = CCMetadataNet()
|
|
|
+ metadataNet.account = account
|
|
|
+ metadataNet.assetLocalIdentifier = k_assetLocalIdentifierFileProviderStorage + CCUtility.createRandomString(20)
|
|
|
+ metadataNet.fileName = fileName
|
|
|
+ metadataNet.path = fileNameLocalPath
|
|
|
+ metadataNet.selector = selectorUploadFile
|
|
|
+ metadataNet.selectorPost = ""
|
|
|
+ metadataNet.serverUrl = serverUrl
|
|
|
+ metadataNet.session = k_upload_session
|
|
|
+ metadataNet.taskStatus = Int(k_taskStatusResume)
|
|
|
+ _ = NCManageDatabase.sharedInstance.addQueueUpload(metadataNet: metadataNet)
|
|
|
+
|
|
|
let task = ocNetworking?.uploadFileNameServerUrl(serverUrl+"/"+fileName, fileNameLocalPath: fileNameLocalPath, communication: CCNetworking.shared().sharedOCCommunicationExtensionUpload(fileName), success: { (fileID, etag, date) in
|
|
|
|
|
|
// Remove file on queueUpload
|
|
@@ -878,6 +911,7 @@ class FileProvider: NSFileProviderExtension {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
func refreshEnumerator(identifier: NSFileProviderItemIdentifier, serverUrl: String) {
|
|
|
|