浏览代码

Improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 年之前
父节点
当前提交
6f8d795b9e
共有 1 个文件被更改,包括 44 次插入0 次删除
  1. 44 0
      iOSClient/Main/Create cloud/NCUploadScanDocument.swift

+ 44 - 0
iOSClient/Main/Create cloud/NCUploadScanDocument.swift

@@ -57,6 +57,50 @@ class NCUploadScanDocument: ObservableObject {
         createPDF(quality: CCUtility.getQualityScanDocument())
     }
 
+    func save(fileName: String) {
+
+        guard fileName.isEmpty else { return }
+
+        let ext = (fileName as NSString).pathExtension.uppercased()
+        var fileNameSave = ""
+
+        if ext.isEmpty {
+            fileNameSave = fileName + ".pdf"
+        } else {
+            fileNameSave = (fileName as NSString).deletingPathExtension + ".pdf"
+        }
+
+        // Create metadata for upload
+        let metadataForUpload = NCManageDatabase.shared.createMetadata(account: userBaseUrl.account,
+                                                                       user: userBaseUrl.user,
+                                                                       userId: userBaseUrl.userId,
+                                                                       fileName: fileNameSave,
+                                                                       fileNameView: fileNameSave,
+                                                                       ocId: UUID().uuidString,
+                                                                       serverUrl: serverUrl,
+                                                                       urlBase: userBaseUrl.urlBase,
+                                                                       url: "",
+                                                                       contentType: "")
+
+        metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
+        metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
+        metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
+
+        if NCManageDatabase.shared.getMetadataConflict(account: userBaseUrl.account, serverUrl: serverUrl, fileNameView: fileNameSave) != nil {
+
+            guard let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return }
+
+            conflict.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "")
+            conflict.serverUrl = serverUrl
+            conflict.metadatasUploadInConflict = [metadataForUpload]
+            conflict.delegate = self
+
+            // self.present(conflict, animated: true, completion: nil)
+        } else {
+            // self.dismissAndUpload(metadataForUpload)
+        }
+    }
+
     func createPDF(password: String = "", textRecognition: Bool = false, quality: Double) {
 
         guard !images.isEmpty else { return }