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

juriproject-skale-filestorage

v0.0.1

Published

Juri SKALE Filestorage client tools

Downloads

4

Readme

SKALE Filestorage.js

npm version Build Status codecov Discord

Javascript library which implements client for decentralized file storage on SKALE chains.

  • Node.js v8 and v10+ support

Install

Run the following command:

npm i --save @skalenetwork/filestorage.js   

Usage

To use Filestorage.js you should have SKALE endpoint.

Example: http://some.local-or-remote.node:8546

Initiating of Filestorage

Construct new Filestorage object:

new Filestorage(web3Provider, enableLogs);
Parameters

| Parameter | Description | | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- | | String | object web3Provider | URL of SKALE endpoint or one of the Web3 provider classes | | boolean enableLogs | (optional) Enable/disable console logs |

Example

Initialize with SKALE endpoint:

const Filestorage = require('@skalenetwork/filestorage.js/src/index');
let filestorage = new Filestorage('----SKALE ENDPOINT----');

Initialize with external web3 provider:

const Filestorage = require('@skalenetwork/filestorage.js/src/index');
const Web3 = require('web3');

const web3Provider = new Web3.providers.HttpProvider('----SKALE ENDPOINT----');
let filestorage = new Filestorage(web3Provider);

Upload file

Upload file using internal signing:

filestorage.uploadFile(address, filePath, fileBuffer, privateKey);

Upload file using external signing (Metamask, etc.):

filestorage.uploadFile(address, filePath, fileBuffer);
Parameters

| Parameter | Description | | ------------------- | ----------------------------------------------------------------- | | String address | Account address | | String filePath | Path of uploaded file in account directory | | Buffer fileBuffer | Uploaded file data | | String privateKey | (optional) Account private key, to sign transactions internally |

Returns

| Type | Description | | :------: | ------------------------------------------- | | String | Path of file in Filestorage |

Download file

Download file from Filestorage into browser downloads folder:

filestorage.downloadToFile(storagePath);
Parameters

| Parameter | Description | | -------------------- | ------------------------------------------- | | String storagePath | Path of file in Filestorage |

Download buffer

Download file from Filestorage into buffer

filestorage.downloadToBuffer(storagePath); 
Parameters

| Parameter | Description | | -------------------- | ------------------------------------------- | | String storagePath | Path of file in Filestorage |

Returns

| Type | Description | | :------: | ------------ | | Buffer | File content |

Delete file

Delete file using internal signing:

filestorage.deleteFile(address, filePath, privateKey);

Delete file using external signing (Metamask etc):

filestorage.deleteFile(address, filePath);
Parameters

| Parameter | Description | | ------------------- | ------------------------------------------------------ | | String address | Account address | | String filePath | Path of the file in account directory to be deleted | | String privateKey | (optional) Account private key, to sign transactions |

Create directory

Creates directory on the specific path. To create directory using internal signing:

filestorage.createDirectory(address, directoryPath, privateKey);

Create directory using external signing (Metamask etc):

filestorage.createDirectory(address, directoryPath);
Parameters

| Parameter | Description | | ------------------------ | ------------------------------------------------------ | | String address | Account address | | String directoryPath | Path of the directory to be created | | String privateKey | (optional) Account private key, to sign transactions |

Returns

| Parameter | Description | | -------------------- | ------------------------------------------------ | | String storagePath | Path of directory in Filestorage |

Delete directory

Deletes directory on the specific path. To delete directory using internal signing:

filestorage.deleteDirectory(address, directoryPath, privateKey);

Create directory using external signing (Metamask etc):

filestorage.deleteDirectory(address, directoryPath);
Parameters

| Parameter | Description | | ------------------------ | ------------------------------------------------------ | | String address | Account address | | String directoryPath | Path of the directory to be deleted | | String privateKey | (optional) Account private key, to sign transactions |

List directory

Lists content of the specific directory

filestorage.listDirectory(storagePath); 
Parameters

| Parameter | Description | | -------------------- | ------------------------------------------------ | | String storagePath | Path of directory in Filestorage |

Returns

Array of content. Each content could be file or directory.

Content Object for file contains:

| Field | Description | | -------------------------- | ------------------------------------------- | | String name | File name | | String storagePath | Path of file in Filestorage | | String isFile | Whether content is file | | number size | File size, in bytes | | number status | File uploading status | | number uploadingProgress | Upload progress, in percents |

Content Object for directory contains:

| Field | Description | | -------------------------- | ------------------------------------------------ | | String name | Directory name | | String storagePath | Path of directory in Filestorage | | String isFile | Whether content is file |

Development

Install

git clone [email protected]:skalenetwork/filestorage.js.git
cd filestorage.js
npm install

Testing

First of all, please create random files for testing:

npm run generate

To run tests locally you need environment variables defining test file path and three keypairs (address, foreign, empty):

  • TEST_FILE_PATH: path to generated file. Default ./test.txt
  • ENTRYPOINT: SKALE endpoint
  • ADDRESS: test account address
  • PRIVATEKEY: test account privatekey
  • FOREIGN_ADDRESS: second test account address
  • FOREIGN_PRIVATEKEY: second test account privatekey
  • EMPTY_ADDRESS: third test account address
  • EMPTY_PRIVATEKEY: third test account privatekey

Then execute:

npm test

Build a dist version

Note: Build scripts also do version updating in package.json

# build patch version
npm run build-patch

# build minor version
npm run build-minor

# build major version
npm run build-major

Publishing on npm:

npm publish

Versioning

The version scheme for this repo is {major}.{minor}.{patch} For more details see: https://semver.org/

Lint

Conforming to linting rules is a prerequisite to commit to filestorage.js.

npm run lint

Notes

Storage path

Storage path is a label used to point to file or directory in Filestorage. It contains 2 parts through slash:

  1. File owner address (without 0x)
  2. File/directory path in owner's root directory

Example:

77333Da3492C4BBB9CCF3EA5BB63D6202F86CDA8/directoryA/random_text.txt
77333Da3492C4BBB9CCF3EA5BB63D6202F86CDA8/random_text.txt
0x77333Da3492C4BBB9CCF3EA5BB63D6202F86CDA8/random_text.txt #Invalid storagePath

Contributing

If you have any questions please ask our development community on Discord.

Discord

License

GitHub

All contributions are made under the GNU Lesser General Public License v3. See LICENSE.