diff --git a/README.md b/README.md index 0dc2317..4f5c69a 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Or build and run the fat JAR: java -jar build/libs/musicmanager-0.1.0-all.jar ``` -The server listens on `http://localhost:8080`. Override with `PORT`, `DATA_DIR`, `LIBRARY_CONFIG`, `USERS_FILE` and `FFMPEG_PATH` (see Section 6.3). The SQLite database and cover cache are written to `./data`. +The server listens on `http://localhost:8080`. Open `http://localhost:8080/ui` for the built-in test client (log in with a user from `users.yaml`). Override with `PORT`, `DATA_DIR`, `LIBRARY_CONFIG`, `USERS_FILE`, `FFMPEG_PATH` and `WEB_UI` (see Section 6.3). The SQLite database and cover cache are written to `./data`. On first start, the server scans automatically because the database is empty. After that, scans are manual. @@ -95,6 +95,10 @@ For quick manual testing you can pass the password in plaintext instead: `&p=cha ### 6. Connect a client (Symfonium) +For a quick browser check, open `http://localhost:8080/ui` and log in with a user from `users.yaml`. It lists folders, albums and songs and can play streams; it is a debugging aid, not a full music client. + +For a real client: + 1. Add a new **Subsonic** server. 2. URL: `http://:8080` (or `https://subsonic.tap-tap.win` when deployed). 3. Username and password from `users.yaml`. @@ -510,6 +514,7 @@ users: | `LIBRARY_CONFIG` | `./config/library.yaml` | Library folder definitions | | `USERS_FILE` | `./config/users.yaml` | Vault-managed users file | | `FFMPEG_PATH` | `ffmpeg` | ffmpeg binary used for transcoding | +| `WEB_UI` | `true` | Serve the built-in test client at `/ui` | ### 6.4 Local development diff --git a/src/main/kotlin/win/taptap/musicmanager/Application.kt b/src/main/kotlin/win/taptap/musicmanager/Application.kt index 8ebee17..1da3fc2 100644 --- a/src/main/kotlin/win/taptap/musicmanager/Application.kt +++ b/src/main/kotlin/win/taptap/musicmanager/Application.kt @@ -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, diff --git a/src/main/kotlin/win/taptap/musicmanager/config/AppConfig.kt b/src/main/kotlin/win/taptap/musicmanager/config/AppConfig.kt index 7f26911..04584f5 100644 --- a/src/main/kotlin/win/taptap/musicmanager/config/AppConfig.kt +++ b/src/main/kotlin/win/taptap/musicmanager/config/AppConfig.kt @@ -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, ) } } diff --git a/src/main/resources/web/index.html b/src/main/resources/web/index.html new file mode 100644 index 0000000..5f255dc --- /dev/null +++ b/src/main/resources/web/index.html @@ -0,0 +1,304 @@ + + + + + +MusicManager + + + + + +
+

MusicManager test client

+

Sign in with a user from users.yaml.

+ + + +
+
+ +
+
+ + + +
+
+
+ + + + + + diff --git a/src/test/kotlin/win/taptap/musicmanager/config/AppConfigTest.kt b/src/test/kotlin/win/taptap/musicmanager/config/AppConfigTest.kt index 2b72bc4..02ccd2a 100644 --- a/src/test/kotlin/win/taptap/musicmanager/config/AppConfigTest.kt +++ b/src/test/kotlin/win/taptap/musicmanager/config/AppConfigTest.kt @@ -16,6 +16,7 @@ class AppConfigTest { assertEquals(Path.of("./config/library.yaml"), config.libraryConfigPath) assertEquals(Path.of("./config/users.yaml"), config.usersFile) assertEquals("ffmpeg", config.ffmpegPath) + assertEquals(true, config.webUiEnabled) assertEquals(Path.of("./data/musicmanager.db"), config.databasePath) } @@ -28,6 +29,7 @@ class AppConfigTest { "LIBRARY_CONFIG" to "/etc/musicmanager/library.yaml", "USERS_FILE" to "/run/secrets/users.yaml", "FFMPEG_PATH" to "/usr/bin/ffmpeg", + "WEB_UI" to "false", ), ) @@ -36,6 +38,7 @@ class AppConfigTest { assertEquals(Path.of("/etc/musicmanager/library.yaml"), config.libraryConfigPath) assertEquals(Path.of("/run/secrets/users.yaml"), config.usersFile) assertEquals("/usr/bin/ffmpeg", config.ffmpegPath) + assertEquals(false, config.webUiEnabled) } @Test