Skip to content

Commit

Permalink
Feat/up and down (#248)
Browse files Browse the repository at this point in the history
* feat: Upload Object add AuthType

* feat: Download s3 object

* feat: Migrate Bucket add authType

* feat: SpClient expose makeHeaders method

* chore: Update constant pathj
  • Loading branch information
rrr523 authored Aug 23, 2023
1 parent c1ef739 commit a3e2210
Show file tree
Hide file tree
Showing 20 changed files with 336 additions and 436 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-lies-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Upload Object add AuthType
5 changes: 5 additions & 0 deletions .changeset/cuddly-radios-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: download s3 object
5 changes: 5 additions & 0 deletions .changeset/fair-impalas-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Migrate bucket
5 changes: 5 additions & 0 deletions .changeset/unlucky-suns-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Export SpClient
27 changes: 19 additions & 8 deletions examples/nextjs/src/components/bucket/migrate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { client, selectSp } from '@/client';
import { getOffchainAuthKeys } from '@/utils/offchainAuth';
import { useState } from 'react';
import { useAccount } from 'wagmi';

export const MigrateBucket = () => {
const { address } = useAccount();
const { address, connector } = useAccount();
const [bucketName, setBucketName] = useState('');

return (
Expand All @@ -23,17 +24,27 @@ export const MigrateBucket = () => {
onClick={async () => {
if (!address) return;

const spInfo = await selectSp();
const destinationSpInfo = await selectSp();
const provider = await connector?.getProvider();
const offChainData = await getOffchainAuthKeys(address, provider);
if (!offChainData) {
alert('No offchain, please create offchain pairs first');
return;
}

const migrateBucketTx = await client.bucket.migrateBucket({
params: {
const migrateBucketTx = await client.bucket.migrateBucket(
{
bucketName,
operator: address,
dstPrimarySpId: spInfo.id,
dstPrimarySpId: destinationSpInfo.id,
},
spInfo,
signType: 'authTypeV2',
});
{
type: 'EDDSA',
address,
domain: window.location.origin,
seed: offChainData.seedString,
},
);

const simulateInfo = await migrateBucketTx.simulate({
denom: 'BNB',
Expand Down
24 changes: 14 additions & 10 deletions examples/nextjs/src/components/object/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,20 @@ export const CreateObject = () => {
return;
}

const uploadRes = await client.object.uploadObject({
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
body: file,
txnHash: txHash,
signType: 'offChainAuth',
domain: window.location.origin,
seedString: offChainData.seedString,
address,
});
const uploadRes = await client.object.uploadObject(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
body: file,
txnHash: txHash,
},
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
);
console.log('uploadRes', uploadRes);

if (uploadRes.code === 0) {
Expand Down
38 changes: 36 additions & 2 deletions examples/nextjs/src/components/object/info/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { client, selectSp } from '@/client';
import { getOffchainAuthKeys } from '@/utils/offchainAuth';
import { useState } from 'react';
import { useAccount } from 'wagmi';

export const ObjectInfo = () => {
const { address, connector } = useAccount();
const [bucketName, setBucketName] = useState('');
const [objectName, setObjectName] = useState('');

Expand All @@ -23,13 +26,44 @@ export const ObjectInfo = () => {
console.log(objInfo);
}}
>
get obj info
get object info (headObject)
</button>

<br />

<button
onClick={async () => {
if (!address) return;
const provider = await connector?.getProvider();
const offChainData = await getOffchainAuthKeys(address, provider);
if (!offChainData) {
alert('No offchain, please create offchain pairs first');
return;
}

const res = await client.object.downloadFile(
{
bucketName,
objectName,
},
{
type: 'EDDSA',
address,
domain: window.location.origin,
seed: offChainData.seedString,
},
);

console.log(res);
}}
>
download object info
</button>

<br />

<div>
get object by bucket name
get objects list by bucket name
<br />
<button
onClick={async () => {
Expand Down
Loading

0 comments on commit a3e2210

Please sign in to comment.