mirror of
https://github.com/cranci1/Sora.git
synced 2026-03-11 17:45:37 +00:00
kingfisher 😭
This commit is contained in:
parent
4ffa34b9ab
commit
d0ac33afb9
4 changed files with 31 additions and 32 deletions
|
|
@ -54,20 +54,6 @@ class KingfisherCacheManager {
|
||||||
cache.memoryStorage.config.cleanInterval = 60
|
cache.memoryStorage.config.cleanInterval = 60
|
||||||
|
|
||||||
KingfisherManager.shared.downloader.downloadTimeout = 15.0
|
KingfisherManager.shared.downloader.downloadTimeout = 15.0
|
||||||
|
|
||||||
struct CustomJPEGCacheSerializer: CacheSerializer {
|
|
||||||
let compressionQuality: CGFloat
|
|
||||||
|
|
||||||
func data(with image: KFCrossPlatformImage, original: Data?) -> Data? {
|
|
||||||
return image.kf.jpegData(compressionQuality: compressionQuality)
|
|
||||||
}
|
|
||||||
|
|
||||||
func image(with data: Data, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? {
|
|
||||||
return DefaultCacheSerializer.default.image(with: data, options: options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache.diskStorage.config.cacheSerializer = CustomJPEGCacheSerializer(compressionQuality: jpegCompressionQuality)
|
|
||||||
|
|
||||||
Logger.shared.log("Configured Kingfisher cache. Enabled: \(isCachingEnabled)", type: "Debug")
|
Logger.shared.log("Configured Kingfisher cache. Enabled: \(isCachingEnabled)", type: "Debug")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import CryptoKit
|
||||||
|
|
||||||
/// A class to manage episode metadata caching, both in-memory and on disk
|
/// A class to manage episode metadata caching, both in-memory and on disk
|
||||||
class MetadataCacheManager {
|
class MetadataCacheManager {
|
||||||
|
|
@ -97,21 +98,23 @@ class MetadataCacheManager {
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - data: The metadata to cache
|
/// - data: The metadata to cache
|
||||||
/// - key: The cache key (usually anilist_id + episode_number)
|
/// - key: The cache key (usually anilist_id + episode_number)
|
||||||
|
private func safeFileName(for key: String) -> String {
|
||||||
|
let hash = SHA256.hash(data: Data(key.utf8))
|
||||||
|
return hash.compactMap { String(format: "%02x", $0) }.joined()
|
||||||
|
}
|
||||||
|
|
||||||
func storeMetadata(_ data: Data, forKey key: String) {
|
func storeMetadata(_ data: Data, forKey key: String) {
|
||||||
guard isCachingEnabled else { return }
|
guard isCachingEnabled else { return }
|
||||||
|
|
||||||
let keyString = key as NSString
|
let keyString = key as NSString
|
||||||
|
|
||||||
// Always store in memory cache
|
|
||||||
memoryCache.setObject(data as NSData, forKey: keyString)
|
memoryCache.setObject(data as NSData, forKey: keyString)
|
||||||
|
|
||||||
// Store on disk if not in memory-only mode
|
|
||||||
if !isMemoryOnlyMode {
|
if !isMemoryOnlyMode {
|
||||||
let fileURL = cacheDirectory.appendingPathComponent(key)
|
let fileName = safeFileName(for: key)
|
||||||
|
let fileURL = cacheDirectory.appendingPathComponent(fileName)
|
||||||
|
let tempURL = fileURL.appendingPathExtension("tmp")
|
||||||
DispatchQueue.global(qos: .background).async { [weak self] in
|
DispatchQueue.global(qos: .background).async { [weak self] in
|
||||||
do {
|
do {
|
||||||
try data.write(to: fileURL)
|
try data.write(to: tempURL)
|
||||||
|
try self?.fileManager.moveItem(at: tempURL, to: fileURL)
|
||||||
|
|
||||||
// Add timestamp as a file attribute instead of using extended attributes
|
// Add timestamp as a file attribute instead of using extended attributes
|
||||||
let attributes: [FileAttributeKey: Any] = [
|
let attributes: [FileAttributeKey: Any] = [
|
||||||
|
|
@ -273,4 +276,4 @@ class MetadataCacheManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,10 +46,10 @@
|
||||||
133D7C932D2BE2640075467E /* Modules.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C892D2BE2640075467E /* Modules.swift */; };
|
133D7C932D2BE2640075467E /* Modules.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C892D2BE2640075467E /* Modules.swift */; };
|
||||||
133D7C942D2BE2640075467E /* JSController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C8B2D2BE2640075467E /* JSController.swift */; };
|
133D7C942D2BE2640075467E /* JSController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133D7C8B2D2BE2640075467E /* JSController.swift */; };
|
||||||
133F55BB2D33B55100E08EEA /* LibraryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133F55BA2D33B55100E08EEA /* LibraryManager.swift */; };
|
133F55BB2D33B55100E08EEA /* LibraryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 133F55BA2D33B55100E08EEA /* LibraryManager.swift */; };
|
||||||
|
134D3A1F2DED84470089C712 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 134D3A1E2DED84470089C712 /* Kingfisher */; };
|
||||||
1359ED142D76F49900C13034 /* finTopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1359ED132D76F49900C13034 /* finTopView.swift */; };
|
1359ED142D76F49900C13034 /* finTopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1359ED132D76F49900C13034 /* finTopView.swift */; };
|
||||||
135CCBE22D4D1138008B9C0E /* SettingsViewPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135CCBE12D4D1138008B9C0E /* SettingsViewPlayer.swift */; };
|
135CCBE22D4D1138008B9C0E /* SettingsViewPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 135CCBE12D4D1138008B9C0E /* SettingsViewPlayer.swift */; };
|
||||||
13637B8A2DE0EA1100BDA2FC /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13637B892DE0EA1100BDA2FC /* UserDefaults.swift */; };
|
13637B8A2DE0EA1100BDA2FC /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13637B892DE0EA1100BDA2FC /* UserDefaults.swift */; };
|
||||||
13637B8D2DE0ECCC00BDA2FC /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 13637B8C2DE0ECCC00BDA2FC /* Kingfisher */; };
|
|
||||||
13637B902DE0ECD200BDA2FC /* Drops in Frameworks */ = {isa = PBXBuildFile; productRef = 13637B8F2DE0ECD200BDA2FC /* Drops */; };
|
13637B902DE0ECD200BDA2FC /* Drops in Frameworks */ = {isa = PBXBuildFile; productRef = 13637B8F2DE0ECD200BDA2FC /* Drops */; };
|
||||||
13637B932DE0ECDB00BDA2FC /* MarqueeLabel in Frameworks */ = {isa = PBXBuildFile; productRef = 13637B922DE0ECDB00BDA2FC /* MarqueeLabel */; };
|
13637B932DE0ECDB00BDA2FC /* MarqueeLabel in Frameworks */ = {isa = PBXBuildFile; productRef = 13637B922DE0ECDB00BDA2FC /* MarqueeLabel */; };
|
||||||
136BBE802DB1038000906B5E /* Notification+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136BBE7F2DB1038000906B5E /* Notification+Name.swift */; };
|
136BBE802DB1038000906B5E /* Notification+Name.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136BBE7F2DB1038000906B5E /* Notification+Name.swift */; };
|
||||||
|
|
@ -201,7 +201,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
13637B8D2DE0ECCC00BDA2FC /* Kingfisher in Frameworks */,
|
134D3A1F2DED84470089C712 /* Kingfisher in Frameworks */,
|
||||||
13637B902DE0ECD200BDA2FC /* Drops in Frameworks */,
|
13637B902DE0ECD200BDA2FC /* Drops in Frameworks */,
|
||||||
13637B932DE0ECDB00BDA2FC /* MarqueeLabel in Frameworks */,
|
13637B932DE0ECDB00BDA2FC /* MarqueeLabel in Frameworks */,
|
||||||
);
|
);
|
||||||
|
|
@ -645,9 +645,9 @@
|
||||||
);
|
);
|
||||||
name = Sulfur;
|
name = Sulfur;
|
||||||
packageProductDependencies = (
|
packageProductDependencies = (
|
||||||
13637B8C2DE0ECCC00BDA2FC /* Kingfisher */,
|
|
||||||
13637B8F2DE0ECD200BDA2FC /* Drops */,
|
13637B8F2DE0ECD200BDA2FC /* Drops */,
|
||||||
13637B922DE0ECDB00BDA2FC /* MarqueeLabel */,
|
13637B922DE0ECDB00BDA2FC /* MarqueeLabel */,
|
||||||
|
134D3A1E2DED84470089C712 /* Kingfisher */,
|
||||||
);
|
);
|
||||||
productName = Sora;
|
productName = Sora;
|
||||||
productReference = 133D7C6A2D2BE2500075467E /* Sulfur.app */;
|
productReference = 133D7C6A2D2BE2500075467E /* Sulfur.app */;
|
||||||
|
|
@ -677,9 +677,9 @@
|
||||||
);
|
);
|
||||||
mainGroup = 133D7C612D2BE2500075467E;
|
mainGroup = 133D7C612D2BE2500075467E;
|
||||||
packageReferences = (
|
packageReferences = (
|
||||||
13637B8B2DE0ECCC00BDA2FC /* XCRemoteSwiftPackageReference "Kingfisher" */,
|
|
||||||
13637B8E2DE0ECD200BDA2FC /* XCRemoteSwiftPackageReference "Drops" */,
|
13637B8E2DE0ECD200BDA2FC /* XCRemoteSwiftPackageReference "Drops" */,
|
||||||
13637B912DE0ECDB00BDA2FC /* XCRemoteSwiftPackageReference "MarqueeLabel" */,
|
13637B912DE0ECDB00BDA2FC /* XCRemoteSwiftPackageReference "MarqueeLabel" */,
|
||||||
|
134D3A1D2DED84470089C712 /* XCRemoteSwiftPackageReference "Kingfisher" */,
|
||||||
);
|
);
|
||||||
productRefGroup = 133D7C6B2D2BE2500075467E /* Products */;
|
productRefGroup = 133D7C6B2D2BE2500075467E /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
|
|
@ -1034,12 +1034,13 @@
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
13637B8B2DE0ECCC00BDA2FC /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
|
134D3A1D2DED84470089C712 /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
|
||||||
isa = XCRemoteSwiftPackageReference;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://github.com/onevcat/Kingfisher.git";
|
repositoryURL = "https://github.com/onevcat/Kingfisher.git";
|
||||||
requirement = {
|
requirement = {
|
||||||
kind = exactVersion;
|
kind = versionRange;
|
||||||
version = 7.9.1;
|
maximumVersion = 9.0.0;
|
||||||
|
minimumVersion = 8.0.0;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
13637B8E2DE0ECD200BDA2FC /* XCRemoteSwiftPackageReference "Drops" */ = {
|
13637B8E2DE0ECD200BDA2FC /* XCRemoteSwiftPackageReference "Drops" */ = {
|
||||||
|
|
@ -1061,9 +1062,9 @@
|
||||||
/* End XCRemoteSwiftPackageReference section */
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
13637B8C2DE0ECCC00BDA2FC /* Kingfisher */ = {
|
134D3A1E2DED84470089C712 /* Kingfisher */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
package = 13637B8B2DE0ECCC00BDA2FC /* XCRemoteSwiftPackageReference "Kingfisher" */;
|
package = 134D3A1D2DED84470089C712 /* XCRemoteSwiftPackageReference "Kingfisher" */;
|
||||||
productName = Kingfisher;
|
productName = Kingfisher;
|
||||||
};
|
};
|
||||||
13637B8F2DE0ECD200BDA2FC /* Drops */ = {
|
13637B8F2DE0ECD200BDA2FC /* Drops */ = {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,15 @@
|
||||||
"version": null
|
"version": null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"package": "Kingfisher",
|
||||||
|
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
|
||||||
|
"state": {
|
||||||
|
"branch": null,
|
||||||
|
"revision": "7deda23bbdca612076c5c315003d8638a08ed0f1",
|
||||||
|
"version": "8.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"package": "MarqueeLabel",
|
"package": "MarqueeLabel",
|
||||||
"repositoryURL": "https://github.com/cbpowell/MarqueeLabel",
|
"repositoryURL": "https://github.com/cbpowell/MarqueeLabel",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue