mirror of
https://github.com/grimsi/gameyfin.git
synced 2026-02-06 11:27:07 +00:00
Refactor plugin config logic into Configurable
This commit is contained in:
parent
4230bf31cc
commit
75a5d5997a
@ -1,7 +1,7 @@
|
||||
package de.grimsi.gameyfin.core.plugins.config
|
||||
|
||||
import de.grimsi.gameyfin.core.plugins.management.GameyfinPluginManager
|
||||
import de.grimsi.gameyfin.pluginapi.core.GameyfinPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.core.Configurable
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigElement
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.springframework.stereotype.Service
|
||||
@ -23,7 +23,7 @@ class PluginConfigService(
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
if (plugin !is GameyfinPlugin) return emptyList()
|
||||
if (plugin !is Configurable) return emptyList()
|
||||
|
||||
return plugin.configMetadata
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package de.grimsi.gameyfin.core.plugins.management
|
||||
|
||||
import de.grimsi.gameyfin.core.plugins.config.PluginConfigRepository
|
||||
import de.grimsi.gameyfin.core.plugins.config.PluginConfigValidationResult
|
||||
import de.grimsi.gameyfin.pluginapi.core.GameyfinPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.core.Configurable
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.pf4j.*
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
@ -157,7 +157,7 @@ class GameyfinPluginManager(
|
||||
fun restart(pluginId: String) {
|
||||
val plugin = getPlugin(pluginId)?.plugin ?: return
|
||||
stopPlugin(pluginId)
|
||||
(plugin as GameyfinPlugin).loadConfig(getConfig(pluginId))
|
||||
if (plugin is Configurable) plugin.config = getConfig(pluginId)
|
||||
startPlugin(pluginId)
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ class GameyfinPluginManager(
|
||||
return PluginConfigValidationResult.UNKNWOWN
|
||||
}
|
||||
|
||||
if (plugin is GameyfinPlugin && plugin.validateConfig()) {
|
||||
if (plugin !is Configurable || plugin.validateConfig()) {
|
||||
return PluginConfigValidationResult.VALID
|
||||
}
|
||||
|
||||
@ -177,9 +177,9 @@ class GameyfinPluginManager(
|
||||
|
||||
private fun configurePlugin(pluginWrapper: PluginWrapper) {
|
||||
val plugin = pluginWrapper.plugin
|
||||
if (plugin is GameyfinPlugin) {
|
||||
if (plugin is Configurable) {
|
||||
val config = getConfig(pluginWrapper.pluginId)
|
||||
plugin.loadConfig(config)
|
||||
plugin.config = config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package de.grimsi.gameyfin.pluginapi.core
|
||||
|
||||
interface Configurable {
|
||||
val configMetadata: List<PluginConfigElement>
|
||||
var config: Map<String, String?>
|
||||
|
||||
fun validateConfig(): Boolean = validateConfig(config)
|
||||
fun validateConfig(config: Map<String, String?>): Boolean
|
||||
}
|
||||
@ -10,23 +10,6 @@ abstract class GameyfinPlugin(wrapper: PluginWrapper) : Plugin(wrapper) {
|
||||
val SUPPORTED_LOGO_FORMATS: List<String> = listOf("png", "jpg", "jpeg", "gif", "svg", "webp")
|
||||
}
|
||||
|
||||
abstract val configMetadata: List<PluginConfigElement>
|
||||
protected open var config: Map<String, String?> = emptyMap()
|
||||
|
||||
open fun getCurrentConfig(): Map<String, String?> {
|
||||
return config
|
||||
}
|
||||
|
||||
open fun loadConfig(config: Map<String, String?>) {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
open fun validateConfig(): Boolean {
|
||||
return validateConfig(config)
|
||||
}
|
||||
|
||||
abstract fun validateConfig(config: Map<String, String?>): Boolean
|
||||
|
||||
fun hasLogo(): Boolean {
|
||||
for (format in SUPPORTED_LOGO_FORMATS) {
|
||||
val resourcePath = "$LOGO_FILE_NAME.$format"
|
||||
|
||||
@ -5,6 +5,7 @@ import com.api.igdb.exceptions.RequestException
|
||||
import com.api.igdb.request.IGDBWrapper
|
||||
import com.api.igdb.request.TwitchAuthenticator
|
||||
import com.api.igdb.request.games
|
||||
import de.grimsi.gameyfin.pluginapi.core.Configurable
|
||||
import de.grimsi.gameyfin.pluginapi.core.GameyfinPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigElement
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigError
|
||||
@ -18,12 +19,22 @@ import proto.Game
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class IgdbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
|
||||
class IgdbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper), Configurable {
|
||||
|
||||
override val configMetadata: List<PluginConfigElement> = listOf(
|
||||
PluginConfigElement("clientId", "Twitch client ID", "Your Twitch Client ID"),
|
||||
PluginConfigElement("clientSecret", "Twitch client secret", "Your Twitch Client Secret", true)
|
||||
override val configMetadata = listOf(
|
||||
PluginConfigElement(
|
||||
key = "clientId",
|
||||
name = "Twitch client ID",
|
||||
description = "Your Twitch Client ID"
|
||||
),
|
||||
PluginConfigElement(
|
||||
key = "clientSecret",
|
||||
name = "Twitch client secret",
|
||||
description = "Your Twitch Client Secret",
|
||||
isSecret = true
|
||||
)
|
||||
)
|
||||
override var config: Map<String, String?> = emptyMap()
|
||||
|
||||
override fun validateConfig(config: Map<String, String?>): Boolean {
|
||||
try {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package de.grimsi.gameyfin.plugins.steam
|
||||
|
||||
import de.grimsi.gameyfin.pluginapi.core.GameyfinPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigElement
|
||||
import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadata
|
||||
import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadataProvider
|
||||
import de.grimsi.gameyfin.plugins.steam.dto.SteamDetailsResultWrapper
|
||||
@ -36,13 +35,6 @@ class SteamPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
|
||||
}
|
||||
}
|
||||
|
||||
override val configMetadata: List<PluginConfigElement> = emptyList()
|
||||
|
||||
override fun validateConfig(config: Map<String, String?>): Boolean {
|
||||
// No config to validate
|
||||
return true
|
||||
}
|
||||
|
||||
@Extension
|
||||
class SteamMetadataProvider : GameMetadataProvider {
|
||||
val log: Logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.grimsi.gameyfin.plugins.steamgriddb
|
||||
|
||||
import de.grimsi.gameyfin.pluginapi.core.Configurable
|
||||
import de.grimsi.gameyfin.pluginapi.core.GameyfinPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigElement
|
||||
import de.grimsi.gameyfin.pluginapi.core.PluginConfigError
|
||||
@ -15,7 +16,7 @@ import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.net.URI
|
||||
|
||||
class SteamGridDbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
|
||||
class SteamGridDbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper), Configurable {
|
||||
|
||||
companion object {
|
||||
private var client: SteamGridDbApiClient? = null
|
||||
@ -24,8 +25,14 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
|
||||
val log: Logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
override val configMetadata: List<PluginConfigElement> = listOf(
|
||||
PluginConfigElement("apiKey", "SteamGridDB API key", "Your SteamGridDB API key", true)
|
||||
PluginConfigElement(
|
||||
key = "apiKey",
|
||||
name = "SteamGridDB API key",
|
||||
description = "Your SteamGridDB API key",
|
||||
isSecret = true
|
||||
)
|
||||
)
|
||||
override var config: Map<String, String?> = emptyMap()
|
||||
|
||||
override fun validateConfig(config: Map<String, String?>): Boolean {
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user