Skip to content

Commit

Permalink
Feat/com new (#186)
Browse files Browse the repository at this point in the history
* feat: Remove GetUserBuckets API Auth

* feat: Update BucketProps type

* feat: Remove listObjects api auth and update response type

* feat: Remove listGroup api auth

* feat: Update Types
  • Loading branch information
rrr523 authored Jul 25, 2023
1 parent 1b803da commit 42e323a
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-ladybugs-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-chain-sdk': patch
---

feat: Remove listObjects api auth and update response type
5 changes: 5 additions & 0 deletions .changeset/flat-plants-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-chain-sdk': patch
---

feat: Update BucketProps type
5 changes: 5 additions & 0 deletions .changeset/gold-ants-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-chain-sdk': patch
---

feat: Remove listGroup api auth
5 changes: 5 additions & 0 deletions .changeset/rare-chefs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-chain-sdk': patch
---

feat: Remove getUserBuckets auth
1 change: 0 additions & 1 deletion examples/nextjs/src/components/bucket/info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const BucketInfo = () => {
const res = await client.bucket.getUserBuckets({
address,
endpoint: spInfo.endpoint,
signType: 'authTypeV2',
});
console.log(res);
}}
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/src/components/group/delete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DeleteGroup = () => {

<input
value={deleteGroupInfo.bucketName}
placeholder="bucket name"
placeholder="group name"
onChange={(e) => {
setDeleteGroupInfo({ ...setDeleteGroupInfo, bucketName: e.target.value });
}}
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs/src/components/object/info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const ObjectInfo = () => {
const res = await client.object.listObjects({
bucketName,
endpoint: spInfo.endpoint,
signType: 'authTypeV2',
});
console.log('res', res);
}}
Expand Down
29 changes: 4 additions & 25 deletions packages/chain-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,39 +316,18 @@ export class Bucket implements IBucket {

public async getUserBuckets(configParam: TGetUserBuckets) {
try {
const { address, duration = 30000, endpoint, signType } = configParam;
const { address, duration = 30000, endpoint } = configParam;
if (!isValidAddress(address)) {
throw new Error('Error address');
}
if (!isValidUrl(endpoint)) {
throw new Error('Invalid endpoint');
}
const url = endpoint;
let headerContent: TKeyValue = {
const headerContent: TKeyValue = {
'X-Gnfd-User-Address': address,
};
if (!signType || signType === 'authTypeV2') {
const Authorization = getAuthorizationAuthTypeV2();
headerContent = {
...headerContent,
Authorization,
};
} else if (configParam.signType === 'offChainAuth') {
const { seedString } = configParam;
const { code, body, statusCode, message } = await this.offChainAuthClient.sign(seedString);
if (code !== 0) {
return {
code: -1,
message: message || 'Get create bucket approval error.',
statusCode: statusCode,
};
}
headerContent = {
...headerContent,
Authorization: body?.authorization as string,
'X-Gnfd-App-Domain': configParam.domain,
};
}

const headers = new Headers(headerContent);
const result = await fetchWithTimeout(
url,
Expand Down Expand Up @@ -526,7 +505,7 @@ export class Bucket implements IBucket {
const url = endpoint + '/greenfield/admin/v1/get-approval?action=MigrateBucket';
const msg = {
operator: params.operator,
bucket_name: 'asddas',
bucket_name: params.bucketName,
dst_primary_sp_id: spInfo.id,
dst_primary_sp_approval: {
expired_height: '0',
Expand Down
29 changes: 3 additions & 26 deletions packages/chain-sdk/src/api/objectt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
} from '..';
import {
ICreateObjectMsgType,
IObjectProps,
IObjectsProps,
IObjectResultType,
Long,
TCreateObject,
Expand Down Expand Up @@ -98,7 +98,7 @@ export interface IObject {

downloadFile(configParam: TGetObject): Promise<void>;

listObjects(configParam: TListObjects): Promise<IObjectResultType<Array<IObjectProps>>>;
listObjects(configParam: TListObjects): Promise<IObjectResultType<IObjectsProps>>;

createFolder(
getApprovalParams: Omit<TCreateObject, 'contentLength' | 'fileType' | 'expectCheckSums'>,
Expand Down Expand Up @@ -561,30 +561,7 @@ export class Objectt implements IObject {
throw new Error('Invalid endpoint');
}
const url = `${generateUrlByBucketName(endpoint, bucketName)}?${query?.toString()}`;
let headerContent: TKeyValue = {};
if (!configParam.signType || configParam.signType === 'authTypeV2') {
const Authorization = getAuthorizationAuthTypeV2();
headerContent = {
...headerContent,
Authorization,
};
} else if (configParam.signType === 'offChainAuth') {
const { seedString, address, domain } = configParam;
const { code, body, statusCode, message } = await this.offChainAuthClient.sign(seedString);
if (code !== 0) {
throw {
code: -1,
message: message || 'Get create bucket approval error.',
statusCode: statusCode,
};
}
headerContent = {
...headerContent,
Authorization: body?.authorization as string,
'X-Gnfd-User-Address': address,
'X-Gnfd-App-Domain': domain,
};
}
const headerContent: TKeyValue = {};
const headers = new Headers(headerContent);

const result = await fetchWithTimeout(
Expand Down
10 changes: 4 additions & 6 deletions packages/chain-sdk/src/api/sp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ export class Sp implements ISp {

let headerContent: Record<string, any> = {};
const sp = await this.getInServiceSP();
const Authorization = getAuthorizationAuthTypeV2();
headerContent = {
...headerContent,
Authorization,
};
const url = `${sp.endpoint}?group-query&name=${groupName}&prefix=${prefix}&source-type=${opts.sourceType}&limit=${opts.limit}&offset=${opts.offset}`;

Expand Down Expand Up @@ -152,10 +150,10 @@ type ListGroupsResult = {
groups: {
group: GroupInfo;
operator: string;
createAt: number;
createTime: number;
updateAt: number;
updateTime: number;
create_at: number;
create_time: number;
update_at: number;
update_time: number;
removed: boolean;
}[];
count: string;
Expand Down
102 changes: 45 additions & 57 deletions packages/chain-sdk/src/types/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,34 @@ export interface ICreateBucketMsgType {
charged_read_quota: string;
}

export type TBaseGetUserBuckets = {
export type TGetUserBuckets = {
address: string;
duration?: number;
endpoint: string;
};
export type TGetUserBucketByOffChainAuth = TBaseGetUserBuckets & {
signType: 'offChainAuth';
domain: string;
seedString: string;
};
export type TGetCreateBucketByAuthTypeV2 = TBaseGetUserBuckets & {
signType?: 'authTypeV2';
};
export type TGetUserBuckets = TGetUserBucketByOffChainAuth | TGetCreateBucketByAuthTypeV2;

export type BucketProps = {
bucket_info: {
owner: string;
bucket_name: string;
visibility: number;
id: string;
source_type: string;
bucket_status: number;
charged_read_quota: string;
create_at: string;
global_virtual_group_family_id: number;
id: string;
owner: string;
payment_address: string;
primary_sp_address: string;
charged_read_quota: string;
billing_info: {
price_time: string;
total_charge_size: string;
secondary_sp_objects_size: Array<string>;
};
bucket_status: number;
primary_sp_id: number;
source_type: string;
visibility: number;
};
removed: boolean;
create_tx_hash: string;
delete_at: string;
delete_reason: string;
operator: string;
create_tx_hash: string;
update_tx_hash: string;
removed: boolean;
update_at: string;
update_time: string;
update_tx_hash: string;
};

export type TBaseGetBucketReadQuota = {
Expand Down Expand Up @@ -226,59 +213,60 @@ export type TGetObjectByOffChainAuth = TBaseGetObject & {

export type TGetObject = TGetObjectByAuthTypeV2 | TGetObjectByOffChainAuth;

export type TBaseListObjects = {
export type TListObjects = {
bucketName: string;
duration?: number;
endpoint: string;
protocol?: string;
query?: URLSearchParams;
};

export type TListObjectsByAuthTypeV2 = TBaseListObjects & {
signType?: 'authTypeV2';
};

export type TListObjectsByOffChainAuth = TBaseListObjects & {
signType: 'offChainAuth';
domain: string;
seedString: string;
address: string;
};

export type TListObjects = TListObjectsByAuthTypeV2 | TListObjectsByOffChainAuth;

export type TDownloadFile = {
bucketName: string;
endpoint: string;
duration?: number;
year?: number;
month?: number;
};
export interface IObjectProps {

export interface IObjectResponse {
create_tx_hash: string;
delete_at: string;
delete_reason: string;
locked_balance: string;
operator: string;
removed: boolean;
seal_tx_hash: string;
update_at: string;
update_tx_hash: string;
object_info: {
owner: string;
bucket_name: string;
object_name: string;
id: string;
payload_size: string;
visibility: number;
checksums: Array<string>;
content_type: string;
create_at: string;
object_status: string;
creator: string;
id: string;
local_virtual_group_id: number;
object_name: string;
object_status: number;
owner: string;
payload_size: string;
redundancy_type: string;
source_type: string;
checksums: Array<string>;
secondary_sp_addresses: Array<string>;
visibility: number;
};
locked_balance: string;
removed: boolean;
update_at: string;
delete_at: string;
delete_reason: string;
operator: string;
create_tx_hash: string;
update_tx_hash: string;
seal_tx_hash: string;
}
export interface IObjectsProps {
common_prefixes: Array<string>;
continuation_token: string;
delimiter: string;
is_truncated: boolean;
key_count: string;
max_keys: string;
name: string;
next_continuation_token: string;
objects: IObjectResponse[];
prefix: string;
}

export interface IGetObjectStaus {
Expand Down

0 comments on commit 42e323a

Please sign in to comment.