Skip to content

Commit

Permalink
update NextcloudNit
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Oct 19, 2023
1 parent 2ccb45e commit 472b560
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
CCUtility.isEnd(toEndEnabled: self.appDelegate.account),
!NCNetworkingE2EE.shared.isInUpload(account: self.appDelegate.account, serverUrl: self.serverUrl) {
let lock = NCManageDatabase.shared.getE2ETokenLock(account: self.appDelegate.account, serverUrl: self.serverUrl)
NextcloudKit.shared.getE2EEMetadata(fileId: metadataFolder.ocId, e2eToken: lock?.e2eToken, route: NCNetworkingE2EE.shared.getRoute()) { _, e2eMetadata, signature, _, error in
NextcloudKit.shared.getE2EEMetadata(fileId: metadataFolder.ocId, e2eToken: lock?.e2eToken) { _, e2eMetadata, signature, _, error in
if error == .success, let e2eMetadata = e2eMetadata {
let error = NCEndToEndMetadata().decodeMetadata(e2eMetadata, signature: signature, serverUrl: self.serverUrl, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
if error == .success {
Expand Down
18 changes: 6 additions & 12 deletions iOSClient/Networking/E2EE/NCNetworkingE2EE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ class NCNetworkingE2EE: NSObject {
return instance
}()

func getRoute() -> String {
let e2eeRouteV1 = "v1"
let e2eeRouteV2 = "v2"
return (NCGlobal.shared.capabilityE2EEApiVersion == NCGlobal.shared.e2eeVersionV20) ? e2eeRouteV1 : e2eeRouteV1
}

func isInUpload(account: String, serverUrl: String) -> Bool {

let counter = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d)", account, serverUrl, NCGlobal.shared.metadataStatusWaitUpload, NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading)).count
Expand Down Expand Up @@ -74,7 +68,7 @@ class NCNetworkingE2EE: NSObject {

// METHOD
//
let resultsGetE2EEMetadata = await NextcloudKit.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken, route: getRoute())
let resultsGetE2EEMetadata = await NextcloudKit.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken)
if resultsGetE2EEMetadata.error == .success {
method = "PUT"
} else if resultsGetE2EEMetadata.error.errorCode != NCGlobal.shared.errorResourceNotFound {
Expand Down Expand Up @@ -112,7 +106,7 @@ class NCNetworkingE2EE: NSObject {
fileId: String,
e2eToken: String) async -> NKError {

let resultsGetE2EEMetadata = await NextcloudKit.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken, route: getRoute())
let resultsGetE2EEMetadata = await NextcloudKit.shared.getE2EEMetadata(fileId: fileId, e2eToken: e2eToken)
guard resultsGetE2EEMetadata.error == .success, let e2eMetadata = resultsGetE2EEMetadata.e2eMetadata else {
return resultsGetE2EEMetadata.error
}
Expand Down Expand Up @@ -141,7 +135,7 @@ class NCNetworkingE2EE: NSObject {
return resultsEncodeMetadata.error
}

let putE2EEMetadataResults = await NextcloudKit.shared.putE2EEMetadata(fileId: fileId, e2eToken: e2eToken, e2eMetadata: e2eMetadata, signature: resultsEncodeMetadata.signature, method: method, route: getRoute())
let putE2EEMetadataResults = await NextcloudKit.shared.putE2EEMetadata(fileId: fileId, e2eToken: e2eToken, e2eMetadata: e2eMetadata, signature: resultsEncodeMetadata.signature, method: method)
guard putE2EEMetadataResults.error == .success else {
return putE2EEMetadataResults.error
}
Expand Down Expand Up @@ -173,7 +167,7 @@ class NCNetworkingE2EE: NSObject {
e2eCounter = "\(counter)"
}

let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: directory.fileId, e2eToken: e2eToken, e2eCounter: e2eCounter, method: "POST", route: getRoute())
let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: directory.fileId, e2eToken: e2eToken, e2eCounter: e2eCounter, method: "POST")
if resultsLockE2EEFolder.error == .success, let e2eToken = resultsLockE2EEFolder.e2eToken {
NCManageDatabase.shared.setE2ETokenLock(account: account, serverUrl: serverUrl, fileId: directory.fileId, e2eToken: e2eToken)
}
Expand All @@ -187,7 +181,7 @@ class NCNetworkingE2EE: NSObject {
return
}

let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: tableLock.fileId, e2eToken: tableLock.e2eToken, e2eCounter: nil, method: "DELETE", route: getRoute())
let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: tableLock.fileId, e2eToken: tableLock.e2eToken, e2eCounter: nil, method: "DELETE")
if resultsLockE2EEFolder.error == .success {
NCManageDatabase.shared.deleteE2ETokenLock(account: account, serverUrl: serverUrl)
}
Expand All @@ -201,7 +195,7 @@ class NCNetworkingE2EE: NSObject {

Task {
for result in NCManageDatabase.shared.getE2EAllTokenLock(account: account) {
let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: result.fileId, e2eToken: result.e2eToken, e2eCounter: nil, method: "DELETE", route: getRoute())
let resultsLockE2EEFolder = await NextcloudKit.shared.lockE2EEFolder(fileId: result.fileId, e2eToken: result.e2eToken, e2eCounter: nil, method: "DELETE")
if resultsLockE2EEFolder.error == .success {
NCManageDatabase.shared.deleteE2ETokenLock(account: account, serverUrl: result.serverUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NCNetworkingE2EECreateFolder: NSObject {

// SET FOLDER AS E2EE
//
let resultsMarkE2EEFolder = await NextcloudKit.shared.markE2EEFolder(fileId: fileId, delete: false, route: NCNetworkingE2EE.shared.getRoute())
let resultsMarkE2EEFolder = await NextcloudKit.shared.markE2EEFolder(fileId: fileId, delete: false)
guard resultsMarkE2EEFolder.error == .success else {
await NCNetworkingE2EE.shared.unlock(account: account, serverUrl: serverUrl)
return resultsMarkE2EEFolder.error
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Networking/E2EE/NCNetworkingE2EEMarkFolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NCNetworkingE2EEMarkFolder: NSObject {
let resultsReadFileOrFolder = await NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0")
guard resultsReadFileOrFolder.error == .success, let file = resultsReadFileOrFolder.files.first else { return resultsReadFileOrFolder.error }

let resultsMarkE2EEFolder = await NextcloudKit.shared.markE2EEFolder(fileId: file.fileId, delete: false, route: NCNetworkingE2EE.shared.getRoute())
let resultsMarkE2EEFolder = await NextcloudKit.shared.markE2EEFolder(fileId: file.fileId, delete: false)
guard resultsMarkE2EEFolder.error == .success else { return resultsMarkE2EEFolder.error }

file.e2eEncrypted = true
Expand Down

0 comments on commit 472b560

Please sign in to comment.