Add chapter view count back to TaoSect. (#9432)

This commit is contained in:
Alessandro Jean 2021-10-12 07:32:53 -03:00 committed by GitHub
parent 258da29ffc
commit c60e0e7831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tao Sect'
pkgNameSuffix = 'pt.taosect'
extClass = '.TaoSect'
extVersionCode = 12
extVersionCode = 13
isNsfw = true
}

View File

@ -319,7 +319,7 @@ class TaoSect : HttpSource() {
val apiUrl = "$baseUrl/$API_BASE_PATH/capitulos/".toHttpUrl().newBuilder()
.addPathSegment(projectSlug)
.addPathSegment(chapterSlug)
.addQueryParameter("_fields", "paginas")
.addQueryParameter("_fields", "id_capitulo,paginas,post_id")
.toString()
return GET(apiUrl, apiHeaders)
@ -342,6 +342,10 @@ class TaoSect : HttpSource() {
Page(i, chapterUrl, pageUrl)
}
// Count the project and chapter views, requested by the scanlator.
val countViewRequest = countProjectViewRequest(result.projectId!!, result.id)
runCatching { client.newCall(countViewRequest).execute().close() }
// Check if the pages have exceeded the view limit of Google Drive.
val firstPage = pages[0]
@ -373,11 +377,16 @@ class TaoSect : HttpSource() {
return GET(page.imageUrl!!, newHeaders)
}
private fun countProjectViewRequest(projectId: String): Request {
val formBody = FormBody.Builder()
private fun countProjectViewRequest(projectId: String, chapterId: String? = null): Request {
val formBodyBuilder = FormBody.Builder()
.add("action", "update_views_v2")
.add("projeto", projectId)
.build()
if (chapterId != null) {
formBodyBuilder.add("capitulo", chapterId)
}
val formBody = formBodyBuilder.build()
val newHeaders = headersBuilder()
.add("Content-Length", formBody.contentLength().toString())