From b6cefef8fb0de76acd31eac1859b96a6beb3472a Mon Sep 17 00:00:00 2001 From: JustMrPhoenix Date: Mon, 14 Oct 2024 11:48:11 +0400 Subject: [PATCH] fix(api-server): Various fixes and improvements (#2496) --- src/plugins/api-server/backend/main.ts | 14 ++++++++ src/plugins/api-server/backend/routes/auth.ts | 5 +-- .../api-server/backend/routes/control.ts | 36 ------------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/plugins/api-server/backend/main.ts b/src/plugins/api-server/backend/main.ts index 409f8d7a..0cb89385 100644 --- a/src/plugins/api-server/backend/main.ts +++ b/src/plugins/api-server/backend/main.ts @@ -73,12 +73,26 @@ export const backend = createBackend({ registerAuth(this.app, ctx); // swagger + this.app.openAPIRegistry.registerComponent( + 'securitySchemes', + 'bearerAuth', + { + type: 'http', + scheme: 'bearer', + bearerFormat: 'JWT', + }, + ); this.app.doc('/doc', { openapi: '3.1.0', info: { version: '1.0.0', title: 'Youtube Music API Server', }, + security: [ + { + bearerAuth: [], + }, + ], }); this.app.get('/swagger', swaggerUI({ url: '/doc' })); diff --git a/src/plugins/api-server/backend/routes/auth.ts b/src/plugins/api-server/backend/routes/auth.ts index 54e034ff..335f7907 100644 --- a/src/plugins/api-server/backend/routes/auth.ts +++ b/src/plugins/api-server/backend/routes/auth.ts @@ -18,6 +18,7 @@ const routes = { path: '/auth/{id}', summary: '', description: '', + security: [], request: { params: z.object({ id: z.string(), @@ -56,11 +57,11 @@ export const register = ( title: t('plugins.api-server.dialog.request.title'), message: t('plugins.api-server.dialog.request.message', { origin: getConnInfo(ctx).remote.address, - id, + ID: id, }), buttons: [ t('plugins.api-server.dialog.request.buttons.allow'), - t('plugins.api-server.dialog.request.deny'), + t('plugins.api-server.dialog.request.buttons.deny'), ], defaultId: 1, cancelId: 1, diff --git a/src/plugins/api-server/backend/routes/control.ts b/src/plugins/api-server/backend/routes/control.ts index 45e6b24e..35d18bee 100644 --- a/src/plugins/api-server/backend/routes/control.ts +++ b/src/plugins/api-server/backend/routes/control.ts @@ -29,9 +29,6 @@ const routes = { path: `/api/${API_VERSION}/previous`, summary: 'play previous song', description: 'Plays the previous song in the queue', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -43,9 +40,6 @@ const routes = { path: `/api/${API_VERSION}/next`, summary: 'play next song', description: 'Plays the next song in the queue', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -57,9 +51,6 @@ const routes = { path: `/api/${API_VERSION}/play`, summary: 'Play', description: 'Change the state of the player to play', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -71,9 +62,6 @@ const routes = { path: `/api/${API_VERSION}/pause`, summary: 'Pause', description: 'Change the state of the player to pause', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -86,9 +74,6 @@ const routes = { summary: 'Toggle play/pause', description: 'Change the state of the player to play if paused, or pause if playing', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -100,9 +85,6 @@ const routes = { path: `/api/${API_VERSION}/like`, summary: 'like song', description: 'Set the current song as liked', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -114,9 +96,6 @@ const routes = { path: `/api/${API_VERSION}/dislike`, summary: 'dislike song', description: 'Set the current song as disliked', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -175,9 +154,6 @@ const routes = { path: `/api/${API_VERSION}/shuffle`, summary: 'shuffle', description: 'Shuffle the queue', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -255,9 +231,6 @@ const routes = { path: `/api/${API_VERSION}/toggle-mute`, summary: 'toggle mute', description: 'Toggle the mute state of the player', - request: { - headers: AuthHeadersSchema, - }, responses: { 204: { description: 'Success', @@ -270,9 +243,6 @@ const routes = { path: `/api/${API_VERSION}/fullscreen`, summary: 'get fullscreen state', description: 'Get the current fullscreen state', - request: { - headers: AuthHeadersSchema, - }, responses: { 200: { description: 'Success', @@ -291,9 +261,6 @@ const routes = { path: `/api/${API_VERSION}/queue-info`, summary: 'get current queue info', description: 'Get the current queue info', - request: { - headers: AuthHeadersSchema, - }, responses: { 200: { description: 'Success', @@ -313,9 +280,6 @@ const routes = { path: `/api/${API_VERSION}/song-info`, summary: 'get current song info', description: 'Get the current song info', - request: { - headers: AuthHeadersSchema, - }, responses: { 200: { description: 'Success',