Skip to content

Commit

Permalink
Merge pull request #18 from filswan/feature/cali-support
Browse files Browse the repository at this point in the history
Feature/cali support
  • Loading branch information
rykci authored Jan 23, 2023
2 parents 18d9b64 + 0063e43 commit f983e97
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 147 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Here is the demo to get you started; you can get more information in the [SDK do
const mcs = await mcsSDK.initialize({
apiKey: process.env.API_KEY,
accessToken: process.env.ACCESS_TOKEN,
chainName: 'polygon.mainnet',
})
}
Expand All @@ -106,8 +107,19 @@ Here is the demo to get you started; you can get more information in the [SDK do
Optionally, you can pass `privateKey` to use the onChain Storage upload and payment functions and pass `rpcUrl` if you wish to use your own RPC URL (this SDK uses https://polygon-rpc.com/ by default).
This SDK is also compatiable with our calibration environment on the Mumbai testnet. Use `chainName: 'polygon.mumbai'` and generate a new API KEY from [calibration-mcs.filswan.com/](https://calibration-mcs.filswan.com/)
### For Onchain Storage
To use certain Onchain Storage features (upload, payment, minting), you will need to set up the web3 environment first.
- Setup Web3
```js
await mcs.setupWeb3(<PRIVATE_KEY>, <RPC_URL>)
console.log(mcs.web3Initialized) // true
```
- Upload File to Onchain storage
```js
Expand Down
29 changes: 13 additions & 16 deletions sdk-test/mcs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ describe('MCS SDK', function () {
expect(mcs)
})

it('Should add private key', async () => {
it('Should setup web3', async () => {
expect(mcs.walletAddress).to.be.undefined
await mcs.addPrivateKey(process.env.PRIVATE_KEY)
await mcs.setupWeb3(process.env.PRIVATE_KEY)
expect(mcs.walletAddress)
})

xdescribe('MCS functions', () => {
describe('Onchain Storage functions', () => {
it('Should upload a file', async () => {
const testFile = JSON.stringify({ address: mcs.walletAddress })
const fileArray = [
Expand Down Expand Up @@ -93,27 +93,26 @@ describe('MCS SDK', function () {
})
})

describe('Buckets functions', () => {
describe('Bucket Storage functions', () => {
let bucketUid
describe('Buckets', () => {
it('Should remove test-bucket', async () => {
let buckets = await mcs.getBuckets()
let testBucket = buckets.data.find(
(b) => b.BucketName === 'test-bucket',
(b) => b.bucket_name === 'test-bucket',
)

if (testBucket) {
await mcs.deleteBucket(testBucket.BucketUid)
await mcs.deleteBucket(testBucket.bucket_uid)
}

buckets = await mcs.getBuckets()
testBucket = buckets.data.find((b) => b.BucketName === 'test-bucket')
testBucket = buckets.data.find((b) => b.bucket_name === 'test-bucket')

expect(testBucket).to.be.undefined
})
it('Should create a new bucket', async () => {
let bucket = await mcs.createBucket('test-bucket')

bucketUid = bucket.data

expect(bucket.status).to.equal('success')
Expand All @@ -134,7 +133,6 @@ describe('MCS SDK', function () {
let upload = await mcs.uploadToBucket(`./${fileName}`, bucketUid, '')

fileId = upload.data.file_id

expect(upload.status).to.equal('success')
})

Expand All @@ -147,7 +145,6 @@ describe('MCS SDK', function () {

it('Should download a file from bucket', async () => {
let res = await mcs.downloadFile(fileId, './download')

const data = await fs.readFile(`./download/${fileName}`, 'utf8')
expect(data).to.equal(fileName)
})
Expand Down Expand Up @@ -196,19 +193,19 @@ describe('MCS SDK', function () {
let upload = await mcs.uploadToBucket(`./f1`, bucketUid, 'test-folder')

let bucketInfo = (await mcs.getBuckets()).data.find(
(buckets) => buckets.BucketUid === bucketUid,
(buckets) => buckets.bucket_uid === bucketUid,
)
expect(bucketInfo.FileNumber).to.equal(3)
expect(bucketInfo.file_number).to.equal(3)
})

it('Should delete the folder', async () => {
let folder = (await mcs.getFileList(bucketUid)).FileList.find(
(file) => file.Name === 'test-folder',
let folder = (await mcs.getFileList(bucketUid)).file_list.find(
(file) => file.name === 'test-folder',
)
let res = await mcs.deleteFile(folder.ID)
let res = await mcs.deleteFile(folder.id)
let updatedList = await mcs.getFileList(bucketUid)
expect(res.status).to.equal('success')
expect(updatedList.Count).to.equal(0)
expect(updatedList.count).to.equal(0)
})
})
})
Expand Down
12 changes: 12 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Here is the demo to get you started; you can get more information in the [SDK do
const mcs = await mcsSDK.initialize({
apiKey: process.env.API_KEY,
accessToken: process.env.ACCESS_TOKEN,
chainName: 'polygon.mainnet',
})
}
Expand All @@ -106,8 +107,19 @@ Here is the demo to get you started; you can get more information in the [SDK do
Optionally, you can pass `privateKey` to use the onChain Storage upload and payment functions and pass `rpcUrl` if you wish to use your own RPC URL (this SDK uses https://polygon-rpc.com/ by default).
This SDK is also compatiable with our calibration environment on the Mumbai testnet. Use `chainName: 'polygon.mumbai'` and generate a new API KEY from [calibration-mcs.filswan.com/](https://calibration-mcs.filswan.com/)
### For Onchain Storage
To use certain Onchain Storage features (upload, payment, minting), you will need to set up the web3 environment first.
- Setup Web3
```js
await mcs.setupWeb3(<PRIVATE_KEY>, <RPC_URL>)
console.log(mcs.web3Initialized) // true
```
- Upload File to Onchain storage
```js
Expand Down
17 changes: 8 additions & 9 deletions sdk/api/buckets/buckets.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
const { BUCKETS_API } = require('../../helper/constants')
const axios = require('axios')

const getBuckets = async (jwt) => {
const getBuckets = async (api, jwt) => {
const config = {
headers: { Authorization: `Bearer ${jwt}` },
}
try {
const res = await axios.get(`${BUCKETS_API}bucket/get_bucket_list`, config)
const res = await axios.get(`${api}/v2/bucket/get_bucket_list`, config)

return res.data
} catch (err) {
console.error(err.response?.data)
}
}

const createBucket = async (jwt, bucketName) => {
const createBucket = async (api, jwt, bucketName) => {
const config = {
headers: { Authorization: `Bearer ${jwt}` },
}

try {
const res = await axios.post(
`${BUCKETS_API}bucket/create/`,
`${api}/v2/bucket/create/`,
{ bucket_name: `${bucketName.trim()}` },
config,
)
Expand All @@ -32,14 +31,14 @@ const createBucket = async (jwt, bucketName) => {
}
}

const deleteBucket = async (jwt, bucketUid) => {
const deleteBucket = async (api, jwt, bucketUid) => {
const config = {
headers: { Authorization: `Bearer ${jwt}` },
}

try {
const res = await axios.get(
`${BUCKETS_API}bucket/delete?bucket_uid=${bucketUid}`,
`${api}/v2/bucket/delete?bucket_uid=${bucketUid}`,
config,
)

Expand All @@ -49,14 +48,14 @@ const deleteBucket = async (jwt, bucketUid) => {
}
}

const renameBucket = async (jwt, bucketUid, newName) => {
const renameBucket = async (api, jwt, bucketUid, newName) => {
const config = {
headers: { Authorization: `Bearer ${jwt}` },
}

try {
const res = await axios.post(
`${BUCKETS_API}bucket/rename`,
`${api}/v2/bucket/rename`,
{
bucket_name: newName,
bucket_uid: bucketUid,
Expand Down
Loading

0 comments on commit f983e97

Please sign in to comment.