1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 22:39:36 +02:00

CDN Route

This commit is contained in:
Sean Morley 2024-06-14 11:43:41 +00:00
parent 7894e8c192
commit 272ea60057
3 changed files with 15 additions and 44 deletions

View file

@ -124,45 +124,3 @@ export async function getImage(adventureTitle: string) {
return `Error fetching Wikipedia data for "${adventureTitle}".`;
}
}
/**
* Returns the URL of an object in the specified bucket.
* @param bucketName - The name of the bucket.
* @param fileName - The name of the file.
* @returns The URL of the object.
*/
export const getObjectUrl = (bucketName: string, fileName: string): string => {
let objectUrl: string;
let endpoint: string = "";
if (import.meta.env.VITE_MINIO_CLIENT_OVERRIDE) {
endpoint = import.meta.env.VITE_MINIO_CLIENT_OVERRIDE as string;
} else {
endpoint = import.meta.env.VITE_AWS_S3_ENDPOINT as string;
}
// This code is not as clean as it could be, but it works for whats needed. Help is welcome to clean it up!
// Currently supports Amazon S3, Google Cloud Storage, DigitalOcean Spaces, and Supabase Storage as well as self-hosted MinIO.
if (endpoint.includes("amazonaws.com")) {
// Amazon S3
objectUrl = `https://${bucketName}.s3.${
import.meta.env.AWS_REGION
}.amazonaws.com/${fileName}`;
} else if (endpoint.includes("storage.googleapis.com")) {
// Google Cloud Storage
objectUrl = `https://storage.googleapis.com/${bucketName}/${fileName}`;
} else if (endpoint.includes("digitaloceanspaces.com")) {
// DigitalOcean Spaces
objectUrl = `https://${bucketName}.${endpoint}/${fileName}`;
} else if (endpoint.includes("supabase.co")) {
// Supabase Storage
endpoint = endpoint.replace("s3", "object/public"); // Remove the version
console.log(endpoint);
objectUrl = `${endpoint}/${bucketName}/${fileName}`;
} else {
// Default fallback
objectUrl = `${endpoint}/${bucketName}/${fileName}`;
}
return objectUrl as string;
};