From f843924b56c706ec65ccd6524730369842d21e5f Mon Sep 17 00:00:00 2001 From: 0fatal <72899968+0fatal@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:22:56 +0800 Subject: [PATCH] refactor(cloud-sdk): get bucket by bucket name, not by short name (#1933) * refactor(cloud-sdk): get bucket by bucket name, not by short name --- packages/cloud-sdk/src/storage.ts | 13 ++++++++----- packages/cloud-sdk/src/util.ts | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 packages/cloud-sdk/src/util.ts diff --git a/packages/cloud-sdk/src/storage.ts b/packages/cloud-sdk/src/storage.ts index 3c2e3374d6..5cf1bfb618 100644 --- a/packages/cloud-sdk/src/storage.ts +++ b/packages/cloud-sdk/src/storage.ts @@ -15,6 +15,7 @@ import { ListObjectsCommandOutput, } from '@aws-sdk/client-s3' import { getSignedUrl } from '@aws-sdk/s3-request-presigner' +import { IS_SEALAF } from './util' export type NodeJsRuntimeStreamingBlobPayloadOutputTypes = SdkStream< Readable | IncomingMessage @@ -163,13 +164,15 @@ export class CloudStorage { } /** - * Get bucket by short name - * @param bucketShortName it is the short name of the bucket, e.g. `images`, NOT `{appid}-images`. + * Get bucket by bucket name * @returns */ - bucket(bucketShortName: string): CloudStorageBucket { - assert(bucketShortName, 'bucketShortName is required') - const name = `${this.appid}-${bucketShortName}` + bucket(bucketName: string): CloudStorageBucket { + assert(bucketName, 'bucketName is required') + if (IS_SEALAF || bucketName.startsWith(`${this.appid}-`)) { + return new CloudStorageBucket(this, bucketName) + } + const name = `${this.appid}-${bucketName}` return new CloudStorageBucket(this, name) } } diff --git a/packages/cloud-sdk/src/util.ts b/packages/cloud-sdk/src/util.ts new file mode 100644 index 0000000000..dd1b722c4a --- /dev/null +++ b/packages/cloud-sdk/src/util.ts @@ -0,0 +1 @@ +export const IS_SEALAF = process.env.IS_SEALAF === 'true'