1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import FileProvider
- extension FileProviderExtension {
- override func fetchThumbnails(for itemIdentifiers: [NSFileProviderItemIdentifier], requestedSize size: CGSize, perThumbnailCompletionHandler: @escaping (NSFileProviderItemIdentifier, Data?, Error?) -> Void, completionHandler: @escaping (Error?) -> Void) -> Progress {
-
- let progress = Progress(totalUnitCount: Int64(itemIdentifiers.count))
- var counterProgress: Int64 = 0
-
-
- if providerData.setupActiveAccount() == false {
- completionHandler(NSFileProviderError(.notAuthenticated))
- return Progress(totalUnitCount:0)
- }
-
- for itemIdentifier in itemIdentifiers {
-
- let metadata = providerData.getTableMetadataFromItemIdentifier(itemIdentifier)
- if metadata != nil {
-
- if (metadata!.typeFile == k_metadataTypeFile_image || metadata!.typeFile == k_metadataTypeFile_video) {
-
- let width = NCUtility.sharedInstance.getScreenWidthForPreview()
- let height = NCUtility.sharedInstance.getScreenHeightForPreview()
-
- OCNetworking.sharedManager().downloadPreview(withAccount: providerData.account, metadata: metadata, withWidth: width, andHeight: height, completion: { (account, preview, message, errorCode) in
-
- if errorCode == 0 && account == self.providerData.account {
- do {
- let url = URL.init(fileURLWithPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata!.fileID, fileNameView: metadata!.fileNameView))
- let data = try Data.init(contentsOf: url)
- perThumbnailCompletionHandler(itemIdentifier, data, nil)
- } catch let error {
- print("error: \(error)")
- perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.noSuchItem))
- }
- } else {
- perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.serverUnreachable))
- }
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- })
-
- } else {
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- }
- } else {
-
- counterProgress += 1
- if (counterProgress == progress.totalUnitCount) {
- completionHandler(nil)
- }
- }
- }
-
- return progress
- }
- }
|