### Enable and Start systemd Cloud Commander Service
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Enables the Cloud Commander systemd service to start automatically on boot and starts the service immediately.
```sh
sudo systemctl enable --now cloudcmd
```
--------------------------------
### Install Nginx on Ubuntu/Debian
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Installs the Nginx web server on Ubuntu and Debian-based Linux distributions using the apt-get package manager.
```sh
sudo apt-get install nginx #for ubuntu and debian
```
--------------------------------
### Start Cloud Commander with CLI Options
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Demonstrates various command-line arguments to start Cloud Commander with different configurations, including custom ports, root directories, authentication, terminal features, and Dropbox integration.
```bash
# Start with default settings (port 8000, root /)
cloudcmd
# Start with custom port and root directory
cloudcmd --port 3000 --root /home/user/files
# Start with authentication enabled
cloudcmd --auth --username admin --password secretpass
# Start with terminal and console features
cloudcmd --terminal --console --terminal-path /usr/bin/bash
# Start with custom editor and save configuration
cloudcmd --editor dword --save
# Start with Dropbox integration
cloudcmd --dropbox --dropbox-token your-token-here
# Show current configuration
cloudcmd --show-config
# Display help
cloudcmd --help
```
--------------------------------
### Start Docker Compose Services
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Starts the services defined in a docker-compose.yml file. This command will launch the Cloud Commander container as configured.
```bash
docker-compose up
```
--------------------------------
### Install Windows Build Tools (Windows)
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Installs 'windows-build-tools' globally on Windows systems. This is often a prerequisite for installing other packages like 'gritty' that have native dependencies.
```sh
npm install windows-build-tools -g
```
--------------------------------
### Cloud Commander Configuration File Example
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
An example JSON object representing the configuration file for Cloud Commander (~/.cloudcmd.json). It lists various settings for customization, including authentication, editor, port, and terminal options.
```json
{
"name": "", // set tab name in web browser
"auth": false, // enable http authentication
"username": "root", // username for authentication
"password": "toor", // password hash for authentication
"algo": "sha512WithRSAEncryption", // cryptographic algorithm
"editor": "edward", // default, could be "dword" or "edward"
"packer": "tar", // default, could be "tar" or "zip"
"diff": true, // when save - send patch, not whole file
"zip": true, // zip text before send / unzip before save
"buffer": true, // buffer for copying files
"dirStorage": true, // store directory listing
"online": false, // do not load js files from cdn
"open": true, // open web browser when server started
"oneFilePanel": false, // show one file panel
"keysPanel": true, // show classic panel with buttons of keys
"port": 8000, // http port
"ip": null, // ip or null(default)
"root": "/", // root directory
"prefix": "", // url prefix
"prefixSocket": "", // prefix for socket connection
"confirmCopy": true, // confirm copy
"confirmMove": true, // confirm move
"showConfig": false, // show config at startup
"showDotFiles": true, // show dot files
"showFileName": false, // do not show file name in view and edit
"contact": true, // enable contact
"configDialog": true, // enable config dialog
"configAuth": true, // enable auth change in config dialog
"console": true, // enable console
"syncConsolePath": false, // do not sync console path
"terminal": false, // disable terminal
"terminalPath": "", // path of a terminal
"terminalCommand": "", // set command to run in terminal
"terminalAutoRestart": true, // restart command on exit
"vim": false, // disable vim hot keys
"themes": "name-size-date-owner-mode", // set visible themes
"export": false, // enable export of config through a server
"exportToken": "root", // token used by export server
"import": false, // enable import of config
"import-url": "http://localhost:8000", // url of an export server
"importToken": "root", // token used to connect to export server
"importListen": false, // listen on config updates
"dropbox": false, // disable dropbox integration
"dropboxToken": "", // unset dropbox token
"log": true // logging
}
```
--------------------------------
### Start Cloud Commander from Terminal
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Starts the Cloud Commander application from the command line. It will typically be accessible at http://localhost:8000.
```bash
cloudcmd
```
--------------------------------
### Initialize Node.js Project for Cloud Commander Middleware
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Initializes a new Node.js project with a package.json file using npm init. This is a prerequisite for installing Cloud Commander and its dependencies as middleware.
```bash
npm init -y
```
--------------------------------
### JavaScript User Menu Configuration Example
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
This JavaScript code defines a user menu for Cloud Commander, allowing custom actions like renaming files, building projects, and creating new menu files. It utilizes Cloud Commander's API for terminal operations, file manipulation, and UI interactions. The example demonstrates asynchronous operations and module usage.
```javascript
const RENAME_FILE = 'Rename file';
export default {
'__settings': {
select: [RENAME_FILE],
run: false,
},
[`F2 - ${RENAME_FILE}`]: async ({DOM}) => {
await DOM.renameCurrent();
},
'D - Build Dev': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client:dev',
autoClose: false, // optional
closeMessage: 'Press any button to close Terminal', // optional
});
await CloudCmd.refresh();
},
'P - Build Prod': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client',
autoClose: true, // optional
});
await CloudCmd.refresh();
},
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
const {CurrentInfo} = DOM;
const {dirPath} = CurrentInfo;
const path = `${dirPath}.cloudcmd.menu.js`;
const {prefix} = CloudCmd;
const data = await readDefaultMenu({
prefix,
});
await createDefaultMenu({
path,
data,
DOM,
CloudCmd,
});
},
};
async function createDefaultMenu({path, data, DOM, CloudCmd}) {
const {IO} = DOM;
await IO.write(path, data);
await CloudCmd.refresh();
DOM.setCurrentByName('.cloudcmd.menu.js');
await CloudCmd.EditFile.show();
}
async function readDefaultMenu({prefix}) {
const res = await fetch(`${prefix}/api/v1/user-menu/default`);
const data = await res.text();
return data;
}
```
--------------------------------
### Install Cloud Commander Globally
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Installs the Cloud Commander package globally using npm, making the 'cloudcmd' command available in the terminal.
```bash
npm i cloudcmd -g
```
--------------------------------
### Start Cloud Commander Service (Shell)
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Starts the Cloud Commander service using the system's service management utility. This command can be run manually or after a system reboot if autostart is enabled.
```shell
service cloudcmd start
```
--------------------------------
### Manage Cloud Commander Configuration Programmatically
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Illustrates how to use the `createConfigManager` function to programmatically create and manage Cloud Commander's configuration. This includes setting and getting configuration values, persisting them to `~/.cloudcmd.json`, and subscribing to configuration change events. It also shows how to use the configuration manager as Express middleware.
```javascript
import {createConfigManager, configPath} from 'cloudcmd';
// Create a configuration manager
const config = createConfigManager({ configPath });
// Get configuration values
const root = config('root'); // Returns current root directory
const allConfig = config('*'); // Returns all configuration as object
// Set configuration values
config('root', '/var/www'); // Set root directory
config('editor', 'deepword'); // Set editor
config('auth', true); // Enable authentication
config('terminal', true); // Enable terminal
config('showDotFiles', true); // Show hidden files
// Persist configuration to ~/.cloudcmd.json
await config.write();
// Subscribe to configuration changes
config.subscribe((key, value) => {
console.log(`Config changed: ${key} = ${value}`);
});
// Unsubscribe from changes
config.unsubscribe(handler);
// Use as Express middleware (handles GET/PATCH /api/v1/config)
app.use(config.middle);
```
--------------------------------
### Install Cloud Commander, Express, and Socket.IO Dependencies
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Installs the necessary npm packages for using Cloud Commander as middleware with Express and Socket.IO. The '-S' flag saves these as production dependencies.
```bash
npm i cloudcmd express socket.io -S
```
--------------------------------
### Convert Media Files to MP3 using Bash Script in Cloud Commander
Source: https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook
This JavaScript code defines user menu actions to convert `.flac` or `.mp4` files to `.mp3` format using `ffmpeg` via bash scripts executed through Cloud Commander's terminal. It includes a helper function `convert` that handles command execution, error checking, and file moving to an 'mp3' directory. Requires `ffmpeg` to be installed and Cloud Commander to be run with the '--terminal' flag.
```javascript
const isMp3 = (a) => /\.mp3$/.test(a);
export default {
'F - Convert flac to mp3': async ({DOM, CloudCmd}) => {
const command = 'for f in *.flac; do ffmpeg -vsync 2 -i "$f" -b:a 320k "${f%flac}mp3"; done';
await convert(command, {
DOM,
CloudCmd,
});
},
'M - Convert mp4 to mp3': async ({DOM, CloudCmd}) => {
const command = 'for f in *.mp4; do ffmpeg -i "$f" "${f%mp4}mp3"; done';
await convert(command, {
DOM,
CloudCmd,
});
},
};
async function convert(command, {DOM, CloudCmd}) {
const {IO, Dialog, CurrentInfo} = DOM;
const root = CloudCmd.config('root');
const cwd = `${root}${CurrentInfo.dirPath}`;
const exitCode = await CloudCmd.TerminalRun.show({
cwd,
command: `bash -c '${command}'`,
});
if (exitCode === -1)
return Dialog.alert(`☝️ Looks like Terminal is disabled, start Cloud Coammnder with '--terminal' flag.`);
if (exitCode)
return Dialog.alert(`☝️ Looks like something bad happend. Exit code: ${exitCode}`);
await CloudCmd.refresh();
const names = DOM.getFilenames(CurrentInfo.files);
const mp3Names = names.filter(isMp3);
const from = CurrentInfo.dirPath;
const to = `${from}mp3`
await IO.move(from, to, mp3Names);
await CloudCmd.refresh();
}
```
--------------------------------
### REST API - Pack Files (Archive) (Bash)
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Create compressed archives (tar.gz or zip) using the `/api/v1/pack` endpoint. Specify source directory (`from`), output path (`to`), and files/directories to include (`names`). The archive format is determined by the `packer` setting and the output file extension. Packed files can also be downloaded via GET.
```bash
# Create a tar.gz archive (default packer)
curl -X PUT "http://localhost:8000/api/v1/pack" \
-H "Content-Type: application/json" \
-d '{ "from": "/home/user/project/", "to": "/home/user/backups/project-backup.tar.gz", "names": ["src", "package.json", "README.md"] }'
# Create archive of entire directory (omit names)
curl -X PUT "http://localhost:8000/api/v1/pack" \
-H "Content-Type: application/json" \
-d '{ "from": "/home/user/documents/report/", "to": "/home/user/archives/report.tar.gz" }'
# Download packed file via GET (streams directly)
curl -X GET "http://localhost:8000/api/v1/pack/home/user/project.tar.gz" \
--output project.tar.gz
# Response on success
# {"message": "pack: ok(\"project\")"}
```
--------------------------------
### Install Cloud Commander Terminal (npm)
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Installs the 'gritty' package globally, which is required for the Cloud Commander terminal functionality. This command uses npm, the Node Package Manager.
```sh
npm i gritty -g
```
--------------------------------
### REST API - File System Operations (Bash)
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Interact with the file system using standard HTTP methods via the `/api/v1/fs` endpoint. Supports GET for retrieval, PUT for creation/update, DELETE for removal, and PATCH for partial updates. Paths are relative to the configured root directory.
```bash
# Get directory listing as JSON
curl -X GET "http://localhost:8000/api/v1/fs/"
# Get specific directory contents
curl -X GET "http://localhost:8000/api/v1/fs/home/user/documents/"
# Read file contents
curl -X GET "http://localhost:8000/api/v1/fs/home/user/file.txt"
# Create or update a file
curl -X PUT "http://localhost:8000/api/v1/fs/home/user/newfile.txt" \
-H "Content-Type: text/plain" \
-d "File content here"
# Delete a file
curl -X DELETE "http://localhost:8000/api/v1/fs/home/user/file.txt"
# Create a directory (PUT with trailing slash)
curl -X PUT "http://localhost:8000/api/v1/fs/home/user/newdir/"
# Delete a directory
curl -X DELETE "http://localhost:8000/api/v1/fs/home/user/olddir/?dir"
```
--------------------------------
### Manage Configuration via REST API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Allows retrieval and modification of Cloud Commander's settings. GET requests return the full configuration, while PATCH requests update specific options. Changes are saved to '~/.cloudcmd.json' if 'configDialog' is enabled.
```bash
# Get current configuration
curl -X GET "http://localhost:8000/api/v1/config"
# Response example:
# {
# "auth": false,
# "username": "root",
# "root": "/",
# "editor": "edward",
# "packer": "tar",
# "terminal": true,
# "console": true,
# "showDotFiles": true,
# "vim": false,
# ...
# }
# Update single configuration option
curl -X PATCH "http://localhost:8000/api/v1/config" \
-H "Content-Type: application/json" \
-d '{"editor": "deepword"}'
# Enable vim mode
curl -X PATCH "http://localhost:8000/api/v1/config" \
-H "Content-Type: application/json" \
-d '{"vim": true}'
# Update multiple options
curl -X PATCH "http://localhost:8000/api/v1/config" \
-H "Content-Type: application/json" \
-d '{"showDotFiles": true, "confirmCopy": false}'
# Response on success
# {"message": "config: ok(\"editor\")"}
```
--------------------------------
### Access Environment Variable in Terminal (Unix/macOS)
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Demonstrates how to access environment variables within the Cloud Commander terminal on Unix-like systems. This example shows how to echo the value of the CURRENT_PATH variable.
```sh
~> echo $CURRENT_PATH
/home/coderaiser/cloudcmd/bin/cloudcmd.js
```
--------------------------------
### Enable Cloud Commander Autostart (Shell)
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
This command enables the automatic startup of Cloud Commander when the system boots. It appends the necessary configuration to the `/etc/rc.conf` file.
```shell
echo cloudcmd_enable="YES" >> /etc/rc.conf
```
--------------------------------
### CloudCmd Initialization with Configuration
Source: https://github.com/coderaiser/cloudcmd/blob/master/html/index.html
Initializes CloudCmd with provided configuration options. This snippet demonstrates how to pass configuration objects for themes and columns to the CloudCmd constructor. The configuration can include various settings to customize the appearance and behavior of CloudCmd.
```javascript
CloudCmd({
config: {
columns: {
// column configuration options
},
themes: {
// theme configuration options
}
}
});
```
--------------------------------
### Socket.IO Client Connection and Event Handling (JavaScript)
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Establishes connections to Socket.IO namespaces for configuration and file operations. It demonstrates listening for events like 'config', 'log', 'err', 'progress', and 'end', as well as sending and emitting data for authentication and updates. Requires the 'socket.io-client' library.
```javascript
import {io} from 'socket.io-client';
// Connect to configuration namespace
const configSocket = io('/config', {
path: '/socket.io',
});
// Listen for configuration updates
configSocket.on('config', (settings) => {
console.log('Current config:', settings);
});
// Send configuration update
configSocket.send({editor: 'dword'});
// Listen for operation logs
configSocket.on('log', (message) => {
console.log('Operation:', message);
});
// Handle errors
configSocket.on('err', (error) => {
console.error('Config error:', error);
});
// Authentication (if auth is enabled)
configSocket.emit('auth', (accept, reject) => {
// Authenticate with stored credentials
});
// Connect to file operations namespace
const fileopSocket = io('/fileop', {
path: '/socket.io',
});
// Monitor file operation progress
fileopSocket.on('progress', ({name, percent}) => {
console.log(`${name}: ${percent}%`);
});
fileopSocket.on('end', () => {
console.log('Operation complete');
});
```
--------------------------------
### Enable and Restart Nginx
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Creates a symbolic link for the Nginx site configuration and restarts the Nginx service to apply the changes.
```sh
# create a symlink of this file
ln -s ./sites-available/io.cloudcmd.io ./sites-enabled
# restart nginx
/etc/init.d/nginx restart
```
--------------------------------
### Deploy Cloud Commander with Docker
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Provides instructions for deploying Cloud Commander using official Docker images. Supports default settings, custom root directories via volume mounts and environment variables, and authentication configuration.
```bash
# Run with default settings
docker run -p 8000:8000 coderaiser/cloudcmd
# Run with custom root directory mounted
docker run -p 8000:8000 \
-v /home/user:/root/files \
-e CLOUDCMD_ROOT=/root/files \
coderaiser/cloudcmd
# Run with authentication
docker run -p 8000:8000 \
-e CLOUDCMD_AUTH=true \
-e CLOUDCMD_USERNAME=admin \
-e CLOUDCMD_PASSWORD=secret \
coderaiser/cloudcmd
# Docker Compose example
# docker-compose.yml:
# version: '3'
# services:
# cloudcmd:
# image: coderaiser/cloudcmd
# ports:
# - "8000:8000"
# volumes:
# - /home/user:/root/files
# - ~/.cloudcmd.json:/root/.cloudcmd.json
# environment:
# - CLOUDCMD_ROOT=/root/files
# - CLOUDCMD_TERMINAL=true
# restart: unless-stopped
docker-compose up -d
```
--------------------------------
### Generate Password Hash for Cloud Commander Authorization
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Demonstrates how to generate a password hash using the 'criton' library for Cloud Commander's authentication feature. It shows both dynamic generation and the use of pre-generated hashes.
```javascript
import criton from 'criton';
const algo = 'sha512WithRSAEncryption';
// default
// you can generate a hash dynamically
const password = criton('root', algo);
// or use a pregenerated hash as well
'2b64f2e..ca5d9a9';
const auth = true;
const username = 'root';
const config = {
algo, // optional
auth,
username,
password,
};
```
--------------------------------
### Deploy Cloud Commander to Heroku
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Provides a direct link to deploy Cloud Commander to Heroku using a pre-defined template from GitHub. Includes a deploy button image for easy access.
```html
```
--------------------------------
### Create User Menu File Action for Cloud Commander
Source: https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook
This JavaScript snippet defines a user menu action to create the `.cloudcmd.menu.js` file in the current directory. It fetches default menu content from an API and writes it to the new file, then refreshes Cloud Commander and opens the file for editing. Requires network access to the default menu API.
```javascript
export default {
'C - Create User Menu File': async ({DOM, CloudCmd}) => {
const {CurrentInfo} = DOM;
const {dirPath} = CurrentInfo;
const path = `${dirPath}.cloudcmd.menu.js`;
const {prefix} = CloudCmd;
const data = await readDefaultMenu({prefix});
await createDefaultMenu({
path,
data,
DOM,
CloudCmd,
});
},
};
async function createDefaultMenu({path, data, DOM, CloudCmd}) {
const {IO} = DOM;
await IO.write(path, data);
await CloudCmd.refresh();
DOM.setCurrentByName('.cloudcmd.menu.js');
await CloudCmd.EditFile.show();
}
async function readDefaultMenu({prefix}) {
const res = await fetch(`${prefix}/api/v1/user-menu/default`);
const data = await res.text();
return data;
}
```
--------------------------------
### Copy URL to Current File Action for Cloud Commander User Menu
Source: https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook
This JavaScript snippet defines a user menu action to copy the URL of the current file to the clipboard. It constructs the URL using the current window location and file path, then uses the `@cloudcmd/clipboard` library to write the text to the clipboard. Ensure the `@cloudcmd/clipboard` library is available via CDN.
```javascript
export default {
'F6 - Copy URL to Current File': async ({DOM}) => {
const {path} = DOM.CurrentInfo;
const url = `${window.location.href}${path}`;
const {default: clipboard} = await import('https://cdn.skypack.dev/@cloudcmd/clipboard');
await clipboard.writeText(url);
}
}
```
--------------------------------
### Pack (Archive) Files API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Creates compressed archives (e.g., tar.gz, zip) from specified files and directories.
```APIDOC
## PUT /api/v1/pack
### Description
Creates a compressed archive from specified files and directories.
### Method
PUT
### Endpoint
`/api/v1/pack`
### Parameters
#### Request Body
- **from** (string) - Required - The base directory path for the files to be archived.
- **to** (string) - Required - The full path for the output archive file (including filename and extension).
- **names** (array of strings) - Optional - An array of file or directory names within the `from` path to include in the archive. If omitted, the entire directory specified by `from` is archived.
### Request Example
```bash
# Create a tar.gz archive of specific files
curl -X PUT "http://localhost:8000/api/v1/pack" \
-H "Content-Type: application/json" \
-d '{
"from": "/home/user/project/",
"to": "/home/user/backups/project-backup.tar.gz",
"names": ["src", "package.json", "README.md"]
}'
# Create archive of an entire directory
curl -X PUT "http://localhost:8000/api/v1/pack" \
-H "Content-Type: application/json" \
-d '{
"from": "/home/user/documents/report/",
"to": "/home/user/archives/report.tar.gz"
}'
```
## GET /api/v1/pack/{archivePath}
### Description
Streams a packed (archived) file directly. This endpoint is used to download the archive created by the PUT /api/v1/pack endpoint.
### Method
GET
### Endpoint
`/api/v1/pack/`
### Parameters
#### Path Parameters
- **archivePath** (string) - Required - The path to the archive file to be downloaded.
### Request Example
```bash
# Download a packed file
curl -X GET "http://localhost:8000/api/v1/pack/home/user/project.tar.gz" --output project.tar.gz
```
### Response
#### Success Response (200)
- The response body will be the content of the requested archive file.
#### Response Example
```json
{"message": "pack: ok(\"project\")"}
```
```
--------------------------------
### Convert YouTube to MP3 Action for Cloud Commander User Menu
Source: https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook
This JavaScript snippet allows users to convert YouTube videos to MP3 format directly within Cloud Commander. It prompts the user for a YouTube URL, then displays an iframe with the conversion service. It requires the `@cloudcmd/create-element` library, available via CDN.
```javascript
export default {
'Y - Youtube to mp3': async ({CloudCmd, DOM}) => {
const {View} = CloudCmd;
const {Dialog} = DOM;
const [, url] = await Dialog.prompt('YouTube URL:');
if (!url)
return;
const {default: createElement} = await import('https://cdn.skypack.dev/@cloudcmd/create-element')
const element = createElement('iframe', {
id: 'youtube-to-mp3',
width: '100%',
height: '100%',
src: `https://convert2mp3s.com/api/single/mp3?url=${url}`,
allowtransparency:"true" ,
scrolling: 'no',
style: 'border: none;',
notAppend: true,
});
createElement('style', {
parent: document.head,
dataName: 'youtube-to-mp3-style',
textContent: `
.view:has(#youtube-to-mp3) {
overflow: hidden
}
`
});
await View.show(element, {
autoSize: true,
});
},
}
```
--------------------------------
### REST API - Copy Files (Bash)
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Copy files and directories using the `/api/v1/copy` endpoint. Requires a JSON body with `from` (source directory), `to` (destination directory), and `names` (files/folders to copy). The operation completes asynchronously.
```bash
# Copy multiple files to a new location
curl -X PUT "http://localhost:8000/api/v1/copy" \
-H "Content-Type: application/json" \
-d '{ "from": "/home/user/source/", "to": "/home/user/destination/", "names": ["file1.txt", "file2.txt", "folder1"] }'
# Copy a single file
curl -X PUT "http://localhost:8000/api/v1/copy" \
-H "Content-Type: application/json" \
-d '{ "from": "/var/log/", "to": "/backup/logs/", "names": ["application.log"] }'
# Response on success
# {"message": "copy: ok(\"file1.txt, file2.txt, folder1\")"}
```
--------------------------------
### Markdown Rendering API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
This endpoint renders markdown files (`.md`) into HTML, which is useful for previewing documentation or README files. The API automatically detects markdown files and applies appropriate styling.
```APIDOC
## GET /api/v1/markdown/{filePath}
### Description
Render markdown files as HTML.
### Method
GET
### Endpoint
/api/v1/markdown/{filePath}
### Parameters
#### Path Parameters
- **filePath** (string) - Required - The full path to the markdown file to be rendered.
### Request Example
```bash
curl -X GET "http://localhost:8000/api/v1/markdown/home/user/README.md"
```
### Response
#### Success Response (200)
- **HTML content** (string) - The HTML-rendered content of the markdown file.
```
--------------------------------
### Compare Directories using JavaScript
Source: https://github.com/coderaiser/cloudcmd/wiki/User-Menu-Cookbook
Compares two lists of filenames to identify differences and selects matching files in the CloudCmd interface. It utilizes helper functions to extract filenames, compare arrays, and select files within a given panel.
```javascript
export default {
'D - Compare directories': async ({DOM}) => {
const {
CurrentInfo,
getFilenames,
getCurrentByName,
selectFile,
} = DOM;
const {
files,
filesPassive,
panel,
panelPassive,
} = CurrentInfo;
const names = getFilenames(files);
const namesPassive = getFilenames(filesPassive);
const selectedNames = compare(names, namesPassive);
const selectedNamesPassive = compare(namesPassive, names);
selectNames(selectedNames, panel, {
selectFile,
getCurrentByName,
});
selectNames(selectedNamesPassive, panelPassive, {
selectFile,
getCurrentByName,
});
},
}
function selectNames(names, panel, {selectFile, getCurrentByName}) {
for (const name of names) {
const file = getCurrentByName(name, panel);
selectFile(file);
}
};
function compare(a, b) {
const result = [];
for (const el of a) {
if (b.includes(el))
continue;
result.push(el);
}
return result;
}
```
--------------------------------
### Cloud Commander with Multiple Config Managers
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Sets up Cloud Commander with two distinct configurations using separate config managers and Socket.IO instances, mounted at different URL prefixes.
```javascript
import http from 'node:http';
import cloudcmd from 'cloudcmd';
import {Server} from 'socket.io';
import express from 'express';
const app = express();
const port = 8000;
const prefix1 = '/1';
const prefix2 = '/2';
const {createConfigManager} = cloudcmd;
const server = http.createServer(app);
const socket1 = new Server(server, {
path: `${prefix1}/socket.io`,
});
const socket2 = new Server(server, {
path: `${prefix2}/socket.io`,
});
const configManager1 = createConfigManager();
configManager1('name', '1');
const configManager2 = createConfigManager();
configManager2('name', '2');
app.use(prefix1, cloudcmd({
socket: socket1,
configManager: configManager1,
}));
app.use(prefix2, cloudcmd({
socket: socket2,
configManager: configManager2,
}));
server.listen(port);
```
--------------------------------
### Render Markdown Files via REST API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Converts markdown files (`.md`) into HTML for previewing purposes, suitable for READMEs and documentation. The endpoint automatically detects markdown files and applies appropriate rendering.
```bash
# Render a markdown file as HTML
curl -X GET "http://localhost:8000/api/v1/markdown/home/user/README.md"
# Render project documentation
curl -X GET "http://localhost:8000/api/v1/markdown/var/www/project/CHANGELOG.md"
# Response: HTML-rendered markdown content
```
--------------------------------
### Run Cloud Commander with Dropbox Integration
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Launches the Cloud Commander application with Dropbox support enabled, requiring a valid Dropbox access token for authentication.
```sh
cloudcmd --dropbox --dropbox-token your-dropbox-token
```
--------------------------------
### Create systemd Service for Cloud Commander
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Creates a systemd service unit file to manage the Cloud Commander application, specifying restart behavior, execution command, and user.
```sh
sudo nano /etc/systemd/system/cloudcmd.service
[Unit]
Description = Cloud Commander
[Service]
TimeoutStartSec = 0
Restart = always
ExecStart = THE RESULT OF which cloudcmd WE'VE EXECUTED EARLIER
User = YOUR_USER
[Install]
WantedBy = multi-user.target
```
--------------------------------
### Create FreeBSD rc Script for Cloud Commander
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Provides a template for an rc script to manage the Cloud Commander service on FreeBSD systems, including options for enabling, running as a specific user, and passing arguments.
```sh
vi /usr/local/etc/rc.d/cloudcmd
#!/bin/sh
#
# PROVIDE: cloudcmd
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Author: IhatemyISP (ihatemyisp.net)
# Version: 1.0.0
# Description:
# This script runs Cloud Commander as a service under the supplied user on boot
# 1) Place file in /usr/local/etc/rc.d/
# 2) Add cloudcmd_enable="YES" to /etc/rc.conf
# 3) (Optional) To run as non-root, add cloudcmd_runAs="user" to /etc/rc.conf
# 4) (Optional) To pass Cloud Commander args, add cloudcmd_args="" to /etc/rc.conf
# Freebsd rc library
. /etc/rc.subr
```
--------------------------------
### REST API - Move Files (Bash)
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Move files and directories using the `/api/v1/move` endpoint. Similar to copy, it requires `from`, `to`, and `names` parameters. Files are removed from the original location. Moving to/from the root directory is restricted on Windows.
```bash
# Move multiple files
curl -X PUT "http://localhost:8000/api/v1/move" \
-H "Content-Type: application/json" \
-d '{ "from": "/home/user/downloads/", "to": "/home/user/documents/", "names": ["report.pdf", "data.csv"] }'
# Move a directory
curl -X PUT "http://localhost:8000/api/v1/move" \
-H "Content-Type: application/json" \
-d '{ "from": "/tmp/", "to": "/var/archive/", "names": ["project-backup"] }'
# Response on success
# {"message": "move: ok(\"report.pdf, data.csv\")"}
```
--------------------------------
### Copy Files API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Copies files and directories from a source location to a destination. Supports copying multiple items at once.
```APIDOC
## PUT /api/v1/copy
### Description
Copies files and directories from a source to a destination.
### Method
PUT
### Endpoint
`/api/v1/copy`
### Parameters
#### Request Body
- **from** (string) - Required - The source directory path.
- **to** (string) - Required - The destination directory path.
- **names** (array of strings) - Required - An array of file or directory names to copy.
### Request Example
```bash
# Copy multiple files and a folder
curl -X PUT "http://localhost:8000/api/v1/copy" \
-H "Content-Type: application/json" \
-d '{
"from": "/home/user/source/",
"to": "/home/user/destination/",
"names": ["file1.txt", "file2.txt", "folder1"]
}'
# Copy a single file
curl -X PUT "http://localhost:8000/api/v1/copy" \
-H "Content-Type: application/json" \
-d '{
"from": "/var/log/",
"to": "/backup/logs/",
"names": ["application.log"]
}'
```
### Response
#### Success Response (200)
- **message** (string) - Confirmation message indicating the copied items.
#### Response Example
```json
{"message": "copy: ok(\"file1.txt, file2.txt, folder1\")"}
```
```
--------------------------------
### Socket.IO Events
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Real-time communication for editors, terminal, and configuration using Socket.IO namespaces.
```APIDOC
## Socket.IO Events
Real-time communication for editors, terminal, and configuration.
Cloud Commander uses Socket.IO for real-time features including live file editing, terminal sessions, console output, and configuration synchronization. Each feature connects to a dedicated namespace with the configured socket prefix.
### Namespaces
- `/config`: For configuration updates and logs.
- `/fileop`: For monitoring file operation progress.
### Events
#### Configuration Namespace (`/config`)
- **`config`**: (Listen) Receives current configuration settings.
- **`log`**: (Listen) Receives operation logs.
- **`err`**: (Listen) Receives configuration errors.
- **`auth`**: (Emit) Emits authentication credentials. Expects `accept` and `reject` callbacks.
- **`send`**: (Send) Sends a configuration update (e.g., `{editor: 'dword'}`).
#### File Operations Namespace (`/fileop`)
- **`progress`**: (Listen) Receives file operation progress updates with `name` and `percent`.
- **`end`**: (Listen) Indicates that an operation is complete.
### Client-Side Connection Example
```javascript
import {io} from 'socket.io-client';
// Connect to configuration namespace
const configSocket = io('/config', {
path: '/socket.io',
});
// Listen for configuration updates
configSocket.on('config', (settings) => {
console.log('Current config:', settings);
});
// Send configuration update
configSocket.send({editor: 'dword'});
// Connect to file operations namespace
const fileopSocket = io('/fileop', {
path: '/socket.io',
});
// Monitor file operation progress
fileopSocket.on('progress', ({name, percent}) => {
console.log(`${name}: ${percent}%`);
});
```
```
--------------------------------
### Integrate Cloud Commander as Express Middleware
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Demonstrates how to use Cloud Commander as middleware within an Express.js application. It sets up an HTTP server, Socket.IO, and configures Cloud Commander with optional settings like socket, config, modules, and configManager.
```javascript
import http from 'node:http';
import cloudcmd from 'cloudcmd';
import {Server} from 'socket.io';
import express from 'express';
const app = express();
const port = 1337;
const prefix = '/';
const server = http.createServer(app);
const socket = new Server(server, {
path: `${prefix}socket.io`,
});
const config = {
name: 'cloudcmd : )',
};
const filePicker = {
data: {
FilePicker: {
key: 'key',
},
},
};
// override option from json/modules.json
const modules = {
filePicker,
};
const {
createConfigManager,
configPath,
} = cloudcmd;
const configManager = createConfigManager({
configPath,
});
app.use(prefix, cloudcmd({
socket, // used by Config, Edit (optional) and Console (required)
config, // config data (optional)
modules, // optional
configManager, // optional
}));
server.listen(port);
```
--------------------------------
### Nginx Configuration for HTTP
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Sets up an Nginx server block to listen on port 80 for a specific domain, proxying requests to a backend server and configuring client body size and access logging.
```nginx
server {
listen 80;
client_max_body_size 100m;
server_name io.cloudcmd.io;
access_log /var/log/nginx/io.cloudcmd.io.access.log;
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
```
--------------------------------
### File System Operations API
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Provides endpoints for basic file system operations like reading, writing, creating, and deleting files and directories. All paths are relative to the configured root directory.
```APIDOC
## GET /api/v1/fs
### Description
Retrieves directory listings or file contents.
### Method
GET
### Endpoint
`/api/v1/fs` or `/api/v1/fs/`
### Parameters
#### Path Parameters
- **path** (string) - Optional - The path to the directory or file to list/read.
### Request Example
```bash
# Get root directory listing
curl -X GET "http://localhost:8000/api/v1/fs/"
# Get specific directory contents
curl -X GET "http://localhost:8000/api/v1/fs/home/user/documents/"
# Read file contents
curl -X GET "http://localhost:8000/api/v1/fs/home/user/file.txt"
```
## PUT /api/v1/fs
### Description
Creates or updates a file with the provided content, or creates a directory if the path ends with a slash.
### Method
PUT
### Endpoint
`/api/v1/fs/`
### Parameters
#### Path Parameters
- **path** (string) - Required - The path for the new file or directory.
#### Request Body
- **content** (string) - Required - The content of the file to create/update.
### Request Example
```bash
# Create or update a file
curl -X PUT "http://localhost:8000/api/v1/fs/home/user/newfile.txt" \
-H "Content-Type: text/plain" \
-d "File content here"
# Create a directory
curl -X PUT "http://localhost:8000/api/v1/fs/home/user/newdir/"
```
## DELETE /api/v1/fs
### Description
Removes a file or directory.
### Method
DELETE
### Endpoint
`/api/v1/fs/`
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to the file or directory to delete.
#### Query Parameters
- **dir** (boolean) - Optional - If present, forces deletion of a directory.
### Request Example
```bash
# Delete a file
curl -X DELETE "http://localhost:8000/api/v1/fs/home/user/file.txt"
# Delete a directory
curl -X DELETE "http://localhost:8000/api/v1/fs/home/user/olddir/?dir"
```
```
--------------------------------
### CloudCmd Module Imports via ESM
Source: https://github.com/coderaiser/cloudcmd/blob/master/html/index.html
Defines the module imports required for CloudCmd, utilizing ESM (ECMAScript Modules) and specifying CDN URLs for each dependency. This ensures that CloudCmd can load and utilize external libraries like putout, fullstore, and jessy efficiently.
```javascript
{
"imports": {
"putout": "https://esm.sh/@putout/bundle@4.7.6",
"@putout/processor-html": "https://esm.sh/@putout/processor-html",
"fullstore": "https://esm.sh/fullstore",
"jessy": "https://esm.sh/jessy"
}
}
```
--------------------------------
### Run Cloud Commander Docker Container
Source: https://github.com/coderaiser/cloudcmd/blob/master/README.md
Runs a Cloud Commander Docker container. It mounts the host's home directory to '/root', the host's root filesystem to '/mnt/fs', sets the working directory to '/root', and exposes port 8000.
```bash
docker run -it --rm -v ~:/root -v /:/mnt/fs -w=/root -p 8000:8000 coderaiser/cloudcmd
```
--------------------------------
### Configure Port Forwarding with iptables
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Sets up iptables rules to redirect incoming traffic on standard ports (80, 443) to higher ports (8000, 4430) used by Cloud Commander, allowing non-root execution.
```bash
iptables -t nat -L # look rules before
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 4430
iptables -t nat -L # look rules after
```
--------------------------------
### Nginx Configuration for HTTPS with SSL
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Configures an Nginx server block for HTTPS traffic on port 443, enabling SSL, specifying certificate and key paths, and proxying requests to a backend server.
```nginx
server {
listen 443;
client_max_body_size 100m;
ssl on;
ssl_certificate /home/coderaiser/cloudcmd/ssl/ssl.crt;
ssl_certificate_key /home/coderaiser/cloudcmd/ssl/ssl.key;
server_name io.cloudcmd.io;
access_log /var/log/nginx/io.cloudcmd.io.access.log;
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
```
--------------------------------
### Integrate Cloud Commander as Express Middleware
Source: https://context7.com/coderaiser/cloudcmd/llms.txt
Shows how to integrate Cloud Commander into an existing Express.js application using its middleware functionality. This allows Cloud Commander to handle file management routes while the main application serves other routes. Socket.IO is required for real-time features.
```javascript
import http from 'node:http';
import express from 'express';
import {Server} from 'socket.io';
import cloudcmd from 'cloudcmd';
const app = express();
const port = 8000;
const server = http.createServer(app);
const socket = new Server(server, {
path: '/socket.io',
});
const config = {
root: '/home/user/files', // Root directory to serve
prefix: '/cloudcmd', // URL prefix for Cloud Commander
editor: 'edward', // Editor: edward, dword, or deepword
packer: 'tar', // Archive format: tar or zip
auth: false, // Enable authentication
username: 'admin', // Auth username
password: 'password', // Auth password (hashed)
terminal: true, // Enable terminal
console: true, // Enable console
oneFilePanel: false, // Single panel mode
confirmCopy: true, // Confirm before copy
confirmMove: true, // Confirm before move
};
// Mount Cloud Commander middleware
const cloudcmdMiddleware = cloudcmd({
config,
socket,
});
app.use(cloudcmdMiddleware);
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
```
--------------------------------
### Nginx Configuration for WebSocket Support
Source: https://github.com/coderaiser/cloudcmd/blob/master/HELP.md
Modifies an Nginx location block to enable WebSocket support by setting appropriate proxy headers for upgrade and connection.
```nginx
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:8000/;
}
```