Skip to content

Commit

Permalink
[no ci]env fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Oct 24, 2024
1 parent 7092469 commit 469a0e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions backend/src/main/kotlin/com/storyteller_f/Backend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.storyteller_f.media.MediaService
import com.storyteller_f.media.MinIoMediaService
import com.storyteller_f.naming.NameService
import io.github.aakira.napier.Napier
import java.io.File
import java.io.FileInputStream
import java.nio.file.Paths
import java.util.*

Expand All @@ -34,8 +36,22 @@ fun readEnv(): Map<out Any, Any> {
Properties().apply {
load(it)
}
}.orEmpty()
return map
}
return if (map != null) {
map
} else {
val userHome = System.getProperty("user.home")
val envFile = File(userHome, ".config/a.env")
if (envFile.exists()) {
FileInputStream(envFile).use {
Properties().apply {
load(it)
}
}
} else {
System.getenv()
}
}
}

fun buildBackendFromEnv(env: Map<out Any, Any>): Backend {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun main(args: Array<String>) {
EngineMain.main(args + extraArgs)
}

private fun processPreSetData(map: MutableMap<out Any, out Any>) {
private fun processPreSetData(map: Map<out Any, Any>) {
val preSetEnable = (map["PRESET_ENABLE"] as String).toBoolean()
if (preSetEnable) {
val preSetScript = map["PRESET_SCRIPT"] as String
Expand Down

0 comments on commit 469a0e9

Please sign in to comment.