mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
use chapter_number instead of ordinal index for syncChaptersWithTrackServiceTwoWay
use v2 api for Komga tracker for series Co-Authored-By: Gauthier <2139133+gotson@users.noreply.github.com>
This commit is contained in:
parent
b172b979ea
commit
68e3a832b6
2 changed files with 43 additions and 14 deletions
|
@ -38,20 +38,22 @@ class KomgaApi(private val client: OkHttpClient) {
|
|||
}
|
||||
|
||||
val progress = client
|
||||
.newCall(GET("$url/read-progress/tachiyomi"))
|
||||
.await()
|
||||
.parseAs<ReadProgressDto>()
|
||||
.newCall(GET("${url.replace("/api/v1/series/", "/api/v2/series/")}/read-progress/tachiyomi"))
|
||||
.await().let {
|
||||
if (url.contains("/api/v1/series/")) it.parseAs<ReadProgressV2Dto>()
|
||||
else it.parseAs<ReadProgressDto>().toV2()
|
||||
}
|
||||
|
||||
track.apply {
|
||||
cover_url = "$url/thumbnail"
|
||||
tracking_url = url
|
||||
total_chapters = progress.booksCount
|
||||
total_chapters = progress.maxNumberSort.toInt()
|
||||
status = when (progress.booksCount) {
|
||||
progress.booksUnreadCount -> Komga.UNREAD
|
||||
progress.booksReadCount -> Komga.COMPLETED
|
||||
else -> Komga.READING
|
||||
}
|
||||
last_chapter_read = progress.lastReadContinuousIndex.toFloat()
|
||||
last_chapter_read = progress.lastReadContinuousNumberSort
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e, "Could not get item: $url")
|
||||
|
@ -60,13 +62,16 @@ class KomgaApi(private val client: OkHttpClient) {
|
|||
}
|
||||
|
||||
suspend fun updateProgress(track: Track): Track {
|
||||
val progress = ReadProgressUpdateDto(track.last_chapter_read.toInt())
|
||||
val payload = json.encodeToString(progress)
|
||||
val payload = if (track.tracking_url.contains("/api/v1/series/")) {
|
||||
json.encodeToString(ReadProgressUpdateV2Dto(track.last_chapter_read))
|
||||
} else {
|
||||
json.encodeToString(ReadProgressUpdateDto(track.last_chapter_read.toInt()))
|
||||
}
|
||||
client.newCall(
|
||||
Request.Builder()
|
||||
.url("${track.tracking_url}/read-progress/tachiyomi")
|
||||
.url("${track.tracking_url.replace("/api/v1/series/", "/api/v2/series/")}/read-progress/tachiyomi")
|
||||
.put(payload.toRequestBody("application/json".toMediaType()))
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
.await()
|
||||
return getTrackSearch(track.tracking_url)
|
||||
|
|
|
@ -15,7 +15,7 @@ data class SeriesDto(
|
|||
val booksUnreadCount: Int,
|
||||
val booksInProgressCount: Int,
|
||||
val metadata: SeriesMetadataDto,
|
||||
val booksMetadata: BookMetadataAggregationDto
|
||||
val booksMetadata: BookMetadataAggregationDto,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -38,7 +38,7 @@ data class SeriesMetadataDto(
|
|||
val genres: Set<String>,
|
||||
val genresLock: Boolean,
|
||||
val tags: Set<String>,
|
||||
val tagsLock: Boolean
|
||||
val tagsLock: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -49,13 +49,13 @@ data class BookMetadataAggregationDto(
|
|||
val summaryNumber: String,
|
||||
|
||||
val created: String,
|
||||
val lastModified: String
|
||||
val lastModified: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class AuthorDto(
|
||||
val name: String,
|
||||
val role: String
|
||||
val role: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -63,6 +63,11 @@ data class ReadProgressUpdateDto(
|
|||
val lastBookRead: Int,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ReadProgressUpdateV2Dto(
|
||||
val lastBookNumberSortRead: Float,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ReadListDto(
|
||||
val id: String,
|
||||
|
@ -70,7 +75,7 @@ data class ReadListDto(
|
|||
val bookIds: List<String>,
|
||||
val createdDate: String,
|
||||
val lastModifiedDate: String,
|
||||
val filtered: Boolean
|
||||
val filtered: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -80,4 +85,23 @@ data class ReadProgressDto(
|
|||
val booksUnreadCount: Int,
|
||||
val booksInProgressCount: Int,
|
||||
val lastReadContinuousIndex: Int,
|
||||
) {
|
||||
fun toV2() = ReadProgressV2Dto(
|
||||
booksCount,
|
||||
booksReadCount,
|
||||
booksUnreadCount,
|
||||
booksInProgressCount,
|
||||
lastReadContinuousIndex.toFloat(),
|
||||
booksCount.toFloat(),
|
||||
)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ReadProgressV2Dto(
|
||||
val booksCount: Int,
|
||||
val booksReadCount: Int,
|
||||
val booksUnreadCount: Int,
|
||||
val booksInProgressCount: Int,
|
||||
val lastReadContinuousNumberSort: Float,
|
||||
val maxNumberSort: Float,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue