|
@@ -22,12 +22,13 @@
|
|
|
//
|
|
|
|
|
|
import SwiftUI
|
|
|
+import NextcloudKit
|
|
|
|
|
|
class NCHostingUploadAssetsView: NSObject {
|
|
|
|
|
|
@objc func makeShipDetailsUI(assets: [PHAsset], cryptated: Bool, session: String, userBaseUrl: NCUserBaseUrl, serverUrl: String) -> UIViewController {
|
|
|
|
|
|
- let uploadAssets = NCUploadAssets(assets: assets, cryptated: cryptated, session: session, userBaseUrl: userBaseUrl, serverUrl: serverUrl)
|
|
|
+ let uploadAssets = NCUploadAssets(assets: assets, session: session, userBaseUrl: userBaseUrl, serverUrl: serverUrl)
|
|
|
let details = UploadAssetsView(uploadAssets: uploadAssets)
|
|
|
let vc = UIHostingController(rootView: details)
|
|
|
return vc
|
|
@@ -37,7 +38,6 @@ class NCHostingUploadAssetsView: NSObject {
|
|
|
class NCUploadAssets: ObservableObject {
|
|
|
|
|
|
internal var assets: [PHAsset]
|
|
|
- internal var cryptated: Bool
|
|
|
internal var session: String
|
|
|
internal var userBaseUrl: NCUserBaseUrl
|
|
|
|
|
@@ -45,10 +45,9 @@ class NCUploadAssets: ObservableObject {
|
|
|
@Published var isMaintainOriginalFilename: Bool = CCUtility.getOriginalFileName(NCGlobal.shared.keyFileNameOriginal)
|
|
|
@Published var isAddFilenametype: Bool = CCUtility.getFileNameType(NCGlobal.shared.keyFileNameType)
|
|
|
|
|
|
- init(assets: [PHAsset], cryptated: Bool, session: String, userBaseUrl: NCUserBaseUrl, serverUrl: String) {
|
|
|
+ init(assets: [PHAsset], session: String, userBaseUrl: NCUserBaseUrl, serverUrl: String) {
|
|
|
|
|
|
self.assets = assets
|
|
|
- self.cryptated = cryptated
|
|
|
self.session = session
|
|
|
self.userBaseUrl = userBaseUrl
|
|
|
self.serverUrl = serverUrl
|
|
@@ -114,6 +113,70 @@ class NCUploadAssets: ObservableObject {
|
|
|
|
|
|
func save() {
|
|
|
|
|
|
+ // DispatchQueue.global().async {
|
|
|
+
|
|
|
+ var metadatasNOConflict: [tableMetadata] = []
|
|
|
+ var metadatasUploadInConflict: [tableMetadata] = []
|
|
|
+ let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: userBaseUrl.urlBase, userId: userBaseUrl.userId, account: userBaseUrl.account)
|
|
|
+
|
|
|
+ for asset in self.assets {
|
|
|
+
|
|
|
+ var serverUrl = self.serverUrl
|
|
|
+ var livePhoto: Bool = false
|
|
|
+ let creationDate = asset.creationDate ?? Date()
|
|
|
+ let fileName = CCUtility.createFileName(asset.value(forKey: "filename") as? String,
|
|
|
+ fileDate: creationDate,
|
|
|
+ fileType: asset.mediaType,
|
|
|
+ keyFileName: NCGlobal.shared.keyFileNameMask,
|
|
|
+ keyFileNameType: NCGlobal.shared.keyFileNameType,
|
|
|
+ keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
|
|
|
+ forcedNewFileName: false)!
|
|
|
+
|
|
|
+ if asset.mediaSubtypes.contains(.photoLive) && CCUtility.getLivePhoto() {
|
|
|
+ livePhoto = true
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check if is in upload
|
|
|
+ let isRecordInSessions = NCManageDatabase.shared.getAdvancedMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", userBaseUrl.account, serverUrl, fileName), sorted: "fileName", ascending: false)
|
|
|
+ if !isRecordInSessions.isEmpty { continue }
|
|
|
+
|
|
|
+ let metadataForUpload = NCManageDatabase.shared.createMetadata(account: userBaseUrl.account, user: userBaseUrl.user, userId: userBaseUrl.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: userBaseUrl.urlBase, url: "", contentType: "", isLivePhoto: livePhoto)
|
|
|
+
|
|
|
+ metadataForUpload.assetLocalIdentifier = asset.localIdentifier
|
|
|
+ metadataForUpload.session = self.session
|
|
|
+ metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
|
|
|
+ metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
|
|
|
+
|
|
|
+ if let result = NCManageDatabase.shared.getMetadataConflict(account: userBaseUrl.account, serverUrl: serverUrl, fileNameView: fileName) {
|
|
|
+ metadataForUpload.fileName = result.fileName
|
|
|
+ metadatasUploadInConflict.append(metadataForUpload)
|
|
|
+ } else {
|
|
|
+ metadatasNOConflict.append(metadataForUpload)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Verify if file(s) exists
|
|
|
+ if !metadatasUploadInConflict.isEmpty {
|
|
|
+
|
|
|
+ /*
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
|
|
|
+ if let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
|
|
|
+
|
|
|
+ conflict.serverUrl = self.serverUrl
|
|
|
+ conflict.metadatasNOConflict = metadatasNOConflict
|
|
|
+ conflict.metadatasUploadInConflict = metadatasUploadInConflict
|
|
|
+ conflict.delegate = self.appDelegate
|
|
|
+
|
|
|
+ self.appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ } else {
|
|
|
+ NCNetworkingProcessUpload.shared.createProcessUploads(metadatas: metadatasNOConflict, completion: { _ in })
|
|
|
+ }
|
|
|
+
|
|
|
+ // DispatchQueue.main.async {self.dismiss(animated: true, completion: nil) }
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -224,7 +287,7 @@ struct UploadAssetsView: View {
|
|
|
struct UploadAssetsView_Previews: PreviewProvider {
|
|
|
static var previews: some View {
|
|
|
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
|
|
|
- let uploadAssets = NCUploadAssets(assets: [], cryptated: false, session: "", userBaseUrl: appDelegate, serverUrl: "/")
|
|
|
+ let uploadAssets = NCUploadAssets(assets: [], session: "", userBaseUrl: appDelegate, serverUrl: "/")
|
|
|
UploadAssetsView(uploadAssets: uploadAssets)
|
|
|
}
|
|
|
}
|