Fix HTTP error 400 in HN. (#13096)
This commit is contained in:
parent
05070ea80b
commit
1ad891e202
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'HQ Now!'
|
||||
pkgNameSuffix = 'pt.hqnow'
|
||||
extClass = '.HQNow'
|
||||
extVersionCode = 6
|
||||
extVersionCode = 7
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -11,12 +11,12 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.put
|
||||
import kotlinx.serialization.json.putJsonObject
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
@ -32,7 +32,7 @@ class HQNow : HttpSource() {
|
||||
|
||||
override val name = "HQ Now!"
|
||||
|
||||
override val baseUrl = "http://www.hq-now.com"
|
||||
override val baseUrl = "https://www.hq-now.com"
|
||||
|
||||
override val lang = "pt-BR"
|
||||
|
||||
@ -79,24 +79,15 @@ class HQNow : HttpSource() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", "getHqsByFilters")
|
||||
put("query", query)
|
||||
putJsonObject("variables") {
|
||||
return queryRequest(
|
||||
query = query,
|
||||
operationName = "getHqsByFilters",
|
||||
variables = buildJsonObject {
|
||||
put("orderByViews", true)
|
||||
put("loadCovers", true)
|
||||
put("limit", 300)
|
||||
}
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
)
|
||||
}
|
||||
|
||||
override fun popularMangaParse(response: Response): MangasPage {
|
||||
@ -125,19 +116,7 @@ class HQNow : HttpSource() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", "getRecentlyUpdatedHqs")
|
||||
put("query", query)
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
return queryRequest(query = query, operationName = "getRecentlyUpdatedHqs")
|
||||
}
|
||||
|
||||
override fun latestUpdatesParse(response: Response): MangasPage {
|
||||
@ -166,22 +145,13 @@ class HQNow : HttpSource() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", "getHqsByName")
|
||||
put("query", queryStr)
|
||||
putJsonObject("variables") {
|
||||
return queryRequest(
|
||||
query = queryStr,
|
||||
operationName = "getHqsByName",
|
||||
variables = buildJsonObject {
|
||||
put("name", query)
|
||||
}
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
)
|
||||
}
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
@ -228,22 +198,13 @@ class HQNow : HttpSource() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", "getHqsById")
|
||||
put("query", query)
|
||||
putJsonObject("variables") {
|
||||
return queryRequest(
|
||||
query = query,
|
||||
operationName = "getHqsById",
|
||||
variables = buildJsonObject {
|
||||
put("id", comicBookId.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
)
|
||||
}
|
||||
|
||||
override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply {
|
||||
@ -298,22 +259,13 @@ class HQNow : HttpSource() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", "getChapterById")
|
||||
put("query", query)
|
||||
putJsonObject("variables") {
|
||||
return queryRequest(
|
||||
query = query,
|
||||
operationName = "getChapterById",
|
||||
variables = buildJsonObject {
|
||||
put("chapterId", chapterId.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
)
|
||||
}
|
||||
|
||||
override fun pageListParse(response: Response): List<Page> {
|
||||
@ -339,6 +291,23 @@ class HQNow : HttpSource() {
|
||||
|
||||
private fun buildQuery(queryAction: () -> String) = queryAction().replace("%", "$")
|
||||
|
||||
private fun queryRequest(query: String, operationName: String, variables: JsonObject? = null): Request {
|
||||
val payload = buildJsonObject {
|
||||
put("operationName", operationName)
|
||||
put("query", query)
|
||||
variables?.let { put("variables", it) }
|
||||
}
|
||||
|
||||
val body = payload.toString().toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
.add("Content-Length", body.contentLength().toString())
|
||||
.add("Content-Type", body.contentType().toString())
|
||||
.build()
|
||||
|
||||
return POST(GRAPHQL_URL, newHeaders, body)
|
||||
}
|
||||
|
||||
private fun String.toSlug(): String {
|
||||
return Normalizer
|
||||
.normalize(this, Normalizer.Form.NFD)
|
||||
@ -355,8 +324,8 @@ class HQNow : HttpSource() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val STATIC_URL = "http://static.hq-now.com/"
|
||||
private const val GRAPHQL_URL = "http://admin.hq-now.com/graphql"
|
||||
private const val STATIC_URL = "https://static.hq-now.com/"
|
||||
private const val GRAPHQL_URL = "https://admin.hq-now.com/graphql"
|
||||
|
||||
private val JSON_MEDIA_TYPE = "application/json; charset=utf-8".toMediaTypeOrNull()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user