Skip to content

Commit

Permalink
Make flaresolverr session options configurable (#854)
Browse files Browse the repository at this point in the history
Signed-off-by: Chance Zibolski <[email protected]>
  • Loading branch information
chancez authored Jan 25, 2024
1 parent 9109d1c commit dc124fb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ object CFClearance {
FlareSolverRequest(
"request.get",
originalRequest.url.toString(),
session = "suwayomi",
sessionTtlMinutes = 15,
session = serverConfig.flareSolverrSessionName.value,
sessionTtlMinutes = serverConfig.flareSolverrSessionTtl.value,
cookies =
network.cookieStore.get(originalRequest.url).map {
FlareSolverCookie(it.name, it.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SettingsMutation {
updateSetting(settings.flareSolverrEnabled, serverConfig.flareSolverrEnabled)
updateSetting(settings.flareSolverrUrl, serverConfig.flareSolverrUrl)
updateSetting(settings.flareSolverrTimeout, serverConfig.flareSolverrTimeout)
updateSetting(settings.flareSolverrSessionName, serverConfig.flareSolverrSessionName)
updateSetting(settings.flareSolverrSessionTtl, serverConfig.flareSolverrSessionTtl)
}

fun setSettings(input: SetSettingsInput): SetSettingsPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ interface Settings : Node {
val flareSolverrEnabled: Boolean?
val flareSolverrUrl: String?
val flareSolverrTimeout: Int?
val flareSolverrSessionName: String?
val flareSolverrSessionTtl: Int?
}

data class PartialSettingsType(
Expand Down Expand Up @@ -127,6 +129,8 @@ data class PartialSettingsType(
override val flareSolverrEnabled: Boolean?,
override val flareSolverrUrl: String?,
override val flareSolverrTimeout: Int?,
override val flareSolverrSessionName: String?,
override val flareSolverrSessionTtl: Int?,
) : Settings

class SettingsType(
Expand Down Expand Up @@ -178,6 +182,8 @@ class SettingsType(
override val flareSolverrEnabled: Boolean,
override val flareSolverrUrl: String,
override val flareSolverrTimeout: Int,
override val flareSolverrSessionName: String,
override val flareSolverrSessionTtl: Int,
) : Settings {
constructor(config: ServerConfig = serverConfig) : this(
config.ip.value,
Expand Down Expand Up @@ -228,5 +234,7 @@ class SettingsType(
config.flareSolverrEnabled.value,
config.flareSolverrUrl.value,
config.flareSolverrTimeout.value,
config.flareSolverrSessionName.value,
config.flareSolverrSessionTtl.value,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
val flareSolverrEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val flareSolverrUrl: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val flareSolverrTimeout: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
val flareSolverrSessionName: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val flareSolverrSessionTtl: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)

@OptIn(ExperimentalCoroutinesApi::class)
fun <T> subscribeTo(
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/resources/server-reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ server.localSourcePath = ""
# Cloudflare bypass
server.flareSolverrEnabled = false
server.flareSolverrUrl = "http://localhost:8191"
server.flareSolverrTimeout = 60 # time in seconds
server.flareSolverrTimeout = 60 # time in seconds
server.flareSolverrSessionName = "suwayomi"
server.flareSolverrSessionTtl = 15 # time in minutes

0 comments on commit dc124fb

Please sign in to comment.