EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
agentFiles.js
Go to the documentation of this file.
1/**
2 * @file agentFiles.js
3 * @module routes/agentFiles
4 * @description Remote file management endpoints for RMM agents via WebSocket communication.
5 * Provides file browser, upload, and download capabilities for remote device file systems.
6 * @requires express
7 * @requires middleware/auth
8 * @requires services/websocketManager
9 * @author RMM-PSA Development Team
10 * @copyright 2026 RMM-PSA Platform
11 * @license Proprietary
12 */
13
14/**
15 * @apiDefine AgentFiles Agent File Management
16 * Remote file system operations via RMM agents
17 */
18
19const express = require('express');
20const router = express.Router();
21const authenticateToken = require('../middleware/auth');
22const wsManager = require('../services/websocketManager');
23
24/**
25 * @api {get} /api/agent/:agentId/files List agent files
26 * @apiName ListAgentFiles
27 * @apiGroup AgentFiles
28 * @apiDescription Retrieve directory listing from remote agent file system via WebSocket.
29 * Returns list of files and folders at specified path. Requires authentication.
30 * @apiParam {string} agentId Agent ID or UUID
31 * @apiParam {string} [path=/] Directory path to list (query parameter, default: root)
32 * @apiSuccess {object[]} files Array of file/folder objects
33 * @apiSuccess {string} files.name File or folder name
34 * @apiSuccess {string} files.type Type: "file" or "directory"
35 * @apiSuccess {number} files.size File size in bytes (files only)
36 * @apiSuccess {DateTime} files.modified Last modified timestamp
37 * @apiError (500) {String} error Error message from WebSocket communication
38 * @apiExample {curl} Example:
39 * curl -X GET "http://localhost:3000/api/agent/123/files?path=/var/log" \\
40 * -H "Authorization: Bearer YOUR_TOKEN"
41 * @apiSuccessExample {json} Success-Response:
42 * HTTP/1.1 200 OK
43 * {
44 * "files": [
45 * {
46 * "name": "syslog",
47 * "type": "file",
48 * "size": 1048576,
49 * "modified": "2026-03-12T10:00:00.000Z"
50 * },
51 * {
52 * "name": "nginx",
53 * "type": "directory",
54 * "modified": "2026-03-10T08:30:00.000Z"
55 * }
56 * ]
57 * }
58 */
59router.get('/:agentId/files', authenticateToken, async (req, res) => {
60 const { agentId } = req.params;
61 const { path = '/' } = req.query;
62 try {
63 const files = await wsManager.requestAgentFileList(agentId, path);
64 res.json({ files });
65 } catch (err) {
66 res.status(500).json({ error: err.message });
67 }
68});
69
70/**
71 * @api {post} /api/agent/:agentId/files Upload file to agent
72 * @apiName UploadAgentFile
73 * @apiGroup AgentFiles
74 * @apiDescription Upload file to remote agent file system via WebSocket.
75 * TODO: Implementation pending - will forward uploaded file data to agent.
76 * @apiParam {string} agentId Agent ID or UUID
77 * @apiParam {File} file File to upload (multipart/form-data)
78 * @apiParam {string} [path=/] Destination directory path
79 * @apiSuccess {boolean} success=true Upload initiated successfully
80 * @apiExample {curl} Example:
81 * curl -X POST http://localhost:3000/api/agent/123/files \\
82 * -H "Authorization: Bearer YOUR_TOKEN" \\
83 * -F "file=@/local/path/script.ps1" \\
84 * -F "path=/opt/scripts"
85 * @apiSuccessExample {json} Success-Response:
86 * HTTP/1.1 200 OK
87 * {
88 * "success": true
89 * }
90 */
91router.post('/:agentId/files', authenticateToken, async (req, res) => {
92 const { agentId } = req.params;
93 // TODO: Handle file upload, forward to agent
94 res.json({ success: true });
95});
96
97/**
98 * @api {get} /api/agent/:agentId/files/download Download file from agent
99 * @apiName DownloadAgentFile
100 * @apiGroup AgentFiles
101 * @apiDescription Download file from remote agent file system via WebSocket stream.
102 * TODO: Implementation pending - will stream file from agent to client.
103 * @apiParam {string} agentId Agent ID or UUID
104 * @apiParam {string} filePath Full path to file on agent (query parameter)
105 * @apiSuccess {File} file Binary file stream
106 * @apiExample {curl} Example:
107 * curl -X GET "http://localhost:3000/api/agent/123/files/download?filePath=/var/log/syslog" \\
108 * -H "Authorization: Bearer YOUR_TOKEN" \\
109 * -o syslog.txt
110 * @apiSuccessExample {binary} Success-Response:
111 * HTTP/1.1 200 OK
112 * Content-Type: application/octet-stream
113 * Content-Disposition: attachment; filename="syslog"
114 *
115 * [binary file content]
116 */
117router.get('/:agentId/files/download', authenticateToken, async (req, res) => {
118 const { agentId } = req.params;
119 const { filePath } = req.query;
120 // TODO: Stream file from agent
121 res.download('/tmp/example.txt'); // Placeholder
122});
123
124module.exports = router;