Skip to content

Commit

Permalink
Support Source Map (#487)
Browse files Browse the repository at this point in the history
* feat: Verify Address

* feat: Support Source Map
  • Loading branch information
rrr523 authored Feb 20, 2024
1 parent 523f1a5 commit 389119e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-sloths-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Support source map
5 changes: 5 additions & 0 deletions .changeset/eight-comics-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Verify Address
2 changes: 2 additions & 0 deletions packages/js-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async () => {
output: {
dir: './dist/esm',
format: 'esm',
sourcemap: true,
},
external: resolveExternal(),
context: 'window',
Expand Down Expand Up @@ -55,6 +56,7 @@ export default async () => {
output: {
dir: './dist/cjs',
format: 'cjs',
sourcemap: true,
},
external: resolveExternal(),
plugins: [
Expand Down
15 changes: 5 additions & 10 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import type {
ReadQuotaRequest,
SpResponse,
} from '../types/sp';
import { isValidAddress, verifyBucketName, verifyUrl } from '../utils/asserts/s3';
import { verifyAddress, verifyBucketName, verifyUrl } from '../utils/asserts/s3';
import { decodeObjectFromHexString } from '../utils/encoding';
import { Sp } from './sp';
import { Storage } from './storage';
Expand Down Expand Up @@ -359,12 +359,9 @@ export class Bucket implements IBucket {
public async listBuckets(configParam: GetUserBucketsRequest) {
try {
const { address, duration = 30000, endpoint } = configParam;
if (!isValidAddress(address)) {
throw new Error('Error address');
}
if (!verifyUrl(endpoint)) {
throw new Error('Invalid endpoint');
}
verifyAddress(address);
verifyUrl(endpoint);

const { url } = getUserBucketMetaInfo(endpoint);

const headers = new Headers({
Expand Down Expand Up @@ -654,9 +651,7 @@ export class Bucket implements IBucket {
if (!endpoint) {
endpoint = await this.sp.getSPUrlByBucket(bucketName);
}
if (!verifyUrl(endpoint)) {
throw new Error('Invalid endpoint');
}
verifyUrl(endpoint);

const { url, optionsWithOutHeaders, reqMeta } = getListBucketReadRecordMetaInfo(
endpoint,
Expand Down
17 changes: 6 additions & 11 deletions packages/js-sdk/src/utils/asserts/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ const verifyObjectName = (objectName?: string) => {
}
};

const isValidAddress = (address?: string) => {
if (!address) {
throw new Error('Address is empty, please check.');
}
if (address.length > 1024) {
throw new Error('Address is limited to 1024 at most, please check.');
}
return true;
const verifyAddress = (address?: string) => {
if (!address) throw new Error('Address is empty, please check.');
if (address.length > 1024) throw new Error('Address is limited to 1024 at most, please check.');
};

const verifyUrl = (url?: string) => {
Expand All @@ -93,9 +88,9 @@ const verifyUrl = (url?: string) => {
'(\\:\\d{1,5})?' + // 端口号
'(\\/[-a-zA-Z\\d%_.~+]*)*' + // 路径
'(\\?[;&a-zA-Z\\d%_.~+=-]*)?' + // 查询字符串
'(\\#[-a-zA-Z\\d_]*)?$',
'(\\#[-a-zA-Z\\d_]*)?$', // 锚点
'i',
); // 锚点
);

if (!pattern.test(url)) throw new Error('Invalid endpoint');
};
Expand All @@ -122,7 +117,7 @@ const generateUrlByBucketName = (endpoint = '', bucketName: string) => {
export {
verifyBucketName,
verifyObjectName,
isValidAddress,
verifyAddress,
trimString,
verifyUrl,
generateUrlByBucketName,
Expand Down

0 comments on commit 389119e

Please sign in to comment.