Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
fix error handling and update README.md (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
shomix authored Mar 1, 2023
1 parent 2b5be77 commit 72363dc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
## Spheron Storage SDK

### Installation

Using NPM

```
npm install @spheron/storage
```

Using Yarn

```
yarn add @spheron/storage
```
Expand All @@ -41,28 +45,44 @@ In the example below, you can see how to create an instance of `SpheronClient` a
```js
import SpheronClient, { ProtocolEnum } from "@spheron/storage";

...
const client = new SpheronClient({ token });
const { uploadId, bucketId, protocolLink, dynamicLinks } = await client.upload(filePath, { protocol: ProtocolEnum.IPFS, name });
...
let currentlyUploaded = 0;
const { uploadId, bucketId, protocolLink, dynamicLinks } = await client.upload(
filePath,
{
protocol: ProtocolEnum.IPFS,
name,
onUploadInitiated: (uploadId) => {
console.log(`Upload with id ${uploadId} started...`);
},
onChunkUploaded: (uploadedSize, totalSize) => {
currentlyUploaded += uploadedSize;
console.log(`Uploaded ${currentlyUploaded} of ${totalSize} Bytes.`);
},
}
);
```

- The `SpheronClient` constructor takes an object that has one property `token`.
- Function `upload` has two parameters `client.upload(filePath, configuration);`
- `filePath` - the path to the file/directory that will be uploaded
- `configuration` - an object with two parameters:
- `configuration` - an object with parameters:
- `configuration.name` - represents the name of the bucket on which you are uploading the data.
- `configuration.protocol` - a protocol on which the data will be uploaded. The supported protocols are [ `ARWEAVE`, `IPFS`, `FILECOIN`].
- `configuration.onUploadInitiated` - **optional** - callback function `(uploadId: string) => void`. The function will be called once, when the upload is initiated, right before the data is uploaded. The function will be called with one parameter, `uploadId`, which represents the id of the started upload.
- `configuration.onChunkUploaded` - **optional** - callback function `(uploadedSize: number, totalSize: number) => void`. The function will be called multiple times, depending on the upload size. The function will be called each time a chunk is uploaded, with two parameters. the first one `uploadedSize` represents the size in Bytes for the uploaded chunk. The `totalSize` represents the total size of the upload in Bytes.
- The response of the upload function is an object with parameters:
- `uploadId` - the id of the upload
- `bucketId` - the id of the bucket
- `protocolLink` - is the protocol link of the upload
- `dynamicLinks` - are domains that you have setup for your bucket. When you upload new data to the same bucket, the domains will point to the new uploaded data.

## Contribution

We encourage you to read the [contribution guidelines](https://github.com/spheronFdn/sdk/blob/main/.github/contribution-guidelines.md) to learn about our development process and how to propose bug fixes and improvements before submitting a pull request.

The Spheron community extends beyond issues and pull requests! You can support Spheron [in many other ways](https://github.com/spheronFdn/sdk/blob/main/.github/support.md) as well.

## Community

For help, discussions or any other queries: [Join us on Discord](https://discord.com/invite/ahxuCtm)
30 changes: 22 additions & 8 deletions packages/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<p align="center">
<a href="https://www.npmjs.com/package/@spheron/storage" target="_blank" rel="noreferrer">
<img src="https://img.shields.io/static/v1?label=npm&message=v1.0.3&color=green" />
<img src="https://img.shields.io/static/v1?label=npm&message=v1.0.5&color=green" />
</a>
<a href="https://github.com/spheronFdn/sdk/blob/main/LICENSE" target="_blank" rel="noreferrer">
<img src="https://img.shields.io/static/v1?label=license&message=Apache%202.0&color=red" />
Expand All @@ -34,27 +34,41 @@ In the example below you can see how to create an instance of `SpheronClient` an
```js
import SpheronClient, { ProtocolEnum } from "@spheron/storage";

...
const client = new SpheronClient({ token });
const { uploadId, bucketId, protocolLink, dynamicLinks } = await client.upload(filePath, { protocol: ProtocolEnum.IPFS, name });
...
let currentlyUploaded = 0;
const { uploadId, bucketId, protocolLink, dynamicLinks } = await client.upload(
filePath,
{
protocol: ProtocolEnum.IPFS,
name,
onUploadInitiated: (uploadId) => {
console.log(`Upload with id ${uploadId} started...`);
},
onChunkUploaded: (uploadedSize, totalSize) => {
currentlyUploaded += uploadedSize;
console.log(`Uploaded ${currentlyUploaded} of ${totalSize} Bytes.`);
},
}
);
```

- The `SpheronClient` constructor takes an object that has one property `token`.
- Function `upload` has two parameters `client.upload(filePath, configuration);`
- `filePath` - the path to the file/directory that will be uploaded
- `configuration` - an object with two parameters:
- `configuration` - an object with parameters:
- `configuration.name` - represents the name of the bucket on which you are uploading the data.
- `configuration.protocol` - a protocol on which the data will be uploaded. The supported protocols are [ `ARWEAVE`, `IPFS`, `FILECOIN`].
- `configuration.onUploadInitiated` - **optional** - callback function `(uploadId: string) => void`. The function will be called once, when the upload is initiated, right before the data is uploaded. The function will be called with one parameter, `uploadId`, which represents the id of the started upload.
- `configuration.onChunkUploaded` - **optional** - callback function `(uploadedSize: number, totalSize: number) => void`. The function will be called multiple times, depending on the upload size. The function will be called each time a chunk is uploaded, with two parameters. the first one `uploadedSize` represents the size in Bytes for the uploaded chunk. The `totalSize` represents the total size of the upload in Bytes.
- The response of the upload function is an object with parameters:
- `uploadId` - the id of the upload
- `bucketId` - the id of the bucket
- `protocolLink` - is the protocol link of the upload
- `dynamicLinks` - are domains that you have setup for your bucket. When you upload new data to the same bucket, the domains will point to the new uploaded data.

## Learn More

You can learn more about Spheron and Storage SDK here:

* [Spheron Discord](https://discord.com/invite/ahxuCtm)
* [Spheron Twitter](https://twitter.com/SpheronFdn)
- [Spheron Discord](https://discord.com/invite/ahxuCtm)
- [Spheron Twitter](https://twitter.com/SpheronFdn)
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spheron/storage",
"version": "1.0.4",
"version": "1.0.5",
"description": "Typescript library for uploading files or directory to IPFS, Filecoin or Arweave via Spheron",
"keywords": [
"Storage",
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/src/upload-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class UploadManager {
);
return response.data;
} catch (error) {
const errorMessage = error?.data?.message || error?.message;
const errorMessage = error?.response?.data?.message || error?.message;
throw new Error(errorMessage);
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ class UploadManager {
);
return response.data;
} catch (error) {
const errorMessage = error?.data?.message || error?.message;
const errorMessage = error?.response?.data?.message || error?.message;
throw new Error(errorMessage);
}
}
Expand Down

0 comments on commit 72363dc

Please sign in to comment.