Change Track.bind to use trackerId + remoteId (#842)

This commit is contained in:
Mitchell Syer
2024-01-22 21:35:56 -05:00
committed by GitHub
parent b9053e3057
commit 4bec027f11
4 changed files with 23 additions and 18 deletions

View File

@@ -8,7 +8,6 @@ import suwayomi.tachidesk.graphql.types.TrackerType
import suwayomi.tachidesk.manga.impl.track.Track import suwayomi.tachidesk.manga.impl.track.Track
import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager
import suwayomi.tachidesk.manga.model.table.TrackRecordTable import suwayomi.tachidesk.manga.model.table.TrackRecordTable
import suwayomi.tachidesk.manga.model.table.TrackSearchTable
import suwayomi.tachidesk.server.JavalinSetup.future import suwayomi.tachidesk.server.JavalinSetup.future
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
@@ -103,7 +102,8 @@ class TrackMutation {
data class BindTrackInput( data class BindTrackInput(
val clientMutationId: String? = null, val clientMutationId: String? = null,
val mangaId: Int, val mangaId: Int,
val trackSearchId: Int, val trackerId: Int,
val remoteId: Long,
) )
data class BindTrackPayload( data class BindTrackPayload(
@@ -112,18 +112,16 @@ class TrackMutation {
) )
fun bindTrack(input: BindTrackInput): CompletableFuture<BindTrackPayload> { fun bindTrack(input: BindTrackInput): CompletableFuture<BindTrackPayload> {
val (clientMutationId, mangaId, trackSearchId) = input val (clientMutationId, mangaId, trackerId, remoteId) = input
return future { return future {
Track.bind( Track.bind(
mangaId, mangaId,
trackSearchId, trackerId,
remoteId,
) )
val trackRecord = val trackRecord =
transaction { transaction {
val trackerId =
TrackSearchTable.select { TrackSearchTable.id eq trackSearchId }
.first()[TrackSearchTable.trackerId]
TrackRecordTable.select { TrackRecordTable.select {
TrackRecordTable.mangaId eq mangaId and (TrackRecordTable.trackerId eq trackerId) TrackRecordTable.mangaId eq mangaId and (TrackRecordTable.trackerId eq trackerId)
}.first() }.first()

View File

@@ -105,15 +105,16 @@ object TrackController {
val bind = val bind =
handler( handler(
queryParam<Int>("mangaId"), queryParam<Int>("mangaId"),
queryParam<Int>("trackSearchId"), queryParam<Int>("trackerId"),
queryParam<String>("remoteId"),
documentWith = { documentWith = {
withOperation { withOperation {
summary("Track Record Bind") summary("Track Record Bind")
description("Bind a Track Record to a Manga") description("Bind a Track Record to a Manga")
} }
}, },
behaviorOf = { ctx, mangaId, trackSearchId -> behaviorOf = { ctx, mangaId, trackerId, remoteId ->
ctx.future(future { Track.bind(mangaId, trackSearchId) }) ctx.future(future { Track.bind(mangaId, trackerId, remoteId.toLong()) })
}, },
withResults = { withResults = {
httpCode(HttpCode.OK) httpCode(HttpCode.OK)

View File

@@ -50,7 +50,6 @@ import suwayomi.tachidesk.server.serverConfig
import java.time.Instant import java.time.Instant
import java.util.TreeSet import java.util.TreeSet
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.collections.listOf
import kotlin.math.max import kotlin.math.max
object Chapter { object Chapter {
@@ -140,6 +139,10 @@ object Chapter {
val numberOfCurrentChapters = getCountOfMangaChapters(mangaId) val numberOfCurrentChapters = getCountOfMangaChapters(mangaId)
val chapterList = source.getChapterList(sManga) val chapterList = source.getChapterList(sManga)
if (chapterList.isEmpty()) {
throw Exception("No chapters found")
}
// Recognize number for new chapters. // Recognize number for new chapters.
chapterList.forEach { chapter -> chapterList.forEach { chapter ->
(source as? HttpSource)?.prepareNewChapter(chapter, sManga) (source as? HttpSource)?.prepareNewChapter(chapter, sManga)
@@ -346,7 +349,7 @@ object Chapter {
} }
if (mangaCategories.isNotEmpty()) { if (mangaCategories.isNotEmpty()) {
var downloadCategoriesMap = Category.getCategoryList().groupBy { it.includeInDownload } val downloadCategoriesMap = Category.getCategoryList().groupBy { it.includeInDownload }
val unsetCategories = downloadCategoriesMap[IncludeOrExclude.UNSET].orEmpty() val unsetCategories = downloadCategoriesMap[IncludeOrExclude.UNSET].orEmpty()
// We only download if it's in the include list, and not in the exclude list. // We only download if it's in the include list, and not in the exclude list.
// Use the unset categories as the included categories if the included categories is // Use the unset categories as the included categories if the included categories is
@@ -354,12 +357,12 @@ object Chapter {
val includedCategories = downloadCategoriesMap[IncludeOrExclude.INCLUDE].orEmpty().ifEmpty { unsetCategories } val includedCategories = downloadCategoriesMap[IncludeOrExclude.INCLUDE].orEmpty().ifEmpty { unsetCategories }
val excludedCategories = downloadCategoriesMap[IncludeOrExclude.EXCLUDE].orEmpty() val excludedCategories = downloadCategoriesMap[IncludeOrExclude.EXCLUDE].orEmpty()
// Only download manga that aren't in any excluded categories // Only download manga that aren't in any excluded categories
val mangaExcludeCategories = mangaCategories.intersect(excludedCategories) val mangaExcludeCategories = mangaCategories.intersect(excludedCategories.toSet())
if (mangaExcludeCategories.isNotEmpty()) { if (mangaExcludeCategories.isNotEmpty()) {
log.debug { "download excluded by categories: '${mangaExcludeCategories.joinToString("', '") { it.name }}'" } log.debug { "download excluded by categories: '${mangaExcludeCategories.joinToString("', '") { it.name }}'" }
return return
} }
val mangaDownloadCategories = mangaCategories.intersect(includedCategories) val mangaDownloadCategories = mangaCategories.intersect(includedCategories.toSet())
if (mangaDownloadCategories.isNotEmpty()) { if (mangaDownloadCategories.isNotEmpty()) {
log.debug { "download inluded by categories: '${mangaDownloadCategories.joinToString("', '") { it.name }}'" } log.debug { "download inluded by categories: '${mangaDownloadCategories.joinToString("', '") { it.name }}'" }
} else { } else {

View File

@@ -137,14 +137,17 @@ object Track {
suspend fun bind( suspend fun bind(
mangaId: Int, mangaId: Int,
trackSearchId: Int, trackerId: Int,
remoteId: Long,
) { ) {
val track = val track =
transaction { transaction {
TrackSearchTable.select { TrackSearchTable.id eq trackSearchId }.first() TrackSearchTable.select {
.toTrack(mangaId) TrackSearchTable.trackerId eq trackerId and
(TrackSearchTable.remoteId eq remoteId)
}.first().toTrack(mangaId)
} }
val tracker = TrackerManager.getTracker(track.sync_id)!! val tracker = TrackerManager.getTracker(trackerId)!!
val chapter = queryMaxReadChapter(mangaId) val chapter = queryMaxReadChapter(mangaId)
val hasReadChapters = chapter != null val hasReadChapters = chapter != null