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)
|
mdex.updateRating(track)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mangadex wont update chapters if manga is not follows this prevents unneeded network call
|
// 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) {
|
if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) {
|
||||||
track.status = FollowStatus.COMPLETED.int
|
track.status = FollowStatus.COMPLETED.int
|
||||||
mdex.updateFollowStatus(MdUtil.getMangaId(track.tracking_url), FollowStatus.COMPLETED)
|
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.source.model.toSManga
|
||||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
import exh.md.dto.MangaDataDto
|
import exh.md.dto.MangaDataDto
|
||||||
|
import exh.md.dto.PersonalRatingDto
|
||||||
import exh.md.dto.ReadingStatusDto
|
import exh.md.dto.ReadingStatusDto
|
||||||
import exh.md.service.MangaDexAuthService
|
import exh.md.service.MangaDexAuthService
|
||||||
import exh.md.utils.FollowStatus
|
import exh.md.utils.FollowStatus
|
||||||
import exh.md.utils.MdUtil
|
import exh.md.utils.MdUtil
|
||||||
|
import exh.md.utils.asMdMap
|
||||||
import exh.md.utils.mdListCall
|
import exh.md.utils.mdListCall
|
||||||
import exh.metadata.metadata.MangaDexSearchMetadata
|
import exh.metadata.metadata.MangaDexSearchMetadata
|
||||||
import exh.util.under
|
import exh.util.under
|
||||||
@ -109,33 +111,21 @@ class FollowsHandler(
|
|||||||
}
|
}
|
||||||
result.isSuccess
|
result.isSuccess
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
suspend fun updateRating(track: Track): Boolean {
|
suspend fun updateRating(track: Track): Boolean {
|
||||||
return true
|
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val mangaID = getMangaId(track.tracking_url)
|
val mangaId = MdUtil.getMangaId(track.tracking_url)
|
||||||
val result = runCatching {
|
val result = runCatching {
|
||||||
client.newCall(
|
if (track.score == 0f) {
|
||||||
GET(
|
service.deleteMangaRating(mangaId)
|
||||||
"$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
|
|
||||||
} else {
|
} else {
|
||||||
XLog.e("error updating rating", it)
|
service.updateMangaRating(mangaId, track.score.toInt())
|
||||||
return@withIOContext false
|
}.result == "ok"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result.isSuccess
|
result.getOrDefault(false)
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetch all manga from all possible pages
|
* fetch all manga from all possible pages
|
||||||
@ -157,11 +147,18 @@ class FollowsHandler(
|
|||||||
suspend fun fetchTrackingInfo(url: String): Track {
|
suspend fun fetchTrackingInfo(url: String): Track {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val mangaId = MdUtil.getMangaId(url)
|
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 {
|
Track.create(TrackManager.MDLIST).apply {
|
||||||
title = ""
|
title = ""
|
||||||
status = followStatus.int
|
status = followStatus.int
|
||||||
tracking_url = url
|
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.LoginResponseDto
|
||||||
import exh.md.dto.LogoutDto
|
import exh.md.dto.LogoutDto
|
||||||
import exh.md.dto.MangaListDto
|
import exh.md.dto.MangaListDto
|
||||||
|
import exh.md.dto.RatingDto
|
||||||
|
import exh.md.dto.RatingResponseDto
|
||||||
import exh.md.dto.ReadChapterDto
|
import exh.md.dto.ReadChapterDto
|
||||||
import exh.md.dto.ReadingStatusDto
|
import exh.md.dto.ReadingStatusDto
|
||||||
import exh.md.dto.ReadingStatusMapDto
|
import exh.md.dto.ReadingStatusMapDto
|
||||||
@ -22,6 +24,7 @@ import exh.md.utils.MdUtil
|
|||||||
import okhttp3.Authenticator
|
import okhttp3.Authenticator
|
||||||
import okhttp3.CacheControl
|
import okhttp3.CacheControl
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
|
||||||
@ -187,4 +190,44 @@ class MangaDexAuthService(
|
|||||||
.build()
|
.build()
|
||||||
).await().parseAs(MdUtil.jsonParser)
|
).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 chapter = "$baseUrl/chapter"
|
||||||
const val group = "$baseUrl/group"
|
const val group = "$baseUrl/group"
|
||||||
const val author = "$baseUrl/author"
|
const val author = "$baseUrl/author"
|
||||||
|
const val rating = "$baseUrl/rating"
|
||||||
const val statistics = "$baseUrl/statistics/manga"
|
const val statistics = "$baseUrl/statistics/manga"
|
||||||
const val chapterImageServer = "$baseUrl/at-home/server"
|
const val chapterImageServer = "$baseUrl/at-home/server"
|
||||||
const val userFollows = "$baseUrl/user/follows/manga"
|
const val userFollows = "$baseUrl/user/follows/manga"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user