fix: cdn routes

This commit is contained in:
BennyKok 2023-12-17 02:02:39 +08:00
parent c511789056
commit ca272ce8f0

View File

@ -18,10 +18,18 @@ const s3Client = new S3({
});
export function replaceCDNUrl(url: string) {
url = url.replace(
process.env.SPACES_ENDPOINT!,
process.env.SPACES_ENDPOINT_CDN!
);
// When using R2, we don't want to include the bucket name in the URL
if (process.env.SPACES_CDN_DONT_INCLUDE_BUCKET === "true") {
url = url.replace(
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`,
process.env.SPACES_ENDPOINT_CDN!
);
} else {
url = url.replace(
process.env.SPACES_ENDPOINT!,
process.env.SPACES_ENDPOINT_CDN!
);
}
return url;
}