chore(web): add process.env.SPACES_CDN_FORCE_PATH_STYLE

This commit is contained in:
BennyKok 2023-12-29 16:02:42 +08:00
parent ba19364f72
commit d54ed35755
2 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,3 @@
export function replaceCDNUrl(url: string) { export function replaceCDNUrl(url: string) {
// When using R2, we don't want to include the bucket name in the URL // When using R2, we don't want to include the bucket name in the URL
if (process.env.SPACES_CDN_DONT_INCLUDE_BUCKET === "true") { if (process.env.SPACES_CDN_DONT_INCLUDE_BUCKET === "true") {
@ -6,6 +5,12 @@ export function replaceCDNUrl(url: string) {
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`, `${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`,
process.env.SPACES_ENDPOINT_CDN! process.env.SPACES_ENDPOINT_CDN!
); );
// When using digital ocean, we need to use the bucket name in the URL
} else if (process.env.SPACES_CDN_FORCE_PATH_STYLE === "false") {
url = url.replace(
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`,
`${process.env.SPACES_BUCKET}.${process.env.SPACES_ENDPOINT_CDN}}`
);
} else { } else {
url = url.replace( url = url.replace(
process.env.SPACES_ENDPOINT!, process.env.SPACES_ENDPOINT!,

View File

@ -15,7 +15,7 @@ const s3Client = new S3({
accessKeyId: process.env.SPACES_KEY!, accessKeyId: process.env.SPACES_KEY!,
secretAccessKey: process.env.SPACES_SECRET!, secretAccessKey: process.env.SPACES_SECRET!,
}, },
forcePathStyle: true, forcePathStyle: process.env.SPACES_CDN_FORCE_PATH_STYLE === "true",
}); });
export type ResourceObject = { export type ResourceObject = {