1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // NCNetworkingE2EEDelete.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 09/11/22.
- // Copyright © 2022 Marino Faggiana. All rights reserved.
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- import NextcloudKit
- class NCNetworkingE2EEDelete: NSObject {
- let networkingE2EE = NCNetworkingE2EE()
- func delete(metadata: tableMetadata) async -> NKError {
- guard let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) else {
- return NKError(errorCode: NCGlobal.shared.errorUnexpectedResponseFromDB, errorDescription: "_e2e_error_")
- }
- // LOCK
- //
- let resultsLock = await networkingE2EE.lock(account: metadata.account, serverUrl: metadata.serverUrl)
- guard resultsLock.error == .success, let e2eToken = resultsLock.e2eToken, let fileId = resultsLock.fileId else { return resultsLock.error }
- // DELETE FILE
- //
- let deleteMetadataPlainError = await NCNetworking.shared.deleteMetadataPlain(metadata, customHeader: ["e2e-token": e2eToken])
- guard deleteMetadataPlainError == .success else {
- await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)
- return deleteMetadataPlainError
- }
- // DOWNLOAD METADATA
- //
- let errorDownloadMetadata = await networkingE2EE.downloadMetadata(account: metadata.account, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, fileId: fileId, e2eToken: e2eToken)
- guard errorDownloadMetadata == .success else {
- await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)
- return errorDownloadMetadata
- }
- // UPDATE DB
- //
- NCManageDatabase.shared.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameIdentifier == %@", metadata.account, metadata.serverUrl, metadata.fileName))
- // UPLOAD METADATA
- //
- let uploadMetadataError = await networkingE2EE.uploadMetadata(account: metadata.account,
- serverUrl: metadata.serverUrl,
- ocIdServerUrl: directory.ocId,
- fileId: fileId,
- userId: metadata.userId,
- e2eToken: e2eToken,
- method: "PUT")
- guard uploadMetadataError == .success else {
- await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)
- return uploadMetadataError
- }
- // UNLOCK
- //
- await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl)
- return NKError()
- }
- }
|