fix(web): build issues

This commit is contained in:
BennyKok
2023-12-21 00:48:27 +08:00
parent 7a60c357d8
commit a8adb59879
4 changed files with 28 additions and 28 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
'use server'
"use server";
import { replaceCDNUrl } from "@/server/resource";
import { replaceCDNUrl } from "./replaceCDNUrl";
export async function getFileDownloadUrl(file: string) {
return replaceCDNUrl(
+16
View File
@@ -0,0 +1,16 @@
export function replaceCDNUrl(url: string) {
// 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;
}
+1 -16
View File
@@ -1,3 +1,4 @@
import { replaceCDNUrl } from "./replaceCDNUrl";
import type { PutObjectCommandInput } from "@aws-sdk/client-s3";
import {
DeleteObjectCommand,
@@ -17,22 +18,6 @@ const s3Client = new S3({
forcePathStyle: true,
});
export function replaceCDNUrl(url: string) {
// 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;
}
export type ResourceObject = {
resourceBucket: string;
resourceId: string;