mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-18 11:46:27 +00:00
36 lines
1.4 KiB
Swift
36 lines
1.4 KiB
Swift
// Copyright © 2021 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
import SDWebImage
|
|
import ServiceLayer
|
|
|
|
struct ImageCacheConfiguration {
|
|
private let environment: AppEnvironment
|
|
|
|
init(environment: AppEnvironment) {
|
|
self.environment = environment
|
|
}
|
|
}
|
|
|
|
extension ImageCacheConfiguration {
|
|
func configure() throws {
|
|
SDImageCache.defaultDiskCacheDirectory = Self.imageCacheDirectoryURL?.path
|
|
ImageDiskCache.service = try ImageSerializationService(environment: environment)
|
|
SDImageCacheConfig.default.diskCacheClass = ImageDiskCache.self
|
|
|
|
if let legacyImageCacheDirectoryURL = Self.legacyImageCacheDirectoryURL,
|
|
FileManager.default.fileExists(atPath: legacyImageCacheDirectoryURL.path) {
|
|
try? FileManager.default.removeItem(at: legacyImageCacheDirectoryURL)
|
|
}
|
|
}
|
|
}
|
|
|
|
private extension ImageCacheConfiguration {
|
|
static let cachesDirectoryURL = FileManager.default.containerURL(
|
|
forSecurityApplicationGroupIdentifier: AppEnvironment.appGroup)?
|
|
.appendingPathComponent("Library")
|
|
.appendingPathComponent("Caches")
|
|
static let imageCacheDirectoryURL = cachesDirectoryURL?.appendingPathComponent("com.metabolist.metatext.images")
|
|
static let legacyImageCacheDirectoryURL =
|
|
cachesDirectoryURL?.appendingPathComponent("com.onevcat.Kingfisher.ImageCache.Images")
|
|
}
|