|
@@ -22,6 +22,7 @@
|
|
|
//
|
|
|
|
|
|
import Foundation
|
|
|
+import NCCommunication
|
|
|
|
|
|
@objc class NCNetworkingNotificationCenter: NSObject, UIDocumentInteractionControllerDelegate {
|
|
|
@objc public static let shared: NCNetworkingNotificationCenter = {
|
|
@@ -102,7 +103,7 @@ import Foundation
|
|
|
|
|
|
case NCGlobal.shared.selectorLoadCopy:
|
|
|
|
|
|
- NCCollectionCommon.shared.copyPasteboard()
|
|
|
+ copyPasteboard()
|
|
|
|
|
|
case NCGlobal.shared.selectorLoadOffline:
|
|
|
|
|
@@ -160,6 +161,24 @@ import Foundation
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //MARK: - Upload
|
|
|
+
|
|
|
+ @objc func uploadedFile(_ notification: NSNotification) {
|
|
|
+
|
|
|
+ if let userInfo = notification.userInfo as NSDictionary? {
|
|
|
+ if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
|
|
|
+
|
|
|
+ if metadata.account == appDelegate.account {
|
|
|
+ if errorCode != 0 {
|
|
|
+ if errorCode != -999 && errorCode != 401 && errorDescription != "" {
|
|
|
+ NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: -
|
|
|
|
|
|
func openShare(ViewController: UIViewController, metadata: tableMetadata, indexPage: Int) {
|
|
@@ -280,22 +299,74 @@ import Foundation
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- //MARK: - Upload
|
|
|
-
|
|
|
- @objc func uploadedFile(_ notification: NSNotification) {
|
|
|
|
|
|
- if let userInfo = notification.userInfo as NSDictionary? {
|
|
|
- if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
|
|
|
+ func copyPasteboard() {
|
|
|
+
|
|
|
+ var metadatas: [tableMetadata] = []
|
|
|
+ var items = [[String : Any]]()
|
|
|
+
|
|
|
+ for ocId in appDelegate.pasteboardOcIds {
|
|
|
+ if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
|
|
|
+ metadatas.append(metadata)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for metadata in metadatas {
|
|
|
+
|
|
|
+ if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
|
|
|
+ do {
|
|
|
+ // Get Data
|
|
|
+ let data = try Data.init(contentsOf: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
|
|
|
+ // Pasteboard item
|
|
|
+ if let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (metadata.fileNameView as NSString).pathExtension as CFString, nil) {
|
|
|
+ let fileUTI = unmanagedFileUTI.takeRetainedValue() as String
|
|
|
+ items.append([fileUTI:data])
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ print("error")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UIPasteboard.general.setItems(items, options: [:])
|
|
|
+ }
|
|
|
+
|
|
|
+ func pastePasteboard(serverUrl: String) {
|
|
|
|
|
|
- if metadata.account == appDelegate.account {
|
|
|
- if errorCode != 0 {
|
|
|
- if errorCode != -999 && errorCode != 401 && errorDescription != "" {
|
|
|
- NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
+ for (index, items) in UIPasteboard.general.items.enumerated() {
|
|
|
+ for item in items {
|
|
|
+ let pasteboardType = item.key
|
|
|
+ if let data = UIPasteboard.general.data(forPasteboardType: pasteboardType, inItemSet: IndexSet([index]))?.first {
|
|
|
+ let results = NCCommunicationCommon.shared.getDescriptionFile(inUTI: pasteboardType as CFString)
|
|
|
+ if results.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue {
|
|
|
+ uploadPasteFile(fileName: results.resultFilename, ext: results.resultExtension, contentType: pasteboardType, serverUrl: serverUrl, data: data)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private func uploadPasteFile(fileName: String, ext: String, contentType: String, serverUrl: String, data: Data) {
|
|
|
+
|
|
|
+ do {
|
|
|
+ let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
|
|
|
+ let ocId = UUID().uuidString
|
|
|
+ let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
|
|
|
+
|
|
|
+ try data.write(to: URL(fileURLWithPath: filePath))
|
|
|
+
|
|
|
+ let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: contentType, livePhoto: false)
|
|
|
+
|
|
|
+ metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
|
|
|
+ metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
|
|
|
+ metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
|
|
|
+ metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
|
|
|
+
|
|
|
+ NCManageDatabase.shared.addMetadata(metadataForUpload)
|
|
|
+
|
|
|
+ } catch { }
|
|
|
+ }
|
|
|
}
|
|
|
|