Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/manifest/src/config/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default (): {
s3Region: string
s3AccessKeyId: string
s3SecretAccessKey: string
s3Provider: string
}
} => {
return {
Expand All @@ -13,7 +14,8 @@ export default (): {
s3Endpoint: process.env.S3_ENDPOINT,
s3Region: process.env.S3_REGION,
s3AccessKeyId: process.env.S3_ACCESS_KEY_ID,
s3SecretAccessKey: process.env.S3_SECRET_ACCESS_KEY
s3SecretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
s3Provider: process.env.S3_PROVIDER,
}
}
}
35 changes: 28 additions & 7 deletions packages/core/manifest/src/storage/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@ export class StorageService {
this.s3Region = this.configService.get('storage.s3Region')
this.s3AccessKeyId = this.configService.get('storage.s3AccessKeyId')
this.s3SecretAccessKey = this.configService.get('storage.s3SecretAccessKey')
this.s3provider = this.s3Endpoint?.includes('amazon')
? 'aws'
: this.s3Endpoint?.includes('digitalocean')
? 'digitalocean'
: 'other'
this.s3provider = this.configService.get('storage.s3Provider')
? this.configService.get('storage.s3Provider')
: this.s3Endpoint?.includes('amazon')
? 'aws'
: this.s3Endpoint?.includes('digitalocean')
? 'digitalocean'
: 'other'

if (this.isS3Enabled) {
let s3Endpoint = this.configService.get('storage.s3Endpoint')
if (this.s3provider === 'supabase') {
s3Endpoint = this.s3Endpoint + '/s3'
}
this.s3Client = new S3Client({
region: this.s3Region,
endpoint: this.s3Endpoint,
endpoint: s3Endpoint,
credentials: {
accessKeyId: this.s3AccessKeyId,
secretAccessKey: this.s3SecretAccessKey
},
forcePathStyle: false
forcePathStyle: this.s3provider === 'supabase'
})
}
}
Expand Down Expand Up @@ -193,6 +199,9 @@ export class StorageService {
* @returns The S3 file URL.
*/
private async uploadToS3(key: string, buffer: Buffer): Promise<string> {
if (this.s3provider === 'supabase') {
return this.uploadToSupabase(key, buffer)
}
await this.s3Client.send(
new PutObjectCommand({
Bucket: this.s3Bucket,
Expand All @@ -204,4 +213,16 @@ export class StorageService {
)
return `${this.s3Endpoint}/${this.s3Bucket}/${STORAGE_PATH}/${key}`
}

private async uploadToSupabase(key: string, buffer: Buffer): Promise<string> {
await this.s3Client.send(
new PutObjectCommand({
Bucket: this.s3Bucket,
Key: `${STORAGE_PATH}/${key}`,
Body: buffer,
})
)

return `${this.s3Endpoint}/object/public/${this.s3Bucket}/${STORAGE_PATH}/${key}`;
}
}