|
@@ -27,8 +27,8 @@ import NCCommunication
|
|
|
import Alamofire
|
|
|
|
|
|
@objc public protocol NCNetworkingDelegate {
|
|
|
- @objc optional func downloadProgress(_ progress: Double, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask)
|
|
|
- @objc optional func uploadProgress(_ progress: Double, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask)
|
|
|
+ @objc optional func downloadProgress(_ progress: Double, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask)
|
|
|
+ @objc optional func uploadProgress(_ progress: Double, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask)
|
|
|
@objc optional func downloadComplete(fileName: String, serverUrl: String, etag: String?, date: NSDate?, dateLastModified: NSDate?, length: Double, description: String?, error: Error?, statusCode: Int)
|
|
|
@objc optional func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, error: Error?, statusCode: Int)
|
|
|
}
|
|
@@ -77,16 +77,8 @@ import Alamofire
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func downloadProgress(_ progress: Double, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask) {
|
|
|
- delegate?.downloadProgress?(progress, fileName: fileName, ServerUrl: ServerUrl, session: session, task: task)
|
|
|
- }
|
|
|
-
|
|
|
- func uploadProgress(_ progress: Double, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask) {
|
|
|
- delegate?.uploadProgress?(progress, fileName: fileName, ServerUrl: ServerUrl, session: session, task: task)
|
|
|
- }
|
|
|
-
|
|
|
- func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, error: Error?, statusCode: Int) {
|
|
|
- delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size:size, description: description, error: error, statusCode: statusCode)
|
|
|
+ func downloadProgress(_ progress: Double, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask) {
|
|
|
+ delegate?.downloadProgress?(progress, totalBytes: totalBytes, totalBytesExpected: totalBytesExpected, fileName: fileName, ServerUrl: ServerUrl, session: session, task: task)
|
|
|
}
|
|
|
|
|
|
func downloadComplete(fileName: String, serverUrl: String, etag: String?, date: NSDate?, dateLastModified: NSDate?, length: Double, description: String?, error: Error?, statusCode: Int) {
|
|
@@ -353,13 +345,15 @@ import Alamofire
|
|
|
}
|
|
|
|
|
|
metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(metadata)
|
|
|
-
|
|
|
- #if !EXTENSION
|
|
|
+
|
|
|
if e2eEncrypted {
|
|
|
+ #if !EXTENSION
|
|
|
NCNetworkingE2EE.shared.upload(metadata: metadataForUpload!, account: account)
|
|
|
+ #endif
|
|
|
+ } else {
|
|
|
+ uploadFile(metadata: metadataForUpload!, account: account)
|
|
|
}
|
|
|
- #endif
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
CCUtility.extractImageVideoFromAssetLocalIdentifier(forUpload: metadata, notification: true) { (extractMetadata, fileNamePath) in
|
|
@@ -378,16 +372,58 @@ import Alamofire
|
|
|
}
|
|
|
|
|
|
metadataForUpload = NCManageDatabase.sharedInstance.addMetadata(extractMetadata)
|
|
|
-
|
|
|
- #if !EXTENSION
|
|
|
+
|
|
|
if e2eEncrypted {
|
|
|
+ #if !EXTENSION
|
|
|
NCNetworkingE2EE.shared.upload(metadata: metadataForUpload!, account: account)
|
|
|
+ #endif
|
|
|
+ } else {
|
|
|
+ self.uploadFile(metadata: metadataForUpload!, account: account)
|
|
|
}
|
|
|
- #endif
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func uploadFile(metadata: tableMetadata, account: tableAccount) {
|
|
|
+
|
|
|
+ let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
|
|
|
+ let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
+
|
|
|
+ if let task = NCCommunicationBackground.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, description: "", session: NCCommunicationBackground.shared.sessionManagerTransferExtension) {
|
|
|
+
|
|
|
+ metadata.status = Int(k_metadataStatusUploading)
|
|
|
+ metadata.sessionError = ""
|
|
|
+ metadata.sessionTaskIdentifier = task.taskIdentifier
|
|
|
+ NCManageDatabase.sharedInstance.addMetadata(metadata)
|
|
|
+
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_uploadFileStart), object: nil, userInfo: ["ocId":metadata.ocId, "task":task, "serverUrl":metadata.serverUrl, "account":metadata.account])
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func uploadProgress(_ progress: Double, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, ServerUrl: String, session: URLSession, task: URLSessionTask) {
|
|
|
+ delegate?.uploadProgress?(progress, totalBytes: totalBytes, totalBytesExpected: totalBytesExpected, fileName: fileName, ServerUrl: ServerUrl, session: session, task: task)
|
|
|
+
|
|
|
+ if let metadata = NCManageDatabase.sharedInstance.getMetadataInSessionFromFileName(fileName, serverUrl: ServerUrl, taskIdentifier: task.taskIdentifier) {
|
|
|
+
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_progressTask), object: nil, userInfo: ["account":metadata.account, "ocId":metadata.ocId, "serverUrl":ServerUrl, "status":NSNumber(value: k_metadataStatusInDownload), "progress":NSNumber(value: progress), "totalBytes":NSNumber(value: totalBytes), "totalBytesExpected":NSNumber(value: totalBytesExpected)])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, error: Error?, statusCode: Int) {
|
|
|
+ if delegate != nil {
|
|
|
+ delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size:size, description: description, error: error, statusCode: statusCode)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if error == nil && statusCode >= 200 && statusCode < 300 {
|
|
|
+
|
|
|
+ } else if error != nil && (error! as NSError).code == -999 {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//MARK: - WebDav Read file, folder
|
|
|
|
|
|
@objc func readFolder(serverUrl: String, account: String, completion: @escaping (_ account: String, _ metadataFolder: tableMetadata?, _ metadatas: [tableMetadata]?, _ errorCode: Int, _ errorDescription: String)->()) {
|