EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
commands.js
Go to the documentation of this file.
1/**
2 * @file commands.js
3 * @module CommandsRoutes
4 * @description Remote command execution result handler. Receives command execution results from agents via callback endpoint. Used for async command execution where agents report back results after completing commands.
5 * @see {@link ../models/Commands} for command model and storage
6 * @apiDefine CommandsGroup Commands
7 * @apiGroup Commands
8 * @apiError (Error 500) ServerError Failed to record command result.
9 */
10
11const express = require("express");
12const router = express.Router();
13
14const Commands = require("../models/Commands");
15
16// ...existing code...
17
18/**
19 * @api {post} /commands/result/:cmdId Record command execution result
20 * @apiName RecordCommandResult
21 * @apiGroup Commands
22 * @apiDescription Callback endpoint for agents to report command execution results. Agents POST their command output to this endpoint after executing a command. Updates the command record with output and marks it as complete.
23 * @apiParam {string} cmdId Command ID (URL parameter).
24 * @apiParam {string} output Command execution output (stdout/stderr).
25 * @apiSuccess {boolean} success Operation success status (always true).
26 * @apiExample {curl} Example usage:
27 * curl -X POST -d '{"output":"Command completed successfully"}' https://api.example.com/commands/result/cmd-123
28 * @apiExample {json} Response example:
29 * {
30 * "success": true
31 * }
32 */
33router.post("/result/:cmdId", async (req, res) => {
34 const { output } = req.body;
35
36 await Commands.completeCommand(req.params.cmdId, output, true);
37 res.json({ success: true });
38});
39
40module.exports = router;