fix(web): build issues
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
Reference in New Issue
Block a user