[RU]Remanga new authorization (#15479)

This commit is contained in:
Eshlender 2023-02-27 23:33:39 +05:00 committed by GitHub
parent ecd137d21a
commit 99106d21a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 17 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Remanga'
pkgNameSuffix = 'ru.remanga'
extClass = '.Remanga'
extVersionCode = 61
extVersionCode = 62
}
dependencies {

View File

@ -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<UserDto>(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<PageWrapperDto<LibraryDto>>(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"

View File

@ -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,
)