Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File provider extension #3236

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions File Provider Extension/FileProviderEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
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
Expand Down Expand Up @@ -110,7 +110,7 @@
isPaginated,
metadatas.count == self.recordsPerPage {
pageNumber += 1
let providerPage = NSFileProviderPage("\(pageNumber)".data(using: .utf8)!)

Check warning on line 113 in File Provider Extension/FileProviderEnumerator.swift

View workflow job for this annotation

GitHub Actions / Lint

Non-optional String -> Data Conversion Violation: Prefer non-optional `Data(_:)` initializer when converting `String` to `Data` (non_optional_string_data_conversion)
observer.finishEnumerating(upTo: providerPage)
} else {
observer.finishEnumerating(upTo: nil)
Expand Down Expand Up @@ -152,35 +152,40 @@
observer.didDeleteItems(withIdentifiers: itemsDelete)
observer.didUpdate(itemsUpdate)

let data = "\(self.anchor)".data(using: .utf8)

Check warning on line 155 in File Provider Extension/FileProviderEnumerator.swift

View workflow job for this annotation

GitHub Actions / Lint

Non-optional String -> Data Conversion Violation: Prefer non-optional `Data(_:)` initializer when converting `String` to `Data` (non_optional_string_data_conversion)
observer.finishEnumeratingChanges(upTo: NSFileProviderSyncAnchor(data!), moreComing: false)
}

func currentSyncAnchor(completionHandler: @escaping (NSFileProviderSyncAnchor?) -> Void) {
let data = "\(self.anchor)".data(using: .utf8)

Check warning on line 160 in File Provider Extension/FileProviderEnumerator.swift

View workflow job for this annotation

GitHub Actions / Lint

Non-optional String -> Data Conversion Violation: Prefer non-optional `Data(_:)` initializer when converting `String` to `Data` (non_optional_string_data_conversion)
completionHandler(NSFileProviderSyncAnchor(data!))
}

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 {
Expand Down
13 changes: 9 additions & 4 deletions File Provider Extension/FileProviderExtension+Thumbnail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +59,7 @@ extension FileProviderExtension {
}
}
}

return progress
}
}
Loading