Shamrock: 暗黙的コンフィギュレータの追加

Signed-off-by: WhiteChi <whitechi73@outlook.com>
This commit is contained in:
WhiteChi 2023-10-31 13:47:49 +08:00
parent 184064d199
commit 52b8db70be
3 changed files with 54 additions and 0 deletions

View File

@ -8,9 +8,12 @@ import moe.fuqiuluo.shamrock.remote.action.handlers.DownloadFile
import moe.fuqiuluo.shamrock.remote.action.handlers.GetDeviceBattery import moe.fuqiuluo.shamrock.remote.action.handlers.GetDeviceBattery
import moe.fuqiuluo.shamrock.remote.action.handlers.GetVersionInfo import moe.fuqiuluo.shamrock.remote.action.handlers.GetVersionInfo
import moe.fuqiuluo.shamrock.remote.action.handlers.RestartMe import moe.fuqiuluo.shamrock.remote.action.handlers.RestartMe
import moe.fuqiuluo.shamrock.remote.entries.Status
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
import moe.fuqiuluo.shamrock.tools.fetchOrNull import moe.fuqiuluo.shamrock.tools.fetchOrNull
import moe.fuqiuluo.shamrock.tools.fetchOrThrow import moe.fuqiuluo.shamrock.tools.fetchOrThrow
import moe.fuqiuluo.shamrock.tools.getOrPost import moe.fuqiuluo.shamrock.tools.getOrPost
import moe.fuqiuluo.shamrock.tools.respond
fun Routing.otherAction() { fun Routing.otherAction() {
@ -36,4 +39,25 @@ fun Routing.otherAction() {
val headers = fetchOrNull("headers") ?: "" val headers = fetchOrNull("headers") ?: ""
call.respondText(DownloadFile(url, threadCnt, headers.split("\r\n"))) call.respondText(DownloadFile(url, threadCnt, headers.split("\r\n")))
} }
getOrPost("/config/set_boolean") {
val key = fetchOrThrow("key")
val value = fetchOrThrow("value").toBooleanStrict()
ShamrockConfig[key] = value
respond(true, Status.Ok, "success")
}
getOrPost("/config/set_int") {
val key = fetchOrThrow("key")
val value = fetchOrThrow("value").toInt()
ShamrockConfig[key] = value
respond(true, Status.Ok, "success")
}
getOrPost("/config/set_string") {
val key = fetchOrThrow("key")
val value = fetchOrThrow("value")
ShamrockConfig[key] = value
respond(true, Status.Ok, "success")
}
} }

View File

@ -9,6 +9,7 @@ data class ServiceConfig(
@SerialName("default_token") var defaultToken: String? = null, @SerialName("default_token") var defaultToken: String? = null,
@SerialName("active_websocket") var activeWebSocket: ConnectionConfig? = null, @SerialName("active_websocket") var activeWebSocket: ConnectionConfig? = null,
@SerialName("passive_websocket") var passiveWebSocket: MutableList<ConnectionConfig>? = null, @SerialName("passive_websocket") var passiveWebSocket: MutableList<ConnectionConfig>? = null,
@SerialName("allow-temp-session") var allowTempSession: Boolean = false
) )
@Serializable @Serializable

View File

@ -75,6 +75,10 @@ internal object ShamrockConfig {
updateConfig() updateConfig()
} }
fun allowTempSession(): Boolean {
return Config.allowTempSession
}
fun getGroupMsgRule(): GroupRule? { fun getGroupMsgRule(): GroupRule? {
return Config.rules?.groupRule return Config.rules?.groupRule
} }
@ -181,4 +185,29 @@ internal object ShamrockConfig {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config") val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
return mmkv.getBoolean("dev", false) return mmkv.getBoolean("dev", false)
} }
operator fun set(key: String, value: String) {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
mmkv.putString(key, value)
}
operator fun set(key: String, value: Boolean) {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
mmkv.putBoolean(key, value)
}
operator fun set(key: String, value: Int) {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
mmkv.putInt(key, value)
}
operator fun set(key: String, value: Long) {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
mmkv.putLong(key, value)
}
operator fun set(key: String, value: Float) {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
mmkv.putFloat(key, value)
}
} }