diff --git a/src/plugins/api-server/backend/routes/control.ts b/src/plugins/api-server/backend/routes/control.ts index 42510e5d..7ffbeb29 100644 --- a/src/plugins/api-server/backend/routes/control.ts +++ b/src/plugins/api-server/backend/routes/control.ts @@ -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); diff --git a/src/plugins/api-server/backend/scheme/index.ts b/src/plugins/api-server/backend/scheme/index.ts index 1cbb91e8..7b3e9379 100644 --- a/src/plugins/api-server/backend/scheme/index.ts +++ b/src/plugins/api-server/backend/scheme/index.ts @@ -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'; diff --git a/src/plugins/api-server/backend/scheme/seek.ts b/src/plugins/api-server/backend/scheme/seek.ts new file mode 100644 index 00000000..161dde78 --- /dev/null +++ b/src/plugins/api-server/backend/scheme/seek.ts @@ -0,0 +1,5 @@ +import { z } from '@hono/zod-openapi'; + +export const SeekSchema = z.object({ + seconds: z.number(), +}); diff --git a/src/providers/song-controls.ts b/src/providers/song-controls.ts index b427235d..94455018 100644 --- a/src/providers/song-controls.ts +++ b/src/providers/song-controls.ts @@ -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) => { + const secondsNumber = parseNumberFromArgsType(seconds); + if (secondsNumber !== null) { + win.webContents.send('ytmd:seek-to', seconds); + } + }, goBack: (seconds: ArgsType) => { const secondsNumber = parseNumberFromArgsType(seconds); if (secondsNumber !== null) {