mirror of
https://github.com/immich-app/immich.git
synced 2026-05-24 00:22:29 -04:00
remove bootstrapCookies
This commit is contained in:
@@ -168,7 +168,7 @@ object HttpClientManager {
|
||||
synchronized(this) { clientChangedListeners.add(listener) }
|
||||
}
|
||||
|
||||
fun setRequestHeaders(headerMap: Map<String, String>, serverUrls: List<String>) {
|
||||
fun setRequestHeaders(headerMap: Map<String, String>, serverUrls: List<String>, token: String?) {
|
||||
synchronized(this) {
|
||||
val builder = Headers.Builder()
|
||||
headerMap.forEach { (key, value) -> builder[key] = value }
|
||||
@@ -186,23 +186,23 @@ object HttpClientManager {
|
||||
putString(PREFS_SERVER_URLS, Json.encodeToString(serverUrls))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bootstrapCookies(token: String, serverUrls: List<String>) {
|
||||
val url = serverUrls.firstNotNullOfOrNull { it.toHttpUrlOrNull() } ?: return
|
||||
val expiry = System.currentTimeMillis() + 400L * 24 * 60 * 60 * 1000
|
||||
fun cookie(name: String, value: String, httpOnly: Boolean) =
|
||||
Cookie.Builder().name(name).value(value).domain(url.host).path("/").expiresAt(expiry)
|
||||
.apply {
|
||||
if (url.isHttps) secure()
|
||||
if (httpOnly) httpOnly()
|
||||
}.build()
|
||||
cookieJar.saveFromResponse(url, listOf(
|
||||
cookie("immich_access_token", token, httpOnly = true),
|
||||
cookie("immich_is_authenticated", "true", httpOnly = false),
|
||||
cookie("immich_auth_type", "password", httpOnly = true),
|
||||
))
|
||||
if (token != null) {
|
||||
val url = serverUrls.firstNotNullOfOrNull { it.toHttpUrlOrNull() } ?: return
|
||||
val expiry = System.currentTimeMillis() + 400L * 24 * 60 * 60 * 1000
|
||||
fun cookie(name: String, value: String, httpOnly: Boolean) =
|
||||
Cookie.Builder().name(name).value(value).domain(url.host).path("/").expiresAt(expiry)
|
||||
.apply {
|
||||
if (url.isHttps) secure()
|
||||
if (httpOnly) httpOnly()
|
||||
}.build()
|
||||
cookieJar.saveFromResponse(url, listOf(
|
||||
cookie("immich_access_token", token, httpOnly = true),
|
||||
cookie("immich_is_authenticated", "true", httpOnly = false),
|
||||
cookie("immich_auth_type", "password", httpOnly = true),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadCookieHeader(url: String): String? {
|
||||
|
||||
@@ -184,8 +184,7 @@ interface NetworkApi {
|
||||
fun removeCertificate(callback: (Result<Unit>) -> Unit)
|
||||
fun hasCertificate(): Boolean
|
||||
fun getClientPointer(): Long
|
||||
fun setRequestHeaders(headers: Map<String, String>, serverUrls: List<String>)
|
||||
fun bootstrapCookies(token: String, serverUrls: List<String>)
|
||||
fun setRequestHeaders(headers: Map<String, String>, serverUrls: List<String>, token: String?)
|
||||
|
||||
companion object {
|
||||
/** The codec used by NetworkApi. */
|
||||
@@ -288,27 +287,9 @@ interface NetworkApi {
|
||||
val args = message as List<Any?>
|
||||
val headersArg = args[0] as Map<String, String>
|
||||
val serverUrlsArg = args[1] as List<String>
|
||||
val tokenArg = args[2] as String?
|
||||
val wrapped: List<Any?> = try {
|
||||
api.setRequestHeaders(headersArg, serverUrlsArg)
|
||||
listOf(null)
|
||||
} catch (exception: Throwable) {
|
||||
NetworkPigeonUtils.wrapError(exception)
|
||||
}
|
||||
reply.reply(wrapped)
|
||||
}
|
||||
} else {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.bootstrapCookies$separatedMessageChannelSuffix", codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val args = message as List<Any?>
|
||||
val tokenArg = args[0] as String
|
||||
val serverUrlsArg = args[1] as List<String>
|
||||
val wrapped: List<Any?> = try {
|
||||
api.bootstrapCookies(tokenArg, serverUrlsArg)
|
||||
api.setRequestHeaders(headersArg, serverUrlsArg, tokenArg)
|
||||
listOf(null)
|
||||
} catch (exception: Throwable) {
|
||||
NetworkPigeonUtils.wrapError(exception)
|
||||
|
||||
@@ -79,11 +79,7 @@ private class NetworkApiImpl : NetworkApi {
|
||||
return HttpClientManager.getClientPointer()
|
||||
}
|
||||
|
||||
override fun setRequestHeaders(headers: Map<String, String>, serverUrls: List<String>) {
|
||||
HttpClientManager.setRequestHeaders(headers, serverUrls)
|
||||
}
|
||||
|
||||
override fun bootstrapCookies(token: String, serverUrls: List<String>) {
|
||||
HttpClientManager.bootstrapCookies(token, serverUrls)
|
||||
override fun setRequestHeaders(headers: Map<String, String>, serverUrls: List<String>, token: String?) {
|
||||
HttpClientManager.setRequestHeaders(headers, serverUrls, token)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user