qgustavor / megajs-cli

The CLI version of MEGAJS
MIT License
11 stars 3 forks source link

MEGAJS CLI

The CLI version of MEGAJS, inspired by megatools.

Development stopped: megatools support new accounts and way more features, this tool is not needed. It will be kept was a way to test MEGAJS with real servers and as a way to use custom thumbnail images. Issues will be fixed but no new features will be implemented.

Installation:

Install it using npm install -g megajs-cli or pnpm add --global megajs-cli or download a pre-built binary.

Usage:

To make this tool easier to MEGA users the commands are the same of megatools, same with the arguments: just replace "megatools" with "megajs".

You can set options by creating a megajs-cli.json file in the current directory, or in any parent diretory, or in your user directory; containing the options in JSON. Example: {"username": "example@example.com", "password": "correct horse battery staple"}

Arguments for all commands:

dl: download

Downloads shared files and folders

# downloads a test file to the current folder
megajs dl <shared file or folder>
megajs dl https://mega.nz/#!N90lwbqL!MkbqwNRYPF4uFCN35zetE3PHOzP-NQc20hasZxPg5k8

If a folder is specified each file will be downloaded. If the download file exists it will not be replaced.

Supported arguments:

You can download single files in folders by specifing the file handle:

$ megajs ls --human --long --header "https://mega.nz/#F!ExampleE!xampleExampleExampleEx"
=============================================================
Handle   Owner    T    Size Mod. Date           Filename
=============================================================
HandleAA OwnerID 0 1.0 KiB 1970-01-01 00:00:00 example-1.txt
HandleZZ OwnerID 0 2.0 KiB 1970-01-01 00:00:00 example-2.txt

$ megajs dl "https://mega.nz/#F!ExampleE!xampleExampleExampleEx!HandleAA"
example-1.txt was downloaded

You can also use regular expressions and glob expressions, like wget:

$ megajs dl "https://mega.nz/#F!ExampleE!xampleExampleExampleEx" -A "*1.txt"
example-1.txt was downloaded

Using unsafe HTTP may leak information about what's being downloaded to network administrators/ISP if the content being downloaded is already known or if the content was uploaded from a vulnerable MEGA client using weak encryption keys (those exist and are popular), but using it can reduce issues with MEGA servers since that's the default behavior in other clients.

Limiting the number of connections to 1 will disable download chunking which is known to reduce issues with MEGA servers and, sometimes, result in faster downloads than the default 4 connections.

The integrity of interrupted downloads and existing files will be checked. It may take time depending on your CPU and, mainly, storage speed (it takes more time in a HDD than SSD). In order to disable this check use --no-verify.

put: upload

Uploads files to MEGA

# downloads a test file to the current folder
megajs put test.txt

Supported arguments:

Note that the underlining library don't support parallel connections when uploading, but pull requests adding this feature are appreciated.

Using unsafe HTTP may leak information about what's being uploaded to network administrators/ISP if the encryption gets leaked or published, but using it can reduce issues with MEGA servers since that's the default behavior in other clients.

ls: list

Lists files in remote folders

# list all files from a user
megajs ls

# list files from a user folder
megajs ls /Root

# list files from a shared folder
megajs ls "https://mega.nz/#F!98NDUTDK!3GatsuNoLion-IsAmazing"

Supported arguments:

In order to keep compatibility sharing functions are handled by this command:

mkdir

Creates a folder in MEGA

megajs mkdir "/Root/Example"
megajs mkdir "/Root/Example Folder"

Creating a folder in contacts isn't supported.

thumbnail / preview

Uploads a thumbnail or preview image to a already uploaded file.

# Upload a thumbnail image
megajs thumbnail /Root/RemoteFile.ext thumbnail-image.jpg
# Upload a preview image
megajs preview /Root/RemoteFile.ext preview-image.jpg

The thumbnail and preview images follow the same rules as in the put command. Any file accepts thumbnails and preview images, so be creative.

Credits

Part of the CLI code was inspired on Firebase CLI by Firebase and WebTorrent CLI by WebTorrent, LLC, both MIT Licensed.