mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Improve Tracker Icons Implementation (#836)
* Improve tracker icons implementation * Fix description
This commit is contained in:
@@ -8,6 +8,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Edge
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Node
|
||||
import suwayomi.tachidesk.graphql.server.primitives.NodeList
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.manga.impl.track.Track
|
||||
import suwayomi.tachidesk.manga.impl.track.tracker.Tracker
|
||||
import suwayomi.tachidesk.manga.model.table.TrackRecordTable
|
||||
import suwayomi.tachidesk.manga.model.table.TrackSearchTable
|
||||
@@ -28,7 +29,7 @@ class TrackerType(
|
||||
constructor(isLoggedIn: Boolean, tracker: Tracker) : this(
|
||||
tracker.id,
|
||||
tracker.name,
|
||||
tracker.getLogo(),
|
||||
Track.proxyThumbnailUrl(tracker.id),
|
||||
isLoggedIn,
|
||||
if (isLoggedIn) {
|
||||
null
|
||||
|
||||
@@ -141,6 +141,7 @@ object MangaAPI {
|
||||
post("search", TrackController.search)
|
||||
post("bind", TrackController.bind)
|
||||
post("update", TrackController.update)
|
||||
get("{trackerId}/thumbnail", TrackController.thumbnail)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ import suwayomi.tachidesk.manga.impl.track.Track
|
||||
import suwayomi.tachidesk.manga.model.dataclass.TrackerDataClass
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import suwayomi.tachidesk.server.util.handler
|
||||
import suwayomi.tachidesk.server.util.pathParam
|
||||
import suwayomi.tachidesk.server.util.queryParam
|
||||
import suwayomi.tachidesk.server.util.withOperation
|
||||
import kotlin.time.Duration.Companion.days
|
||||
|
||||
object TrackController {
|
||||
private val json by DI.global.instance<Json>()
|
||||
@@ -136,4 +138,30 @@ object TrackController {
|
||||
httpCode(HttpCode.OK)
|
||||
},
|
||||
)
|
||||
|
||||
val thumbnail =
|
||||
handler(
|
||||
pathParam<Int>("trackerId"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Get a tracker thumbnail")
|
||||
description("Get a tracker thumbnail from the resources.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, trackerId ->
|
||||
ctx.future(
|
||||
future { Track.getTrackerThumbnail(trackerId) }
|
||||
.thenApply {
|
||||
ctx.header("content-type", it.second)
|
||||
val httpCacheSeconds = 1.days.inWholeSeconds
|
||||
ctx.header("cache-control", "max-age=$httpCacheSeconds")
|
||||
it.first
|
||||
},
|
||||
)
|
||||
},
|
||||
withResults = {
|
||||
image(HttpCode.OK)
|
||||
httpCode(HttpCode.NOT_FOUND)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.TrackRecordTable
|
||||
import suwayomi.tachidesk.manga.model.table.TrackSearchTable
|
||||
import suwayomi.tachidesk.manga.model.table.insertAll
|
||||
import suwayomi.tachidesk.server.generated.BuildConfig
|
||||
import java.io.InputStream
|
||||
|
||||
object Track {
|
||||
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
@@ -39,7 +41,7 @@ object Track {
|
||||
TrackerDataClass(
|
||||
id = it.id,
|
||||
name = it.name,
|
||||
icon = it.getLogo(),
|
||||
icon = proxyThumbnailUrl(it.id),
|
||||
isLogin = isLogin,
|
||||
authUrl = authUrl,
|
||||
)
|
||||
@@ -60,6 +62,16 @@ object Track {
|
||||
tracker.logout()
|
||||
}
|
||||
|
||||
fun proxyThumbnailUrl(trackerId: Int): String {
|
||||
return "/api/v1/track/$trackerId/thumbnail"
|
||||
}
|
||||
|
||||
fun getTrackerThumbnail(trackerId: Int): Pair<InputStream, String> {
|
||||
val tracker = TrackerManager.getTracker(trackerId)!!
|
||||
val logo = BuildConfig::class.java.getResourceAsStream(tracker.getLogo())!!
|
||||
return logo to "image/png"
|
||||
}
|
||||
|
||||
fun getTrackRecordsByMangaId(mangaId: Int): List<MangaTrackerDataClass> {
|
||||
if (!TrackerManager.hasLoggedTracker()) {
|
||||
return emptyList()
|
||||
@@ -85,7 +97,7 @@ object Track {
|
||||
MangaTrackerDataClass(
|
||||
id = it.id,
|
||||
name = it.name,
|
||||
icon = it.getLogo(),
|
||||
icon = proxyThumbnailUrl(it.id),
|
||||
statusList = it.getStatusList(),
|
||||
statusTextMap = it.getStatusList().associateWith { k -> it.getStatus(k) ?: "" },
|
||||
scoreList = it.getScoreList(),
|
||||
|
||||
@@ -7,7 +7,7 @@ import suwayomi.tachidesk.manga.impl.track.tracker.model.TrackSearch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
abstract class Tracker(val id: Int, val name: String) {
|
||||
val trackPreferences = TrackerPreferences()
|
||||
val trackPreferences = TrackerPreferences
|
||||
private val networkService: NetworkHelper by injectLazy()
|
||||
|
||||
open val client: OkHttpClient
|
||||
|
||||
@@ -7,7 +7,7 @@ import suwayomi.tachidesk.manga.impl.track.tracker.anilist.Anilist
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class TrackerPreferences {
|
||||
object TrackerPreferences {
|
||||
private val preferenceStore =
|
||||
Injekt.get<Application>().getSharedPreferences("tracker", Context.MODE_PRIVATE)
|
||||
private val logger = KotlinLogging.logger {}
|
||||
@@ -57,13 +57,11 @@ class TrackerPreferences {
|
||||
|
||||
fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true)
|
||||
|
||||
companion object {
|
||||
fun trackUsername(trackerId: Int) = "pref_mangasync_username_$trackerId"
|
||||
fun trackUsername(trackerId: Int) = "pref_mangasync_username_$trackerId"
|
||||
|
||||
private fun trackPassword(trackerId: Int) = "pref_mangasync_password_$trackerId"
|
||||
private fun trackPassword(trackerId: Int) = "pref_mangasync_password_$trackerId"
|
||||
|
||||
private fun trackToken(trackerId: Int) = "track_token_$trackerId"
|
||||
private fun trackToken(trackerId: Int) = "track_token_$trackerId"
|
||||
|
||||
private fun scoreType(trackerId: Int) = "score_type_$trackerId"
|
||||
}
|
||||
private fun scoreType(trackerId: Int) = "score_type_$trackerId"
|
||||
}
|
||||
|
||||
@@ -91,13 +91,6 @@ object JavalinSetup {
|
||||
|
||||
config.server { server }
|
||||
|
||||
config.addStaticFiles { staticFiles ->
|
||||
staticFiles.hostedPath = "/static"
|
||||
staticFiles.directory = "/static"
|
||||
staticFiles.location = Location.CLASSPATH
|
||||
staticFiles.headers = mapOf("cache-control" to "max-age=86400")
|
||||
}
|
||||
|
||||
config.enableCorsForAllOrigins()
|
||||
|
||||
config.accessManager { handler, ctx, _ ->
|
||||
|
||||
Reference in New Issue
Block a user