Improve login process regarding IP restriction

This commit is contained in:
FooIbar authored and tarsin committed 2023-02-23 17:55:45 +08:00
1 parent 6022144dce
commit 43556f219b
5 files changed
+42 -17

No files matched your search

@@ -183,7 +183,10 @@ object EhCookieStore : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
for (cookie in cookies) {
addCookie(cookie)
// See https://github.com/Ehviewer-Overhauled/Ehviewer/issues/873
if (cookie.name != "__utmp") {
addCookie(cookie)
}
}
}
@@ -30,6 +30,7 @@ import com.hippo.ehviewer.client.data.PreviewSet
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.client.exception.ParseException
import com.hippo.ehviewer.client.parser.ArchiveParser
import com.hippo.ehviewer.client.parser.EventPaneParser
import com.hippo.ehviewer.client.parser.FavoritesParser
import com.hippo.ehviewer.client.parser.ForumsParser
import com.hippo.ehviewer.client.parser.GalleryApiParser
@@ -840,6 +841,30 @@ object EhEngine {
}
}
@Throws(Throwable::class)
suspend fun getNews(parse: Boolean): String? {
val url = EhUrl.URL_NEWS
val referer = EhUrl.REFERER_E
Log.d(TAG, url)
val request = EhRequestBuilder(url, referer).build()
val call = okHttpClient.newCall(request)
var body: String? = null
var headers: Headers? = null
var code = -1
try {
call.executeAsync().use { response ->
code = response.code
headers = response.headers
body = response.body.string()
return if (parse) EventPaneParser.parse(body!!) else null
}
} catch (e: Throwable) {
ExceptionUtils.throwIfFatal(e)
transformException(code, headers, body, e)
throw e
}
}
@Throws(Throwable::class)
private suspend fun getProfileInternal(
url: String, referer: String
@@ -46,6 +46,7 @@ object EhUrl {
const val URL_FORUMS = "https://forums.e-hentai.org/"
const val URL_FUNDS = HOST_E + "exchange.php?t=gp"
const val URL_HOME = HOST_E + "home.php"
const val URL_NEWS = HOST_E + "news.php"
const val REFERER_EX = "https://$DOMAIN_EX"
const val ORIGIN_EX = REFERER_EX
const val REFERER_E = "https://$DOMAIN_E"
@@ -7,19 +7,18 @@ import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequest
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.hippo.ehviewer.EhApplication
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhRequestBuilder
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.parser.EventPaneParser
import com.hippo.ehviewer.client.EhEngine
import eu.kanade.tachiyomi.util.lang.withIOContext
import java.time.Duration
import java.time.LocalDateTime
@@ -29,24 +28,17 @@ private val signedIn
private const val CHANNEL_ID = "DailyCheckNotification"
class DailyCheckWork(val context: Context, workerParams: WorkerParameters) :
Worker(context, workerParams) {
override fun doWork(): Result {
CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result = withIOContext {
runCatching {
if (signedIn) {
val referer = EhUrl.REFERER_E
val request = EhRequestBuilder(EhUrl.HOST_E + "news.php", referer).build()
val call = EhApplication.okHttpClient.newCall(request)
call.execute().use { response ->
val responseBody = response.body
val body = responseBody.string()
EventPaneParser.parse(body)?.let { showEventPane(it) }
}
EhEngine.getNews(true)?.let { showEventPane(it) }
}
}.onFailure {
it.printStackTrace()
return Result.retry()
return@withIOContext Result.retry()
}
return Result.success()
Result.success()
}
@SuppressLint("MissingPermission")
@@ -78,6 +78,10 @@ suspend fun postLogin() = coroutineScope {
}
launch {
runCatching {
// For the `star` cookie
EhEngine.getNews(false)
// Sad panda check
Settings.putGallerySite(EhUrl.SITE_EX)
EhEngine.getUConfig()
}.onFailure {