diff --git a/app/build.gradle b/app/build.gradle index 0b94a0515..e2b7b427d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,7 +82,7 @@ afterEvaluate { } dependencies { //noinspection GradleDependency - implementation('com.github.KotatsuApp:kotatsu-parsers:98cbee11b9') { + implementation('com.github.KotatsuApp:kotatsu-parsers:f91ff0b9d0') { exclude group: 'org.json', module: 'json' } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/TooManyRequestExceptions.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/TooManyRequestExceptions.kt deleted file mode 100644 index 6e99991f6..000000000 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/TooManyRequestExceptions.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.koitharu.kotatsu.core.exceptions - -import okio.IOException -import java.time.Instant -import java.time.temporal.ChronoUnit - -class TooManyRequestExceptions( - val url: String, - val retryAt: Instant?, -) : IOException() { - val retryAfter: Long - get() = retryAt?.until(Instant.now(), ChronoUnit.MILLIS) ?: 0 -} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/RateLimitInterceptor.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/RateLimitInterceptor.kt index 3b3168d47..79584c8a1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/RateLimitInterceptor.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/RateLimitInterceptor.kt @@ -3,28 +3,27 @@ package org.koitharu.kotatsu.core.network import okhttp3.Interceptor import okhttp3.Response import okhttp3.internal.closeQuietly -import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions -import java.time.Instant +import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions import java.time.ZonedDateTime import java.time.format.DateTimeFormatter +import java.util.concurrent.TimeUnit class RateLimitInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) if (response.code == 429) { - val retryDate = response.header(CommonHeaders.RETRY_AFTER)?.parseRetryDate() val request = response.request response.closeQuietly() throw TooManyRequestExceptions( url = request.url.toString(), - retryAt = retryDate, + retryAfter = response.header(CommonHeaders.RETRY_AFTER)?.parseRetryAfter() ?: 0L, ) } return response } - private fun String.parseRetryDate(): Instant? { - return toLongOrNull()?.let { Instant.now().plusSeconds(it) } - ?: ZonedDateTime.parse(this, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant() + private fun String.parseRetryAfter(): Long { + return toLongOrNull()?.let { TimeUnit.SECONDS.toMillis(it) } + ?: ZonedDateTime.parse(this, DateTimeFormatter.RFC_1123_DATE_TIME).toInstant().toEpochMilli() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt index 19b89ba43..5b8e5b23e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt @@ -20,7 +20,6 @@ import org.koitharu.kotatsu.core.exceptions.IncompatiblePluginException import org.koitharu.kotatsu.core.exceptions.NoDataReceivedException import org.koitharu.kotatsu.core.exceptions.ProxyConfigException import org.koitharu.kotatsu.core.exceptions.SyncApiException -import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException import org.koitharu.kotatsu.core.exceptions.UnsupportedSourceException import org.koitharu.kotatsu.core.exceptions.WrongPasswordException @@ -33,6 +32,7 @@ import org.koitharu.kotatsu.parsers.exception.AuthRequiredException import org.koitharu.kotatsu.parsers.exception.ContentUnavailableException import org.koitharu.kotatsu.parsers.exception.NotFoundException import org.koitharu.kotatsu.parsers.exception.ParseException +import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions import java.net.SocketTimeoutException import java.net.UnknownHostException diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt index 4a30fa7b8..703a7c1e7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt @@ -41,7 +41,6 @@ import okio.buffer import okio.sink import okio.use import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.model.ids import org.koitharu.kotatsu.core.model.isLocal import org.koitharu.kotatsu.core.network.MangaHttpClient @@ -72,6 +71,7 @@ import org.koitharu.kotatsu.local.data.TempFileFilter import org.koitharu.kotatsu.local.data.input.LocalMangaInput import org.koitharu.kotatsu.local.data.output.LocalMangaOutput import org.koitharu.kotatsu.local.domain.model.LocalManga +import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter import org.koitharu.kotatsu.parsers.model.MangaSource diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/domain/model/MangaUpdates.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/domain/model/MangaUpdates.kt index 6c6cda809..5d27a2f36 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/domain/model/MangaUpdates.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/domain/model/MangaUpdates.kt @@ -1,7 +1,7 @@ package org.koitharu.kotatsu.tracker.domain.model -import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.util.ext.ifZero +import org.koitharu.kotatsu.parsers.exception.TooManyRequestExceptions import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter