mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
feat(api-server): add absolute seek endpoint (#2748)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -8,6 +8,7 @@ import {
|
||||
AuthHeadersSchema,
|
||||
type ResponseSongInfo,
|
||||
SongInfoSchema,
|
||||
SeekSchema,
|
||||
GoForwardScheme,
|
||||
GoBackSchema,
|
||||
SwitchRepeatSchema,
|
||||
@ -103,7 +104,28 @@ const routes = {
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
seekTo: createRoute({
|
||||
method: 'post',
|
||||
path: `/api/${API_VERSION}/seek-to`,
|
||||
summary: 'seek',
|
||||
description: 'Seek to a specific time in the current song',
|
||||
request: {
|
||||
headers: AuthHeadersSchema,
|
||||
body: {
|
||||
description: 'seconds to seek to',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: SeekSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
204: {
|
||||
description: 'Success',
|
||||
},
|
||||
},
|
||||
}),
|
||||
goBack: createRoute({
|
||||
method: 'post',
|
||||
path: `/api/${API_VERSION}/go-back`,
|
||||
@ -294,25 +316,6 @@ const routes = {
|
||||
},
|
||||
},
|
||||
}),
|
||||
seekTime: createRoute({
|
||||
method: 'get',
|
||||
path: `/api/${API_VERSION}/seek-time`,
|
||||
summary: 'get current play time and video duration',
|
||||
description: 'Get current play time and video duration in seconds',
|
||||
responses: {
|
||||
200: {
|
||||
description: 'Success',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: z.object({
|
||||
current: z.number().nullable().openapi({ example: 3 }),
|
||||
duration: z.number().nullable().openapi({ example: 233 }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
songInfo: createRoute({
|
||||
method: 'get',
|
||||
path: `/api/${API_VERSION}/song-info`,
|
||||
@ -384,6 +387,13 @@ export const register = (
|
||||
ctx.status(204);
|
||||
return ctx.body(null);
|
||||
});
|
||||
app.openapi(routes.seekTo, (ctx) => {
|
||||
const { seconds } = ctx.req.valid('json');
|
||||
controller.seekTo(seconds);
|
||||
|
||||
ctx.status(204);
|
||||
return ctx.body(null);
|
||||
});
|
||||
app.openapi(routes.goBack, (ctx) => {
|
||||
const { seconds } = ctx.req.valid('json');
|
||||
controller.goBack(seconds);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export * from './auth';
|
||||
export * from './song-info';
|
||||
export * from './seek';
|
||||
export * from './go-back';
|
||||
export * from './go-forward';
|
||||
export * from './switch-repeat';
|
||||
|
||||
5
src/plugins/api-server/backend/scheme/seek.ts
Normal file
5
src/plugins/api-server/backend/scheme/seek.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { z } from '@hono/zod-openapi';
|
||||
|
||||
export const SeekSchema = z.object({
|
||||
seconds: z.number(),
|
||||
});
|
||||
@ -34,6 +34,12 @@ export default (win: BrowserWindow) => {
|
||||
playPause: () => win.webContents.send('ytmd:toggle-play'),
|
||||
like: () => win.webContents.send('ytmd:update-like', 'LIKE'),
|
||||
dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'),
|
||||
seekTo: (seconds: ArgsType<number>) => {
|
||||
const secondsNumber = parseNumberFromArgsType(seconds);
|
||||
if (secondsNumber !== null) {
|
||||
win.webContents.send('ytmd:seek-to', seconds);
|
||||
}
|
||||
},
|
||||
goBack: (seconds: ArgsType<number>) => {
|
||||
const secondsNumber = parseNumberFromArgsType(seconds);
|
||||
if (secondsNumber !== null) {
|
||||
|
||||
Reference in New Issue
Block a user