Skip to content

Commit be4c323

Browse files
committed
Merge branch 'kats/s3'
2 parents 5b0cd71 + 4df3a39 commit be4c323

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/models/config/s3-storage-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ export type S3StorageConfig = {
1111
region: string,
1212
bucket: string,
1313
endpoint?: string,
14+
fastlyBackendName?: string,
1415
};
1516

1617
export function getS3StorageConfigFromRc(rc: StaticPublishS3Storage): S3StorageConfig {
1718
return {
1819
region: rc.s3.region,
1920
bucket: rc.s3.bucket,
2021
endpoint: rc.s3.endpoint,
22+
fastlyBackendName: rc.s3.fastlyBackendName,
2123
};
2224
}

src/models/config/static-publish-rc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export type StaticPublishPartialS3Storage = {
7171
region: string,
7272
bucket: string,
7373
endpoint?: string,
74+
fastlyBackendName?: string,
7475
},
7576
};
7677

@@ -90,6 +91,10 @@ export function isS3StorageConfigRc(rc: unknown): rc is StaticPublishS3Storage {
9091
!('endpoint' in rc.s3) ||
9192
rc.s3.endpoint === undefined ||
9293
typeof rc.s3.endpoint === 'string'
94+
) && (
95+
!('fastlyBackendName' in rc.s3) ||
96+
rc.s3.fastlyBackendName === undefined ||
97+
typeof rc.s3.fastlyBackendName === 'string'
9398
)
9499
) {
95100
return true;

src/server/storage/s3-storage-provider.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export const buildStoreProvider: StorageProviderBuilder = (config: StaticPublish
4343
return new S3StorageProvider(
4444
s3StorageConfig.region,
4545
s3StorageConfig.bucket,
46-
s3StorageConfig.endpoint,
46+
{
47+
s3Endpoint: s3StorageConfig.endpoint,
48+
s3FastlyBackendName: s3StorageConfig.fastlyBackendName,
49+
},
4750
);
4851
};
4952

@@ -93,27 +96,35 @@ export function setAwsCredentialsBuilder(awsCredentialsBuilder: AwsCredentialsBu
9396
_awsCredentialsBuilder = awsCredentialsBuilder;
9497
}
9598

99+
export type S3StorageProviderParams = {
100+
s3Endpoint?: string,
101+
s3FastlyBackendName?: string,
102+
};
103+
96104
export class S3StorageProvider implements StorageProvider {
97105
constructor(
98106
s3Region: string,
99107
s3Bucket: string,
100-
s3Endpoint?: string,
108+
params?: S3StorageProviderParams,
101109
) {
102110
this.s3Region = s3Region;
103111
this.s3Bucket = s3Bucket;
104-
this.s3Endpoint = s3Endpoint;
112+
this.s3Endpoint = params?.s3Endpoint;
113+
this.s3FastlyBackendName = params?.s3FastlyBackendName;
105114
}
106115

107116
private readonly s3Region: string;
108117
private readonly s3Bucket: string;
109118
private readonly s3Endpoint?: string;
119+
private readonly s3FastlyBackendName?: string;
110120

111121
private s3Client?: S3Client;
112122
async getS3Client() {
113123
if (this.s3Client != null) {
114124
return this.s3Client;
115125
}
116126
const awsCredentials = await _awsCredentialsBuilder();
127+
const s3FastlyBackendName = this.s3FastlyBackendName ?? "aws";
117128
this.s3Client = new S3Client({
118129
region: this.s3Region,
119130
endpoint: this.s3Endpoint,
@@ -124,7 +135,7 @@ export class S3StorageProvider implements StorageProvider {
124135
},
125136
maxAttempts: 1,
126137
requestHandler: new FetchHttpHandler({
127-
requestInit() { return { backend: "aws" } }
138+
requestInit() { return { backend: s3FastlyBackendName } }
128139
}),
129140
});
130141
return this.s3Client;

0 commit comments

Comments
 (0)