All files / Rindu/utils/spotifyCalls play.ts

16.66% Statements 2/12
0% Branches 0/6
0% Functions 0/1
16.66% Lines 2/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  42x   4x                                                              
import type { ServerApiContext } from "types/serverContext";
import { callSpotifyApi } from "utils/spotifyCalls";
 
export async function play(
  deviceId: string,
  options: { context_uri?: string; uris?: string[]; offset?: number },
  context?: ServerApiContext
): Promise<Response> {
  const { context_uri, offset, uris } = options;
  const body: {
    context_uri?: string;
    uris?: string[];
    offset?: { position: number };
    position_ms: number;
  } = { position_ms: 0 };
 
  Iif (offset !== undefined) {
    body.offset = { position: offset };
  }
 
  if (context_uri) {
    body.context_uri = context_uri;
  } else Iif (Array.isArray(uris) && uris.length) {
    body.uris = [...new Set(uris)];
  }
 
  const res = await callSpotifyApi({
    endpoint: `/me/player/play?device_id=${deviceId}`,
    method: "PUT",
    body: JSON.stringify(body),
    context,
  });
  return res;
}