feat: add a built-in browser test client

- serve a single-page client at /ui (and redirect / to it)
- login, folder switch, album grid, album songs, search and streaming
- enabled by default, disable with WEB_UI=false
- document the test client and WEB_UI
This commit is contained in:
TapTap committed 2026-11-13 12:45:41 +00:00
1 parent 1571ec65ff
commit 26d31834a5
5 files changed
+334 -1

No files matched your search

@@ -1,5 +1,6 @@
package win.taptap.musicmanager
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.install
@@ -11,6 +12,7 @@ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.plugins.partialcontent.PartialContent
import io.ktor.server.plugins.statuspages.StatusPages
import io.ktor.server.request.path
import io.ktor.server.response.respondRedirect
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
@@ -53,6 +55,12 @@ fun main() {
scanner.start(applicationScope)
}
val webUiHtml = if (config.webUiEnabled) {
AppConfig::class.java.getResource("/web/index.html")?.readText()
} else {
null
}
val server = embeddedServer(Netty, port = config.port, host = "0.0.0.0") {
install(ContentNegotiation) {
json(
@@ -79,6 +87,10 @@ fun main() {
routing {
get("/health") { call.respondText("ok") }
if (webUiHtml != null) {
get("/") { call.respondRedirect("/ui") }
get("/ui") { call.respondText(webUiHtml, ContentType.Text.Html) }
}
subsonicRoutes(
users = users,
library = library,
@@ -14,6 +14,7 @@ data class AppConfig(
val libraryConfigPath: Path,
val usersFile: Path,
val ffmpegPath: String,
val webUiEnabled: Boolean = true,
) {
val databasePath: Path get() = dataDir.resolve("musicmanager.db")
@@ -27,12 +28,20 @@ data class AppConfig(
?: throw IllegalArgumentException("PORT must be an integer, got: $rawPort")
require(port in 1..65535) { "PORT must be between 1 and 65535, got: $port" }
val webUi = value("WEB_UI", "true").lowercase()
val webUiEnabled = when (webUi) {
"true", "1", "yes", "on" -> true
"false", "0", "no", "off" -> false
else -> throw IllegalArgumentException("WEB_UI must be true or false, got: $webUi")
}
return AppConfig(
port = port,
dataDir = Path.of(value("DATA_DIR", "./data")),
libraryConfigPath = Path.of(value("LIBRARY_CONFIG", "./config/library.yaml")),
usersFile = Path.of(value("USERS_FILE", "./config/users.yaml")),
ffmpegPath = value("FFMPEG_PATH", "ffmpeg"),
webUiEnabled = webUiEnabled,
)
}
}