Skip to content

Commit

Permalink
feat: Add visibility params
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Mar 19, 2024
1 parent d99981c commit 8d91b2a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/nextjs/src/components/object/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const CreateObject = () => {
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
body: file,
visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
},
{
type: 'EDDSA',
Expand Down
10 changes: 9 additions & 1 deletion packages/js-sdk/src/api/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,14 @@ export class Objects implements IObject {
}

public async delegateUploadObject(params: DelegatedPubObjectRequest, authType: AuthType) {
const { bucketName, objectName, body, contentType = body.type, timeout = 5000 } = params;
const {
bucketName,
objectName,
body,
contentType = body.type,
timeout = 5000,
visibility,
} = params;
verifyBucketName(bucketName);
verifyObjectName(objectName);
assertAuthType(authType);
Expand All @@ -226,6 +233,7 @@ export class Objects implements IObject {
objectName,
contentType,
body,
visibility,
delegated: true,
});
const signHeaders = await this.spClient.signHeaders(reqMeta, authType);
Expand Down
15 changes: 12 additions & 3 deletions packages/js-sdk/src/clients/spclient/spApis/putObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EMPTY_STRING_SHA256, METHOD_PUT } from '@/constants';
import { ReqMeta } from '@/types';
import { ReqMeta, VisibilityType } from '@/types';
import { generateUrlByBucketName } from '@/utils/asserts/s3';
import { encodePath, getSortQueryParams } from '../auth';

Expand All @@ -13,9 +13,18 @@ export const getPutObjectMetaInfo = async (
body: File;
delegated?: boolean;
txnHash?: string;
visibility?: VisibilityType;
},
) => {
const { bucketName, objectName, txnHash, contentType, body, delegated = false } = params;
const {
bucketName,
objectName,
txnHash,
contentType,
body,
delegated = false,
visibility = VisibilityType.VISIBILITY_TYPE_PRIVATE,
} = params;
const path = `/${encodePath(objectName)}`;
let queryMap = {};

Expand All @@ -24,7 +33,7 @@ export const getPutObjectMetaInfo = async (
delegate: '',
is_update: 'false',
payload_size: String(body.size),
visibility: '0',
visibility: visibility,
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/js-sdk/src/types/sp/PutObject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VisibilityType } from '../common';

export type PutObjectRequest = {
bucketName: string;
objectName: string;
Expand All @@ -12,6 +14,7 @@ export type DelegatedPubObjectRequest = {
bucketName: string;
objectName: string;
body: File;
visibility?: VisibilityType;
endpoint?: string;
timeout?: number;
contentType?: string;
Expand Down

0 comments on commit 8d91b2a

Please sign in to comment.