2023-03-11 19:46:51 +00:00
|
|
|
export type Response<A> =
|
|
|
|
| { type: "Success"; content: A }
|
|
|
|
| { type: "Failure"; content: string }
|
|
|
|
| { type: "Fatal"; content: string };
|
|
|
|
|
2023-03-01 14:20:58 +00:00
|
|
|
export interface TrackInfo {
|
|
|
|
id: string;
|
|
|
|
track_number?: number;
|
2023-03-02 04:54:23 +00:00
|
|
|
duration?: number;
|
2023-03-01 14:20:58 +00:00
|
|
|
name?: string;
|
|
|
|
album?: string;
|
|
|
|
artist?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getTracks = (): Promise<TrackInfo[]> =>
|
2023-03-11 19:46:51 +00:00
|
|
|
fetch("/api/v1/tracks")
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((result: Response<TrackInfo[]>) => {
|
|
|
|
switch (result.type) {
|
|
|
|
case "Success":
|
|
|
|
return result.content || [];
|
|
|
|
case "Failure":
|
|
|
|
console.log("failed: ", result.content);
|
|
|
|
return [];
|
|
|
|
case "Fatal":
|
|
|
|
console.log("fatal: ", result.content);
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2023-03-10 14:35:18 +00:00
|
|
|
|
2023-03-11 19:46:51 +00:00
|
|
|
export const playTrack = (id: string): Promise<void> =>
|
2023-03-10 14:35:18 +00:00
|
|
|
fetch("/api/v1/play", {
|
|
|
|
method: "POST",
|
|
|
|
headers: { "content-type": "application/json" },
|
|
|
|
body: JSON.stringify({ id: id }),
|
2023-03-11 19:46:51 +00:00
|
|
|
})
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((result: Response<null>) => {
|
|
|
|
console.log("result: ", result);
|
|
|
|
});
|
2023-03-11 20:08:39 +00:00
|
|
|
|
|
|
|
export const stopPlayback = (): Promise<void> =>
|
|
|
|
fetch("api/v1/stop", {
|
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((result: Response<null>) => {
|
|
|
|
console.log("result: ", result);
|
|
|
|
});
|