|
@@ -37,7 +37,6 @@ import NCCommunication
|
|
|
private let copyMoveQueue = Queuer(name: "copyMoveQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
|
|
|
private let synchronizationQueue = Queuer(name: "synchronizationQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
|
|
|
private let downloadThumbnailQueue = Queuer(name: "downloadThumbnailQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
|
|
|
- private let readFileForMediaQueue = Queuer(name: "readFileForMediaQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
|
|
|
|
|
|
private var timerReadFileForMediaQueue: Timer?
|
|
|
|
|
@@ -47,7 +46,6 @@ import NCCommunication
|
|
|
copyMoveCancelAll()
|
|
|
synchronizationCancelAll()
|
|
|
downloadThumbnailCancelAll()
|
|
|
- readFileForMediaCancelAll()
|
|
|
}
|
|
|
|
|
|
// Download file
|
|
@@ -139,39 +137,6 @@ import NCCommunication
|
|
|
@objc func downloadThumbnailCancelAll() {
|
|
|
downloadThumbnailQueue.cancelAll()
|
|
|
}
|
|
|
-
|
|
|
- // Get file information
|
|
|
-
|
|
|
- @objc func readFileForMedia(metadata: tableMetadata) {
|
|
|
- for operation in readFileForMediaQueue.operations as! [NCOperationReadFileForMediaQueue] {
|
|
|
- if operation.metadata.ocId == metadata.ocId {
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- readFileForMediaQueue.addOperation(NCOperationReadFileForMediaQueue.init(metadata: metadata))
|
|
|
- }
|
|
|
-
|
|
|
- func cancelReadFileForMedia(metadata: tableMetadata) {
|
|
|
- for operation in readFileForMediaQueue.operations as! [NCOperationReadFileForMediaQueue] {
|
|
|
- if operation.metadata.ocId == metadata.ocId {
|
|
|
- operation.cancel()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @objc func readFileForMediaCancelAll() {
|
|
|
- readFileForMediaQueue.cancelAll()
|
|
|
- }
|
|
|
-
|
|
|
- @objc func notificationReloadDataSourceMedia() {
|
|
|
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadMediaDataSource)
|
|
|
- }
|
|
|
-
|
|
|
- func reloadDataSourceMedia() {
|
|
|
- if !(timerReadFileForMediaQueue?.isValid ?? false) {
|
|
|
- timerReadFileForMediaQueue = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(notificationReloadDataSourceMedia), userInfo: nil, repeats: false)
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//MARK: -
|
|
@@ -411,65 +376,3 @@ class NCOperationDownloadThumbnail: ConcurrentOperation {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-//MARK: -
|
|
|
-
|
|
|
-class NCOperationReadFileForMediaQueue: ConcurrentOperation {
|
|
|
-
|
|
|
- var metadata: tableMetadata
|
|
|
-
|
|
|
- init(metadata: tableMetadata) {
|
|
|
- self.metadata = tableMetadata.init(value: metadata)
|
|
|
- }
|
|
|
-
|
|
|
- override func start() {
|
|
|
-
|
|
|
- if isCancelled {
|
|
|
- self.finish()
|
|
|
- } else {
|
|
|
- let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
|
|
|
- let requestBody =
|
|
|
- """
|
|
|
- <?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
|
- <d:propfind xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">
|
|
|
- <d:prop>
|
|
|
- <has-preview xmlns=\"http://nextcloud.org/ns\"/>
|
|
|
- <creation_time xmlns=\"http://nextcloud.org/ns\"/>
|
|
|
- <upload_time xmlns=\"http://nextcloud.org/ns\"/>
|
|
|
- </d:prop>
|
|
|
- </d:propfind>
|
|
|
- """
|
|
|
-
|
|
|
- NCCommunication.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", requestBody: requestBody.data(using: .utf8)) { (account, files, responseData, errorCode, errorDescription) in
|
|
|
- if errorCode == 0 && files.count > 0 {
|
|
|
- let file = files[0]
|
|
|
- let metadata = tableMetadata.init(value: self.metadata)
|
|
|
- var modify = false
|
|
|
- if metadata.hasPreview != file.hasPreview {
|
|
|
- metadata.hasPreview = file.hasPreview
|
|
|
- modify = true
|
|
|
- }
|
|
|
- if file.creationDate != nil && metadata.creationDate != file.creationDate {
|
|
|
- metadata.creationDate = file.creationDate!
|
|
|
- modify = true
|
|
|
- }
|
|
|
- if file.uploadDate != nil && metadata.uploadDate != file.uploadDate {
|
|
|
- metadata.uploadDate = file.uploadDate!
|
|
|
- modify = true
|
|
|
- }
|
|
|
- if modify {
|
|
|
- NCManageDatabase.sharedInstance.addMetadata(metadata)
|
|
|
- NCOperationQueue.shared.reloadDataSourceMedia()
|
|
|
- }
|
|
|
- } else if errorCode == 404 {
|
|
|
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", self.metadata.ocId))
|
|
|
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_mediaFileNotFound, userInfo: ["metadata": self.metadata])
|
|
|
- }
|
|
|
- self.finish()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|