|
@@ -435,8 +435,27 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
DispatchQueue.main.async { hud?.progress = Float(counter) / Float(numChunks) }
|
|
|
} start: {
|
|
|
DispatchQueue.main.async { hud?.dismiss() }
|
|
|
- } completion: { _, _, _, error in
|
|
|
+ } completion: { account, _, afError, error in
|
|
|
DispatchQueue.main.async { hud?.dismiss() }
|
|
|
+ var sessionTaskFailedCode = 0
|
|
|
+ let directory = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)
|
|
|
+ if let error = NextcloudKit.shared.nkCommonInstance.getSessionErrorFromAFError(afError) {
|
|
|
+ sessionTaskFailedCode = error.code
|
|
|
+ }
|
|
|
+ switch error.errorCode {
|
|
|
+ case NKError.chunkNoEnoughMemory, NKError.chunkCreateFolder, NKError.chunkFilesNull, NKError.chunkFileNull:
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+ NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
+ NCContentPresenter().messageNotification("_error_files_upload_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error, afterDelay: 0.5)
|
|
|
+ case NKError.chunkFileUpload:
|
|
|
+ if let afError, (afError.isExplicitlyCancelledError || sessionTaskFailedCode == NCGlobal.shared.errorExplicitlyCancelled ) {
|
|
|
+ NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
+ }
|
|
|
+ case NKError.chunkMoveFile:
|
|
|
+ NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
+ NCContentPresenter().messageNotification("_chunk_move_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error, afterDelay: 0.5)
|
|
|
+ default: break
|
|
|
+ }
|
|
|
completion(error)
|
|
|
}
|
|
|
} else if metadata.session == NextcloudKit.shared.nkCommonInstance.sessionIdentifierUpload {
|
|
@@ -570,47 +589,13 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
|
|
|
} completion: { account, _, file, afError, error in
|
|
|
|
|
|
- var sessionTaskFailedCode = 0
|
|
|
self.uploadRequest.removeValue(forKey: fileNameLocalPath)
|
|
|
-
|
|
|
if error == .success {
|
|
|
NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
}
|
|
|
- if let error = NextcloudKit.shared.nkCommonInstance.getSessionErrorFromAFError(afError) {
|
|
|
- sessionTaskFailedCode = error.code
|
|
|
- }
|
|
|
-
|
|
|
- switch error.errorCode {
|
|
|
- case NKError.chunkNoEnoughMemory:
|
|
|
- NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- NCContentPresenter().messageNotification("_chunk_enough_memory_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
|
- case NKError.chunkCreateFolder:
|
|
|
- NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- NCContentPresenter().messageNotification("_chunk_create_folder_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
|
- case NKError.chunkFilesNull:
|
|
|
- NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- NCContentPresenter().messageNotification("_chunk_files_null_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
|
- case NKError.chunkFileNull:
|
|
|
- NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- NCContentPresenter().messageNotification("_chunk_file_null_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
|
- case NKError.chunkFileUpload:
|
|
|
- if let afError, (afError.isExplicitlyCancelledError || sessionTaskFailedCode == NCGlobal.shared.errorExplicitlyCancelled ) {
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- }
|
|
|
- case NKError.chunkMoveFile:
|
|
|
- NCManageDatabase.shared.deleteChunks(account: account, ocId: metadata.ocId, directory: directory)
|
|
|
- NCContentPresenter().messageNotification("_chunk_move_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: .error)
|
|
|
- default: break
|
|
|
- }
|
|
|
-
|
|
|
if withUploadComplete, let uploadTask {
|
|
|
self.uploadComplete(fileName: metadata.fileName, serverUrl: metadata.serverUrl, ocId: file?.ocId, etag: file?.etag, date: file?.date, size: file?.size ?? 0, description: metadata.ocId, task: uploadTask, error: error)
|
|
|
}
|
|
|
-
|
|
|
completion(account, file, afError, error)
|
|
|
}
|
|
|
}
|
|
@@ -702,11 +687,14 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(ocIdTemp))
|
|
|
}
|
|
|
|
|
|
- uploadLivePhoto(metadata: metadata)
|
|
|
-
|
|
|
NextcloudKit.shared.nkCommonInstance.writeLog("[SUCCESS] Upload complete " + serverUrl + "/" + fileName + ", result: success(\(size) bytes)")
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
|
|
|
|
|
|
+ let userInfo: [AnyHashable: Any] = ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error]
|
|
|
+ if metadata.isLivePhoto, NCGlobal.shared.isLivePhotoServerAvailable {
|
|
|
+ uploadLivePhoto(metadata: metadata, userInfo: userInfo)
|
|
|
+ } else {
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: userInfo)
|
|
|
+ }
|
|
|
} else {
|
|
|
|
|
|
if error.errorCode == NSURLErrorCancelled || error.errorCode == NCGlobal.shared.errorRequestExplicityCancelled {
|
|
@@ -803,28 +791,31 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
|
|
|
// MARK: - Live Photo
|
|
|
|
|
|
- func uploadLivePhoto(metadata: tableMetadata) {
|
|
|
+ func uploadLivePhoto(metadata: tableMetadata, userInfo aUserInfo: [AnyHashable: Any]) {
|
|
|
|
|
|
- guard NCGlobal.shared.isLivePhotoServerAvailable,
|
|
|
- metadata.isLivePhoto,
|
|
|
- let metadata1 = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND urlBase == %@ AND path == %@ AND fileName == %@ AND status == %d", metadata.account, metadata.urlBase, metadata.path, metadata.livePhotoFile, NCGlobal.shared.metadataStatusNormal)) else {
|
|
|
+ guard let metadata1 = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND urlBase == %@ AND path == %@ AND fileName == %@ AND status == %d", metadata.account, metadata.urlBase, metadata.path, metadata.livePhotoFile, NCGlobal.shared.metadataStatusNormal)) else {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
Task {
|
|
|
let serverUrlfileNamePath = metadata.urlBase + metadata.path + metadata.fileName
|
|
|
var livePhotoFile = metadata1.fileId
|
|
|
- var results = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath, livePhotoFile: livePhotoFile)
|
|
|
+ let results = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath, livePhotoFile: livePhotoFile)
|
|
|
if results.error == .success {
|
|
|
NCManageDatabase.shared.setMetadataLivePhotoByServer(account: metadata.account, ocId: metadata.ocId, livePhotoFile: livePhotoFile)
|
|
|
+ } else {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Uplod set LivePhoto with error \(results.error.errorCode)")
|
|
|
}
|
|
|
|
|
|
let serverUrlfileNamePath1 = metadata1.urlBase + metadata1.path + metadata1.fileName
|
|
|
livePhotoFile = metadata.fileId
|
|
|
- results = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath1, livePhotoFile: livePhotoFile)
|
|
|
- if results.error == .success {
|
|
|
+ let results1 = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath1, livePhotoFile: livePhotoFile)
|
|
|
+ if results1.error == .success {
|
|
|
NCManageDatabase.shared.setMetadataLivePhotoByServer(account: metadata1.account, ocId: metadata1.ocId, livePhotoFile: livePhotoFile)
|
|
|
+ } else {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Upload set LivePhoto with error \(results.error.errorCode)")
|
|
|
}
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: aUserInfo)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1496,12 +1487,10 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
if !metadata.permissions.isEmpty && permission == false {
|
|
|
return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_")
|
|
|
}
|
|
|
-
|
|
|
let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
|
|
|
let options = NKRequestOptions(customHeader: customHeader)
|
|
|
|
|
|
let result = await NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName, options: options)
|
|
|
-
|
|
|
if result.error == .success || result.error.errorCode == NCGlobal.shared.errorResourceNotFound {
|
|
|
|
|
|
do {
|
|
@@ -1511,8 +1500,8 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
NCManageDatabase.shared.deleteVideo(metadata: metadata)
|
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
-
|
|
|
- if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
|
|
|
+ // LIVE PHOTO SERVER
|
|
|
+ if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata), metadataLive.isFlaggedAsLivePhotoByServer {
|
|
|
do {
|
|
|
try FileManager.default.removeItem(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadataLive.ocId))
|
|
|
} catch { }
|
|
@@ -1526,7 +1515,6 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
NCManageDatabase.shared.deleteDirectoryAndSubDirectory(serverUrl: utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName), account: metadata.account)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return result.error
|
|
|
}
|
|
|
|
|
@@ -1640,53 +1628,36 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
if fileNameNew.isEmpty || fileNameNew == metadata.fileNameView {
|
|
|
return completion(NKError())
|
|
|
}
|
|
|
-
|
|
|
let fileNamePath = metadata.serverUrl + "/" + metadata.fileName
|
|
|
let fileNameToPath = metadata.serverUrl + "/" + fileNameNew
|
|
|
- let ocId = metadata.ocId
|
|
|
|
|
|
NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePath, serverUrlFileNameDestination: fileNameToPath, overwrite: false) { _, error in
|
|
|
-
|
|
|
if error == .success {
|
|
|
-
|
|
|
- NCManageDatabase.shared.renameMetadata(fileNameTo: fileNameNew, ocId: ocId)
|
|
|
-
|
|
|
if metadata.directory {
|
|
|
-
|
|
|
let serverUrl = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)
|
|
|
let serverUrlTo = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: fileNameNew)
|
|
|
if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
|
|
|
-
|
|
|
NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: serverUrlTo, etag: "", ocId: nil, fileId: nil, encrypted: directory.e2eEncrypted, richWorkspace: nil, account: metadata.account)
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
-
|
|
|
- let ext = (metadata.fileName as NSString).pathExtension
|
|
|
- let extNew = (fileNameNew as NSString).pathExtension
|
|
|
-
|
|
|
- if ext != extNew {
|
|
|
-
|
|
|
- self.utilityFileSystem.removeFile(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId))
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSourceNetworkForced)
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- NCManageDatabase.shared.setLocalFile(ocId: ocId, fileName: fileNameNew, etag: nil)
|
|
|
- // Move file system
|
|
|
- let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId) + "/" + metadata.fileName
|
|
|
- let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId) + "/" + fileNameNew
|
|
|
+ do {
|
|
|
+ try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId))
|
|
|
+ } catch { }
|
|
|
+ NCManageDatabase.shared.deleteVideo(metadata: metadata)
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+ NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+ // LIVE PHOTO SERVER
|
|
|
+ if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata), metadataLive.isFlaggedAsLivePhotoByServer {
|
|
|
do {
|
|
|
- try FileManager.default.moveItem(atPath: atPath, toPath: toPath)
|
|
|
+ try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadataLive.ocId))
|
|
|
} catch { }
|
|
|
+ NCManageDatabase.shared.deleteVideo(metadata: metadataLive)
|
|
|
+ NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
|
|
|
+ NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account, "indexPath": indexPath])
|
|
|
- }
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account, "indexPath": indexPath])
|
|
|
}
|
|
|
-
|
|
|
completion(error)
|
|
|
}
|
|
|
}
|
|
@@ -1712,7 +1683,6 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
if !metadata.permissions.isEmpty && !permission {
|
|
|
return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_")
|
|
|
}
|
|
|
-
|
|
|
let serverUrlFileNameSource = metadata.serverUrl + "/" + metadata.fileName
|
|
|
let serverUrlFileNameDestination = serverUrlTo + "/" + metadata.fileName
|
|
|
|
|
@@ -1721,13 +1691,23 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
if metadata.directory {
|
|
|
NCManageDatabase.shared.deleteDirectoryAndSubDirectory(serverUrl: utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName), account: result.account)
|
|
|
} else {
|
|
|
+ do {
|
|
|
+ try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId))
|
|
|
+ } catch { }
|
|
|
+ NCManageDatabase.shared.deleteVideo(metadata: metadata)
|
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
- if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
|
|
|
+ NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
|
+ // LIVE PHOTO SERVER
|
|
|
+ if let metadataLive = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata), metadataLive.isFlaggedAsLivePhotoByServer {
|
|
|
+ do {
|
|
|
+ try FileManager.default.removeItem(atPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadataLive.ocId))
|
|
|
+ } catch { }
|
|
|
+ NCManageDatabase.shared.deleteVideo(metadata: metadataLive)
|
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
|
|
|
+ NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadataLive.ocId))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return result.error
|
|
|
}
|
|
|
|
|
@@ -1752,7 +1732,6 @@ class NCNetworking: NSObject, NKCommonDelegate {
|
|
|
if !metadata.permissions.isEmpty && !permission {
|
|
|
return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_")
|
|
|
}
|
|
|
-
|
|
|
let serverUrlFileNameSource = metadata.serverUrl + "/" + metadata.fileName
|
|
|
let serverUrlFileNameDestination = serverUrlTo + "/" + metadata.fileName
|
|
|
|