mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Still not broken: Next commit decides the fate
This commit is contained in:
parent
cb2afda0f2
commit
dc45c50df4
17 changed files with 1028 additions and 608 deletions
49
DynamicIsland/managers/ImageService.swift
Normal file
49
DynamicIsland/managers/ImageService.swift
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// ImageService.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by Alexander on 2025-09-13.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Defaults
|
||||
|
||||
public protocol ImageServiceProtocol {
|
||||
func fetchImageData(from url: URL) async throws -> Data
|
||||
}
|
||||
|
||||
public final class ImageService: ImageServiceProtocol {
|
||||
public static let shared = ImageService()
|
||||
|
||||
private let session: URLSession
|
||||
|
||||
private init() {
|
||||
let config = URLSessionConfiguration.default
|
||||
let cache = URLCache(memoryCapacity: 50 * 1024 * 1024, // 50MB
|
||||
diskCapacity: 100 * 1024 * 1024, // 100MB
|
||||
diskPath: "artwork_cache")
|
||||
config.urlCache = cache
|
||||
config.timeoutIntervalForRequest = 15
|
||||
config.timeoutIntervalForResource = 30
|
||||
config.httpShouldSetCookies = false
|
||||
self.session = URLSession(configuration: config)
|
||||
|
||||
performLegacyCacheCleanupIfNeeded()
|
||||
}
|
||||
|
||||
private func performLegacyCacheCleanupIfNeeded() {
|
||||
|
||||
if !Defaults[.didClearLegacyURLCacheV1] {
|
||||
URLCache.shared.removeAllCachedResponses()
|
||||
Defaults[.didClearLegacyURLCacheV1] = true
|
||||
}
|
||||
}
|
||||
|
||||
public func fetchImageData(from url: URL) async throws -> Data {
|
||||
guard let scheme = url.scheme?.lowercased(), scheme == "http" || scheme == "https" else {
|
||||
throw URLError(.unsupportedURL)
|
||||
}
|
||||
let (data, _) = try await session.data(from: url)
|
||||
return data
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue