|
@@ -79,7 +79,7 @@ import Photos
|
|
|
return session
|
|
|
}()
|
|
|
|
|
|
- #if EXTENSION
|
|
|
+#if EXTENSION
|
|
|
@objc public lazy var sessionManagerBackgroundExtension: URLSession = {
|
|
|
let configuration = URLSessionConfiguration.background(withIdentifier: sessionIdentifierBackgroundExtension)
|
|
|
configuration.allowsCellularAccess = true
|
|
@@ -91,7 +91,7 @@ import Photos
|
|
|
let session = URLSession(configuration: configuration, delegate: NKBackground.shared, delegateQueue: OperationQueue.main)
|
|
|
return session
|
|
|
}()
|
|
|
- #endif
|
|
|
+#endif
|
|
|
|
|
|
// REQUESTS
|
|
|
|
|
@@ -103,19 +103,19 @@ import Photos
|
|
|
override init() {
|
|
|
super.init()
|
|
|
|
|
|
- #if EXTENSION
|
|
|
+#if EXTENSION
|
|
|
_ = sessionIdentifierBackgroundExtension
|
|
|
- #else
|
|
|
+#else
|
|
|
_ = sessionManagerBackground
|
|
|
_ = sessionManagerBackgroundWWan
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
// MARK: - Communication Delegate
|
|
|
|
|
|
func networkReachabilityObserver(_ typeReachability: NKCommon.typeReachability) {
|
|
|
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
if typeReachability == NKCommon.typeReachability.reachableCellular || typeReachability == NKCommon.typeReachability.reachableEthernetOrWiFi {
|
|
|
if !lastReachability {
|
|
|
NCService.shared.startRequestServicesServer()
|
|
@@ -129,7 +129,7 @@ import Photos
|
|
|
lastReachability = false
|
|
|
}
|
|
|
networkReachability = typeReachability
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
func authenticationChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
|
|
@@ -148,13 +148,13 @@ import Photos
|
|
|
|
|
|
func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
|
|
|
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let completionHandler = appDelegate.backgroundSessionCompletionHandler {
|
|
|
NKCommon.shared.writeLog("[INFO] Called urlSessionDidFinishEvents for Background URLSession")
|
|
|
appDelegate.backgroundSessionCompletionHandler = nil
|
|
|
completionHandler()
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
// MARK: - Pinning check
|
|
@@ -194,9 +194,9 @@ import Photos
|
|
|
if isTrusted {
|
|
|
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
|
|
|
} else {
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
DispatchQueue.main.async { (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host) }
|
|
|
- #endif
|
|
|
+#endif
|
|
|
completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
|
|
|
}
|
|
|
}
|
|
@@ -366,12 +366,12 @@ import Photos
|
|
|
|
|
|
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: "", sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusNormal, etag: etag)
|
|
|
NCManageDatabase.shared.addLocalFile(metadata: metadata)
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
if let result = NCManageDatabase.shared.getE2eEncryption(predicate: NSPredicate(format: "fileNameIdentifier == %@ AND serverUrl == %@", metadata.fileName, metadata.serverUrl)) {
|
|
|
NCEndToEndEncryption.sharedManager()?.decryptFileName(metadata.fileName, fileNameView: metadata.fileNameView, ocId: metadata.ocId, key: result.key, initializationVector: result.initializationVector, authenticationTag: result.authenticationTag)
|
|
|
}
|
|
|
CCUtility.setExif(metadata) { _, _, _, _, _ in }
|
|
|
- #endif
|
|
|
+#endif
|
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
|
|
|
|
|
|
} else {
|
|
@@ -397,12 +397,12 @@ import Photos
|
|
|
NKCommon.shared.writeLog("[INFO] Upload file \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier) with size \(metadata.size) [CHUNCK \(metadata.chunk), E2EE \(isDirectoryE2EE)]")
|
|
|
|
|
|
if isDirectoryE2EE {
|
|
|
- #if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
|
|
|
+#if !EXTENSION_FILE_PROVIDER_EXTENSION && !EXTENSION_WIDGET
|
|
|
Task {
|
|
|
let error = await NCNetworkingE2EEUpload.shared.upload(metadata: metadata, uploadE2EEDelegate: uploadE2EEDelegate)
|
|
|
completion(error)
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
} else if metadata.chunk {
|
|
|
uploadChunkedFile(metadata: metadata, start: start, progressHandler: progressHandler) { error in
|
|
|
completion(error)
|
|
@@ -508,9 +508,9 @@ import Photos
|
|
|
|
|
|
func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, error: NKError) {
|
|
|
var isApplicationStateActive = false
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
isApplicationStateActive = UIApplication.shared.applicationState == .active
|
|
|
- #endif
|
|
|
+#endif
|
|
|
DispatchQueue.global().async {
|
|
|
guard self.delegate == nil, let metadata = NCManageDatabase.shared.getMetadataFromOcId(description) else {
|
|
|
self.delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: task, error: error)
|
|
@@ -578,10 +578,10 @@ import Photos
|
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
|
|
|
}))
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
appDelegate.window?.rootViewController?.present(alertController, animated: true)
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -736,9 +736,9 @@ import Photos
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
NCOperationQueue.shared.downloadCancelAll()
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
func cancelAllDownloadTransfer() {
|
|
@@ -753,9 +753,9 @@ import Photos
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
NCOperationQueue.shared.downloadCancelAll()
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
// MARK: - WebDav Read file, folder
|
|
@@ -1032,12 +1032,12 @@ import Photos
|
|
|
let fileName = fileName.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
|
|
if isDirectoryEncrypted {
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
Task {
|
|
|
let error = await NCNetworkingE2EECreateFolder.shared.createFolder(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, userId: userId)
|
|
|
completion(error)
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
} else {
|
|
|
createFolderPlain(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, overwrite: overwrite, completion: completion)
|
|
|
}
|
|
@@ -1168,7 +1168,7 @@ import Photos
|
|
|
let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
|
|
|
|
|
|
if isDirectoryEncrypted {
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
Task {
|
|
|
if let metadataLive = metadataLive {
|
|
|
let error = await NCNetworkingE2EEDelete.shared.delete(metadata: metadataLive)
|
|
@@ -1183,7 +1183,7 @@ import Photos
|
|
|
completion(error)
|
|
|
}
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
} else {
|
|
|
if metadataLive == nil {
|
|
|
self.deleteMetadataPlain(metadata, customHeader: nil, completion: completion)
|
|
@@ -1268,11 +1268,11 @@ import Photos
|
|
|
NextcloudKit.shared.setFavorite(fileName: fileName, favorite: favorite) { account, error in
|
|
|
if error == .success && metadata.account == account {
|
|
|
NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite)
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
if favorite {
|
|
|
NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorReadFile)
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId, "serverUrl": metadata.serverUrl])
|
|
|
}
|
|
|
completion(error)
|
|
@@ -1292,11 +1292,11 @@ import Photos
|
|
|
NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in
|
|
|
NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas)
|
|
|
if selector != NCGlobal.shared.selectorListingFavorite {
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
for metadata in metadatas {
|
|
|
NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selector)
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
}
|
|
|
completion(account, metadatas, error)
|
|
|
}
|
|
@@ -1331,7 +1331,7 @@ import Photos
|
|
|
let fileNameNewLive = (fileNameNew as NSString).deletingPathExtension + ".mov"
|
|
|
|
|
|
if isDirectoryEncrypted {
|
|
|
- #if !EXTENSION
|
|
|
+#if !EXTENSION
|
|
|
Task {
|
|
|
if let metadataLive = metadataLive {
|
|
|
let error = await NCNetworkingE2EERename.shared.rename(metadata: metadataLive, fileNameNew: fileNameNew)
|
|
@@ -1346,7 +1346,7 @@ import Photos
|
|
|
DispatchQueue.main.async { completion(error) }
|
|
|
}
|
|
|
}
|
|
|
- #endif
|
|
|
+#endif
|
|
|
} else {
|
|
|
if metadataLive == nil {
|
|
|
renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion)
|