fix: accept POST form posts on every Subsonic endpoint
Clients that use the formPost extension (Feishin, Symfonium) send requests as application/x-www-form-urlencoded POSTs, not only GET. Register both methods for every route and cover it in the smoke test.
This commit is contained in:
1 parent
4d313a2846
commit
1571ec65ff
9 files changed
+168
-113
No files matched your search
@@ -116,6 +116,26 @@ check() {
|
|||||||
pass "$name"
|
pass "$name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check_post <name> <path> <extra-form-data>
|
||||||
|
check_post() {
|
||||||
|
local name="$1" path="$2" extra="${3:-}" body status
|
||||||
|
body="$(curl -s -w '\n%{http_code}' -X POST \
|
||||||
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
|
--data "${AUTH}${extra}" "$BASE$path")"
|
||||||
|
status="$(printf '%s' "$body" | tail -1)"
|
||||||
|
body="$(printf '%s' "$body" | sed '$d')"
|
||||||
|
|
||||||
|
if [[ "$status" != "200" ]]; then
|
||||||
|
fail "$name (POST)" "HTTP $status: $(printf '%s' "$body" | head -c 200)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if ! printf '%s' "$body" | grep -q '"status":"ok"'; then
|
||||||
|
fail "$name (POST)" "$(printf '%s' "$body" | head -c 200)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
pass "$name (POST)"
|
||||||
|
}
|
||||||
|
|
||||||
check "ping" "/rest/ping.view?$AUTH"
|
check "ping" "/rest/ping.view?$AUTH"
|
||||||
check "getLicense" "/rest/getLicense.view?$AUTH"
|
check "getLicense" "/rest/getLicense.view?$AUTH"
|
||||||
check "getOpenSubsonicExtensions" "/rest/getOpenSubsonicExtensions.view?$AUTH"
|
check "getOpenSubsonicExtensions" "/rest/getOpenSubsonicExtensions.view?$AUTH"
|
||||||
@@ -145,6 +165,13 @@ check "getTopSongs" "/rest/getTopSongs.view?$AUTH&artist=Smoke%20Artist"
|
|||||||
check "getInternetRadioStations" "/rest/getInternetRadioStations.view?$AUTH"
|
check "getInternetRadioStations" "/rest/getInternetRadioStations.view?$AUTH"
|
||||||
check "jukeboxControl" "/rest/jukeboxControl.view?$AUTH&action=status"
|
check "jukeboxControl" "/rest/jukeboxControl.view?$AUTH&action=status"
|
||||||
|
|
||||||
|
# The formPost extension means clients may use POST for every endpoint.
|
||||||
|
check_post "ping" "/rest/ping.view"
|
||||||
|
check_post "getAlbumList2" "/rest/getAlbumList2.view" "&type=alphabeticalByName&size=10"
|
||||||
|
check_post "getGenres" "/rest/getGenres.view"
|
||||||
|
check_post "getPlaylists" "/rest/getPlaylists.view"
|
||||||
|
check_post "getUser" "/rest/getUser.view" "&username=$USER"
|
||||||
|
|
||||||
check "scrobble" "/rest/scrobble.view?$AUTH&id=$SONG_ID"
|
check "scrobble" "/rest/scrobble.view?$AUTH&id=$SONG_ID"
|
||||||
check "star" "/rest/star.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
check "star" "/rest/star.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
||||||
check "getStarred2 after star" "/rest/getStarred2.view?$AUTH"
|
check "getStarred2 after star" "/rest/getStarred2.view?$AUTH"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import win.taptap.musicmanager.subsonic.respondSubsonicError
|
|||||||
|
|
||||||
fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
||||||
|
|
||||||
subsonicGet(users, "/getMusicFolders") { call, user ->
|
subsonicEndpoint(users, "/getMusicFolders") { call, user ->
|
||||||
val visible = user.visibleFolderIds(library)
|
val visible = user.visibleFolderIds(library)
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -41,7 +41,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getIndexes") { call, user ->
|
subsonicEndpoint(users, "/getIndexes") { call, user ->
|
||||||
val artists = LibraryRepository.artists(user.visibleFolderIds(library), user.name)
|
val artists = LibraryRepository.artists(user.visibleFolderIds(library), user.name)
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -54,7 +54,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getArtists") { call, user ->
|
subsonicEndpoint(users, "/getArtists") { call, user ->
|
||||||
val artists = LibraryRepository.artists(user.visibleFolderIds(library), user.name)
|
val artists = LibraryRepository.artists(user.visibleFolderIds(library), user.name)
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -66,64 +66,64 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getArtist") { call, user ->
|
subsonicEndpoint(users, "/getArtist") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
val artist = LibraryRepository.artist(id, folders, user.name)
|
val artist = LibraryRepository.artist(id, folders, user.name)
|
||||||
if (artist == null) {
|
if (artist == null) {
|
||||||
call.respondSubsonicError(70, "Artist not found")
|
call.respondSubsonicError(70, "Artist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val albums = LibraryRepository.albumsForArtist(id, folders, user.name)
|
val albums = LibraryRepository.albumsForArtist(id, folders, user.name)
|
||||||
call.respondSubsonic(buildJsonObject { put("artist", artistJson(artist, albums)) })
|
call.respondSubsonic(buildJsonObject { put("artist", artistJson(artist, albums)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getAlbum") { call, user ->
|
subsonicEndpoint(users, "/getAlbum") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
val album = LibraryRepository.album(id, folders, user.name)
|
val album = LibraryRepository.album(id, folders, user.name)
|
||||||
if (album == null) {
|
if (album == null) {
|
||||||
call.respondSubsonicError(70, "Album not found")
|
call.respondSubsonicError(70, "Album not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val songs = LibraryRepository.albumSongs(id, folders, user.name)
|
val songs = LibraryRepository.albumSongs(id, folders, user.name)
|
||||||
call.respondSubsonic(buildJsonObject { put("album", albumJson(album, songs)) })
|
call.respondSubsonic(buildJsonObject { put("album", albumJson(album, songs)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getSong") { call, user ->
|
subsonicEndpoint(users, "/getSong") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val song = LibraryRepository.song(id, user.visibleFolderIds(library), user.name)
|
val song = LibraryRepository.song(id, user.visibleFolderIds(library), user.name)
|
||||||
if (song == null) {
|
if (song == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondSubsonic(buildJsonObject { put("song", songJson(song)) })
|
call.respondSubsonic(buildJsonObject { put("song", songJson(song)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getMusicDirectory") { call, user ->
|
subsonicEndpoint(users, "/getMusicDirectory") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val id = parameters["id"]
|
val id = parameters["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
@@ -131,7 +131,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
val album = LibraryRepository.album(id, folders, user.name)
|
val album = LibraryRepository.album(id, folders, user.name)
|
||||||
if (album == null) {
|
if (album == null) {
|
||||||
call.respondSubsonicError(70, "Album not found")
|
call.respondSubsonicError(70, "Album not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val songs = LibraryRepository.albumSongs(id, folders, user.name)
|
val songs = LibraryRepository.albumSongs(id, folders, user.name)
|
||||||
@@ -146,18 +146,18 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folderId = id.toIntOrNull()
|
val folderId = id.toIntOrNull()
|
||||||
if (folderId == null || folderId !in folders) {
|
if (folderId == null || folderId !in folders) {
|
||||||
call.respondSubsonicError(70, "Directory not found")
|
call.respondSubsonicError(70, "Directory not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folder = library.byId(folderId) ?: run {
|
val folder = library.byId(folderId) ?: run {
|
||||||
call.respondSubsonicError(70, "Directory not found")
|
call.respondSubsonicError(70, "Directory not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
val albums = LibraryRepository.albumList(
|
val albums = LibraryRepository.albumList(
|
||||||
type = "alphabeticalByName",
|
type = "alphabeticalByName",
|
||||||
@@ -206,12 +206,12 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
for (endpoint in listOf("/getAlbumList2", "/getAlbumList")) {
|
for (endpoint in listOf("/getAlbumList2", "/getAlbumList")) {
|
||||||
subsonicGet(users, endpoint) { call, user ->
|
subsonicEndpoint(users, endpoint) { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val type = parameters["type"] ?: "newest"
|
val type = parameters["type"] ?: "newest"
|
||||||
if (type !in albumListTypes) {
|
if (type !in albumListTypes) {
|
||||||
call.respondSubsonicError(10, "Invalid album list type: $type")
|
call.respondSubsonicError(10, "Invalid album list type: $type")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val size = parameters.intParam("size", 10)
|
val size = parameters.intParam("size", 10)
|
||||||
@@ -242,7 +242,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getRandomSongs") { call, user ->
|
subsonicEndpoint(users, "/getRandomSongs") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val songs = LibraryRepository.randomSongs(
|
val songs = LibraryRepository.randomSongs(
|
||||||
size = parameters.intParam("size", 10),
|
size = parameters.intParam("size", 10),
|
||||||
@@ -262,7 +262,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getGenres") { call, user ->
|
subsonicEndpoint(users, "/getGenres") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val genres = LibraryRepository.genres(
|
val genres = LibraryRepository.genres(
|
||||||
user.effectiveFolderIds(library, parameters["musicFolderId"]),
|
user.effectiveFolderIds(library, parameters["musicFolderId"]),
|
||||||
@@ -277,12 +277,12 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getSongsByGenre") { call, user ->
|
subsonicEndpoint(users, "/getSongsByGenre") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val genre = parameters["genre"]
|
val genre = parameters["genre"]
|
||||||
if (genre.isNullOrBlank()) {
|
if (genre.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: genre")
|
call.respondSubsonicError(10, "Required parameter is missing: genre")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val songs = LibraryRepository.songsByGenre(
|
val songs = LibraryRepository.songsByGenre(
|
||||||
@@ -303,7 +303,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (endpoint in listOf("/getStarred2", "/getStarred")) {
|
for (endpoint in listOf("/getStarred2", "/getStarred")) {
|
||||||
subsonicGet(users, endpoint) { call, user ->
|
subsonicEndpoint(users, endpoint) { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val starred = LibraryRepository.starred(
|
val starred = LibraryRepository.starred(
|
||||||
userName = user.name,
|
userName = user.name,
|
||||||
@@ -325,7 +325,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
|
|
||||||
// No external metadata provider yet, but clients expect a valid empty response.
|
// No external metadata provider yet, but clients expect a valid empty response.
|
||||||
for (endpoint in listOf("/getArtistInfo2", "/getArtistInfo")) {
|
for (endpoint in listOf("/getArtistInfo2", "/getArtistInfo")) {
|
||||||
subsonicGet(users, endpoint) { call, _ ->
|
subsonicEndpoint(users, endpoint) { call, _ ->
|
||||||
val key = if (endpoint == "/getArtistInfo2") "artistInfo2" else "artistInfo"
|
val key = if (endpoint == "/getArtistInfo2") "artistInfo2" else "artistInfo"
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -339,14 +339,14 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (endpoint in listOf("/getAlbumInfo2", "/getAlbumInfo")) {
|
for (endpoint in listOf("/getAlbumInfo2", "/getAlbumInfo")) {
|
||||||
subsonicGet(users, endpoint) { call, _ ->
|
subsonicEndpoint(users, endpoint) { call, _ ->
|
||||||
val key = if (endpoint == "/getAlbumInfo2") "albumInfo2" else "albumInfo"
|
val key = if (endpoint == "/getAlbumInfo2") "albumInfo2" else "albumInfo"
|
||||||
call.respondSubsonic(buildJsonObject { put(key, buildJsonObject { }) })
|
call.respondSubsonic(buildJsonObject { put(key, buildJsonObject { }) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (endpoint in listOf("/getSimilarSongs2", "/getSimilarSongs")) {
|
for (endpoint in listOf("/getSimilarSongs2", "/getSimilarSongs")) {
|
||||||
subsonicGet(users, endpoint) { call, _ ->
|
subsonicEndpoint(users, endpoint) { call, _ ->
|
||||||
val key = if (endpoint == "/getSimilarSongs2") "similarSongs2" else "similarSongs"
|
val key = if (endpoint == "/getSimilarSongs2") "similarSongs2" else "similarSongs"
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -356,7 +356,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getTopSongs") { call, _ ->
|
subsonicEndpoint(users, "/getTopSongs") { call, _ ->
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
put("topSongs", buildJsonObject { put("song", buildJsonArray { }) })
|
put("topSongs", buildJsonObject { put("song", buildJsonArray { }) })
|
||||||
@@ -364,7 +364,7 @@ fun Route.browsingRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/search3") { call, user ->
|
subsonicEndpoint(users, "/search3") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val query = parameters["query"].orEmpty()
|
val query = parameters["query"].orEmpty()
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ import win.taptap.musicmanager.subsonic.respondSubsonicError
|
|||||||
/** Per-user interaction: scrobbling, stars, ratings, bookmarks and lyrics. */
|
/** Per-user interaction: scrobbling, stars, ratings, bookmarks and lyrics. */
|
||||||
fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
||||||
|
|
||||||
subsonicGet(users, "/scrobble") { call, user ->
|
subsonicEndpoint(users, "/scrobble") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val ids = parameters.getAll("id").orEmpty().filter { it.isNotBlank() }
|
val ids = parameters.getAll("id").orEmpty().filter { it.isNotBlank() }
|
||||||
if (ids.isEmpty()) {
|
if (ids.isEmpty()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val submission = parameters["submission"]?.toBooleanStrictOrNull() ?: true
|
val submission = parameters["submission"]?.toBooleanStrictOrNull() ?: true
|
||||||
@@ -30,7 +30,7 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
if (LibraryRepository.song(id, folders, user.name) == null) {
|
if (LibraryRepository.song(id, folders, user.name) == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
UserStateRepository.scrobble(user.name, id, submission)
|
UserStateRepository.scrobble(user.name, id, submission)
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/star") { call, user ->
|
subsonicEndpoint(users, "/star") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
|
|
||||||
@@ -48,12 +48,12 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
|
|
||||||
if (songIds.isEmpty() && albumIds.isEmpty() && artistIds.isEmpty()) {
|
if (songIds.isEmpty() && albumIds.isEmpty() && artistIds.isEmpty()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id, albumId or artistId")
|
call.respondSubsonicError(10, "Required parameter is missing: id, albumId or artistId")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateVisible(songIds, albumIds, artistIds, folders, user.name)) {
|
if (!validateVisible(songIds, albumIds, artistIds, folders, user.name)) {
|
||||||
call.respondSubsonicError(70, "Item not found")
|
call.respondSubsonicError(70, "Item not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
songIds.forEach { UserStateRepository.starSong(user.name, it) }
|
songIds.forEach { UserStateRepository.starSong(user.name, it) }
|
||||||
@@ -63,7 +63,7 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/unstar") { call, user ->
|
subsonicEndpoint(users, "/unstar") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
|
|
||||||
@@ -73,12 +73,12 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
|
|
||||||
if (songIds.isEmpty() && albumIds.isEmpty() && artistIds.isEmpty()) {
|
if (songIds.isEmpty() && albumIds.isEmpty() && artistIds.isEmpty()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id, albumId or artistId")
|
call.respondSubsonicError(10, "Required parameter is missing: id, albumId or artistId")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateVisible(songIds, albumIds, artistIds, folders, user.name)) {
|
if (!validateVisible(songIds, albumIds, artistIds, folders, user.name)) {
|
||||||
call.respondSubsonicError(70, "Item not found")
|
call.respondSubsonicError(70, "Item not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
songIds.forEach { UserStateRepository.unstarSong(user.name, it) }
|
songIds.forEach { UserStateRepository.unstarSong(user.name, it) }
|
||||||
@@ -88,19 +88,19 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/setRating") { call, user ->
|
subsonicEndpoint(users, "/setRating") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val id = parameters["id"]
|
val id = parameters["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val rawRating = parameters["rating"]
|
val rawRating = parameters["rating"]
|
||||||
val rating = rawRating?.toIntOrNull()
|
val rating = rawRating?.toIntOrNull()
|
||||||
if (rating == null || rating !in 0..5) {
|
if (rating == null || rating !in 0..5) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing or invalid: rating")
|
call.respondSubsonicError(10, "Required parameter is missing or invalid: rating")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
@@ -110,34 +110,34 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
id.startsWith("sg-") -> {
|
id.startsWith("sg-") -> {
|
||||||
if (LibraryRepository.song(id, folders, user.name) == null) {
|
if (LibraryRepository.song(id, folders, user.name) == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
UserStateRepository.setSongRating(user.name, id, storedRating)
|
UserStateRepository.setSongRating(user.name, id, storedRating)
|
||||||
}
|
}
|
||||||
id.startsWith("al-") -> {
|
id.startsWith("al-") -> {
|
||||||
if (LibraryRepository.album(id, folders, user.name) == null) {
|
if (LibraryRepository.album(id, folders, user.name) == null) {
|
||||||
call.respondSubsonicError(70, "Album not found")
|
call.respondSubsonicError(70, "Album not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
UserStateRepository.setItemRating(user.name, "album", id, storedRating)
|
UserStateRepository.setItemRating(user.name, "album", id, storedRating)
|
||||||
}
|
}
|
||||||
id.startsWith("ar-") -> {
|
id.startsWith("ar-") -> {
|
||||||
if (LibraryRepository.artist(id, folders, user.name) == null) {
|
if (LibraryRepository.artist(id, folders, user.name) == null) {
|
||||||
call.respondSubsonicError(70, "Artist not found")
|
call.respondSubsonicError(70, "Artist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
UserStateRepository.setItemRating(user.name, "artist", id, storedRating)
|
UserStateRepository.setItemRating(user.name, "artist", id, storedRating)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
call.respondSubsonicError(70, "Item not found")
|
call.respondSubsonicError(70, "Item not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getBookmarks") { call, user ->
|
subsonicEndpoint(users, "/getBookmarks") { call, user ->
|
||||||
val folders = user.effectiveFolderIds(library, call.subsonicParams()["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, call.subsonicParams()["musicFolderId"])
|
||||||
|
|
||||||
val bookmarks = UserStateRepository.bookmarks(user.name).mapNotNull { bookmark ->
|
val bookmarks = UserStateRepository.bookmarks(user.name).mapNotNull { bookmark ->
|
||||||
@@ -160,53 +160,53 @@ fun Route.interactionRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/createBookmark") { call, user ->
|
subsonicEndpoint(users, "/createBookmark") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val id = parameters["id"]
|
val id = parameters["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val position = parameters["position"]?.toLongOrNull()
|
val position = parameters["position"]?.toLongOrNull()
|
||||||
if (position == null || position < 0) {
|
if (position == null || position < 0) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing or invalid: position")
|
call.respondSubsonicError(10, "Required parameter is missing or invalid: position")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LibraryRepository.song(id, user.effectiveFolderIds(library, parameters["musicFolderId"]), user.name) == null) {
|
if (LibraryRepository.song(id, user.effectiveFolderIds(library, parameters["musicFolderId"]), user.name) == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
UserStateRepository.createBookmark(user.name, id, position)
|
UserStateRepository.createBookmark(user.name, id, position)
|
||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/deleteBookmark") { call, user ->
|
subsonicEndpoint(users, "/deleteBookmark") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
UserStateRepository.deleteBookmark(user.name, id)
|
UserStateRepository.deleteBookmark(user.name, id)
|
||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getLyricsBySongId") { call, user ->
|
subsonicEndpoint(users, "/getLyricsBySongId") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val id = parameters["id"]
|
val id = parameters["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
val folders = user.effectiveFolderIds(library, parameters["musicFolderId"])
|
||||||
val song = LibraryRepository.song(id, folders, user.name)
|
val song = LibraryRepository.song(id, folders, user.name)
|
||||||
if (song == null) {
|
if (song == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val lyrics = LibraryRepository.lyrics(id, folders)
|
val lyrics = LibraryRepository.lyrics(id, folders)
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ fun Route.mediaRoutes(
|
|||||||
coverArtService: CoverArtService,
|
coverArtService: CoverArtService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
subsonicGet(users, "/stream") { call, user ->
|
subsonicEndpoint(users, "/stream") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolved = LibraryRepository.resolveSong(
|
val resolved = LibraryRepository.resolveSong(
|
||||||
@@ -33,17 +33,17 @@ fun Route.mediaRoutes(
|
|||||||
)
|
)
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondFile(resolved.file.toFile())
|
call.respondFile(resolved.file.toFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/download") { call, user ->
|
subsonicEndpoint(users, "/download") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolved = LibraryRepository.resolveSong(
|
val resolved = LibraryRepository.resolveSong(
|
||||||
@@ -54,7 +54,7 @@ fun Route.mediaRoutes(
|
|||||||
)
|
)
|
||||||
if (resolved == null) {
|
if (resolved == null) {
|
||||||
call.respondSubsonicError(70, "Song not found")
|
call.respondSubsonicError(70, "Song not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.response.headers.append(
|
call.response.headers.append(
|
||||||
@@ -64,19 +64,19 @@ fun Route.mediaRoutes(
|
|||||||
call.respondFile(resolved.file.toFile())
|
call.respondFile(resolved.file.toFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getCoverArt") { call, user ->
|
subsonicEndpoint(users, "/getCoverArt") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val id = parameters["id"]
|
val id = parameters["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val requestedSize = parameters["size"]
|
val requestedSize = parameters["size"]
|
||||||
val size = requestedSize?.toIntOrNull()
|
val size = requestedSize?.toIntOrNull()
|
||||||
if (requestedSize != null && (size == null || size !in 1..2048)) {
|
if (requestedSize != null && (size == null || size !in 1..2048)) {
|
||||||
call.respondSubsonicError(10, "Invalid cover size")
|
call.respondSubsonicError(10, "Invalid cover size")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
@@ -90,7 +90,7 @@ fun Route.mediaRoutes(
|
|||||||
|
|
||||||
if (albumId == null) {
|
if (albumId == null) {
|
||||||
call.respond(HttpStatusCode.NotFound)
|
call.respond(HttpStatusCode.NotFound)
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val cover = if (size == null) {
|
val cover = if (size == null) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import win.taptap.musicmanager.subsonic.respondSubsonic
|
|||||||
fun Route.playQueueRoutes(users: UsersConfig, library: LibraryConfig) {
|
fun Route.playQueueRoutes(users: UsersConfig, library: LibraryConfig) {
|
||||||
|
|
||||||
for (endpoint in listOf("/savePlayQueue", "/savePlayQueueByIndex")) {
|
for (endpoint in listOf("/savePlayQueue", "/savePlayQueueByIndex")) {
|
||||||
subsonicGet(users, endpoint) { call, user ->
|
subsonicEndpoint(users, endpoint) { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ fun Route.playQueueRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (endpoint in listOf("/getPlayQueue", "/getPlayQueueByIndex")) {
|
for (endpoint in listOf("/getPlayQueue", "/getPlayQueueByIndex")) {
|
||||||
subsonicGet(users, endpoint) { call, user ->
|
subsonicEndpoint(users, endpoint) { call, user ->
|
||||||
val state = PlayQueueStore.get(user.name)
|
val state = PlayQueueStore.get(user.name)
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
val songs = LibraryRepository.songsByIds(state?.songIds.orEmpty(), folders, user.name)
|
val songs = LibraryRepository.songsByIds(state?.songIds.orEmpty(), folders, user.name)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import win.taptap.musicmanager.subsonic.respondSubsonicError
|
|||||||
/** Playlist CRUD. Visibility: owned playlists plus all public playlists. */
|
/** Playlist CRUD. Visibility: owned playlists plus all public playlists. */
|
||||||
fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
||||||
|
|
||||||
subsonicGet(users, "/getPlaylists") { call, user ->
|
subsonicEndpoint(users, "/getPlaylists") { call, user ->
|
||||||
val playlists = PlaylistRepository.visibleTo(user.name)
|
val playlists = PlaylistRepository.visibleTo(user.name)
|
||||||
|
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
@@ -28,17 +28,17 @@ fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getPlaylist") { call, user ->
|
subsonicEndpoint(users, "/getPlaylist") { call, user ->
|
||||||
val id = call.subsonicParams()["id"]
|
val id = call.subsonicParams()["id"]
|
||||||
if (id.isNullOrBlank()) {
|
if (id.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val playlist = PlaylistRepository.get(id, user.name)
|
val playlist = PlaylistRepository.get(id, user.name)
|
||||||
if (playlist == null) {
|
if (playlist == null) {
|
||||||
call.respondSubsonicError(70, "Playlist not found")
|
call.respondSubsonicError(70, "Playlist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
@@ -47,7 +47,7 @@ fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(playlist, songs)) })
|
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(playlist, songs)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/createPlaylist") { call, user ->
|
subsonicEndpoint(users, "/createPlaylist") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
val requestedSongs = parameters.getAll("songId").orEmpty()
|
val requestedSongs = parameters.getAll("songId").orEmpty()
|
||||||
@@ -59,11 +59,11 @@ fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
val existing = PlaylistRepository.get(playlistId, user.name)
|
val existing = PlaylistRepository.get(playlistId, user.name)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
call.respondSubsonicError(70, "Playlist not found")
|
call.respondSubsonicError(70, "Playlist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
if (existing.owner != user.name) {
|
if (existing.owner != user.name) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val newName = parameters["name"]?.takeIf { it.isNotBlank() }
|
val newName = parameters["name"]?.takeIf { it.isNotBlank() }
|
||||||
@@ -80,35 +80,35 @@ fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
|
|
||||||
val updated = PlaylistRepository.get(playlistId, user.name)!!
|
val updated = PlaylistRepository.get(playlistId, user.name)!!
|
||||||
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(updated)) })
|
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(updated)) })
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val name = parameters["name"]
|
val name = parameters["name"]
|
||||||
if (name.isNullOrBlank()) {
|
if (name.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: name")
|
call.respondSubsonicError(10, "Required parameter is missing: name")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val playlist = PlaylistRepository.create(user.name, name.trim(), requestedSongs)
|
val playlist = PlaylistRepository.create(user.name, name.trim(), requestedSongs)
|
||||||
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(playlist)) })
|
call.respondSubsonic(buildJsonObject { put("playlist", playlistJson(playlist)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/updatePlaylist") { call, user ->
|
subsonicEndpoint(users, "/updatePlaylist") { call, user ->
|
||||||
val parameters = call.subsonicParams()
|
val parameters = call.subsonicParams()
|
||||||
val playlistId = parameters["playlistId"]
|
val playlistId = parameters["playlistId"]
|
||||||
if (playlistId.isNullOrBlank()) {
|
if (playlistId.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: playlistId")
|
call.respondSubsonicError(10, "Required parameter is missing: playlistId")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val existing = PlaylistRepository.get(playlistId, user.name)
|
val existing = PlaylistRepository.get(playlistId, user.name)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
call.respondSubsonicError(70, "Playlist not found")
|
call.respondSubsonicError(70, "Playlist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
if (existing.owner != user.name) {
|
if (existing.owner != user.name) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val folders = user.visibleFolderIds(library)
|
val folders = user.visibleFolderIds(library)
|
||||||
@@ -136,21 +136,21 @@ fun Route.playlistRoutes(users: UsersConfig, library: LibraryConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/deletePlaylist") { call, user ->
|
subsonicEndpoint(users, "/deletePlaylist") { call, user ->
|
||||||
val playlistId = call.subsonicParams()["id"]
|
val playlistId = call.subsonicParams()["id"]
|
||||||
if (playlistId.isNullOrBlank()) {
|
if (playlistId.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: id")
|
call.respondSubsonicError(10, "Required parameter is missing: id")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val existing = PlaylistRepository.get(playlistId, user.name)
|
val existing = PlaylistRepository.get(playlistId, user.name)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
call.respondSubsonicError(70, "Playlist not found")
|
call.respondSubsonicError(70, "Playlist not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
if (existing.owner != user.name) {
|
if (existing.owner != user.name) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaylistRepository.delete(playlistId, user.name)
|
PlaylistRepository.delete(playlistId, user.name)
|
||||||
|
|||||||
+18
-13
@@ -3,16 +3,18 @@ package win.taptap.musicmanager.subsonic.routes
|
|||||||
import io.ktor.server.application.ApplicationCall
|
import io.ktor.server.application.ApplicationCall
|
||||||
import io.ktor.server.routing.Route
|
import io.ktor.server.routing.Route
|
||||||
import io.ktor.server.routing.get
|
import io.ktor.server.routing.get
|
||||||
|
import io.ktor.server.routing.post
|
||||||
import win.taptap.musicmanager.config.UserAccount
|
import win.taptap.musicmanager.config.UserAccount
|
||||||
import win.taptap.musicmanager.config.UsersConfig
|
import win.taptap.musicmanager.config.UsersConfig
|
||||||
import win.taptap.musicmanager.subsonic.SubsonicAuthenticator
|
import win.taptap.musicmanager.subsonic.SubsonicAuthenticator
|
||||||
import win.taptap.musicmanager.subsonic.respondSubsonicError
|
import win.taptap.musicmanager.subsonic.respondSubsonicError
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a Subsonic GET endpoint for both `/{path}` and `/{path}.view`.
|
* Registers a Subsonic endpoint for both `/{path}` and `/{path}.view`, and for both
|
||||||
|
* GET and POST form posts (the `formPost` OpenSubsonic extension).
|
||||||
* Authentication failures always return HTTP 200 with error code 40.
|
* Authentication failures always return HTTP 200 with error code 40.
|
||||||
*/
|
*/
|
||||||
internal fun Route.subsonicGet(
|
internal fun Route.subsonicEndpoint(
|
||||||
users: UsersConfig,
|
users: UsersConfig,
|
||||||
path: String,
|
path: String,
|
||||||
handler: suspend (ApplicationCall, UserAccount) -> Unit,
|
handler: suspend (ApplicationCall, UserAccount) -> Unit,
|
||||||
@@ -20,17 +22,20 @@ internal fun Route.subsonicGet(
|
|||||||
val authenticator = SubsonicAuthenticator(users)
|
val authenticator = SubsonicAuthenticator(users)
|
||||||
val paths = if (path.endsWith(".view")) listOf(path) else listOf(path, "$path.view")
|
val paths = if (path.endsWith(".view")) listOf(path) else listOf(path, "$path.view")
|
||||||
|
|
||||||
paths.forEach { routePath ->
|
suspend fun handle(call: ApplicationCall) {
|
||||||
get(routePath) {
|
val parameters = subsonicParameters(call)
|
||||||
val parameters = subsonicParameters(call)
|
val user = authenticator.authenticate(parameters)
|
||||||
val user = authenticator.authenticate(parameters)
|
if (user == null) {
|
||||||
if (user == null) {
|
call.respondSubsonicError(40, "Wrong username or password")
|
||||||
call.respondSubsonicError(40, "Wrong username or password")
|
} else {
|
||||||
} else {
|
call.attributes.put(CurrentUserKey, user)
|
||||||
call.attributes.put(CurrentUserKey, user)
|
call.attributes.put(SubsonicParametersKey, parameters)
|
||||||
call.attributes.put(SubsonicParametersKey, parameters)
|
handler(call, user)
|
||||||
handler(call, user)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paths.forEach { routePath ->
|
||||||
|
get(routePath) { handle(call) }
|
||||||
|
post(routePath) { handle(call) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,11 +21,11 @@ fun Route.systemRoutes(
|
|||||||
startScan: () -> Boolean,
|
startScan: () -> Boolean,
|
||||||
scanStatus: () -> ScanStatus,
|
scanStatus: () -> ScanStatus,
|
||||||
) {
|
) {
|
||||||
subsonicGet(users, "/ping") { call, _ ->
|
subsonicEndpoint(users, "/ping") { call, _ ->
|
||||||
call.respondSubsonic()
|
call.respondSubsonic()
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getLicense") { call, _ ->
|
subsonicEndpoint(users, "/getLicense") { call, _ ->
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
put("license", buildJsonObject { put("valid", true) })
|
put("license", buildJsonObject { put("valid", true) })
|
||||||
@@ -33,7 +33,7 @@ fun Route.systemRoutes(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getOpenSubsonicExtensions") { call, _ ->
|
subsonicEndpoint(users, "/getOpenSubsonicExtensions") { call, _ ->
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
put(
|
put(
|
||||||
@@ -48,7 +48,7 @@ fun Route.systemRoutes(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/startScan") { call, user ->
|
subsonicEndpoint(users, "/startScan") { call, user ->
|
||||||
if (!user.admin) {
|
if (!user.admin) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
} else {
|
} else {
|
||||||
@@ -57,7 +57,7 @@ fun Route.systemRoutes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getScanStatus") { call, _ ->
|
subsonicEndpoint(users, "/getScanStatus") { call, _ ->
|
||||||
val status = scanStatus()
|
val status = scanStatus()
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
@@ -69,28 +69,28 @@ fun Route.systemRoutes(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getUser") { call, currentUser ->
|
subsonicEndpoint(users, "/getUser") { call, currentUser ->
|
||||||
val username = call.subsonicParams()["username"]
|
val username = call.subsonicParams()["username"]
|
||||||
if (username.isNullOrBlank()) {
|
if (username.isNullOrBlank()) {
|
||||||
call.respondSubsonicError(10, "Required parameter is missing: username")
|
call.respondSubsonicError(10, "Required parameter is missing: username")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username != currentUser.name && !currentUser.admin) {
|
if (username != currentUser.name && !currentUser.admin) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
val requested = users.byName(username)
|
val requested = users.byName(username)
|
||||||
if (requested == null) {
|
if (requested == null) {
|
||||||
call.respondSubsonicError(70, "User not found")
|
call.respondSubsonicError(70, "User not found")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondSubsonic(buildJsonObject { put("user", userJson(requested, library)) })
|
call.respondSubsonic(buildJsonObject { put("user", userJson(requested, library)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getInternetRadioStations") { call, _ ->
|
subsonicEndpoint(users, "/getInternetRadioStations") { call, _ ->
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
buildJsonObject {
|
buildJsonObject {
|
||||||
put("internetRadioStations", buildJsonObject {
|
put("internetRadioStations", buildJsonObject {
|
||||||
@@ -105,15 +105,15 @@ fun Route.systemRoutes(
|
|||||||
"/updateInternetRadioStation",
|
"/updateInternetRadioStation",
|
||||||
"/deleteInternetRadioStation",
|
"/deleteInternetRadioStation",
|
||||||
)) {
|
)) {
|
||||||
subsonicGet(users, endpoint) { call, _ ->
|
subsonicEndpoint(users, endpoint) { call, _ ->
|
||||||
call.respondSubsonicError(0, "Internet radio is not supported")
|
call.respondSubsonicError(0, "Internet radio is not supported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/jukeboxControl") { call, _ ->
|
subsonicEndpoint(users, "/jukeboxControl") { call, _ ->
|
||||||
if (call.subsonicParams()["action"] != "status") {
|
if (call.subsonicParams()["action"] != "status") {
|
||||||
call.respondSubsonicError(0, "Jukebox is not supported")
|
call.respondSubsonicError(0, "Jukebox is not supported")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
@@ -128,10 +128,10 @@ fun Route.systemRoutes(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
subsonicGet(users, "/getUsers") { call, currentUser ->
|
subsonicEndpoint(users, "/getUsers") { call, currentUser ->
|
||||||
if (!currentUser.admin) {
|
if (!currentUser.admin) {
|
||||||
call.respondSubsonicError(50, "Not authorized")
|
call.respondSubsonicError(50, "Not authorized")
|
||||||
return@subsonicGet
|
return@subsonicEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
call.respondSubsonic(
|
call.respondSubsonic(
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package win.taptap.musicmanager.subsonic
|
|||||||
|
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.request.header
|
import io.ktor.client.request.header
|
||||||
|
import io.ktor.client.request.post
|
||||||
|
import io.ktor.client.request.setBody
|
||||||
import io.ktor.client.statement.bodyAsBytes
|
import io.ktor.client.statement.bodyAsBytes
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.http.HttpHeaders
|
import io.ktor.http.HttpHeaders
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import io.ktor.http.contentType
|
||||||
import io.ktor.serialization.kotlinx.json.json
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import io.ktor.server.application.install
|
import io.ktor.server.application.install
|
||||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||||
@@ -335,6 +339,25 @@ class BrowsingRoutesTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `form posts are accepted for client compatibility`() {
|
||||||
|
seededContext().use { seed ->
|
||||||
|
testApplication {
|
||||||
|
setupApp(seed)
|
||||||
|
|
||||||
|
val response = client.post("/rest/getAlbumList2.view") {
|
||||||
|
contentType(ContentType.Application.FormUrlEncoded)
|
||||||
|
setBody("${credentials("alice", "alice-pw")}&type=alphabeticalByName&size=10")
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(HttpStatusCode.OK, response.status)
|
||||||
|
val albums = parseBody(response.bodyAsText())["albumList2"]!!
|
||||||
|
.jsonObject["album"]!!.jsonArray
|
||||||
|
assertEquals(seed.aliceAlbumId, albums[0].jsonObject["id"]!!.jsonPrimitive.content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `music directory and play queue expose folders albums and songs`() {
|
fun `music directory and play queue expose folders albums and songs`() {
|
||||||
seededContext().use { seed ->
|
seededContext().use { seed ->
|
||||||
|
|||||||
Reference in new issue
Block a user