mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
feat(api-server): add endpoint to get shuffle state (#2792)
This commit is contained in:
@ -173,7 +173,24 @@ const routes = {
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
getShuffleState: createRoute({
|
||||
method: 'get',
|
||||
path: `/api/${API_VERSION}/shuffle`,
|
||||
summary: 'get shuffle state',
|
||||
description: 'Get the current shuffle state',
|
||||
responses: {
|
||||
200: {
|
||||
description: 'Success',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: z.object({
|
||||
state: z.boolean().nullable(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
shuffle: createRoute({
|
||||
method: 'post',
|
||||
path: `/api/${API_VERSION}/shuffle`,
|
||||
@ -581,6 +598,25 @@ export const register = (
|
||||
ctx.status(204);
|
||||
return ctx.body(null);
|
||||
});
|
||||
|
||||
app.openapi(routes.getShuffleState, async (ctx) => {
|
||||
const stateResponsePromise = new Promise<boolean>((resolve) => {
|
||||
ipcMain.once(
|
||||
'ytmd:get-shuffle-response',
|
||||
(_, isShuffled: boolean | undefined) => {
|
||||
return resolve(!!isShuffled);
|
||||
},
|
||||
);
|
||||
|
||||
controller.requestShuffleInformation();
|
||||
});
|
||||
|
||||
const isShuffled = await stateResponsePromise;
|
||||
|
||||
ctx.status(200);
|
||||
return ctx.json({ state: isShuffled });
|
||||
});
|
||||
|
||||
app.openapi(routes.shuffle, (ctx) => {
|
||||
controller.shuffle();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user