|
|
@ -1,12 +1,14 @@ |
|
|
|
package io.legado.app.help.http |
|
|
|
package io.legado.app.help.http |
|
|
|
|
|
|
|
|
|
|
|
import android.text.TextUtils |
|
|
|
import android.text.TextUtils |
|
|
|
|
|
|
|
import com.franmontiel.persistentcookiejar.persistence.CookiePersistor |
|
|
|
|
|
|
|
import com.franmontiel.persistentcookiejar.persistence.SerializableCookie |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.data.entities.Cookie |
|
|
|
import io.legado.app.data.entities.Cookie |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object CookieStore { |
|
|
|
object CookieStore : CookiePersistor { |
|
|
|
|
|
|
|
|
|
|
|
fun setCookie(url: String, cookie: String?) { |
|
|
|
fun setCookie(url: String, cookie: String?) { |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
@ -76,5 +78,36 @@ object CookieStore { |
|
|
|
return builder.deleteCharAt(builder.lastIndexOf(";")).toString() |
|
|
|
return builder.deleteCharAt(builder.lastIndexOf(";")).toString() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun loadAll(): MutableList<okhttp3.Cookie> { |
|
|
|
|
|
|
|
val cookies = arrayListOf<okhttp3.Cookie>() |
|
|
|
|
|
|
|
App.db.cookieDao().getOkHttpCookies().forEach { |
|
|
|
|
|
|
|
val serializedCookie = it.cookie |
|
|
|
|
|
|
|
SerializableCookie().decode(serializedCookie)?.let { ck -> |
|
|
|
|
|
|
|
cookies.add(ck) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cookies |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun saveAll(cookies: MutableCollection<okhttp3.Cookie>?) { |
|
|
|
|
|
|
|
val mCookies = arrayListOf<Cookie>() |
|
|
|
|
|
|
|
cookies?.forEach { |
|
|
|
|
|
|
|
mCookies.add(Cookie(createCookieKey(it), SerializableCookie().encode(it))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
App.db.cookieDao().insert(*mCookies.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun removeAll(cookies: MutableCollection<okhttp3.Cookie>?) { |
|
|
|
|
|
|
|
cookies?.forEach { |
|
|
|
|
|
|
|
App.db.cookieDao().delete(createCookieKey(it)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun clear() { |
|
|
|
|
|
|
|
App.db.cookieDao().deleteOkHttp() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun createCookieKey(cookie: okhttp3.Cookie): String { |
|
|
|
|
|
|
|
return (if (cookie.secure()) "https" else "http") + "://" + cookie.domain() + cookie.path() + "|" + cookie.name() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |