From 99106d21a9bc1fc2ef84a08eb3bc99873b040f99 Mon Sep 17 00:00:00 2001 From: Eshlender <35057681+e-shl@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:33:39 +0500 Subject: [PATCH] [RU]Remanga new authorization (#15479) --- src/ru/remanga/build.gradle | 2 +- .../tachiyomi/extension/ru/remanga/Remanga.kt | 24 ++++++++----------- .../tachiyomi/extension/ru/remanga/dto/Dto.kt | 3 +-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/ru/remanga/build.gradle b/src/ru/remanga/build.gradle index 9947cb2dd..522c8f8e1 100644 --- a/src/ru/remanga/build.gradle +++ b/src/ru/remanga/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Remanga' pkgNameSuffix = 'ru.remanga' extClass = '.Remanga' - extVersionCode = 61 + extVersionCode = 62 } dependencies { diff --git a/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/Remanga.kt b/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/Remanga.kt index d3db5fc69..9b14b81d3 100644 --- a/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/Remanga.kt +++ b/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/Remanga.kt @@ -48,7 +48,6 @@ import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -import java.io.IOException import java.net.URLDecoder import java.text.SimpleDateFormat import java.util.Date @@ -88,18 +87,20 @@ class Remanga : ConfigurableSource, HttpSource() { val cookies = client.cookieJar.loadForRequest(baseUrl.replace("api.", "").toHttpUrl()) val authCookie = cookies - .firstOrNull { cookie -> cookie.name == USER_COOKIE_NAME } + .firstOrNull { cookie -> cookie.name == "user" } ?.let { cookie -> URLDecoder.decode(cookie.value, "UTF-8") } ?.let { jsonString -> json.decodeFromString(jsonString) } ?: return chain.proceed(request) - if (authCookie.access_token == null) { - throw IOException("Авторизация слетела. Очистите cookies и переавторизуйтесь.") - } + val access_token = cookies + .firstOrNull { cookie -> cookie.name == "token" } + ?.let { cookie -> URLDecoder.decode(cookie.value, "UTF-8") } + ?: return chain.proceed(request) USER_ID = authCookie.id.toString() + val authRequest = request.newBuilder() - .addHeader("Authorization", "bearer ${authCookie.access_token}") + .addHeader("Authorization", "bearer $access_token") .build() return chain.proceed(authRequest) } @@ -143,7 +144,7 @@ class Remanga : ConfigurableSource, HttpSource() { it.title.toSManga() } - return MangasPage(mangas, page.props.page < page.props.total_pages) + return MangasPage(mangas, true) } else { val page = json.decodeFromString>(response.body.string()) var content = page.content @@ -155,7 +156,7 @@ class Remanga : ConfigurableSource, HttpSource() { it.toSManga() } - if (mangas.isEmpty() && page.props.page < page.props.total_pages && preferences.getBoolean(isLib_PREF, false)) { + if (mangas.isEmpty() && page.props.page < page.props.total_pages!! && preferences.getBoolean(isLib_PREF, false)) { mangas = listOf( SManga.create().apply { val nextPage = "Пустая страница. Всё в «Закладках»" @@ -165,7 +166,7 @@ class Remanga : ConfigurableSource, HttpSource() { }, ) } - return MangasPage(mangas, page.props.page < page.props.total_pages) + return MangasPage(mangas, page.props.page < page.props.total_pages!!) } } @@ -223,9 +224,6 @@ class Remanga : ConfigurableSource, HttpSource() { } is AgeList -> filter.state.forEach { age -> if (age.state) { - if ((age.id == "2") and (USER_ID == "")) { - throw Exception("Для просмотра 18+ контента необходима авторизация через WebView") - } url.addQueryParameter("age_limit", age.id) } } @@ -763,8 +761,6 @@ class Remanga : ConfigurableSource, HttpSource() { companion object { private var USER_ID = "" - private const val USER_COOKIE_NAME = "user" - const val PREFIX_SLUG_SEARCH = "slug:" private const val DOMAIN_PREF = "REMangaDomain" diff --git a/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/dto/Dto.kt b/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/dto/Dto.kt index 9525771af..1df9fbbb1 100644 --- a/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/dto/Dto.kt +++ b/src/ru/remanga/src/eu/kanade/tachiyomi/extension/ru/remanga/dto/Dto.kt @@ -64,7 +64,7 @@ data class MangaDetDto( @Serializable data class PropsDto( - val total_pages: Int, + val total_pages: Int? = 0, val page: Int, ) @@ -117,5 +117,4 @@ data class ChunksPageDto( @Serializable data class UserDto( val id: Long, - val access_token: String? = null, )