fix(api-server): Various fixes and improvements (#2496)

This commit is contained in:
JustMrPhoenix
2024-10-14 11:48:11 +04:00
committed by GitHub
parent 9d7e2a06bc
commit b6cefef8fb
3 changed files with 17 additions and 38 deletions

View File

@ -73,12 +73,26 @@ export const backend = createBackend<BackendType, APIServerConfig>({
registerAuth(this.app, ctx); registerAuth(this.app, ctx);
// swagger // swagger
this.app.openAPIRegistry.registerComponent(
'securitySchemes',
'bearerAuth',
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
);
this.app.doc('/doc', { this.app.doc('/doc', {
openapi: '3.1.0', openapi: '3.1.0',
info: { info: {
version: '1.0.0', version: '1.0.0',
title: 'Youtube Music API Server', title: 'Youtube Music API Server',
}, },
security: [
{
bearerAuth: [],
},
],
}); });
this.app.get('/swagger', swaggerUI({ url: '/doc' })); this.app.get('/swagger', swaggerUI({ url: '/doc' }));

View File

@ -18,6 +18,7 @@ const routes = {
path: '/auth/{id}', path: '/auth/{id}',
summary: '', summary: '',
description: '', description: '',
security: [],
request: { request: {
params: z.object({ params: z.object({
id: z.string(), id: z.string(),
@ -56,11 +57,11 @@ export const register = (
title: t('plugins.api-server.dialog.request.title'), title: t('plugins.api-server.dialog.request.title'),
message: t('plugins.api-server.dialog.request.message', { message: t('plugins.api-server.dialog.request.message', {
origin: getConnInfo(ctx).remote.address, origin: getConnInfo(ctx).remote.address,
id, ID: id,
}), }),
buttons: [ buttons: [
t('plugins.api-server.dialog.request.buttons.allow'), 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, defaultId: 1,
cancelId: 1, cancelId: 1,

View File

@ -29,9 +29,6 @@ const routes = {
path: `/api/${API_VERSION}/previous`, path: `/api/${API_VERSION}/previous`,
summary: 'play previous song', summary: 'play previous song',
description: 'Plays the previous song in the queue', description: 'Plays the previous song in the queue',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -43,9 +40,6 @@ const routes = {
path: `/api/${API_VERSION}/next`, path: `/api/${API_VERSION}/next`,
summary: 'play next song', summary: 'play next song',
description: 'Plays the next song in the queue', description: 'Plays the next song in the queue',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -57,9 +51,6 @@ const routes = {
path: `/api/${API_VERSION}/play`, path: `/api/${API_VERSION}/play`,
summary: 'Play', summary: 'Play',
description: 'Change the state of the player to play', description: 'Change the state of the player to play',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -71,9 +62,6 @@ const routes = {
path: `/api/${API_VERSION}/pause`, path: `/api/${API_VERSION}/pause`,
summary: 'Pause', summary: 'Pause',
description: 'Change the state of the player to pause', description: 'Change the state of the player to pause',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -86,9 +74,6 @@ const routes = {
summary: 'Toggle play/pause', summary: 'Toggle play/pause',
description: description:
'Change the state of the player to play if paused, or pause if playing', 'Change the state of the player to play if paused, or pause if playing',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -100,9 +85,6 @@ const routes = {
path: `/api/${API_VERSION}/like`, path: `/api/${API_VERSION}/like`,
summary: 'like song', summary: 'like song',
description: 'Set the current song as liked', description: 'Set the current song as liked',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -114,9 +96,6 @@ const routes = {
path: `/api/${API_VERSION}/dislike`, path: `/api/${API_VERSION}/dislike`,
summary: 'dislike song', summary: 'dislike song',
description: 'Set the current song as disliked', description: 'Set the current song as disliked',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -175,9 +154,6 @@ const routes = {
path: `/api/${API_VERSION}/shuffle`, path: `/api/${API_VERSION}/shuffle`,
summary: 'shuffle', summary: 'shuffle',
description: 'Shuffle the queue', description: 'Shuffle the queue',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -255,9 +231,6 @@ const routes = {
path: `/api/${API_VERSION}/toggle-mute`, path: `/api/${API_VERSION}/toggle-mute`,
summary: 'toggle mute', summary: 'toggle mute',
description: 'Toggle the mute state of the player', description: 'Toggle the mute state of the player',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
204: { 204: {
description: 'Success', description: 'Success',
@ -270,9 +243,6 @@ const routes = {
path: `/api/${API_VERSION}/fullscreen`, path: `/api/${API_VERSION}/fullscreen`,
summary: 'get fullscreen state', summary: 'get fullscreen state',
description: 'Get the current fullscreen state', description: 'Get the current fullscreen state',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
200: { 200: {
description: 'Success', description: 'Success',
@ -291,9 +261,6 @@ const routes = {
path: `/api/${API_VERSION}/queue-info`, path: `/api/${API_VERSION}/queue-info`,
summary: 'get current queue info', summary: 'get current queue info',
description: 'Get the current queue info', description: 'Get the current queue info',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
200: { 200: {
description: 'Success', description: 'Success',
@ -313,9 +280,6 @@ const routes = {
path: `/api/${API_VERSION}/song-info`, path: `/api/${API_VERSION}/song-info`,
summary: 'get current song info', summary: 'get current song info',
description: 'Get the current song info', description: 'Get the current song info',
request: {
headers: AuthHeadersSchema,
},
responses: { responses: {
200: { 200: {
description: 'Success', description: 'Success',