add trackers support (#720)

* add trackers support

* Cleanup Tracker Code

* Add GraphQL support for Tracking

* Fix lint and deprecation errors

* remove password from logs

* Fixes after merge

* Disable tracking for now

* More disabled

---------

Co-authored-by: Syer10 <syer10@users.noreply.github.com>
This commit is contained in:
Tachimanga
2024-01-08 04:07:41 +08:00
committed by GitHub
parent 230427e758
commit 5a178ada74
44 changed files with 3726 additions and 10 deletions

View File

@@ -0,0 +1,142 @@
package suwayomi.tachidesk.manga.controller
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import io.javalin.http.HttpCode
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import suwayomi.tachidesk.manga.impl.track.Track
import suwayomi.tachidesk.manga.model.dataclass.TrackSearchDataClass
import suwayomi.tachidesk.manga.model.dataclass.TrackerDataClass
import suwayomi.tachidesk.server.JavalinSetup.future
import suwayomi.tachidesk.server.util.handler
import suwayomi.tachidesk.server.util.queryParam
import suwayomi.tachidesk.server.util.withOperation
object TrackController {
private val json by DI.global.instance<Json>()
private val logger = KotlinLogging.logger {}
val list =
handler(
documentWith = {
withOperation {
summary("List Supported Trackers")
description("List all supported Trackers")
}
},
behaviorOf = { ctx ->
ctx.json(Track.getTrackerList())
},
withResults = {
json<Array<TrackerDataClass>>(HttpCode.OK)
},
)
val login =
handler(
documentWith = {
withOperation {
summary("Tracker Login")
description("Login to a tracker")
}
body<Track.LoginInput>()
},
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.LoginInput>(ctx.body())
logger.debug { "tracker login $input" }
ctx.future(future { Track.login(input) })
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
},
)
val logout =
handler(
documentWith = {
withOperation {
summary("Tracker Logout")
description("Logout of a Tracker")
}
body<Track.LogoutInput>()
},
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.LogoutInput>(ctx.body())
logger.debug { "tracker logout $input" }
ctx.future(future { Track.logout(input) })
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
},
)
val search =
handler(
documentWith = {
withOperation {
summary("Tracker Search")
description("Search for a title on a tracker")
}
body<Track.SearchInput>()
},
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.SearchInput>(ctx.body())
logger.debug { "tracker search $input" }
ctx.future(future { Track.search(input) })
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
},
)
val bind =
handler(
queryParam<Int>("mangaId"),
documentWith = {
withOperation {
summary("Track Record Bind")
description("Bind a Track Record to a Manga")
}
body<TrackSearchDataClass>()
},
behaviorOf = { ctx, mangaId ->
val input = json.decodeFromString<TrackSearchDataClass>(ctx.body())
logger.debug { "tracker bind $input" }
ctx.future(future { Track.bind(mangaId, input) })
},
withResults = {
httpCode(HttpCode.OK)
},
)
val update =
handler(
documentWith = {
withOperation {
summary("Track Update")
description("Update a Track Record with the Tracker")
}
body<Track.UpdateInput>()
},
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.UpdateInput>(ctx.body())
logger.debug { "tracker update $input" }
ctx.future(future { Track.update(input) })
},
withResults = {
httpCode(HttpCode.OK)
},
)
}