Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/controllers/clientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,61 @@ const getLabels = async (req, res) => {
}
}

/**
* update the profile Picture of the session user
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @throws {Error} If there is an issue setting the profile picture, an error will be thrown.
*/
const getScreenshotImage = async (req, res) => {
// #swagger.summary = 'Get client screenshot image'
// #swagger.description = 'Screenshot of the client with the given session ID.'
try {
const sessionId = req.params.sessionId
const session = sessions.get(sessionId)
if (!session) {
return res.json({ success: false, message: 'session_not_found' })
}

if (!session.pupPage) {
return res.json({ success: false, message: 'page_not_ready' })
}

const imgBase64Buffer = await session.pupPage.screenshot({
encoding: 'base64',
type: 'png'
});
const img = Buffer.from(imgBase64Buffer, 'base64');

/* #swagger.responses[200] = {
description: "Screenshot image.",
content: {
"image/png": {}
}
}
*/

res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});

return res.end(img);
} catch (error) {
console.log('getScreenshotImage ERROR', error)
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}

/**
* Adds or removes labels to/from chats.
* @async
Expand Down Expand Up @@ -1291,6 +1346,7 @@ module.exports = {
getInviteInfo,
getLabelById,
getLabels,
getScreenshotImage,
addOrRemoveLabels,
isRegisteredUser,
getNumberId,
Expand Down
1 change: 1 addition & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ clientRouter.post('/unarchiveChat/:sessionId', [middleware.sessionNameValidation
clientRouter.post('/unmuteChat/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.unmuteChat)
clientRouter.post('/unpinChat/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.unpinChat)
clientRouter.get('/getWWebVersion/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.getWWebVersion)
clientRouter.get('/getScreenshotImage/:sessionId', [middleware.sessionNameValidation], clientController.getScreenshotImage)

/**
* ================
Expand Down
74 changes: 74 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,80 @@
]
}
},
"/client/getScreenshotImage/{sessionId}": {
"get": {
"tags": [
"Client"
],
"summary": "Get client screenshot image",
"description": "Screenshot of the client with the given session ID.",
"parameters": [
{
"name": "sessionId",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Unique identifier for the session (alphanumeric and - allowed)",
"example": "f8377d8d-a589-4242-9ba6-9486a04ef80c"
}
],
"responses": {
"200": {
"description": "Screenshot image.",
"content": {
"image/png": {}
}
},
"403": {
"description": "Forbidden.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForbiddenResponse"
}
}
}
},
"404": {
"description": "Not Found.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFoundResponse"
}
}
}
},
"422": {
"description": "Unprocessable Entity.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Server Failure.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
]
}
},
"/chat/getClassInfo/{sessionId}": {
"post": {
"tags": [
Expand Down