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
8 * @apiError (Error 500) ServerError Failed to record command result.
11const express = require("express");
12const router = express.Router();
14const Commands = require("../models/Commands");
19 * @api {post} /commands/result/:cmdId Record command execution result
20 * @apiName RecordCommandResult
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:
33router.post("/result/:cmdId", async (req, res) => {
34 const { output } = req.body;
36 await Commands.completeCommand(req.params.cmdId, output, true);
37 res.json({ success: true });
40module.exports = router;