fix(player): now-playing с нашего бэкенда вместо сырого Record-эндпоинта
Record /stations/now использует id now-слотов, не совпадающие с id каталога, поэтому клиент не находил трек по station.id (трек/обложка не показывались). Теперь берём GET /now-playing с нашего бэка (корректный маппинг recordSync, ключ = id станции) -> плеер показывает название трека и обложку.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.radiola.data.remote
|
||||
|
||||
import com.radiola.data.remote.dto.AuthResponseDto
|
||||
import com.radiola.data.remote.dto.BackendNowPlayingDto
|
||||
import com.radiola.data.remote.dto.BackendStationDto
|
||||
import com.radiola.data.remote.dto.ChartsResponseDto
|
||||
import com.radiola.data.remote.dto.HistoryResponseDto
|
||||
@@ -25,6 +26,9 @@ interface RadiolaApi {
|
||||
@POST("auth/verify")
|
||||
suspend fun verifyMagicLink(@Body dto: MagicLinkVerifyDto): AuthResponseDto
|
||||
|
||||
@GET("now-playing")
|
||||
suspend fun getNowPlaying(): List<BackendNowPlayingDto>
|
||||
|
||||
@GET("users/me")
|
||||
suspend fun getMe(): JsonObject
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.radiola.data.remote.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
// Текущий трек станции с нашего бэкенда (ключ — числовой id станции каталога).
|
||||
@Serializable
|
||||
data class BackendNowPlayingDto(
|
||||
@SerialName("stationId") val stationId: Int,
|
||||
@SerialName("song") val song: String,
|
||||
@SerialName("artist") val artist: String,
|
||||
@SerialName("coverUrl") val coverUrl: String? = null
|
||||
)
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.radiola.data.repository
|
||||
|
||||
import com.radiola.data.remote.NowPlayingSocketClient
|
||||
import com.radiola.data.remote.RecordApi
|
||||
import com.radiola.data.remote.ApiMapper.toDomain
|
||||
import com.radiola.data.remote.RadiolaApi
|
||||
import com.radiola.domain.model.Track
|
||||
import com.radiola.domain.repository.NowPlayingRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -11,7 +10,7 @@ import kotlinx.coroutines.flow.combine
|
||||
import javax.inject.Inject
|
||||
|
||||
class NowPlayingRepositoryImpl @Inject constructor(
|
||||
private val api: RecordApi,
|
||||
private val radiolaApi: RadiolaApi,
|
||||
private val socketClient: NowPlayingSocketClient
|
||||
) : NowPlayingRepository {
|
||||
|
||||
@@ -21,9 +20,9 @@ class NowPlayingRepositoryImpl @Inject constructor(
|
||||
socketClient.connect()
|
||||
}
|
||||
|
||||
// Объединяем два источника: сокет (реалтайм, приоритет) и REST-поллинг
|
||||
// (refreshNowPlaying). Раньше REST-данные писались в _nowPlaying, но никем
|
||||
// не читались — из-за этого трек и обложка не отображались.
|
||||
// Сокет (реалтайм, приоритет) + REST-поллинг с нашего бэкенда.
|
||||
// Оба источника ключуются по числовому id станции (как в каталоге),
|
||||
// поэтому корректно сопоставляются с station.id плеера.
|
||||
override fun getNowPlaying(stationId: Int): Flow<Track?> {
|
||||
return combine(socketClient.nowPlaying, _nowPlaying) { socketMap, restMap ->
|
||||
socketMap[stationId] ?: restMap[stationId]
|
||||
@@ -37,9 +36,18 @@ class NowPlayingRepositoryImpl @Inject constructor(
|
||||
|
||||
override suspend fun refreshNowPlaying(): Result<Unit> {
|
||||
return try {
|
||||
val response = api.getNowPlaying()
|
||||
val map = response.result.associate { it.id to it.toDomain() }
|
||||
_nowPlaying.value = map
|
||||
// Берём now-playing с нашего бэкенда: там корректный маппинг
|
||||
// now-слотов Record -> id станций (recordSync). Сырой Record-эндпоинт
|
||||
// использует id now-слотов, которые не совпадают с id каталога.
|
||||
val list = radiolaApi.getNowPlaying()
|
||||
_nowPlaying.value = list.associate { dto ->
|
||||
dto.stationId to Track(
|
||||
artist = dto.artist,
|
||||
song = dto.song,
|
||||
coverUrl = dto.coverUrl,
|
||||
stationName = ""
|
||||
)
|
||||
}
|
||||
Result.success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
|
||||
Reference in New Issue
Block a user