fix(medusa-interfaces, medusa-file-*): flag for streaming to a private bucket (#4771)
* wip: unify file service api * fix: flag type * fix: update Spaces service * fix: S3/Spaces - default to private * fix: MinIO `isPrivate` for `getPresignedDownloadUrl`, add `isPrivate` to `GetUploadedFileType` * chore: changeset
This commit is contained in:
1 parent
80d603a63d
commit
edf9ed4e59
5 files changed
+29
-14
No files matched your search
@@ -120,11 +120,10 @@ class MinioService extends AbstractFileService implements IFileService {
|
||||
|
||||
async getUploadStreamDescriptor(
|
||||
fileData: UploadStreamDescriptorType & {
|
||||
usePrivateBucket?: boolean
|
||||
contentType?: string
|
||||
}
|
||||
) {
|
||||
const usePrivateBucket = fileData.usePrivateBucket ?? true
|
||||
const usePrivateBucket = fileData.isPrivate ?? true
|
||||
|
||||
this.validatePrivateBucketConfiguration_(usePrivateBucket)
|
||||
|
||||
@@ -149,10 +148,8 @@ class MinioService extends AbstractFileService implements IFileService {
|
||||
}
|
||||
}
|
||||
|
||||
async getDownloadStream(
|
||||
fileData: GetUploadedFileType & { usePrivateBucket?: boolean }
|
||||
) {
|
||||
const usePrivateBucket = !!fileData.usePrivateBucket
|
||||
async getDownloadStream(fileData: GetUploadedFileType) {
|
||||
const usePrivateBucket = fileData.isPrivate ?? true
|
||||
this.validatePrivateBucketConfiguration_(usePrivateBucket)
|
||||
const client = this.getClient(usePrivateBucket)
|
||||
|
||||
@@ -164,14 +161,17 @@ class MinioService extends AbstractFileService implements IFileService {
|
||||
return client.getObject(params).createReadStream()
|
||||
}
|
||||
|
||||
async getPresignedDownloadUrl({ usePrivateBucket = true, ...fileData }) {
|
||||
this.validatePrivateBucketConfiguration_(usePrivateBucket)
|
||||
const client = this.getClient(usePrivateBucket, {
|
||||
async getPresignedDownloadUrl({
|
||||
isPrivate = true,
|
||||
...fileData
|
||||
}: GetUploadedFileType) {
|
||||
this.validatePrivateBucketConfiguration_(isPrivate)
|
||||
const client = this.getClient(isPrivate, {
|
||||
signatureVersion: "v4",
|
||||
})
|
||||
|
||||
const params = {
|
||||
Bucket: usePrivateBucket ? this.private_bucket_ : this.bucket_,
|
||||
Bucket: isPrivate ? this.private_bucket_ : this.bucket_,
|
||||
Key: `${fileData.fileKey}`,
|
||||
Expires: this.downloadUrlDuration,
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class MinioService extends AbstractFileService implements IFileService {
|
||||
return await client.getSignedUrlPromise("getObject", params)
|
||||
}
|
||||
|
||||
validatePrivateBucketConfiguration_(usePrivateBucket) {
|
||||
validatePrivateBucketConfiguration_(usePrivateBucket: boolean) {
|
||||
if (
|
||||
usePrivateBucket &&
|
||||
(!this.private_access_key_id_ || !this.private_bucket_)
|
||||
|
||||
Reference in new issue
Block a user