Skip to content

Commit

Permalink
refactor(cloud-sdk): get bucket by bucket name, not by short name (#1933
Browse files Browse the repository at this point in the history
)

* refactor(cloud-sdk): get bucket by bucket name, not by short name
  • Loading branch information
0fatal authored Apr 1, 2024
1 parent c39772b commit f843924
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/cloud-sdk/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cloud-sdk/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const IS_SEALAF = process.env.IS_SEALAF === 'true'

0 comments on commit f843924

Please sign in to comment.