mailru-cloud is a lightweight Node.js library that simplifies working with Mail.ru Cloud storage using the WebDAV API. It provides an easy-to-use interface for uploading, downloading, managing files, and organizing folders in your Mail.ru Cloud account.
- File Management: Upload, download, move, copy, delete, and search for files effortlessly.
- Folder Operations: Create, list, and delete directories with ease.
- Secure Authentication: Supports application-specific passwords for enhanced security.
- Stream-based Data Handling: Handles large files efficiently by utilizing streams.
Before using the library, you'll need to generate an application-specific password for Mail.ru Cloud. Here's how:
- Go to your Mail.ru Account Security Settings.
- Click "Пароли для внешних приложений" ("Passwords for external applications").
- Add a descriptive name (e.g., "WebDAV Cloud").
- Select "Полный доступ к Облаку (WebDAV)" ("Full access to Cloud (WebDAV)") for permission.
- Copy the generated password—it will only appear once!
- Use this password in your code.
Install the package using npm or yarn:
npm install mailru-cloud
# or
yarn add mailru-cloud
Import the library and initialize the client using MailRuCloud
:
import { MailRuCloud } from 'mailru-cloud'
const cloud = new MailRuCloud({
username: 'your_email@mail.ru', // Full email address
password: 'your_application_password', // Generated password
})
Use the upload
method to upload files to your Mail.ru Cloud:
import { createReadStream } from 'fs'
await cloud.file.upload(
createReadStream('./local_file.txt'),
'/cloud_directory/file.txt'
)
Download files from Mail.ru Cloud using the download
method:
import { createWriteStream } from 'fs'
const fileStream = await cloud.file.download('/cloud_directory/file.txt')
fileStream.pipe(createWriteStream('./downloaded_file.txt'))
The find
method allows you to search for specific files based on their names, ETags, or other criteria. Both filename
and etag
parameters are optional, allowing flexible searches based on one or both criteria. Here's how to use it:
const foundFile = await cloud.file.find({
filename: 'example.txt', // Search by filename
etag: '12345', // Optional: Search by ETag
folderPath: '/cloud_directory/', // Specify the starting directory
recursive: true, // Enable recursive search
sensitive: false, // Case-insensitive search
})
console.log(foundFile) // Output the result
-
filename
(optional): The name of the file you're searching for. Can be combined withetag
for precise searches. -
etag
(optional): An ETag for the file, which can help identify the latest version. Can be used alone or together withfilename
. -
folderPath
(default:/
): The directory where the search starts. -
recursive
(default:false
): Whether to perform a recursive search through subdirectories. -
sensitive
(default:false
): Whether the search should be case-sensitive.
Move files within your Mail.ru Cloud using the move
method:
await cloud.file.move('/current_path/file.txt', '/new_path/file.txt')
Copy files within your Mail.ru Cloud using the copy
method:
await cloud.file.copy('/original_path/file.txt', '/duplicate_path/file.txt')
Remove files from your Mail.ru Cloud using the remove
method:
await cloud.file.remove('/path_to_delete/file.txt')
Use the create
method to create new directories:
await cloud.folder.create('new_folder', '/parent_directory/')
List the contents of a directory using the list
method:
const folderContents = await cloud.folder.list('/parent_directory/')
console.log(folderContents)
Delete directories recursively using the delete
method:
await cloud.folder.delete('/parent_directory/new_folder/')
If you're experiencing issues with authentication or file operations, double-check that you've correctly generated and used your application-specific password. Also ensure that the paths specified are correct and that the requested actions align with the limitations imposed by Mail.ru Cloud's WebDAV API.
This project is licensed under the MIT License—see the LICENSE file for more information.