1.0.0 • Published 8 months ago
@oronila/nebula-client v1.0.0
Nebula Node.js Client
A Node.js client library for interacting with the Nebula file system API.
Installation
npm install nebula-clientUsage
const { NebulaClient } = require('nebula-client');
// Initialize the client with your API key
const client = new NebulaClient({ apiKey: 'your_api_key' });
// List files in a cluster
async function listFiles() {
try {
const files = await client.listFiles({
clusterId: 'your_cluster_id',
folderId: 'ROOT' // optional, defaults to ROOT
});
console.log(files);
} catch (error) {
console.error('Error listing files:', error);
}
}
// Upload a file
async function uploadFile() {
try {
const result = await client.uploadFile({
clusterId: 'your_cluster_id',
filePath: 'path/to/your/file.txt',
folderId: 'ROOT' // optional
});
console.log(result);
} catch (error) {
console.error('Error uploading file:', error);
}
}
// Download a file
async function downloadFile() {
try {
await client.downloadFile({
clusterId: 'your_cluster_id',
fileId: 'file_id',
outputPath: 'path/to/save'
});
console.log('File downloaded successfully');
} catch (error) {
console.error('Error downloading file:', error);
}
}
// Create a folder
async function createFolder() {
try {
const folder = await client.createFolder({
clusterId: 'your_cluster_id',
folderName: 'New Folder',
parentFolderId: 'ROOT' // optional
});
console.log(folder);
} catch (error) {
console.error('Error creating folder:', error);
}
}
// Delete files or folders
async function deleteFiles() {
try {
await client.deleteFiles({
clusterId: 'your_cluster_id',
fileIds: ['file_id_1', 'file_id_2']
});
console.log('Files deleted successfully');
} catch (error) {
console.error('Error deleting files:', error);
}
}
// Move files to a different folder
async function moveFiles() {
try {
await client.moveFiles({
clusterId: 'your_cluster_id',
fileIds: ['file_id_1', 'file_id_2'],
targetFolderId: 'target_folder_id'
});
console.log('Files moved successfully');
} catch (error) {
console.error('Error moving files:', error);
}
}
// Rename a file or folder
async function renameFile() {
try {
await client.renameFile({
clusterId: 'your_cluster_id',
fileId: 'file_id',
newName: 'New Name'
});
console.log('File renamed successfully');
} catch (error) {
console.error('Error renaming file:', error);
}
}API Reference
NebulaClient
The main client class for interacting with the Nebula API.
constructor({ apiKey, baseUrl })
Initialize a new client instance.
apiKey(string): Your Nebula API keybaseUrl(string, optional): Custom API base URL. Defaults to production API.
File Operations
listFiles({ clusterId, folderId }): List files and foldersgetUploadUrl({ clusterId, fileName, folderId, contentType }): Get a pre-signed upload URLuploadFile({ clusterId, filePath, folderId, contentType }): Upload a filegetDownloadUrl({ clusterId, fileId }): Get a pre-signed download URLdownloadFile({ clusterId, fileId, outputPath }): Download a filecreateFolder({ clusterId, folderName, parentFolderId }): Create a folderdeleteFiles({ clusterId, fileIds }): Delete files/foldersmoveFiles({ clusterId, fileIds, targetFolderId }): Move files to another folderrenameFile({ clusterId, fileId, newName }): Rename a file/folder
License
MIT
1.0.0
8 months ago