|
@@ -27,10 +27,10 @@ import NCCommunication
|
|
|
import Alamofire
|
|
|
|
|
|
@objc public protocol NCNetworkingDelegate {
|
|
|
- @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)
|
|
|
+ @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?, task: URLSessionTask, error: Error?, statusCode: Int)
|
|
|
+ @objc optional func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, error: Error?, statusCode: Int)
|
|
|
}
|
|
|
|
|
|
@objc class NCNetworking: NSObject, NCCommunicationCommonDelegate {
|
|
@@ -77,12 +77,12 @@ import Alamofire
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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 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) {
|
|
|
- delegate?.downloadComplete?(fileName: fileName, serverUrl: serverUrl, etag: etag, date: date, dateLastModified: dateLastModified, length: length, description: description, error: error, statusCode: statusCode)
|
|
|
+ func downloadComplete(fileName: String, serverUrl: String, etag: String?, date: NSDate?, dateLastModified: NSDate?, length: Double, description: String?, task: URLSessionTask, error: Error?, statusCode: Int) {
|
|
|
+ delegate?.downloadComplete?(fileName: fileName, serverUrl: serverUrl, etag: etag, date: date, dateLastModified: dateLastModified, length: length, description: description, task: task, error: error, statusCode: statusCode)
|
|
|
}
|
|
|
|
|
|
//MARK: - Pinning check
|
|
@@ -401,25 +401,39 @@ import Alamofire
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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)
|
|
|
+ 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) {
|
|
|
+ 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)])
|
|
|
+ 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) {
|
|
|
+ func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, 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)
|
|
|
+ delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size:size, description: description, task: task, error: error, statusCode: statusCode)
|
|
|
} else {
|
|
|
|
|
|
+ guard let metadata = NCManageDatabase.sharedInstance.getMetadataInSessionFromFileName(fileName, serverUrl: serverUrl, taskIdentifier: task.taskIdentifier) else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if error == nil && statusCode >= 200 && statusCode < 300 {
|
|
|
|
|
|
} else if error != nil && (error! as NSError).code == -999 {
|
|
|
|
|
|
+ if metadata.status == k_metadataStatusUploadForcedStart {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
|
|
|
+ NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_reloadDataSource), object: nil, userInfo: ["ocId":metadata.ocId,"serverUrl":metadata.serverUrl])
|
|
|
}
|
|
|
}
|
|
|
|