npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rabbit-company/cloudky-api

v0.1.0

Published

API for Cloudky Server

Downloads

178

Readme

CloudkyAPI-JS

The CloudkyAPI library provides a set of functions for interacting with the Cloudky server, including managing accounts, handling files, and creating shareable links. This library simplifies the process of making HTTP requests to the Cloudky API, validating input data, and handling common error scenarios.

Installation

npm i --save @rabbit-company/cloudky-api

Importing the Library

You can import the CloudkyAPI class, along with the types and error handling utilities provided by the library, like this:

import { CloudkyAPI, Errors, Validate, StandardResponse } from "@rabbit-company/cloudky-api";

If you are using TypeScript, you can also import specific types for better type checking:

import type { AccountDataResponse, AccountTokenResponse } from "@rabbit-company/cloudky-api";

Usage

Creating New Account

To create a new account using the CloudkyAPI, use the createAccount function as shown below:

const response = await CloudkyAPI.createAccount("https://your-cloudky-server.com", "yourUsername", "yourEmail", "yourPassword", 0);

if (response.error === Error.SUCCESS) {
	console.log("Account creation successful");
} else {
	console.error("Error: " + response.message);
}

Getting an Account Token

To authenticate with the Cloudky server, you can retrieve an account token using the getToken method.

const response = await CloudkyAPI.getToken("https://your-cloudky-server.com", "yourUsername", "yourPassword", "yourOTP");

if (response.token) {
	console.log("Your Authentication Token: " + response.token);
} else {
	console.error("Error: " + response.message);
}

Creating an Instance

To use the CloudkyAPI, you first need to create an instance of the CloudkyAPI class with your server URL, username and token.

const cloudky = new CloudkyAPI("https://your-cloudky-server.com", "yourUsername", "yourToken");

Retrieving Account Data

Once you have a valid instance of the CloudkyAPI, you can retrieve account data using the getAccountData method.

const accountData = await cloudky.getAccountData();

if (accountData.error === Error.SUCCESS) {
	console.log("Account Data:", accountData.data);
} else {
	console.error("Failed to retrieve account data: " + accountData.message);
}

Deleting an Account

To delete an account from the Cloudky server, use the deleteAccount method.

const res = await cloudky.deleteAccount();

if (res.error === Error.SUCCESS) {
	console.log("Account deleted successfully.");
} else {
	console.error("Failed to delete account: " + res.message);
}

Getting List of Files

To list all files, use the listFiles method.

const res = await cloudky.listFiles();

if (res.data) {
	console.log("File list: " + res.data);
} else {
	console.error("Failed to list files: " + res.message);
}

Uploading a File

To upload a file, use the uploadFile method.

const res = await cloudky.uploadFile("Documents/hello.txt", new Blob(["Hello World!"], { type: "text/plain" }));

if (res.error === Error.SUCCESS) {
	console.log("File uploaded successfully!");
} else {
	console.error("Failed to upload file: " + res.message);
}

Downloading a File

To download a file, use the downloadFile method.

const res = await cloudky.downloadFile("Documents/hello.txt");

if (res instanceof Blob) {
	console.log("File downloaded successfully!");
} else {
	console.error("Failed to download a file: " + res.message);
}

Moving Files

To move files, use the moveFiles method.

const res = await cloudky.moveFiles(["Documents/hello.txt"], "Documents/Test");

if (res.error === Error.SUCCESS) {
	console.log("Files moved successfully!");
} else {
	console.error("Failed to move files: " + res.message);
}

Renaming File

To rename a files, use the renameFile method.

const res = await cloudky.renameFile("Documents/Test/hello.txt", "Documents/Test/helloWorld.txt");

if (res.error === Error.SUCCESS) {
	console.log("File renamed successfully!");
} else {
	console.error("Failed to rename a file: " + res.message);
}

Deleting Files

To delete files, use the deleteFiles method.

const res = await cloudky.deleteFiles(["Documents/Test/helloWorld.txt"]);

if (res.error === Error.SUCCESS) {
	console.log("Files deleted successfully!");
} else {
	console.error("Failed to delete files: " + res.message);
}

Creating Share Link

To create a share link, use the createShareLink method.

Set the password or expiration to null if you do not want to protect your share link with a password or set an expiry date.

const res = await cloudky.createShareLink("Documents/Test/helloWorld.txt", "PasswordForShareLink", 1918296000000);

if (res.link) {
	console.log("Share Link successfully created: " + res.link);
} else {
	console.error("Failed to create share link: " + res.message);
}

Getting List of Share Links

To list all share links, use the listShareLinks method.

const res = await cloudky.listShareLinks();

if (res.links) {
	console.log("Share Links: " + res.links);
} else {
	console.error("Failed to list share links: " + res.message);
}

Downloading a File from Share Link

To download a file from a share link, use the downloadFromShareLink method.

Set the password to null if a share link is not protected with a password.

const res = await cloudky.downloadFromShareLink("DplrSDYswSI8ov8", "Password");

if (res instanceof Blob) {
	console.log("File from share link downloaded successfully!");
} else {
	console.error("Failed to download a file from share link: " + res.message);
}

Deleting Share Link

To delete a share link, use the deleteShareLink method.

const res = await cloudky.deleteShareLink("DplrSDYswSI8ov8");

if (res.error === Error.SUCCESS) {
	console.log("Share Link deleted successfully!");
} else {
	console.error("Failed to delete share link: " + res.message);
}

Types

The library provides several TypeScript types that are useful for type checking and code clarity:

  • StandardResponse: A standard response object from the server.
  • AccountTokenResponse: The response object when retrieving an account token.
  • AccountDataResponse: The response object when retrieving account data.
  • FileInformation: Information about a file.
  • FileListResponse: The response object when listing files.
  • ShareLink: Information about a shareable link.
  • ShareLinkCreateResponse: The response object when creating shareable links.
  • ShareLinkListResponse: The response object when listing shareable links.

Error Handling

The library uses the Errors object and Error enum for handling different types of errors. You can use these to handle specific errors based on your needs.

Example of handling an error:

import { Error } from "@rabbit-company/cloudky-api";

const res = cloudky.getAccountData();
if (res.error === Error.TOKEN_EXPIRED) {
	console.error("Token has expired.");
}

License

This project is licensed under the MIT License. See the LICENSE file for details.