diff --git a/File Provider Extension/FileProviderEnumerator.swift b/File Provider Extension/FileProviderEnumerator.swift index 5af23b3648..f9cdd88cde 100644 --- a/File Provider Extension/FileProviderEnumerator.swift +++ b/File Provider Extension/FileProviderEnumerator.swift @@ -33,9 +33,9 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { let database = NCManageDatabase.shared var anchor: UInt64 = 0 // X-NC-PAGINATE - var recordsPerPage: Int = 5 + var recordsPerPage: Int = 100 var paginateToken: String? - var paginatedTotal: Int? + var paginatedTotal: Int = 0 init(enumeratedItemIdentifier: NSFileProviderItemIdentifier) { self.enumeratedItemIdentifier = enumeratedItemIdentifier @@ -162,25 +162,30 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { } func fetchItemsForPage(serverUrl: String, pageNumber: Int, completion: @escaping (_ metadatas: [tableMetadata]?, _ isPaginated: Bool) -> Void) { + var useFirstAsMetadataFolder: Bool = false var isPaginated: Bool = false var paginateCount = recordsPerPage if pageNumber == 0 { paginateCount += 1 } - var useFirstAsMetadataFolder: Bool = false - let offset = pageNumber * recordsPerPage + var offset = pageNumber * recordsPerPage + if pageNumber > 0 { + offset += 1 + } let options = NKRequestOptions(paginate: true, paginateToken: self.paginateToken, paginateOffset: offset, paginateCount: paginateCount, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) + print("PAGINATE OFFSET: \(offset) COUNT: \(paginateCount) TOTAL: \(self.paginatedTotal)") + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles, account: fileProviderData.shared.session.account, options: options) { _, files, responseData, error in if let headers = responseData?.response?.allHeaderFields as? [String: String] { let normalizedHeaders = Dictionary(uniqueKeysWithValues: headers.map { ($0.key.lowercased(), $0.value) }) isPaginated = Bool(normalizedHeaders["x-nc-paginate"] ?? "false") ?? false self.paginateToken = normalizedHeaders["x-nc-paginate-token"] - self.paginatedTotal = Int(normalizedHeaders["x-nc-paginate-total"] ?? "0") + self.paginatedTotal = Int(normalizedHeaders["x-nc-paginate-total"] ?? "0") ?? 0 } if error == .success, let files { diff --git a/File Provider Extension/FileProviderExtension+Thumbnail.swift b/File Provider Extension/FileProviderExtension+Thumbnail.swift index 0cffbb8515..e3d58c2e8b 100644 --- a/File Provider Extension/FileProviderExtension+Thumbnail.swift +++ b/File Provider Extension/FileProviderExtension+Thumbnail.swift @@ -32,15 +32,19 @@ extension FileProviderExtension { var counterProgress: Int64 = 0 for itemIdentifier in itemIdentifiers { - guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier), metadata.hasPreview else { + guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier), + metadata.hasPreview + else { counterProgress += 1 - if counterProgress == progress.totalUnitCount { completionHandler(nil) } + if counterProgress == progress.totalUnitCount { + completionHandler(nil) + } continue } NextcloudKit.shared.downloadPreview(fileId: metadata.fileId, - width: Int(size.width), - height: Int(size.height), + width: Int(NCGlobal.shared.size512.width), + height: Int(NCGlobal.shared.size512.height), etag: metadata.etag, account: metadata.account) { _ in } completion: { _, _, _, _, responseData, error in @@ -55,6 +59,7 @@ extension FileProviderExtension { } } } + return progress } }