mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-10 06:14:35 -05:00
Feature/graphql server settings (#629)
* Add "uiName" to WebUI enum * Add "Custom" WebUI to enum * Rename "WebUI" enum to "WebUIFlavor" * Add "WebUIInterface" enum * Add query for server settings * Add mutation for server settings * Add mutation to reset the server settings * Only update the config in case the value changed In case the value of the config is already the same as the new value of the state flow, it is not necessary to update the config file
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import suwayomi.tachidesk.graphql.types.PartialSettingsType
|
||||
import suwayomi.tachidesk.graphql.types.Settings
|
||||
import suwayomi.tachidesk.graphql.types.SettingsType
|
||||
import suwayomi.tachidesk.server.SERVER_CONFIG_MODULE_NAME
|
||||
import suwayomi.tachidesk.server.ServerConfig
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import xyz.nulldev.ts.config.GlobalConfigManager
|
||||
|
||||
class SettingsMutation {
|
||||
data class SetSettingsInput(
|
||||
val clientMutationId: String? = null,
|
||||
val settings: PartialSettingsType
|
||||
)
|
||||
|
||||
data class SetSettingsPayload(
|
||||
val clientMutationId: String?,
|
||||
val settings: SettingsType
|
||||
)
|
||||
|
||||
private fun updateSettings(settings: Settings) {
|
||||
if (settings.ip != null) serverConfig.ip.value = settings.ip!!
|
||||
if (settings.port != null) serverConfig.port.value = settings.port!!
|
||||
|
||||
if (settings.socksProxyEnabled != null) serverConfig.socksProxyEnabled.value = settings.socksProxyEnabled!!
|
||||
if (settings.socksProxyHost != null) serverConfig.socksProxyHost.value = settings.socksProxyHost!!
|
||||
if (settings.socksProxyPort != null) serverConfig.socksProxyPort.value = settings.socksProxyPort!!
|
||||
|
||||
if (settings.webUIFlavor != null) serverConfig.webUIFlavor.value = settings.webUIFlavor!!.uiName
|
||||
if (settings.initialOpenInBrowserEnabled != null) serverConfig.initialOpenInBrowserEnabled.value = settings.initialOpenInBrowserEnabled!!
|
||||
if (settings.webUIInterface != null) serverConfig.webUIInterface.value = settings.webUIInterface!!.name.lowercase()
|
||||
if (settings.electronPath != null) serverConfig.electronPath.value = settings.electronPath!!
|
||||
if (settings.webUIChannel != null) serverConfig.webUIChannel.value = settings.webUIChannel!!.name.lowercase()
|
||||
if (settings.webUIUpdateCheckInterval != null) serverConfig.webUIUpdateCheckInterval.value = settings.webUIUpdateCheckInterval!!
|
||||
|
||||
if (settings.downloadAsCbz != null) serverConfig.downloadAsCbz.value = settings.downloadAsCbz!!
|
||||
if (settings.downloadsPath != null) serverConfig.downloadsPath.value = settings.downloadsPath!!
|
||||
if (settings.autoDownloadNewChapters != null) serverConfig.autoDownloadNewChapters.value = settings.autoDownloadNewChapters!!
|
||||
|
||||
if (settings.maxSourcesInParallel != null) serverConfig.maxSourcesInParallel.value = settings.maxSourcesInParallel!!
|
||||
|
||||
if (settings.excludeUnreadChapters != null) serverConfig.excludeUnreadChapters.value = settings.excludeUnreadChapters!!
|
||||
if (settings.excludeNotStarted != null) serverConfig.excludeNotStarted.value = settings.excludeNotStarted!!
|
||||
if (settings.excludeCompleted != null) serverConfig.excludeCompleted.value = settings.excludeCompleted!!
|
||||
if (settings.globalUpdateInterval != null) serverConfig.globalUpdateInterval.value = settings.globalUpdateInterval!!
|
||||
|
||||
if (settings.basicAuthEnabled != null) serverConfig.basicAuthEnabled.value = settings.basicAuthEnabled!!
|
||||
if (settings.basicAuthUsername != null) serverConfig.basicAuthUsername.value = settings.basicAuthUsername!!
|
||||
if (settings.basicAuthPassword != null) serverConfig.basicAuthPassword.value = settings.basicAuthPassword!!
|
||||
|
||||
if (settings.debugLogsEnabled != null) serverConfig.debugLogsEnabled.value = settings.debugLogsEnabled!!
|
||||
if (settings.systemTrayEnabled != null) serverConfig.systemTrayEnabled.value = settings.systemTrayEnabled!!
|
||||
|
||||
if (settings.backupPath != null) serverConfig.backupPath.value = settings.backupPath!!
|
||||
if (settings.backupTime != null) serverConfig.backupTime.value = settings.backupTime!!
|
||||
if (settings.backupInterval != null) serverConfig.backupInterval.value = settings.backupInterval!!
|
||||
if (settings.backupTTL != null) serverConfig.backupTTL.value = settings.backupTTL!!
|
||||
|
||||
if (settings.localSourcePath != null) serverConfig.localSourcePath.value = settings.localSourcePath!!
|
||||
}
|
||||
|
||||
fun setSettings(input: SetSettingsInput): SetSettingsPayload {
|
||||
val (clientMutationId, settings) = input
|
||||
|
||||
updateSettings(settings)
|
||||
|
||||
return SetSettingsPayload(clientMutationId, SettingsType())
|
||||
}
|
||||
|
||||
data class ResetSettingsInput(val clientMutationId: String? = null)
|
||||
|
||||
data class ResetSettingsPayload(
|
||||
val clientMutationId: String?,
|
||||
val settings: SettingsType
|
||||
)
|
||||
|
||||
fun resetSettings(input: ResetSettingsInput): ResetSettingsPayload {
|
||||
val (clientMutationId) = input
|
||||
|
||||
GlobalConfigManager.resetUserConfig()
|
||||
val defaultServerConfig = ServerConfig({ GlobalConfigManager.config.getConfig(SERVER_CONFIG_MODULE_NAME) })
|
||||
|
||||
val settings = SettingsType(defaultServerConfig)
|
||||
updateSettings(settings)
|
||||
|
||||
return ResetSettingsPayload(clientMutationId, settings)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package suwayomi.tachidesk.graphql.queries
|
||||
|
||||
import suwayomi.tachidesk.graphql.types.SettingsType
|
||||
|
||||
class SettingsQuery {
|
||||
fun settings(): SettingsType {
|
||||
return SettingsType()
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import suwayomi.tachidesk.graphql.mutations.ExtensionMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.InfoMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.MangaMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.MetaMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.SettingsMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.SourceMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.UpdateMutation
|
||||
import suwayomi.tachidesk.graphql.queries.BackupQuery
|
||||
@@ -31,6 +32,7 @@ import suwayomi.tachidesk.graphql.queries.ExtensionQuery
|
||||
import suwayomi.tachidesk.graphql.queries.InfoQuery
|
||||
import suwayomi.tachidesk.graphql.queries.MangaQuery
|
||||
import suwayomi.tachidesk.graphql.queries.MetaQuery
|
||||
import suwayomi.tachidesk.graphql.queries.SettingsQuery
|
||||
import suwayomi.tachidesk.graphql.queries.SourceQuery
|
||||
import suwayomi.tachidesk.graphql.queries.UpdateQuery
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
@@ -67,6 +69,7 @@ val schema = toSchema(
|
||||
TopLevelObject(InfoQuery()),
|
||||
TopLevelObject(MangaQuery()),
|
||||
TopLevelObject(MetaQuery()),
|
||||
TopLevelObject(SettingsQuery()),
|
||||
TopLevelObject(SourceQuery()),
|
||||
TopLevelObject(UpdateQuery())
|
||||
),
|
||||
@@ -79,6 +82,7 @@ val schema = toSchema(
|
||||
TopLevelObject(InfoMutation()),
|
||||
TopLevelObject(MangaMutation()),
|
||||
TopLevelObject(MetaMutation()),
|
||||
TopLevelObject(SettingsMutation()),
|
||||
TopLevelObject(SourceMutation()),
|
||||
TopLevelObject(UpdateMutation())
|
||||
),
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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/. */
|
||||
|
||||
package suwayomi.tachidesk.graphql.types
|
||||
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Node
|
||||
import suwayomi.tachidesk.server.ServerConfig
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import suwayomi.tachidesk.server.util.WebUIChannel
|
||||
import suwayomi.tachidesk.server.util.WebUIFlavor
|
||||
import suwayomi.tachidesk.server.util.WebUIInterface
|
||||
|
||||
interface Settings : Node {
|
||||
val ip: String?
|
||||
val port: Int?
|
||||
|
||||
// proxy
|
||||
val socksProxyEnabled: Boolean?
|
||||
val socksProxyHost: String?
|
||||
val socksProxyPort: String?
|
||||
|
||||
// webUI
|
||||
// requires restart (found no way to mutate (serve + "unserve") served files during runtime), exclude for now
|
||||
// val webUIEnabled: Boolean,
|
||||
val webUIFlavor: WebUIFlavor?
|
||||
val initialOpenInBrowserEnabled: Boolean?
|
||||
val webUIInterface: WebUIInterface?
|
||||
val electronPath: String?
|
||||
val webUIChannel: WebUIChannel?
|
||||
val webUIUpdateCheckInterval: Double?
|
||||
|
||||
// downloader
|
||||
val downloadAsCbz: Boolean?
|
||||
val downloadsPath: String?
|
||||
val autoDownloadNewChapters: Boolean?
|
||||
|
||||
// requests
|
||||
val maxSourcesInParallel: Int?
|
||||
|
||||
// updater
|
||||
val excludeUnreadChapters: Boolean?
|
||||
val excludeNotStarted: Boolean?
|
||||
val excludeCompleted: Boolean?
|
||||
val globalUpdateInterval: Double?
|
||||
|
||||
// Authentication
|
||||
val basicAuthEnabled: Boolean?
|
||||
val basicAuthUsername: String?
|
||||
val basicAuthPassword: String?
|
||||
|
||||
// misc
|
||||
val debugLogsEnabled: Boolean?
|
||||
val systemTrayEnabled: Boolean?
|
||||
|
||||
// backup
|
||||
val backupPath: String?
|
||||
val backupTime: String?
|
||||
val backupInterval: Int?
|
||||
val backupTTL: Int?
|
||||
|
||||
// local source
|
||||
val localSourcePath: String?
|
||||
}
|
||||
|
||||
data class PartialSettingsType(
|
||||
override val ip: String?,
|
||||
override val port: Int?,
|
||||
|
||||
// proxy
|
||||
override val socksProxyEnabled: Boolean?,
|
||||
override val socksProxyHost: String?,
|
||||
override val socksProxyPort: String?,
|
||||
|
||||
// webUI
|
||||
override val webUIFlavor: WebUIFlavor?,
|
||||
override val initialOpenInBrowserEnabled: Boolean?,
|
||||
override val webUIInterface: WebUIInterface?,
|
||||
override val electronPath: String?,
|
||||
override val webUIChannel: WebUIChannel?,
|
||||
override val webUIUpdateCheckInterval: Double?,
|
||||
|
||||
// downloader
|
||||
override val downloadAsCbz: Boolean?,
|
||||
override val downloadsPath: String?,
|
||||
override val autoDownloadNewChapters: Boolean?,
|
||||
|
||||
// requests
|
||||
override val maxSourcesInParallel: Int?,
|
||||
|
||||
// updater
|
||||
override val excludeUnreadChapters: Boolean?,
|
||||
override val excludeNotStarted: Boolean?,
|
||||
override val excludeCompleted: Boolean?,
|
||||
override val globalUpdateInterval: Double?,
|
||||
|
||||
// Authentication
|
||||
override val basicAuthEnabled: Boolean?,
|
||||
override val basicAuthUsername: String?,
|
||||
override val basicAuthPassword: String?,
|
||||
|
||||
// misc
|
||||
override val debugLogsEnabled: Boolean?,
|
||||
override val systemTrayEnabled: Boolean?,
|
||||
|
||||
// backup
|
||||
override val backupPath: String?,
|
||||
override val backupTime: String?,
|
||||
override val backupInterval: Int?,
|
||||
override val backupTTL: Int?,
|
||||
|
||||
// local source
|
||||
override val localSourcePath: String?
|
||||
) : Settings
|
||||
|
||||
class SettingsType(
|
||||
override val ip: String,
|
||||
override val port: Int,
|
||||
|
||||
// proxy
|
||||
override val socksProxyEnabled: Boolean,
|
||||
override val socksProxyHost: String,
|
||||
override val socksProxyPort: String,
|
||||
|
||||
// webUI
|
||||
override val webUIFlavor: WebUIFlavor,
|
||||
override val initialOpenInBrowserEnabled: Boolean,
|
||||
override val webUIInterface: WebUIInterface,
|
||||
override val electronPath: String,
|
||||
override val webUIChannel: WebUIChannel,
|
||||
override val webUIUpdateCheckInterval: Double,
|
||||
|
||||
// downloader
|
||||
override val downloadAsCbz: Boolean,
|
||||
override val downloadsPath: String,
|
||||
override val autoDownloadNewChapters: Boolean,
|
||||
|
||||
// requests
|
||||
override val maxSourcesInParallel: Int,
|
||||
|
||||
// updater
|
||||
override val excludeUnreadChapters: Boolean,
|
||||
override val excludeNotStarted: Boolean,
|
||||
override val excludeCompleted: Boolean,
|
||||
override val globalUpdateInterval: Double,
|
||||
|
||||
// Authentication
|
||||
override val basicAuthEnabled: Boolean,
|
||||
override val basicAuthUsername: String,
|
||||
override val basicAuthPassword: String,
|
||||
|
||||
// misc
|
||||
override val debugLogsEnabled: Boolean,
|
||||
override val systemTrayEnabled: Boolean,
|
||||
|
||||
// backup
|
||||
override val backupPath: String,
|
||||
override val backupTime: String,
|
||||
override val backupInterval: Int,
|
||||
override val backupTTL: Int,
|
||||
|
||||
// local source
|
||||
override val localSourcePath: String
|
||||
) : Settings {
|
||||
constructor(config: ServerConfig = serverConfig) : this(
|
||||
config.ip.value,
|
||||
config.port.value,
|
||||
|
||||
config.socksProxyEnabled.value,
|
||||
config.socksProxyHost.value,
|
||||
config.socksProxyPort.value,
|
||||
|
||||
WebUIFlavor.from(config.webUIFlavor.value),
|
||||
config.initialOpenInBrowserEnabled.value,
|
||||
WebUIInterface.from(config.webUIInterface.value),
|
||||
config.electronPath.value,
|
||||
WebUIChannel.from(config.webUIChannel.value),
|
||||
config.webUIUpdateCheckInterval.value,
|
||||
|
||||
config.downloadAsCbz.value,
|
||||
config.downloadsPath.value,
|
||||
config.autoDownloadNewChapters.value,
|
||||
|
||||
config.maxSourcesInParallel.value,
|
||||
|
||||
config.excludeUnreadChapters.value,
|
||||
config.excludeNotStarted.value,
|
||||
config.excludeCompleted.value,
|
||||
config.globalUpdateInterval.value,
|
||||
|
||||
config.basicAuthEnabled.value,
|
||||
config.basicAuthUsername.value,
|
||||
config.basicAuthPassword.value,
|
||||
|
||||
config.debugLogsEnabled.value,
|
||||
config.systemTrayEnabled.value,
|
||||
|
||||
config.backupPath.value,
|
||||
config.backupTime.value,
|
||||
config.backupInterval.value,
|
||||
config.backupTTL.value,
|
||||
|
||||
config.localSourcePath.value
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user