mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix rebase
This commit is contained in:
@@ -146,70 +146,6 @@ class URLSessionManager: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func setServerUrls(_ urls: [String]) {
|
|
||||||
guard urls != serverUrls else { return }
|
|
||||||
serverUrls = urls
|
|
||||||
UserDefaults.group.set(urls, forKey: SERVER_URLS_KEY)
|
|
||||||
syncAuthCookies()
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private static func cookiesDidChange(_ notification: Notification) {
|
|
||||||
guard !isSyncing, !serverUrls.isEmpty else { return }
|
|
||||||
syncAuthCookies()
|
|
||||||
}
|
|
||||||
|
|
||||||
private static func syncAuthCookies() {
|
|
||||||
let serverHosts = Set(serverUrls.compactMap { URL(string: $0)?.host })
|
|
||||||
let allCookies = cookieStorage.cookies ?? []
|
|
||||||
let now = Date()
|
|
||||||
|
|
||||||
let serverAuthCookies = allCookies.filter {
|
|
||||||
AuthCookie.names.contains($0.name) && serverHosts.contains($0.domain)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceCookies: [String: HTTPCookie] = [:]
|
|
||||||
for cookie in serverAuthCookies {
|
|
||||||
if cookie.expiresDate.map({ $0 > now }) ?? true {
|
|
||||||
sourceCookies[cookie.name] = cookie
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isSyncing = true
|
|
||||||
defer { isSyncing = false }
|
|
||||||
|
|
||||||
if sourceCookies.isEmpty {
|
|
||||||
for cookie in serverAuthCookies {
|
|
||||||
cookieStorage.deleteCookie(cookie)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for serverUrl in serverUrls {
|
|
||||||
guard let url = URL(string: serverUrl), let domain = url.host else { continue }
|
|
||||||
let isSecure = serverUrl.hasPrefix("https")
|
|
||||||
|
|
||||||
for (_, source) in sourceCookies {
|
|
||||||
if allCookies.contains(where: { $0.name == source.name && $0.domain == domain && $0.value == source.value }) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var properties: [HTTPCookiePropertyKey: Any] = [
|
|
||||||
.name: source.name,
|
|
||||||
.value: source.value,
|
|
||||||
.domain: domain,
|
|
||||||
.path: "/",
|
|
||||||
.expires: source.expiresDate ?? Date().addingTimeInterval(COOKIE_EXPIRY_DAYS * 24 * 60 * 60),
|
|
||||||
]
|
|
||||||
if isSecure { properties[.secure] = "TRUE" }
|
|
||||||
if source.isHTTPOnly { properties[.init("HttpOnly")] = "TRUE" }
|
|
||||||
|
|
||||||
if let cookie = HTTPCookie(properties: properties) {
|
|
||||||
cookieStorage.setCookie(cookie)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static func buildSession(delegate: URLSessionDelegate) -> URLSession {
|
private static func buildSession(delegate: URLSessionDelegate) -> URLSession {
|
||||||
let config = URLSessionConfiguration.default
|
let config = URLSessionConfiguration.default
|
||||||
config.urlCache = urlCache
|
config.urlCache = urlCache
|
||||||
|
|||||||
Reference in New Issue
Block a user