feat: report download status in the mood detail
The client can show a per-track Downloading/Added/Failed state in search instead of relying on a snackbar under the keyboard.
This commit is contained in:
1 parent
de1e95bfc6
commit
6763a83b03
4 files changed
+35
-4
No files matched your search
@@ -133,7 +133,7 @@ Media URLs may use `?token=` because HTML audio and images cannot send headers.
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `GET` | `/moods` | List the user's moods |
|
| `GET` | `/moods` | List the user's moods |
|
||||||
| `POST` | `/moods` | Create `{name,description,query,genres,source,collectionPercent,recommendationCount,refreshHours}` |
|
| `POST` | `/moods` | Create `{name,description,query,genres,source,collectionPercent,recommendationCount,refreshHours}` |
|
||||||
| `GET` | `/moods/{id}` | Mood detail: songs and active recommendations |
|
| `GET` | `/moods/{id}` | Mood detail: songs, active recommendations and download status |
|
||||||
| `PATCH` | `/moods/{id}` | Update options |
|
| `PATCH` | `/moods/{id}` | Update options |
|
||||||
| `DELETE` | `/moods/{id}` | Delete mood, detach songs and run GC |
|
| `DELETE` | `/moods/{id}` | Delete mood, detach songs and run GC |
|
||||||
| `GET` | `/moods/{id}/preview` | Unpersisted radio preview |
|
| `GET` | `/moods/{id}/preview` | Unpersisted radio preview |
|
||||||
|
|||||||
@@ -131,6 +131,18 @@ data class MoodDetailDto(
|
|||||||
val mood: MoodDto,
|
val mood: MoodDto,
|
||||||
val songs: List<MoodSongDto> = emptyList(),
|
val songs: List<MoodSongDto> = emptyList(),
|
||||||
val recommendations: List<RecommendationDto> = emptyList(),
|
val recommendations: List<RecommendationDto> = emptyList(),
|
||||||
|
/** In-flight and recent downloads, so the client can show a per-track status. */
|
||||||
|
val downloads: List<DownloadStatusDto> = emptyList(),
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class DownloadStatusDto(
|
||||||
|
val source: String,
|
||||||
|
val externalId: String,
|
||||||
|
val state: String,
|
||||||
|
val attempts: Int = 0,
|
||||||
|
val error: String? = null,
|
||||||
|
val songId: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -342,6 +342,18 @@ private fun detail(mood: MoodRecord): MoodDetailDto {
|
|||||||
mood = mood.toDto(),
|
mood = mood.toDto(),
|
||||||
songs = songs,
|
songs = songs,
|
||||||
recommendations = recommendations(mood),
|
recommendations = recommendations(mood),
|
||||||
|
downloads = DownloadRepository.forMood(mood.id)
|
||||||
|
.take(MAX_REPORTED_DOWNLOADS)
|
||||||
|
.map { job ->
|
||||||
|
DownloadStatusDto(
|
||||||
|
source = job.source,
|
||||||
|
externalId = job.externalId,
|
||||||
|
state = job.state,
|
||||||
|
attempts = job.attempts,
|
||||||
|
error = job.error,
|
||||||
|
songId = job.songId,
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,3 +381,6 @@ private fun recommendations(mood: MoodRecord): List<RecommendationDto> {
|
|||||||
|
|
||||||
private fun recommendationSong(moodId: String, externalId: String): SongRecord? =
|
private fun recommendationSong(moodId: String, externalId: String): SongRecord? =
|
||||||
MoodRepository.recommendation(moodId, externalId)?.songId?.let(SongRepository::byId)
|
MoodRepository.recommendation(moodId, externalId)?.songId?.let(SongRepository::byId)
|
||||||
|
|
||||||
|
/** Newest first; older finished jobs do not need to reach the client. */
|
||||||
|
private const val MAX_REPORTED_DOWNLOADS = 100
|
||||||
@@ -398,9 +398,13 @@ class ApiRoutesTest {
|
|||||||
setBody("""{"source":"youtube","externalId":"vid-new"}""")
|
setBody("""{"source":"youtube","externalId":"vid-new"}""")
|
||||||
}
|
}
|
||||||
assertEquals(HttpStatusCode.Accepted, queued.status)
|
assertEquals(HttpStatusCode.Accepted, queued.status)
|
||||||
assertTrue(
|
val queuedBody = parse(queued.bodyAsText())
|
||||||
parse(queued.bodyAsText())["downloading"]!!.jsonPrimitive.content.toBoolean(),
|
assertTrue(queuedBody["downloading"]!!.jsonPrimitive.content.toBoolean())
|
||||||
)
|
val queuedDownload = queuedBody["detail"]!!.jsonObject["downloads"]!!.jsonArray
|
||||||
|
.map { it.jsonObject }
|
||||||
|
.first { it.string("externalId") == "vid-new" }
|
||||||
|
assertEquals("queued", queuedDownload.string("state"))
|
||||||
|
assertEquals("youtube", queuedDownload.string("source"))
|
||||||
val youtubeJob = DownloadRepository.find(
|
val youtubeJob = DownloadRepository.find(
|
||||||
moodId,
|
moodId,
|
||||||
"vid-new",
|
"vid-new",
|
||||||
|
|||||||
Reference in new issue
Block a user