Copy star cookie to ex as well
This commit is contained in:
1 parent
f58c33354e
commit
39336a447b
3 files changed
+20
-31
No files matched your search
@@ -48,6 +48,7 @@ object EhCookieStore : CookieJar, CookiesStorage {
|
||||
const val KEY_IPB_PASS_HASH = "ipb_pass_hash"
|
||||
const val KEY_IGNEOUS = "igneous"
|
||||
const val KEY_SETTINGS_PROFILE = "sp"
|
||||
const val KEY_STAR = "star"
|
||||
private const val KEY_CONTENT_WARNING = "nw"
|
||||
private const val CONTENT_WARNING_NOT_SHOW = "1"
|
||||
private val sTipsCookie: Cookie = Cookie.Builder()
|
||||
@@ -59,8 +60,8 @@ object EhCookieStore : CookieJar, CookiesStorage {
|
||||
.build()
|
||||
|
||||
fun newCookie(
|
||||
cookie: Cookie, newDomain: String, forcePersistent: Boolean,
|
||||
forceLongLive: Boolean, forceNotHostOnly: Boolean
|
||||
cookie: Cookie, newDomain: String, forcePersistent: Boolean = false,
|
||||
forceLongLive: Boolean = false, forceNotHostOnly: Boolean = false
|
||||
): Cookie {
|
||||
val builder = Cookie.Builder()
|
||||
builder.name(cookie.name)
|
||||
@@ -87,6 +88,11 @@ object EhCookieStore : CookieJar, CookiesStorage {
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun copyCookie(domain: String, newDomain: String, name: String, path: String = "/") {
|
||||
val cookie = map[domain]?.get(name, domain, path)
|
||||
cookie?.let { addCookie(newCookie(it, newDomain)) }
|
||||
}
|
||||
|
||||
fun deleteCookie(url: HttpUrl, name: String) {
|
||||
val deletedCookie = Cookie.Builder()
|
||||
.name(name)
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.google.accompanist.themeadapter.material3.Mdc3Theme
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.ui.EhActivity
|
||||
@@ -80,6 +81,7 @@ suspend fun postLogin() = coroutineScope {
|
||||
runCatching {
|
||||
// For the `star` cookie
|
||||
EhEngine.getNews(false)
|
||||
EhCookieStore.copyCookie(EhUrl.DOMAIN_E, EhUrl.DOMAIN_EX, EhCookieStore.KEY_STAR)
|
||||
|
||||
// Sad panda check
|
||||
Settings.putGallerySite(EhUrl.SITE_EX)
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.hippo.network
|
||||
|
||||
import com.hippo.util.HashCodeUtils
|
||||
import com.hippo.yorozuya.ObjectUtils
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.HttpUrl
|
||||
|
||||
@@ -44,44 +42,27 @@ internal class CookieSet {
|
||||
/**
|
||||
* Get cookies for the url. Fill `accepted` and `expired`.
|
||||
*/
|
||||
operator fun get(url: HttpUrl?, accepted: MutableList<Cookie>, expired: MutableList<Cookie>) {
|
||||
operator fun get(url: HttpUrl, accepted: MutableList<Cookie>, expired: MutableList<Cookie>) {
|
||||
val now = System.currentTimeMillis()
|
||||
val iterator: MutableIterator<Map.Entry<Key, Cookie>> = map.entries.iterator()
|
||||
val iterator = map.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val cookie = iterator.next().value
|
||||
if (cookie.expiresAt <= now) {
|
||||
iterator.remove()
|
||||
expired.add(cookie)
|
||||
} else if (cookie.matches(url!!)) {
|
||||
} else if (cookie.matches(url)) {
|
||||
accepted.add(cookie)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class Key(cookie: Cookie) {
|
||||
private val name: String
|
||||
private val domain: String
|
||||
private val path: String
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) {
|
||||
return true
|
||||
}
|
||||
if (other is Key) {
|
||||
return ObjectUtils.equal(other.name, name) &&
|
||||
ObjectUtils.equal(other.domain, domain) &&
|
||||
ObjectUtils.equal(other.path, path)
|
||||
}
|
||||
return false
|
||||
}
|
||||
fun get(name: String, domain: String, path: String) = map[Key(name, domain, path)]
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return HashCodeUtils.hashCode(name, domain, path)
|
||||
}
|
||||
|
||||
init {
|
||||
name = cookie.name
|
||||
domain = cookie.domain
|
||||
path = cookie.path
|
||||
}
|
||||
internal data class Key(
|
||||
val name: String,
|
||||
val domain: String,
|
||||
val path: String
|
||||
) {
|
||||
constructor(cookie: Cookie) : this(cookie.name, cookie.domain, cookie.path)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user