mirror of
https://github.com/immich-app/immich.git
synced 2025-07-31 15:08:44 -04:00
cleanly migrate the server URL value to a JSON array (ie coming from 1.135.0 app)
This commit is contained in:
parent
88e008c4c2
commit
0a90f490f2
@ -65,7 +65,7 @@ class ImmichAPI {
|
|||||||
init() async throws {
|
init() async throws {
|
||||||
// fetch the credentials from the UserDefaults store that dart placed here
|
// fetch the credentials from the UserDefaults store that dart placed here
|
||||||
guard let defaults = UserDefaults(suiteName: "group.app.immich.share"),
|
guard let defaults = UserDefaults(suiteName: "group.app.immich.share"),
|
||||||
let serverURL = defaults.string(forKey: "widget_server_url"),
|
var serverURL = defaults.string(forKey: "widget_server_url"),
|
||||||
let sessionKey = defaults.string(forKey: "widget_auth_token")
|
let sessionKey = defaults.string(forKey: "widget_auth_token")
|
||||||
else {
|
else {
|
||||||
throw WidgetError.noLogin
|
throw WidgetError.noLogin
|
||||||
@ -75,31 +75,30 @@ class ImmichAPI {
|
|||||||
throw WidgetError.noLogin
|
throw WidgetError.noLogin
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the stored value is an array of URLs
|
// migrate the server list value to a JSON array if it is not already
|
||||||
if serverURL.starts(with: "[") {
|
if !serverURL.starts(with: "[") {
|
||||||
guard let urls = try? JSONDecoder().decode([String].self, from: serverURL.data(using: .utf8)!) else {
|
let newServerList = "[\"\(serverURL)\"]"
|
||||||
throw WidgetError.noLogin
|
defaults.set(newServerList, forKey: "widget_server_url")
|
||||||
}
|
serverURL = newServerList
|
||||||
|
|
||||||
for url in urls {
|
|
||||||
guard let endpointURL = URL(string: url) else { continue }
|
|
||||||
|
|
||||||
if let apiURL = await Self.validateServer(at: endpointURL) {
|
|
||||||
serverConfig = ServerConfig(
|
|
||||||
serverEndpoint: apiURL.absoluteString,
|
|
||||||
sessionKey: sessionKey
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw WidgetError.fetchFailed
|
|
||||||
} else {
|
|
||||||
serverConfig = ServerConfig(
|
|
||||||
serverEndpoint: serverURL,
|
|
||||||
sessionKey: sessionKey
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guard let urls = try? JSONDecoder().decode([String].self, from: serverURL.data(using: .utf8)!) else {
|
||||||
|
throw WidgetError.noLogin
|
||||||
|
}
|
||||||
|
|
||||||
|
for url in urls {
|
||||||
|
guard let endpointURL = URL(string: url) else { continue }
|
||||||
|
|
||||||
|
if let apiURL = await Self.validateServer(at: endpointURL) {
|
||||||
|
serverConfig = ServerConfig(
|
||||||
|
serverEndpoint: apiURL.absoluteString,
|
||||||
|
sessionKey: sessionKey
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw WidgetError.fetchFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func validateServer(at endpointURL: URL) async -> URL? {
|
private static func validateServer(at endpointURL: URL) async -> URL? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user