Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
This commit is contained in:
Marino Faggiana 2024-07-29 09:07:32 +02:00
Родитель 4752803645
Коммит 7dabb0e2c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 2F5F63C3EF460487
2 изменённых файлов: 12 добавлений и 32 удалений

Просмотреть файл

@ -26,54 +26,34 @@ import FileProvider
import NextcloudKit
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
for itemIdentifier in itemIdentifiers {
guard let metadata = fpUtility.getTableMetadataFromItemIdentifier(itemIdentifier) else {
guard let metadata = fpUtility.getTableMetadataFromItemIdentifier(itemIdentifier), metadata.hasPreview else {
counterProgress += 1
if counterProgress == progress.totalUnitCount { completionHandler(nil) }
continue
}
let fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
if metadata.hasPreview {
let fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
let fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
if let urlBase = metadata.urlBase.urlEncoded,
let fileNamePath = fileNamePath.urlEncoded,
let url = URL(string: "\(urlBase)/index.php/core/preview.png?file=\(fileNamePath)&x=\(size.width)&y=\(size.height)&a=1&mode=cover") {
NextcloudKit.shared.getPreview(url: url) { _, data, error in
if error == .success && data != nil {
do {
try data!.write(to: URL(fileURLWithPath: fileNameIconLocalPath), options: .atomic)
} catch { }
perThumbnailCompletionHandler(itemIdentifier, data, nil)
} else {
perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.serverUnreachable))
}
counterProgress += 1
if counterProgress == progress.totalUnitCount {
completionHandler(nil)
}
}
NextcloudKit.shared.downloadPreview(fileId: metadata.fileId, widthPreview: Int(size.width), heightPreview: Int(size.height), etag: metadata.etag) { _ in
} completion: { _, data, error in
if error == .success, let data {
do {
try data.write(to: URL(fileURLWithPath: fileNameIconLocalPath), options: .atomic)
} catch { }
perThumbnailCompletionHandler(itemIdentifier, data, nil)
} else {
perThumbnailCompletionHandler(itemIdentifier, nil, NSFileProviderError(.serverUnreachable))
}
} else {
counterProgress += 1
if counterProgress == progress.totalUnitCount {
completionHandler(nil)
}
}
}
return progress
}
}

Просмотреть файл

@ -238,7 +238,7 @@ class FileProviderExtension: NSFileProviderExtension {
if error == .success {
metadata.status = NCGlobal.shared.metadataStatusNormal
metadata.date = date ?? NSDate()
metadata.date = (date as? NSDate) ?? NSDate()
metadata.etag = etag ?? ""
NCManageDatabase.shared.addLocalFile(metadata: metadata)