Skip to content

Commit 1e61ae2

Browse files
Refactor Spotify selection feature branch
- Remove legacy `duration` fallback from API payload and unit tests to adhere to `duration_ms` naming convention. - Refactor `spotifyCommandParams` parsing in `socketManager.ts` to utilize concise object destructuring. - Clean up unused types and variables to simplify implementation. Co-authored-by: arii <342438+arii@users.noreply.github.com>
1 parent 7e498e7 commit 1e61ae2

3 files changed

Lines changed: 3 additions & 18 deletions

File tree

app/api/spotify/playlists/[playlistId]/tracks/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ async function getPlaylistTracks(
104104
images: track.album.images,
105105
},
106106
duration_ms: track.duration_ms,
107-
duration: track.duration_ms, // Legacy fallback
108107
uri: track.uri,
109108
}
110109
})

tests/unit/app/api/spotify/playlists/[playlistId]/tracks/route.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ describe('GET /api/spotify/playlists/[playlistId]/tracks', () => {
5959
name: 'Album 1',
6060
},
6161
duration_ms: 180000,
62-
duration: 180000,
6362
uri: 'spotify:track:t1',
6463
})
6564
})

utils/socketManager.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ExtWebSocket,
1313
HrmInputMessage,
1414
} from '../types/websocket'
15-
import { HrmStreamData, SpotifyCommandParameters } from '../types/core'
15+
import { HrmStreamData } from '../types/core'
1616
import {
1717
MAX_CALORIE_JUMP_PER_UPDATE,
1818
MAX_INITIAL_CALORIES,
@@ -426,22 +426,9 @@ const handleIncomingMessage = (
426426
)
427427

428428
const spotifyService = services.spotifyService
429-
const spotifyCommandParams: SpotifyCommandParameters = {}
430-
if (commandMsg.deviceId)
431-
spotifyCommandParams.deviceId = commandMsg.deviceId
432-
if (commandMsg.volume !== undefined)
433-
spotifyCommandParams.volume = commandMsg.volume
434-
if (commandMsg.playlistUri)
435-
spotifyCommandParams.playlistUri = commandMsg.playlistUri
436-
if (commandMsg.contextUri)
437-
spotifyCommandParams.contextUri = commandMsg.contextUri
438-
if (commandMsg.uri) spotifyCommandParams.uri = commandMsg.uri
439-
if (commandMsg.offset) {
440-
spotifyCommandParams.offset =
441-
commandMsg.offset as SpotifyCommandParameters['offset']
442-
}
429+
const { type: _type, command, ...spotifyCommandParams } = commandMsg
443430

444-
spotifyService.handleCommand(commandMsg.command, spotifyCommandParams)
431+
spotifyService.handleCommand(command, spotifyCommandParams)
445432
break
446433
}
447434
default: {

0 commit comments

Comments
 (0)