- 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
32 lines
1.1 KiB
Kotlin
32 lines
1.1 KiB
Kotlin
package win.taptap.musicmanager.subsonic.routes
|
|
|
|
import io.ktor.http.ContentType
|
|
import io.ktor.http.HttpMethod
|
|
import io.ktor.http.Parameters
|
|
import io.ktor.server.application.ApplicationCall
|
|
import io.ktor.server.request.contentType
|
|
import io.ktor.server.request.httpMethod
|
|
import io.ktor.server.request.receiveParameters
|
|
import io.ktor.util.AttributeKey
|
|
import win.taptap.musicmanager.config.UserAccount
|
|
|
|
val CurrentUserKey = AttributeKey<UserAccount>("musicmanager.currentUser")
|
|
|
|
/**
|
|
* Unified parameter access for Subsonic: query parameters plus URL-encoded form
|
|
* bodies (the `formPost` OpenSubsonic extension).
|
|
*/
|
|
suspend fun subsonicParameters(call: ApplicationCall): Parameters {
|
|
val query = call.request.queryParameters
|
|
if (call.request.httpMethod != HttpMethod.Post) return query
|
|
|
|
val contentType = call.request.contentType()
|
|
if (!contentType.match(ContentType.Application.FormUrlEncoded)) return query
|
|
|
|
val form = call.receiveParameters()
|
|
return Parameters.build {
|
|
query.forEach { name, values -> values.forEach { append(name, it) } }
|
|
form.forEach { name, values -> values.forEach { append(name, it) } }
|
|
}
|
|
}
|