feat: bootstrap MusicManager with scanner and Subsonic auth
- Gradle/Kotlin/Ktor project on JVM 21 with ShadowJar - SQLite WAL, Flyway migrations and config-driven users/folders - deterministic IDs, MP3 tag extraction, cover cache and delta scanner - OpenSubsonic JSON envelope with token/password authentication - system endpoints: ping, license, extensions, scan status
This commit is contained in:
1 parent
961341b449
commit
e194badefb
45 files changed
+4079
-126
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package win.taptap.musicmanager.config
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class AppConfigTest {
|
||||
|
||||
@Test
|
||||
fun `uses documented defaults`() {
|
||||
val config = AppConfig.fromEnv(emptyMap())
|
||||
|
||||
assertEquals(8080, config.port)
|
||||
assertEquals(Path.of("./data"), config.dataDir)
|
||||
assertEquals(Path.of("./config/library.yaml"), config.libraryConfigPath)
|
||||
assertEquals(Path.of("./config/users.yaml"), config.usersFile)
|
||||
assertEquals("ffmpeg", config.ffmpegPath)
|
||||
assertEquals(Path.of("./data/musicmanager.db"), config.databasePath)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reads overrides from the environment`() {
|
||||
val config = AppConfig.fromEnv(
|
||||
mapOf(
|
||||
"PORT" to "9090",
|
||||
"DATA_DIR" to "/var/lib/musicmanager",
|
||||
"LIBRARY_CONFIG" to "/etc/musicmanager/library.yaml",
|
||||
"USERS_FILE" to "/run/secrets/users.yaml",
|
||||
"FFMPEG_PATH" to "/usr/bin/ffmpeg",
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(9090, config.port)
|
||||
assertEquals(Path.of("/var/lib/musicmanager"), config.dataDir)
|
||||
assertEquals(Path.of("/etc/musicmanager/library.yaml"), config.libraryConfigPath)
|
||||
assertEquals(Path.of("/run/secrets/users.yaml"), config.usersFile)
|
||||
assertEquals("/usr/bin/ffmpeg", config.ffmpegPath)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects a malformed port`() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
AppConfig.fromEnv(mapOf("PORT" to "not-a-number"))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
AppConfig.fromEnv(mapOf("PORT" to "70000"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package win.taptap.musicmanager.config
|
||||
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.createTempDirectory
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class LibraryConfigTest {
|
||||
|
||||
private val validYaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: "Music"
|
||||
type: music
|
||||
path: "./media/music"
|
||||
- id: 10
|
||||
name: "Long-form"
|
||||
type: longform
|
||||
path: "./media/longform"
|
||||
""".trimIndent()
|
||||
|
||||
@Test
|
||||
fun `parses folders and resolves absolute paths`() {
|
||||
val config = LibraryConfig.parse(validYaml)
|
||||
|
||||
assertEquals(2, config.folders.size)
|
||||
assertEquals(setOf(10), config.longformFolderIds)
|
||||
assertEquals(FolderType.MUSIC, config.folders[0].type)
|
||||
assertEquals(FolderType.LONGFORM, config.folders[1].type)
|
||||
assertTrue(config.folders[0].path.isAbsolute)
|
||||
assertEquals(1, config.byId(1)?.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects duplicate folder ids`() {
|
||||
val yaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: A
|
||||
type: music
|
||||
path: /music/a
|
||||
- id: 1
|
||||
name: B
|
||||
type: music
|
||||
path: /music/b
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { LibraryConfig.parse(yaml) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects duplicate folder paths`() {
|
||||
val yaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: A
|
||||
type: music
|
||||
path: /music/a
|
||||
- id: 2
|
||||
name: B
|
||||
type: music
|
||||
path: /music/a
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { LibraryConfig.parse(yaml) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects unknown folder types`() {
|
||||
val yaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: A
|
||||
type: video
|
||||
path: /music/a
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { LibraryConfig.parse(yaml) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validatePaths fails for a missing root`() {
|
||||
val root = createTempDirectory("musicmanager-test")
|
||||
try {
|
||||
val yaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: A
|
||||
type: music
|
||||
path: "${root.resolve("missing")}"
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
LibraryConfig.parse(yaml).validatePaths()
|
||||
}
|
||||
} finally {
|
||||
root.toFile().deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validatePaths accepts existing readable roots`() {
|
||||
val root = createTempDirectory("musicmanager-test")
|
||||
try {
|
||||
val music = Files.createDirectories(root.resolve("music"))
|
||||
val yaml = """
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: A
|
||||
type: music
|
||||
path: "$music"
|
||||
""".trimIndent()
|
||||
|
||||
LibraryConfig.parse(yaml).validatePaths()
|
||||
} finally {
|
||||
root.toFile().deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package win.taptap.musicmanager.config
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class UsersConfigTest {
|
||||
|
||||
private val library = LibraryConfig.parse(
|
||||
"""
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: "Music A"
|
||||
type: music
|
||||
path: /music/a
|
||||
- id: 2
|
||||
name: "Music B"
|
||||
type: music
|
||||
path: /music/b
|
||||
- id: 10
|
||||
name: "Long-form"
|
||||
type: longform
|
||||
path: /longform
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
private val usersYaml = """
|
||||
users:
|
||||
- name: alice
|
||||
password: "secret-a"
|
||||
admin: true
|
||||
folders: [1]
|
||||
- name: bob
|
||||
password: "secret-b"
|
||||
folders: [1, 2]
|
||||
""".trimIndent()
|
||||
|
||||
@Test
|
||||
fun `parses users and shares long-form folders`() {
|
||||
val users = UsersConfig.parse(usersYaml)
|
||||
users.validateAgainst(library)
|
||||
|
||||
val alice = users.byName("alice")!!
|
||||
val bob = users.byName("bob")!!
|
||||
|
||||
assertTrue(alice.admin)
|
||||
assertFalse(bob.admin)
|
||||
assertEquals(setOf(1, 10), alice.visibleFolderIds(library))
|
||||
assertEquals(setOf(1, 2, 10), bob.visibleFolderIds(library))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects missing passwords`() {
|
||||
val yaml = """
|
||||
users:
|
||||
- name: alice
|
||||
folders: [1]
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { UsersConfig.parse(yaml) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects duplicate names`() {
|
||||
val yaml = """
|
||||
users:
|
||||
- name: alice
|
||||
password: a
|
||||
folders: [1]
|
||||
- name: alice
|
||||
password: b
|
||||
folders: [2]
|
||||
""".trimIndent()
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { UsersConfig.parse(yaml) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects unknown folder references`() {
|
||||
val users = UsersConfig.parse(
|
||||
"""
|
||||
users:
|
||||
- name: alice
|
||||
password: a
|
||||
folders: [99]
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { users.validateAgainst(library) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects a user with no visible folders`() {
|
||||
val emptyLibrary = LibraryConfig.parse(
|
||||
"""
|
||||
library:
|
||||
folders:
|
||||
- id: 1
|
||||
name: "Music"
|
||||
type: music
|
||||
path: /music
|
||||
""".trimIndent(),
|
||||
)
|
||||
val users = UsersConfig.parse(
|
||||
"""
|
||||
users:
|
||||
- name: alice
|
||||
password: a
|
||||
folders: []
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
assertFailsWith<IllegalArgumentException> { users.validateAgainst(emptyLibrary) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `does not expose passwords in toString`() {
|
||||
val alice = UsersConfig.parse(usersYaml).byName("alice")!!
|
||||
|
||||
assertFalse(alice.toString().contains("secret-a"))
|
||||
assertTrue(alice.toString().contains("password=***"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user