MDList support rating mangas
This commit is contained in:
parent
d7856fe351
commit
34f98a3cd4
@ -63,13 +63,13 @@ class MdList(private val context: Context, id: Int) : TrackService(id) {
|
||||
}
|
||||
}
|
||||
|
||||
/*if (track.score.toInt() > 0) {
|
||||
if (remoteTrack.score != track.score) {
|
||||
mdex.updateRating(track)
|
||||
}
|
||||
|
||||
// mangadex wont update chapters if manga is not follows this prevents unneeded network call
|
||||
|
||||
if (followStatus != FollowStatus.UNFOLLOWED) {
|
||||
/*if (followStatus != FollowStatus.UNFOLLOWED) {
|
||||
if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) {
|
||||
track.status = FollowStatus.COMPLETED.int
|
||||
mdex.updateFollowStatus(MdUtil.getMangaId(track.tracking_url), FollowStatus.COMPLETED)
|
||||
|
18
app/src/main/java/exh/md/dto/RatingDto.kt
Normal file
18
app/src/main/java/exh/md/dto/RatingDto.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package exh.md.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
data class RatingResponseDto(
|
||||
val ratings: JsonElement
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class PersonalRatingDto(
|
||||
val rating: Int,
|
||||
val createdAt: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class RatingDto(val rating: Int)
|
@ -7,10 +7,12 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.md.dto.MangaDataDto
|
||||
import exh.md.dto.PersonalRatingDto
|
||||
import exh.md.dto.ReadingStatusDto
|
||||
import exh.md.service.MangaDexAuthService
|
||||
import exh.md.utils.FollowStatus
|
||||
import exh.md.utils.MdUtil
|
||||
import exh.md.utils.asMdMap
|
||||
import exh.md.utils.mdListCall
|
||||
import exh.metadata.metadata.MangaDexSearchMetadata
|
||||
import exh.util.under
|
||||
@ -109,33 +111,21 @@ class FollowsHandler(
|
||||
}
|
||||
result.isSuccess
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
suspend fun updateRating(track: Track): Boolean {
|
||||
return true
|
||||
return withIOContext {
|
||||
val mangaID = getMangaId(track.tracking_url)
|
||||
val mangaId = MdUtil.getMangaId(track.tracking_url)
|
||||
val result = runCatching {
|
||||
client.newCall(
|
||||
GET(
|
||||
"$baseUrl/ajax/actions.ajax.php?function=manga_rating&id=$mangaID&rating=${track.score.toInt()}",
|
||||
headers
|
||||
)
|
||||
)
|
||||
.execute()
|
||||
}
|
||||
|
||||
result.exceptionOrNull()?.let {
|
||||
if (it is EOFException) {
|
||||
return@withIOContext true
|
||||
if (track.score == 0f) {
|
||||
service.deleteMangaRating(mangaId)
|
||||
} else {
|
||||
XLog.e("error updating rating", it)
|
||||
return@withIOContext false
|
||||
}
|
||||
service.updateMangaRating(mangaId, track.score.toInt())
|
||||
}.result == "ok"
|
||||
}
|
||||
result.isSuccess
|
||||
result.getOrDefault(false)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch all manga from all possible pages
|
||||
@ -157,11 +147,18 @@ class FollowsHandler(
|
||||
suspend fun fetchTrackingInfo(url: String): Track {
|
||||
return withIOContext {
|
||||
val mangaId = MdUtil.getMangaId(url)
|
||||
val followStatus = FollowStatus.fromDex(service.readingStatusForManga(mangaId).status)
|
||||
val followStatusDef = async {
|
||||
FollowStatus.fromDex(service.readingStatusForManga(mangaId).status)
|
||||
}
|
||||
val ratingDef = async {
|
||||
service.mangasRating(mangaId).ratings.asMdMap<PersonalRatingDto>()[mangaId]
|
||||
}
|
||||
val (followStatus, rating) = followStatusDef.await() to ratingDef.await()
|
||||
Track.create(TrackManager.MDLIST).apply {
|
||||
title = ""
|
||||
status = followStatus.int
|
||||
tracking_url = url
|
||||
score = rating?.rating?.toFloat() ?: 0F
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import exh.md.dto.LoginRequestDto
|
||||
import exh.md.dto.LoginResponseDto
|
||||
import exh.md.dto.LogoutDto
|
||||
import exh.md.dto.MangaListDto
|
||||
import exh.md.dto.RatingDto
|
||||
import exh.md.dto.RatingResponseDto
|
||||
import exh.md.dto.ReadChapterDto
|
||||
import exh.md.dto.ReadingStatusDto
|
||||
import exh.md.dto.ReadingStatusMapDto
|
||||
@ -22,6 +24,7 @@ import exh.md.utils.MdUtil
|
||||
import okhttp3.Authenticator
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
||||
@ -187,4 +190,44 @@ class MangaDexAuthService(
|
||||
.build()
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
}
|
||||
|
||||
suspend fun updateMangaRating(mangaId: String, rating: Int): ResultDto {
|
||||
return client.newCall(
|
||||
POST(
|
||||
"${MdApi.rating}/$mangaId",
|
||||
getHeaders(),
|
||||
body = MdUtil.encodeToBody(RatingDto(rating)),
|
||||
cache = CacheControl.FORCE_NETWORK
|
||||
)
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
}
|
||||
|
||||
suspend fun deleteMangaRating(mangaId: String): ResultDto {
|
||||
return client.newCall(
|
||||
Request.Builder()
|
||||
.delete()
|
||||
.url("${MdApi.rating}/$mangaId")
|
||||
.headers(getHeaders())
|
||||
.cacheControl(CacheControl.FORCE_NETWORK)
|
||||
.build()
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
}
|
||||
|
||||
suspend fun mangasRating(vararg mangaIds: String): RatingResponseDto {
|
||||
return client.newCall(
|
||||
GET(
|
||||
MdApi.rating.toHttpUrl()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
mangaIds.forEach {
|
||||
addQueryParameter("manga[]", it)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
.toString(),
|
||||
getHeaders(),
|
||||
cache = CacheControl.FORCE_NETWORK
|
||||
)
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ object MdApi {
|
||||
const val chapter = "$baseUrl/chapter"
|
||||
const val group = "$baseUrl/group"
|
||||
const val author = "$baseUrl/author"
|
||||
const val rating = "$baseUrl/rating"
|
||||
const val statistics = "$baseUrl/statistics/manga"
|
||||
const val chapterImageServer = "$baseUrl/at-home/server"
|
||||
const val userFollows = "$baseUrl/user/follows/manga"
|
||||
|
Loading…
x
Reference in New Issue
Block a user