Update Kingfisher to 8.3.1
Changelog-Changed: Updated image cache for better stability Closes: https://github.com/damus-io/damus/issues/2899 Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -354,7 +354,7 @@ func preload_image(url: URL) {
|
||||
|
||||
//print("Preloading image \(url.absoluteString)")
|
||||
|
||||
KingfisherManager.shared.retrieveImage(with: Kingfisher.ImageResource(downloadURL: url)) { val in
|
||||
KingfisherManager.shared.retrieveImage(with: Kingfisher.KF.ImageResource(downloadURL: url)) { val in
|
||||
//print("Preloaded image \(url.absoluteString)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ extension KFOptionSetter {
|
||||
|
||||
func onFailure(fallbackUrl: URL?, cacheKey: String?) -> Self {
|
||||
guard let url = fallbackUrl, let key = cacheKey else { return self }
|
||||
let imageResource = Kingfisher.ImageResource(downloadURL: url, cacheKey: key)
|
||||
let imageResource = Kingfisher.KF.ImageResource(downloadURL: url, cacheKey: key)
|
||||
let source = imageResource.convertToSource()
|
||||
options.alternativeSources = [source]
|
||||
|
||||
@@ -159,20 +159,25 @@ struct CustomCacheSerializer: CacheSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomSessionDelegate: SessionDelegate {
|
||||
override func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
|
||||
class CustomSessionDelegate: SessionDelegate, @unchecked Sendable {
|
||||
override func urlSession(
|
||||
_ session: URLSession,
|
||||
dataTask: URLSessionDataTask,
|
||||
didReceive response: URLResponse
|
||||
) async -> URLSession.ResponseDisposition {
|
||||
let contentLength = response.expectedContentLength
|
||||
|
||||
// Content-Length header is optional (-1 when missing)
|
||||
if (contentLength != -1 && contentLength > MAX_FILE_SIZE) {
|
||||
return super.urlSession(session, dataTask: dataTask, didReceive: URLResponse(), completionHandler: completionHandler)
|
||||
return await super.urlSession(session, dataTask: dataTask, didReceive: URLResponse())
|
||||
}
|
||||
|
||||
super.urlSession(session, dataTask: dataTask, didReceive: response, completionHandler: completionHandler)
|
||||
return await super.urlSession(session, dataTask: dataTask, didReceive: response)
|
||||
}
|
||||
}
|
||||
|
||||
class CustomImageDownloader: ImageDownloader {
|
||||
|
||||
class CustomImageDownloader: ImageDownloader, @unchecked Sendable {
|
||||
|
||||
static let shared = CustomImageDownloader(name: "shared")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user