|
@@ -50,9 +50,10 @@ class NCAutoUpload: NSObject {
|
|
|
completion(0)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- self.uploadAssetsNewAndFull(viewController: viewController, selector: NCGlobal.shared.selectorUploadAutoUpload, log: "Init Auto Upload") { items in
|
|
|
- completion(items)
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ self.uploadAssetsNewAndFull(viewController: viewController, selector: NCGlobal.shared.selectorUploadAutoUpload, log: "Init Auto Upload") { items in
|
|
|
+ completion(items)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -64,8 +65,10 @@ class NCAutoUpload: NSObject {
|
|
|
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_create_full_upload_")
|
|
|
NCContentPresenter.shared.showWarning(error: error, priority: .max)
|
|
|
NCActivityIndicator.shared.start()
|
|
|
- self.uploadAssetsNewAndFull(viewController: viewController, selector: NCGlobal.shared.selectorUploadAutoUploadAll, log: log) { _ in
|
|
|
- NCActivityIndicator.shared.stop()
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ self.uploadAssetsNewAndFull(viewController: viewController, selector: NCGlobal.shared.selectorUploadAutoUploadAll, log: log) { _ in
|
|
|
+ NCActivityIndicator.shared.stop()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -76,105 +79,102 @@ class NCAutoUpload: NSObject {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- DispatchQueue.global().async {
|
|
|
-
|
|
|
- let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: account.urlBase, account: account.account)
|
|
|
- var metadatas: [tableMetadata] = []
|
|
|
+ let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: account.urlBase, account: account.account)
|
|
|
+ var metadatas: [tableMetadata] = []
|
|
|
|
|
|
- self.getCameraRollAssets(viewController: viewController, account: account, selector: selector, alignPhotoLibrary: false) { assets in
|
|
|
- guard let assets = assets, !assets.isEmpty else {
|
|
|
- NKCommon.shared.writeLog("[INFO] Automatic upload, no new assets found [" + log + "]")
|
|
|
- completion(0)
|
|
|
- return
|
|
|
- }
|
|
|
- NKCommon.shared.writeLog("[INFO] Automatic upload, new \(assets.count) assets found [" + log + "]")
|
|
|
- // Create the folder for auto upload & if request the subfolders
|
|
|
- if !NCNetworking.shared.createFolder(assets: assets, selector: selector, useSubFolder: account.autoUploadCreateSubfolder, account: account.account, urlBase: account.urlBase) {
|
|
|
- if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
- let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_error_createsubfolders_upload_")
|
|
|
- NCContentPresenter.shared.showError(error: error, priority: .max)
|
|
|
- }
|
|
|
- return completion(0)
|
|
|
+ self.getCameraRollAssets(viewController: viewController, account: account, selector: selector, alignPhotoLibrary: false) { assets in
|
|
|
+ guard let assets = assets, !assets.isEmpty else {
|
|
|
+ NKCommon.shared.writeLog("[INFO] Automatic upload, no new assets found [" + log + "]")
|
|
|
+ completion(0)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ NKCommon.shared.writeLog("[INFO] Automatic upload, new \(assets.count) assets found [" + log + "]")
|
|
|
+ // Create the folder for auto upload & if request the subfolders
|
|
|
+ if !NCNetworking.shared.createFolder(assets: assets, selector: selector, useSubFolder: account.autoUploadCreateSubfolder, account: account.account, urlBase: account.urlBase) {
|
|
|
+ if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
+ let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_error_createsubfolders_upload_")
|
|
|
+ NCContentPresenter.shared.showError(error: error, priority: .max)
|
|
|
}
|
|
|
+ return completion(0)
|
|
|
+ }
|
|
|
|
|
|
- self.endForAssetToUpload = false
|
|
|
+ self.endForAssetToUpload = false
|
|
|
|
|
|
- for asset in assets {
|
|
|
+ for asset in assets {
|
|
|
|
|
|
- var livePhoto = false
|
|
|
- var session: String = ""
|
|
|
- guard let assetDate = asset.creationDate else { continue }
|
|
|
- let assetMediaType = asset.mediaType
|
|
|
- var serverUrl: String = ""
|
|
|
- let fileName = CCUtility.createFileName(asset.value(forKey: "filename") as? String, fileDate: assetDate, fileType: assetMediaType, keyFileName: NCGlobal.shared.keyFileNameAutoUploadMask, keyFileNameType: NCGlobal.shared.keyFileNameAutoUploadType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginalAutoUpload, forcedNewFileName: false)!
|
|
|
- let formatter = DateFormatter()
|
|
|
- formatter.dateFormat = "yyyy"
|
|
|
- let yearString = formatter.string(from: assetDate)
|
|
|
- formatter.dateFormat = "MM"
|
|
|
- let monthString = formatter.string(from: assetDate)
|
|
|
+ var livePhoto = false
|
|
|
+ var session: String = ""
|
|
|
+ guard let assetDate = asset.creationDate else { continue }
|
|
|
+ let assetMediaType = asset.mediaType
|
|
|
+ var serverUrl: String = ""
|
|
|
+ let fileName = CCUtility.createFileName(asset.value(forKey: "filename") as? String, fileDate: assetDate, fileType: assetMediaType, keyFileName: NCGlobal.shared.keyFileNameAutoUploadMask, keyFileNameType: NCGlobal.shared.keyFileNameAutoUploadType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginalAutoUpload, forcedNewFileName: false)!
|
|
|
+ let formatter = DateFormatter()
|
|
|
+ formatter.dateFormat = "yyyy"
|
|
|
+ let yearString = formatter.string(from: assetDate)
|
|
|
+ formatter.dateFormat = "MM"
|
|
|
+ let monthString = formatter.string(from: assetDate)
|
|
|
|
|
|
- if asset.mediaSubtypes.contains(.photoLive) && CCUtility.getLivePhoto() {
|
|
|
- livePhoto = true
|
|
|
- }
|
|
|
+ if asset.mediaSubtypes.contains(.photoLive) && CCUtility.getLivePhoto() {
|
|
|
+ livePhoto = true
|
|
|
+ }
|
|
|
|
|
|
- if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
- session = NKCommon.shared.sessionIdentifierUpload
|
|
|
- } else {
|
|
|
- if assetMediaType == PHAssetMediaType.image && account.autoUploadWWAnPhoto == false {
|
|
|
- session = NCNetworking.shared.sessionIdentifierBackground
|
|
|
- } else if assetMediaType == PHAssetMediaType.video && account.autoUploadWWAnVideo == false {
|
|
|
- session = NCNetworking.shared.sessionIdentifierBackground
|
|
|
- } else if assetMediaType == PHAssetMediaType.image && account.autoUploadWWAnPhoto {
|
|
|
- session = NCNetworking.shared.sessionIdentifierBackgroundWWan
|
|
|
- } else if assetMediaType == PHAssetMediaType.video && account.autoUploadWWAnVideo {
|
|
|
- session = NCNetworking.shared.sessionIdentifierBackgroundWWan
|
|
|
- } else { session = NCNetworking.shared.sessionIdentifierBackground }
|
|
|
- }
|
|
|
+ if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
+ session = NKCommon.shared.sessionIdentifierUpload
|
|
|
+ } else {
|
|
|
+ if assetMediaType == PHAssetMediaType.image && account.autoUploadWWAnPhoto == false {
|
|
|
+ session = NCNetworking.shared.sessionIdentifierBackground
|
|
|
+ } else if assetMediaType == PHAssetMediaType.video && account.autoUploadWWAnVideo == false {
|
|
|
+ session = NCNetworking.shared.sessionIdentifierBackground
|
|
|
+ } else if assetMediaType == PHAssetMediaType.image && account.autoUploadWWAnPhoto {
|
|
|
+ session = NCNetworking.shared.sessionIdentifierBackgroundWWan
|
|
|
+ } else if assetMediaType == PHAssetMediaType.video && account.autoUploadWWAnVideo {
|
|
|
+ session = NCNetworking.shared.sessionIdentifierBackgroundWWan
|
|
|
+ } else { session = NCNetworking.shared.sessionIdentifierBackground }
|
|
|
+ }
|
|
|
|
|
|
- if account.autoUploadCreateSubfolder {
|
|
|
- serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
|
|
|
- } else {
|
|
|
- serverUrl = autoUploadPath
|
|
|
- }
|
|
|
+ if account.autoUploadCreateSubfolder {
|
|
|
+ serverUrl = autoUploadPath + "/" + yearString + "/" + monthString
|
|
|
+ } else {
|
|
|
+ serverUrl = autoUploadPath
|
|
|
+ }
|
|
|
|
|
|
- // MOST COMPATIBLE SEARCH --> HEIC --> JPG
|
|
|
- var fileNameSearchMetadata = fileName
|
|
|
- let ext = (fileNameSearchMetadata as NSString).pathExtension.uppercased()
|
|
|
- if ext == "HEIC" && CCUtility.getFormatCompatibility() {
|
|
|
- fileNameSearchMetadata = (fileNameSearchMetadata as NSString).deletingPathExtension + ".jpg"
|
|
|
+ // MOST COMPATIBLE SEARCH --> HEIC --> JPG
|
|
|
+ var fileNameSearchMetadata = fileName
|
|
|
+ let ext = (fileNameSearchMetadata as NSString).pathExtension.uppercased()
|
|
|
+ if ext == "HEIC" && CCUtility.getFormatCompatibility() {
|
|
|
+ fileNameSearchMetadata = (fileNameSearchMetadata as NSString).deletingPathExtension + ".jpg"
|
|
|
+ }
|
|
|
+ if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView == %@", account.account, serverUrl, fileNameSearchMetadata)) != nil {
|
|
|
+ if selector == NCGlobal.shared.selectorUploadAutoUpload {
|
|
|
+ NCManageDatabase.shared.addPhotoLibrary([asset], account: account.account)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let metadata = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", isLivePhoto: livePhoto)
|
|
|
+ metadata.assetLocalIdentifier = asset.localIdentifier
|
|
|
+ metadata.session = session
|
|
|
+ metadata.sessionSelector = selector
|
|
|
+ metadata.status = NCGlobal.shared.metadataStatusWaitUpload
|
|
|
+ if assetMediaType == PHAssetMediaType.video {
|
|
|
+ metadata.classFile = NKCommon.typeClassFile.video.rawValue
|
|
|
+ } else if assetMediaType == PHAssetMediaType.image {
|
|
|
+ metadata.classFile = NKCommon.typeClassFile.image.rawValue
|
|
|
}
|
|
|
- if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView == %@", account.account, serverUrl, fileNameSearchMetadata)) != nil {
|
|
|
- if selector == NCGlobal.shared.selectorUploadAutoUpload {
|
|
|
- NCManageDatabase.shared.addPhotoLibrary([asset], account: account.account)
|
|
|
- }
|
|
|
- } else {
|
|
|
- let metadata = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", isLivePhoto: livePhoto)
|
|
|
- metadata.assetLocalIdentifier = asset.localIdentifier
|
|
|
- metadata.session = session
|
|
|
- metadata.sessionSelector = selector
|
|
|
- metadata.status = NCGlobal.shared.metadataStatusWaitUpload
|
|
|
- if assetMediaType == PHAssetMediaType.video {
|
|
|
- metadata.classFile = NKCommon.typeClassFile.video.rawValue
|
|
|
- } else if assetMediaType == PHAssetMediaType.image {
|
|
|
- metadata.classFile = NKCommon.typeClassFile.image.rawValue
|
|
|
- }
|
|
|
- if selector == NCGlobal.shared.selectorUploadAutoUpload {
|
|
|
- NKCommon.shared.writeLog("[INFO] Automatic upload added \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier)")
|
|
|
- NCManageDatabase.shared.addPhotoLibrary([asset], account: account.account)
|
|
|
- }
|
|
|
- metadatas.append(metadata)
|
|
|
+ if selector == NCGlobal.shared.selectorUploadAutoUpload {
|
|
|
+ NKCommon.shared.writeLog("[INFO] Automatic upload added \(metadata.fileNameView) with Identifier \(metadata.assetLocalIdentifier)")
|
|
|
+ NCManageDatabase.shared.addPhotoLibrary([asset], account: account.account)
|
|
|
}
|
|
|
+ metadatas.append(metadata)
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- self.endForAssetToUpload = true
|
|
|
- if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
- self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
|
|
|
+ self.endForAssetToUpload = true
|
|
|
+ if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
|
|
|
+ self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
|
|
|
+ } else {
|
|
|
+ if self.applicationState == .background {
|
|
|
+ self.createBackgroundProcessAutoUpload(metadatas: metadatas, completion: completion)
|
|
|
} else {
|
|
|
- if self.applicationState == .background {
|
|
|
- self.createBackgroundProcessAutoUpload(metadatas: metadatas, completion: completion)
|
|
|
- } else {
|
|
|
- self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
|
|
|
- }
|
|
|
+ self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
|
|
|
}
|
|
|
}
|
|
|
}
|