feat: add get all session endpoint

This commit is contained in:
Anton Voylenko 2025-01-30 00:10:28 +02:00
commit 2b30d5c1b0
4 changed files with 94 additions and 1 deletions

View file

@ -339,6 +339,30 @@ const requestPairingCode = async (req, res) => {
} }
} }
/**
* Get all sessions.
*
* @function
* @async
* @param {Object} req - The HTTP request object.
* @param {Object} res - The HTTP response object.
* @returns {<Object>}
*/
const getSessions = async (req, res) => {
// #swagger.summary = 'Get all sessions'
// #swagger.description = 'Get all sessions.'
/* #swagger.responses[200] = {
description: "Retrieved all sessions.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/GetSessionsResponse" }
}
}
}
*/
return res.json({ success: true, result: Array.from(sessions.keys()) })
}
module.exports = { module.exports = {
startSession, startSession,
statusSession, statusSession,
@ -348,5 +372,6 @@ module.exports = {
restartSession, restartSession,
terminateSession, terminateSession,
terminateInactiveSessions, terminateInactiveSessions,
terminateAllSessions terminateAllSessions,
getSessions
} }

View file

@ -36,6 +36,7 @@ sessionRouter.use(middleware.apikey)
sessionRouter.use(middleware.sessionSwagger) sessionRouter.use(middleware.sessionSwagger)
routes.use('/session', sessionRouter) routes.use('/session', sessionRouter)
sessionRouter.get('/getSessions', sessionController.getSessions)
sessionRouter.get('/start/:sessionId', middleware.sessionNameValidation, sessionController.startSession) sessionRouter.get('/start/:sessionId', middleware.sessionNameValidation, sessionController.startSession)
sessionRouter.get('/status/:sessionId', middleware.sessionNameValidation, sessionController.statusSession) sessionRouter.get('/status/:sessionId', middleware.sessionNameValidation, sessionController.statusSession)
sessionRouter.get('/qr/:sessionId', middleware.sessionNameValidation, sessionController.sessionQrCode) sessionRouter.get('/qr/:sessionId', middleware.sessionNameValidation, sessionController.sessionQrCode)

View file

@ -72,6 +72,10 @@ const doc = {
ForbiddenResponse: { ForbiddenResponse: {
success: false, success: false,
error: 'Invalid API key' error: 'Invalid API key'
},
GetSessionsResponse: {
success: true,
result: []
} }
} }
} }

View file

@ -106,6 +106,52 @@
] ]
} }
}, },
"/session/getSessions": {
"get": {
"tags": [
"Session"
],
"summary": "Get all sessions",
"description": "Get all sessions.",
"responses": {
"200": {
"description": "Retrieved all sessions.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetSessionsResponse"
}
}
}
},
"403": {
"description": "Forbidden.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForbiddenResponse"
}
}
}
},
"500": {
"description": "Server failure.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
]
}
},
"/session/start/{sessionId}": { "/session/start/{sessionId}": {
"get": { "get": {
"tags": [ "tags": [
@ -11069,6 +11115,23 @@
"xml": { "xml": {
"name": "ForbiddenResponse" "name": "ForbiddenResponse"
} }
},
"GetSessionsResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"result": {
"type": "array",
"example": [],
"items": {}
}
},
"xml": {
"name": "GetSessionsResponse"
}
} }
}, },
"securitySchemes": { "securitySchemes": {