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,71 @@
|
||||
package win.taptap.musicmanager.subsonic.routes
|
||||
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.route
|
||||
import kotlinx.serialization.json.buildJsonArray
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.put
|
||||
import win.taptap.musicmanager.config.UsersConfig
|
||||
import win.taptap.musicmanager.scanner.ScanStatus
|
||||
import win.taptap.musicmanager.subsonic.respondSubsonic
|
||||
import win.taptap.musicmanager.subsonic.respondSubsonicError
|
||||
|
||||
/** System endpoints from the MVP specification. */
|
||||
fun Route.systemRoutes(
|
||||
users: UsersConfig,
|
||||
startScan: () -> Boolean,
|
||||
scanStatus: () -> ScanStatus,
|
||||
) {
|
||||
subsonicGet(users, "/ping") { call, _ ->
|
||||
call.respondSubsonic()
|
||||
}
|
||||
|
||||
subsonicGet(users, "/getLicense") { call, _ ->
|
||||
call.respondSubsonic(
|
||||
buildJsonObject {
|
||||
put("license", buildJsonObject { put("valid", true) })
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
subsonicGet(users, "/getOpenSubsonicExtensions") { call, _ ->
|
||||
call.respondSubsonic(
|
||||
buildJsonObject {
|
||||
put(
|
||||
"openSubsonicExtensions",
|
||||
buildJsonArray {
|
||||
add(extension("formPost", 1))
|
||||
add(extension("songLyrics", 1))
|
||||
add(extension("transcodeOffset", 1))
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
subsonicGet(users, "/startScan") { call, user ->
|
||||
if (!user.admin) {
|
||||
call.respondSubsonicError(50, "Not authorized")
|
||||
} else {
|
||||
startScan()
|
||||
call.respondSubsonic()
|
||||
}
|
||||
}
|
||||
|
||||
subsonicGet(users, "/getScanStatus") { call, _ ->
|
||||
val status = scanStatus()
|
||||
call.respondSubsonic(
|
||||
buildJsonObject {
|
||||
put("scanStatus", buildJsonObject {
|
||||
put("scanning", status.scanning)
|
||||
put("count", status.count)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun extension(name: String, version: Int) = buildJsonObject {
|
||||
put("name", name)
|
||||
put("versions", buildJsonArray { add(kotlinx.serialization.json.JsonPrimitive(version)) })
|
||||
}
|
||||
Reference in new issue
Block a user